RFR: 8203352: Improve java implementation of Integer/Long.numberOfLeadingZeros

Martin Buchholz martinrb at google.com
Fri May 18 23:12:42 UTC 2018


+1

Consider checking in your exhaustive test in such a way that it doesn't get
run automatically in exhaustive mode by jtreg, perhaps controlled by a
system property.

On Fri, May 18, 2018 at 2:44 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com>
wrote:

> I vote for this variant.
>
> With kind regards,
>
> Ivan
>
>
>
> On 5/18/18 12:05 PM, Claes Redestad wrote:
>
>>
>>
>> On 2018-05-18 20:23, Ivan Gerasimov wrote:
>>
>>> Another approach may be to just delegate to
>>> Integer.numberOfLeadingZeros() like this:
>>>
>>>     public static int numberOfLeadingZeros(long i) {
>>>         int x = (int)(i >>> 32);
>>>         return x == 0 ? 32 + Integer.numberOfLeadingZeros((int)i)
>>>                 : Integer.numberOfLeadingZeros(x);
>>>     }
>>>
>>
>> I'm partial to the simplicity of this solution - whether or not there are
>> platforms where 64-bit
>> lz instruction is missing. It's very slightly slower than baseline for
>> -Xint, but markedly faster
>> when C1-compiled, which I think weighs heavier.
>>
>> http://cr.openjdk.java.net/~redestad/8203352/open.01/
>>
>> /Claes
>>
>>
> --
> With kind regards,
> Ivan Gerasimov
>
>


More information about the core-libs-dev mailing list