Skip to content

Commit

Permalink
Only check LongVector.SPECIES_PREFERRED when jdk.incubator.vector is …
Browse files Browse the repository at this point in the history
…enabled (opensearch-project#11939)

Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta authored Jan 18, 2024
1 parent 6ccb46b commit 774e7d4
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import org.opensearch.common.annotation.InternalApi;

import jdk.incubator.vector.LongVector;

/**
* Factory class to create and return the fastest implementation of {@link Roundable}.
*
Expand All @@ -34,10 +32,30 @@ public final class RoundableFactory {
*/
private static final boolean USE_BTREE_SEARCHER;

/**
* This class is initialized only when:
* - JDK-20+
* - jdk.incubator.vector.LongVector is available (--add-modules=jdk.incubator.vector is passed)
*/
private static final class VectorCheck {
final static int SPECIES_PREFERRED = jdk.incubator.vector.LongVector.SPECIES_PREFERRED.length();
}

static {
String simdRoundingFeatureFlag = System.getProperty("opensearch.experimental.feature.simd.rounding.enabled");
USE_BTREE_SEARCHER = "forced".equalsIgnoreCase(simdRoundingFeatureFlag)
|| (LongVector.SPECIES_PREFERRED.length() >= 4 && "true".equalsIgnoreCase(simdRoundingFeatureFlag));
boolean useBtreeSearcher = false;

try {
final Class<?> incubator = Class.forName("jdk.incubator.vector.LongVector");

useBtreeSearcher = "forced".equalsIgnoreCase(simdRoundingFeatureFlag)
|| (VectorCheck.SPECIES_PREFERRED >= 4 && "true".equalsIgnoreCase(simdRoundingFeatureFlag));

} catch (final ClassNotFoundException ex) {
/* do not use BtreeSearcher */
}

USE_BTREE_SEARCHER = useBtreeSearcher;
}

private RoundableFactory() {}
Expand Down

0 comments on commit 774e7d4

Please sign in to comment.