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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With