Can I execute a SIMD comparison statement in Java8?

In Java8, several kinds of SIMD instructions can be executed, as stated in http://prestodb.rocks/code/simd/ .

I am wondering if it is possible to execute SIMD comparison instruction in Java8.

I want to check the equality of two characters (UTF-16, 16-bit number) and get the value 0xffff if they are the same, and 0x0 if not in a fast way. I have a large char array, and I want to perform the above equality check between each char element and a specific char, such as 0x0022, by looping the array.

Can I execute a SIMD comparison statement in Java8? Or is there bitwise manipulation or an algorithm that can efficiently and quickly perform char comparisons?

Thanks.

+6
source share
1 answer

The uniformity of arrays is vectorized in jdk-9(when it is possible as fas, as I can tell), according to this

Even the method inside has a definition like:

@HotSpotIntrinsicCandidate
static int vectorizedMismatch...

But this does not carry over to jdk-8.

As for bitwise manipulation, many operations have already been completed; as indicated by annotation @HotSpotIntrinsicCandidate.

It is best to actually check with a few options, for example:

 -XX:-TieredCompilation 
 -XX:CICompilerCount=1
 -XX:+UnlockDiagnosticVMOptions 
 -XX:+PrintCompilation 
 -XX:+PrintInlining 

And check whether you have such recordings: Unsafe::getAndAddInt (27 bytes) (intrinsic).

And perhaps the last obvious point is what is your goal for speed here? Even if you don’t get insides where you really can think what you want, the speed may be in the range in which you want.

+3
source

All Articles