@@ -323,7 +323,7 @@ public ByteVector unary(ByteVector xVec, int vectorOpcode) {
323
323
case Bytecode .VECTOR_V128_NOT -> unop (x , I8X16 , VectorOperators .NOT );
324
324
case Bytecode .VECTOR_I8X16_ABS -> unop (x , I8X16 , VectorOperators .ABS );
325
325
case Bytecode .VECTOR_I8X16_NEG -> unop (x , I8X16 , VectorOperators .NEG );
326
- case Bytecode .VECTOR_I8X16_POPCNT -> unop ( x , I8X16 , VectorOperators . BIT_COUNT );
326
+ case Bytecode .VECTOR_I8X16_POPCNT -> i8x16_popcnt ( x ); // GR-68892
327
327
case Bytecode .VECTOR_I16X8_EXTADD_PAIRWISE_I8X16_S -> extadd_pairwise (x , I8X16 , VectorOperators .B2S );
328
328
case Bytecode .VECTOR_I16X8_EXTADD_PAIRWISE_I8X16_U -> extadd_pairwise (x , I8X16 , VectorOperators .ZERO_EXTEND_B2S );
329
329
case Bytecode .VECTOR_I16X8_EXTEND_LOW_I8X16_S -> extend (x , 0 , I8X16 , VectorOperators .B2S );
@@ -747,6 +747,13 @@ private static <E> ByteVector unop(ByteVector xBytes, Shape<E> shape, VectorOper
747
747
return result .reinterpretAsBytes ();
748
748
}
749
749
750
+ private static ByteVector i8x16_popcnt (ByteVector x ) {
751
+ // Based on the same approach as Integer#bitCount
752
+ ByteVector popcnt = x .sub (x .lanewise (VectorOperators .LSHR , 1 ).and ((byte ) 0x55 ));
753
+ popcnt = popcnt .and ((byte ) 0x33 ).add (popcnt .lanewise (VectorOperators .LSHR , 2 ).and ((byte ) 0x33 ));
754
+ return popcnt .add (popcnt .lanewise (VectorOperators .LSHR , 4 )).and ((byte ) 0x0F );
755
+ }
756
+
750
757
private static <E , F > ByteVector extadd_pairwise (ByteVector xBytes , Shape <E > shape , VectorOperators .Conversion <E , F > conv ) {
751
758
Vector <E > x = shape .reinterpret (xBytes );
752
759
Vector <F > evens = x .compress (shape .evensMask ).convert (conv , 0 );
0 commit comments