Class PhiloxSupport
- java.lang.Object
-
- org.apache.commons.rng.core.source64.PhiloxSupport
-
final class PhiloxSupport extends java.lang.ObjectUtility support for the Philox family of generators.Contains methods that use the
java.lang.invokepackage to calljava.lang.Mathfunctions for computing the high part of the 128-bit result of a multiply of two 64-bit longs. These methods may be supported by intrinsic calls to native operations if supported on the platform for a significant performance gain.Note
This class is used specifically in the
Philox4x64generator which has a state update cycle which is performance dependent on the multiply of two unsigned long values. Other classes which use unsigned multiply and are not performance dependent on the method do not use this implementation (for example the LXM family of generators). This allows the multiply method to be adapted to the usage ofPhilox4x64which always has the first argument as a negative constant.- Since:
- 1.7
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.function.LongBinaryOperatorUNSIGNED_MULTIPLY_HIGHMethod to compute unsigned multiply high.
-
Constructor Summary
Constructors Modifier Constructor Description privatePhiloxSupport()No instances.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.lang.invoke.MethodHandlegetMathMethod(java.lang.String methodName)Gets the named method from theMathclass.private static java.util.function.LongBinaryOperatorgetMathMultiplyHigh()Gets a method to compute the high 64-bits of an unsigned 64-bit multiplication using the Math multiplyHigh method from JDK 9.private static java.util.function.LongBinaryOperatorgetMathUnsignedMultiplyHigh()Gets a method to compute the high 64-bits of an unsigned 64-bit multiplication using the Math unsignedMultiplyHigh method from JDK 18.(package private) static booleantestUnsignedMultiplyHigh(java.util.function.LongBinaryOperator op)Test the implementation of unsigned multiply high.(package private) static longunsignedMultiplyHigh(long value1, long value2)Multiply the two values as if unsigned 64-bit longs to produce the high 64-bits of the 128-bit unsigned result.
-
-
-
Method Detail
-
getMathUnsignedMultiplyHigh
private static java.util.function.LongBinaryOperator getMathUnsignedMultiplyHigh()
Gets a method to compute the high 64-bits of an unsigned 64-bit multiplication using the Math unsignedMultiplyHigh method from JDK 18.- Returns:
- the method, or null
-
getMathMultiplyHigh
private static java.util.function.LongBinaryOperator getMathMultiplyHigh()
Gets a method to compute the high 64-bits of an unsigned 64-bit multiplication using the Math multiplyHigh method from JDK 9.- Returns:
- the method, or null
-
getMathMethod
static java.lang.invoke.MethodHandle getMathMethod(java.lang.String methodName) throws java.lang.NoSuchMethodException, java.lang.IllegalAccessExceptionGets the named method from theMathclass.The look-up assumes the named method accepts two long arguments and returns a long.
- Parameters:
methodName- Method name.- Returns:
- the method
- Throws:
java.lang.NoSuchMethodException- if the method does not existjava.lang.IllegalAccessException- if the method cannot be accessed
-
testUnsignedMultiplyHigh
static boolean testUnsignedMultiplyHigh(java.util.function.LongBinaryOperator op)
Test the implementation of unsigned multiply high. It is assumed the invocation of the method may raise anIllegalStateExceptionif it cannot be invoked.- Parameters:
op- Method implementation.- Returns:
- True if the method can be called to generate the expected result
-
unsignedMultiplyHigh
static long unsignedMultiplyHigh(long value1, long value2)Multiply the two values as if unsigned 64-bit longs to produce the high 64-bits of the 128-bit unsigned result. The first argument is assumed to be negative.This method uses a
MethodHandleto call Java functions added since Java 8 to theMathclass:java.lang.Math.unsignedMultiplyHighif Java 18java.lang.Math.multiplyHighif Java 9- otherwise a default implementation.
Warning
For performance reasons this method assumes the first argument is negative. This allows some operations to be dropped if running on Java 9 to 17.
- Parameters:
value1- the first value (must be negative)value2- the second value- Returns:
- the high 64-bits of the 128-bit result
-
-