uschindler commented on code in PR #12363:
URL: https://github.com/apache/lucene/pull/12363#discussion_r1227232392


##########
lucene/core/src/java21/org/apache/lucene/util/VectorUtilPanamaProvider.java:
##########
@@ -0,0 +1,493 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Logger;
+import jdk.incubator.vector.ByteVector;
+import jdk.incubator.vector.FloatVector;
+import jdk.incubator.vector.IntVector;
+import jdk.incubator.vector.ShortVector;
+import jdk.incubator.vector.Vector;
+import jdk.incubator.vector.VectorOperators;
+import jdk.incubator.vector.VectorShape;
+import jdk.incubator.vector.VectorSpecies;
+
+/** A VectorUtil provider implementation that leverages the Panama Vector API. 
*/
+final class VectorUtilPanamaProvider implements VectorUtilProvider {
+
+  private static final int INT_SPECIES_PREF_BIT_SIZE = 
IntVector.SPECIES_PREFERRED.vectorBitSize();
+
+  private static final VectorSpecies<Float> PREF_FLOAT_SPECIES = 
FloatVector.SPECIES_PREFERRED;
+  private static final VectorSpecies<Byte> PREF_BYTE_SPECIES;
+  private static final VectorSpecies<Short> PREF_SHORT_SPECIES;
+
+  /**
+   * x86 and less than 256-bit vectors.
+   *
+   * <p>it could be that it has only AVX1 and integer vectors are fast. it 
could also be that it has
+   * no AVX and integer vectors are extremely slow. don't use integer vectors 
to avoid landmines.
+   */
+  private static final boolean IS_AMD64_WITHOUT_AVX2 =
+      Constants.OS_ARCH.equals("amd64") && INT_SPECIES_PREF_BIT_SIZE < 256;
+
+  static {
+    if (INT_SPECIES_PREF_BIT_SIZE >= 256) {
+      PREF_BYTE_SPECIES =
+          ByteVector.SPECIES_MAX.withShape(
+              
VectorShape.forBitSize(IntVector.SPECIES_PREFERRED.vectorBitSize() >> 2));
+      PREF_SHORT_SPECIES =
+          ShortVector.SPECIES_MAX.withShape(
+              
VectorShape.forBitSize(IntVector.SPECIES_PREFERRED.vectorBitSize() >> 1));
+    } else {
+      PREF_BYTE_SPECIES = null;
+      PREF_SHORT_SPECIES = null;
+    }
+  }
+
+  // Extracted to a method to be able to apply the SuppressForbidden annotation
+  @SuppressWarnings("removal")
+  @SuppressForbidden(reason = "security manager")
+  private static <T> T doPrivileged(PrivilegedAction<T> action) {
+    return AccessController.doPrivileged(action);
+  }
+
+  VectorUtilPanamaProvider() {
+    if (INT_SPECIES_PREF_BIT_SIZE < 128) {
+      throw new UnsupportedOperationException(
+          "Vector bit size is less than 128: " + INT_SPECIES_PREF_BIT_SIZE);
+    }
+
+    // hack to work around for JDK-8309727:

Review Comment:
   If we remove, the doPrivileged forbidden wrapper can go away, too.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to