Skip to content

Commit 62c8a7e

Browse files
committed
Preserve first-record scanner short circuit
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 01071e57-12fd-4f42-bc67-e2b274d0b007
1 parent ef9e31b commit 62c8a7e

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/x86_simd.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,9 +1453,17 @@ unsafe fn array_first_avx512<const WIDTH: usize>(
14531453
single: unsafe fn(*const u8, *const u8) -> u64,
14541454
) -> Option<usize> {
14551455
let count = big_array.len() / WIDTH;
1456-
let mut index = 0;
14571456
let big_ptr = big_array.as_ptr();
14581457
let query_ptr = small_array.as_ptr();
1458+
if count == 0 {
1459+
return None;
1460+
}
1461+
1462+
let first_distance = single(big_ptr, query_ptr);
1463+
if within_fixed_threshold(first_distance, max_dist) {
1464+
return Some(0);
1465+
}
1466+
let mut index = 1;
14591467

14601468
while index + 4 <= count {
14611469
let distances = batch4(big_ptr.add(index * WIDTH), query_ptr);
@@ -1491,10 +1499,18 @@ unsafe fn array_best_avx512<const WIDTH: usize>(
14911499
single: unsafe fn(*const u8, *const u8) -> u64,
14921500
) -> Option<(u64, usize)> {
14931501
let count = big_array.len() / WIDTH;
1494-
let mut best: Option<(u64, usize)> = None;
1495-
let mut index = 0;
14961502
let big_ptr = big_array.as_ptr();
14971503
let query_ptr = small_array.as_ptr();
1504+
if count == 0 {
1505+
return None;
1506+
}
1507+
1508+
let first_distance = single(big_ptr, query_ptr);
1509+
let mut best = within_fixed_threshold(first_distance, max_dist).then_some((first_distance, 0));
1510+
if first_distance == 0 {
1511+
return best;
1512+
}
1513+
let mut index = 1;
14981514

14991515
while index + 4 <= count {
15001516
let distances = batch4(big_ptr.add(index * WIDTH), query_ptr);

0 commit comments

Comments
 (0)