Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only check LongVector.SPECIES_PREFERRED when jdk.incubator.vector is enabled #11939

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading