[vectorIntrinsics] RFR: 8283598: [vectorapi] Add new vector operation for compress bits

Xiaohong Gong xgong at openjdk.java.net
Thu Mar 24 08:43:05 UTC 2022


On Thu, 24 Mar 2022 06:31:31 GMT, Smita Kamath <svkamath at openjdk.org> wrote:

> Hi,
> 
> I've added support for new vector operations for compressing bits of integral vector types(Byte/Short/Integer/Long).
> The implementation is based on Compress or Generalized Extract mentioned in Hackers Delight by Henry S. Warren, Jr.
> The implementation does the following: given a mask and the number to be compressed, the bits of the number corresponding to the set mask bit are selected and compressed. 
> 
> Currently, this PR addresses only Java changes for compress bits operation. I've also updated the test framework.
> Do review and share feedback.

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java line 470:

> 468:             a = (byte) (a ^ temp | (temp >> (1 << i))); // Compress a
> 469:             count_mask = (byte) (count_mask & ~prefix_mask); // adjust count_mask by identifying bits that have 0 to the right
> 470:         }

Hi @smita-kamath , can we simply count the bits number and then do a left shift on the result, e.g:

1) b =  a & bitmask
2) b = popcount(b)
3) result = (0x1 << b) - 1

Please correct me if I misunderstood something. Thanks so much!

-------------

PR: https://git.openjdk.java.net/panama-vector/pull/184


More information about the panama-dev mailing list