slow-J commented on code in PR #16631:
URL: https://github.com/apache/lucene/pull/16631#discussion_r3968307579
##########
lucene/core/src/java25/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java:
##########
@@ -584,6 +588,24 @@ private static int int4DotProductBody(ByteVectorLoader a,
ByteVectorLoader b, in
return sum;
}
+ @Override
+ public void int4Unpack(byte[] packed, byte[] unpacked) {
+ final int len = packed.length;
+ final int bound = BYTE_SPECIES_FULL.loopBound(len);
+ int i = 0;
+ for (; i < bound; i += BYTE_SPECIES_FULL.length()) {
+ ByteVector v = ByteVector.fromArray(BYTE_SPECIES_FULL, packed, i);
+ // LSHR is a logical shift within the byte lane, so the high nibble
needs no mask.
+ v.lanewise(LSHR, 4).intoArray(unpacked, i);
+ v.lanewise(VectorOperators.AND, (byte) 0x0F).intoArray(unpacked, len +
i);
+ }
+ // scalar tail
+ for (; i < len; i++) {
+ unpacked[i] = (byte) ((packed[i] >> 4) & 0x0F);
+ unpacked[len + i] = (byte) (packed[i] & 0x0F);
+ }
Review Comment:
I ran another JMH (baseline no --add-modules) with no changes to the code.
```
java --module-path lucene/benchmark-jmh/build/benchmarks \
-m org.apache.lucene.benchmark.jmh \
'VectorUtilBenchmark.binaryHalfByteUnpack(Vector|Scalar)$' \
-p size=207,300,512,702,1024 \
-wi 5 -i 8 -f 2 \
-rf json -rff jmh-unpack-tail.json
```
There is still a speedup at every size, but less so where the tail is
non-empty:
| size | packed | tail | Scalar (ops/us) | Vector (ops/us) | speedup |
| ---: | ---: | ---: | ---: | ---: | ---: |
| 1024 | 512 | 0 | 2.152 ± 0.007 | 27.604 ± 0.954 | 12.83x |
| 512 | 256 | 0 | 4.156 ± 0.010 | 44.814 ± 1.929 | 10.78x |
| 702 | 351 | 15 | 3.095 ± 0.006 | 22.103 ± 0.465 | 7.14x |
| 300 | 150 | 6 | 7.184 ± 0.018 | 38.761 ± 0.660 | 5.40x |
I'll see about hacking something up regarding the tail and testing it, it
may add some complexity so I want to see the results first.
--
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]