VectorUtil
Utilities for computations with numeric arrays, especially algebraic operations like vector dot products. This class uses SIMD vectorization if the corresponding Java module is available and enabled. To enable vectorized code, pass --add-modules jdk.incubator.vector to Java's command line.
It will use CPU's FMA instructions if it is known to perform faster than separate multiply+add. This requires at least Hotspot C2 enabled, which is the default for OpenJDK based JVMs.
To explicitly disable or enable FMA usage, pass the following system properties:
-Dlucene.useScalarFMA=(auto|true|false)for scalar operations-Dlucene.useVectorFMA=(auto|true|false)for vectorized operations (with vector incubator module)
The default is auto, which enables this for known CPU types and JVM settings. If Hotspot C2 is disabled, FMA and vectorization are not used.
Vectorization and FMA is only supported for Hotspot-based JVMs; it won't work on OpenJ9-based JVMs unless they provide com.sun.management.HotSpotDiagnosticMXBean. Please also make sure that you have the jdk.management module enabled in modularized applications.
Properties
For xorBitCount we stride over the values as either 64-bits (long) or 32-bits (int) at a time. On ARM Long::bitCount is not vectorized, and therefore produces less than optimal code, when compared to Integer::bitCount. While Long::bitCount is optimal on x64. See https://bugs.openjdk.org/browse/JDK-8336000
Functions
Adds the second argument to the first
Checks if a float vector only has finite components.
Returns the cosine similarity between the two vectors.
Dot product computed over signed bytes.
Returns the vector dot product of the two vectors.
Dot product score computed over signed bytes, scaled to be in 0, 1.
Given an array buffer that is sorted between indexes 0 inclusive and to exclusive, find the first array index whose value is greater than or equal to target. This index is guaranteed to be at least from. If there is no such array index, to is returned.
Dot product computed over int4 (values between 0,15) bytes and a binary vector.
Dot product computed over int4 (values between 0,15) bytes. The second vector is considered "packed" (i.e. every byte representing two values). The following packing is assumed:
Modifies the argument to be unit length, dividing by its l2-norm. IllegalArgumentException is thrown for zero vectors.
Modifies the argument to be unit length, dividing by its l2-norm.
Returns the sum of squared differences of the two vectors.
XOR bit count computed over signed bytes.
XOR bit count striding over 4 bytes at a time.
XOR bit count striding over 8 bytes at a time.