Skip to content

Commit

Permalink
Only enable this optimization for 4+ lanes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpountz committed Oct 27, 2024
1 parent 338a3bb commit 614b807
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,10 @@ private static int squareDistanceBody128(MemorySegment a, MemorySegment b, int l

@Override
public int findFirstGreater(long[] buffer, int length, long target, int from) {
if (from + LONG_SPECIES.length() <= length) {
if (LONG_SPECIES.length() >= 4 && from + LONG_SPECIES.length() <= length) {
// This optimization only works well when the target is likely found in the next
// `LONG_SPECIES.length()` doc IDs. This is true for `LONG_SPECIES.length()` >= 4, but not for
// lower values, so we disable the optimization if we don't have enough long lanes.
LongVector vector = LongVector.fromArray(LONG_SPECIES, buffer, from);
VectorMask<Long> mask = vector.compare(VectorOperators.LT, target);
int trueCount = mask.trueCount();
Expand Down

0 comments on commit 614b807

Please sign in to comment.