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