mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8188044: We need Math.unsignedMultiplyHigh
Reviewed-by: rriggs, aph, darcy
This commit is contained in:
parent
3d84398d12
commit
ca4bea4665
3 changed files with 81 additions and 10 deletions
|
@ -1156,6 +1156,7 @@ public final class Math {
|
|||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @see #unsignedMultiplyHigh
|
||||
* @since 9
|
||||
*/
|
||||
@IntrinsicCandidate
|
||||
|
@ -1187,6 +1188,24 @@ public final class Math {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns as a {@code long} the most significant 64 bits of the unsigned
|
||||
* 128-bit product of two unsigned 64-bit factors.
|
||||
*
|
||||
* @param x the first value
|
||||
* @param y the second value
|
||||
* @return the result
|
||||
* @see #multiplyHigh
|
||||
* @since 18
|
||||
*/
|
||||
public static long unsignedMultiplyHigh(long x, long y) {
|
||||
// Compute via multiplyHigh() to leverage the intrinsic
|
||||
long result = Math.multiplyHigh(x, y);
|
||||
result += (y & (x >> 63)); // equivalent to `if (x < 0) result += y;`
|
||||
result += (x & (y >> 63)); // equivalent to `if (y < 0) result += x;`
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest (closest to positive infinity)
|
||||
* {@code int} value that is less than or equal to the algebraic quotient.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue