RFR: 8238669: Long.divideUnsigned is extremely slow for certain values (Needs to be Intrinsic) [v2]

rgiulietti github.com+70726043+rgiulietti at openjdk.java.net
Tue Sep 8 22:07:41 UTC 2020


On Tue, 8 Sep 2020 20:42:41 GMT, rgiulietti <github.com+70726043+rgiulietti at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Long.java line 1697:
>> 
>>> 1695:             final long q = (dividend >>> 1) / divisor << 1;
>>> 1696:             final long r = dividend - q * divisor;
>>> 1697:             return r - (~(r - divisor) >> Long.SIZE - 1 & divisor);
>> 
>> Parentheses would be particularly helpful here. I'd certainly have to think hard about the relative precedences of
>> `>>`, `-`, and `&`, whereas I wouldn't have to with: return r - ((~(r - divisor) >> (Long.SIZE - 1)) & divisor);
>> 
>> I also think it would be worth adding a comment saying that this is deliberately `>>` not `>>>`, even though we have
>> `>>>` in the divide method. Here we're propagating the sign bit so that `thing & divisor` is either 0 or `divisor`
>> according as `thing` is –1 or 0.
>
> Hi Éamonn,
> 
> I have no problems adding non-strictly needed parentheses. I usually don't because I'm quite familiar with operator
> precedence and often forget that other people are not.
> I'll add comments for parts, like the one you point out, that are not already discussed at length in the
> bibliographical reference.
> Thanks
> Raffaello

Hi,

I just committed the changes.

Greetings
Raffaello

-------------

PR: https://git.openjdk.java.net/jdk/pull/31


More information about the core-libs-dev mailing list