[
https://issues.apache.org/jira/browse/RNG-191?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Alex Herbert resolved RNG-191.
------------------------------
Fix Version/s: 1.7
Resolution: Implemented
Added in commit:
d73cbc42d380ab63fdeadb83eebf6105ea573373
> Use java.lang.invoke to dynamically call Math multiply high methods
> -------------------------------------------------------------------
>
> Key: RNG-191
> URL: https://issues.apache.org/jira/browse/RNG-191
> Project: Commons RNG
> Issue Type: Improvement
> Components: core
> Reporter: Alex Herbert
> Priority: Minor
> Fix For: 1.7
>
>
> The following generators rely on a 128-bit multiplication result from two
> 64-bit longs:
> * L128_X128_MIX
> * L128_X256_MIX
> * L128_X1024_MIX
> * PHILOX_4X64
> Java added support to java.lang.Math to compute the upper 64-bit result with
> potential intrinsic calls to native functions:
> ||Method||JDK||Notes||
> |[multiplyHigh (Javadoc JDK
> 21)|https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Math.html#multiplyHigh(long,long)]|9|Convert
> to unsigned using:
> Math.multiplyHigh(a, b) + ((a >> 63) & b) + ((b >> 63) & a)|
> |[unsignedMultiplyHigh (Javadoc JDK
> 21)|https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Math.html#unsignedMultiplyHigh(long,long)]|18|
> |
> Since Commons RNG targets Java 8 these methods cannot be used. The current
> RNGs use a software implementation to compose the upper bits of the 128-bit
> result. However the methods can be used with a
> [MethodHandle|https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/invoke/MethodHandle.html]
> introduced in Java 7:
> {code:java}
> // find the method
> MethodHandle h = MethodHandles.publicLookup()
> .findStatic(Math.class,
> "unsignedMultiplyHigh",
> MethodType.methodType(long.class, long.class, long.class));
> // invoke (snippet)
> long a, b;
> try {
> long r = (long) h2.invokeExact(a, b);
> } catch (Throwable e) {
> throw new RuntimeException(e);
> }
> {code}
> Investigate the use of MethodHandle within the named RNGs.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)