Replicating _mm256_shuffle_epi8 Intrinsic With Java Vector API Shuffle?

293 Views Asked by At

I am (mostly for fun) attempting to write a SHA-256 digest function using Java's Vector API. I am using the following AVX2 implementation from bitcoin as a reference:

https://github.com/bitcoin/bitcoin/blob/7fcf53f7b4524572d1d0c9a5fdc388e87eb02416/src/crypto/sha256_avx2.cpp

I have been able to make it to the point where the shuffle intrinsic is used: return _mm256_shuffle_epi8(ret, _mm256_set_epi32(0x0C0D0E0FUL, 0x08090A0BUL, 0x04050607UL, 0x00010203UL, 0x0C0D0E0FUL, 0x08090A0BUL, 0x04050607UL, 0x00010203UL));.

I see that the Java Vector API provides a VectorShuffle class and rearrange methods on the Vector class but the API docs seem to be approaching shuffles from the angle of indexes and not masks.

So my question is - how to replicate (as close as possible) the behavior of the _mm256_shuffle_epi8 intrinsic with Java's vector API?

Update: I just realized that the AVX2 SHA-256 bitcoin implementation seems to be a Double SHA-256 implementation. This complicates matters...

0

There are 0 best solutions below