RFR: 8188044: We need Math.unsignedMultiplyHigh [v2]
Andrew Haley
aph at openjdk.java.net
Fri Jul 2 09:44:02 UTC 2021
On Fri, 2 Jul 2021 09:37:47 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>>
>> 8188044: Add @see links between multiplyHigh() and unsignedMultiplyHigh().
>
> src/java.base/share/classes/java/lang/Math.java line 1211:
>
>> 1209: long z1 = t >>> 32;
>> 1210:
>> 1211: return x1 * y1 + z1 + (z0 >>> 32);
>
> Suggestion:
>
> long result = Math.multiplyHigh(x, y);
> if (x < 0) result += y;
> if (y < 0) result += x;
> return result;
This is just subtracting the 2's-complement offset. I guess the idea, longer term, is that this be an intrinsic anyway, but if you do `unsignedMultiplyHigh` this way you'll utilize the existing `multiplyHigh` intrinsic on all platforms that have it.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4644
More information about the core-libs-dev
mailing list