gf2121 opened a new issue, #12639: URL: https://github.com/apache/lucene/issues/12639
### Description I played with vector API to sum up bit count. This pattern can be used in [bitset cardinality](https://github.com/apache/lucene/blob/dfff1e635805ffc61dd6029a8060e2635bfcbdb9/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java#L188C1-L200C4), [disjunction count](https://github.com/apache/lucene/blob/dfff1e635805ffc61dd6029a8060e2635bfcbdb9/lucene/core/src/java/org/apache/lucene/search/BooleanScorer.java#L187C1-L191C20), [IndexedDISI](https://github.com/apache/lucene/blob/dfff1e635805ffc61dd6029a8060e2635bfcbdb9/lucene/core/src/java/org/apache/lucene/codecs/lucene90/IndexedDISI.java#L605) etc.. Maybe worth implementing? ### Benchmark Result > jdk 20.0.2 > AVX-512 ``` Benchmark (size) Mode Cnt Score Error Units BitcountBenchmark.bitCountNew 1024 thrpt 5 4.062 ± 0.004 ops/us BitcountBenchmark.bitCountOld 1024 thrpt 5 1.195 ± 0.001 ops/us ``` ### Code ``` @Benchmark public int bitCountOld() { int sum = 0; for (int i = 0; i < size; i++) { sum += Long.bitCount(longs[i]); } return sum; } @Benchmark public int bitCountNew() { int i = 0; int res = 0; int upperBound = PREFERRED_LONG_SPECIES.loopBound(longs.length); LongVector acc = LongVector.zero(PREFERRED_LONG_SPECIES); for (; i < upperBound; i += PREFERRED_LONG_SPECIES.length()) { LongVector longVector = LongVector.fromArray(PREFERRED_LONG_SPECIES, longs, i); LongVector bitCount = longVector.lanewise(VectorOperators.BIT_COUNT); acc = acc.add(bitCount); } res += (int) acc.reduceLanes(VectorOperators.ADD); for (; i < longs.length; i++) { res += Long.bitCount(longs[i]); } return res; } ``` -- 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: issues-unsubscr...@lucene.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org