Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to execute SIMD comparison instruction in Java8?

Tags:

java

java-8

simd

In Java8, a few kind of SIMD instructions can be executed as this article http://prestodb.rocks/code/simd/ says.

I'm wondering if an SIMD comparison instruction can be executed in Java8.

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

Is it possible to execute SIMD comparison instruction in Java8? Or is there any bitwise manipulation or algorithm which can execute char comparison efficiently and fast?

Thanks.

like image 231
bluesun Avatar asked Jun 20 '17 05:06

bluesun


1 Answers

Arrays equality is vectorized in jdk-9 (when possible as fas as I can tell), according to this

Even the method internally has a definition as :

@HotSpotIntrinsicCandidate
static int vectorizedMismatch...

But this is not ported to jdk-8.

As far as bitwise manipulation goes, lots of operations are already intrensified; as denoted by the @HotSpotIntrinsicCandidate annotation.

Your best bet it to actually test with with a few options like:

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

And check if you have entries like this: Unsafe::getAndAddInt (27 bytes) (intrinsic).

And the last obvious point probably is what is your target of speed here? Even if you don't get intrinsics where you actually might think you want, the speed could be in the range where you want it to be.

like image 158
Eugene Avatar answered Oct 23 '22 15:10

Eugene