rmuir commented on code in PR #16691:
URL: https://github.com/apache/lucene/pull/16691#discussion_r4058599157


##########
lucene/core/src/java25/org/apache/lucene/internal/vectorization/PanamaDocValuesBulkDecodeSupport.java:
##########
@@ -16,41 +16,164 @@
  */
 package org.apache.lucene.internal.vectorization;
 
+import static jdk.incubator.vector.VectorOperators.ZERO_EXTEND_B2L;
+import static jdk.incubator.vector.VectorOperators.ZERO_EXTEND_I2L;
+import static jdk.incubator.vector.VectorOperators.ZERO_EXTEND_S2L;
+
 import java.nio.ByteOrder;
 import jdk.incubator.vector.ByteVector;
+import jdk.incubator.vector.IntVector;
+import jdk.incubator.vector.LongVector;
+import jdk.incubator.vector.ShortVector;
 import jdk.incubator.vector.VectorSpecies;
 
 /** Panama Vector API implementation of {@link DocValuesBulkDecodeSupport}. */
 final class PanamaDocValuesBulkDecodeSupport implements 
DocValuesBulkDecodeSupport {
 
   static final PanamaDocValuesBulkDecodeSupport INSTANCE = new 
PanamaDocValuesBulkDecodeSupport();
 
+  private static final VectorSpecies<Long> LONG_SPECIES = 
LongVector.SPECIES_PREFERRED;
   private static final VectorSpecies<Byte> BYTE_SPECIES = 
ByteVector.SPECIES_PREFERRED;
 
   private PanamaDocValuesBulkDecodeSupport() {}
 
   @Override
   public void decodeByteAligned(
       byte[] bytes, int bytesOffset, int bitsPerValue, long[] values, int 
valuesOffset, int count) {
-    if (bitsPerValue != Long.SIZE
-        || ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN
-        || BYTE_SPECIES.vectorByteSize() < 32) {
+
+    if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN || 
BYTE_SPECIES.vectorByteSize() < 32) {
       DefaultDocValuesBulkDecodeSupport.INSTANCE.decodeByteAligned(
           bytes, bytesOffset, bitsPerValue, values, valuesOffset, count);
       return;
     }
 
+    switch (bitsPerValue) {
+      case Byte.SIZE -> decode8(bytes, bytesOffset, values, valuesOffset, 
count);
+      case Short.SIZE -> decode16(bytes, bytesOffset, values, valuesOffset, 
count);
+      case Integer.SIZE -> decode32(bytes, bytesOffset, values, valuesOffset, 
count);
+      case Long.SIZE -> decode64(bytes, bytesOffset, values, valuesOffset, 
count);
+      default ->
+          DefaultDocValuesBulkDecodeSupport.INSTANCE.decodeByteAligned(
+              bytes, bytesOffset, bitsPerValue, values, valuesOffset, count);
+    }
+  }
+
+  private static void decode8(
+      byte[] bytes, int bytesOffset, long[] values, int valuesOffset, int 
count) {
+    final VectorSpecies<Long> L_SPECIES = LongVector.SPECIES_256;
+    final VectorSpecies<Byte> B_SPECIES = ByteVector.SPECIES_128;
+    final int L = L_SPECIES.length();
+    final int byteLen = B_SPECIES.length();
+
+    int i = 0;
+    final int loopBound = count - (count % byteLen);
+
+    if (loopBound > 0) {
+      for (; i < loopBound; i += byteLen) {
+        ByteVector bv = ByteVector.fromArray(B_SPECIES, bytes, bytesOffset + 
i);
+
+        LongVector lv0 = (LongVector) bv.convertShape(ZERO_EXTEND_B2L, 
L_SPECIES, 0);
+        LongVector lv1 = (LongVector) bv.convertShape(ZERO_EXTEND_B2L, 
L_SPECIES, 1);
+        LongVector lv2 = (LongVector) bv.convertShape(ZERO_EXTEND_B2L, 
L_SPECIES, 2);
+        LongVector lv3 = (LongVector) bv.convertShape(ZERO_EXTEND_B2L, 
L_SPECIES, 3);

Review Comment:
   Don't unroll integer-based math, let the compiler do it. This kind of thing 
is only needed with floating point.



-- 
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