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

Ivan Gerasimov ivan.gerasimov at oracle.com
Fri May 18 21:44:14 UTC 2018


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