Hi Claes!
On 5/18/18 3:51 AM, Claes Redestad wrote:
Hi,
while there are C2 intrinsics on most platforms providing access to
specialized hardware instructions, e.g., lzcnt on Intel, optimizing
the java implementations of Integer/Long.numberOfLeadingZeros can
still be worthwhile, especially if it also helps C1 and implicitly
startup/warmup. This implementation wins slightly (5-25%) over the
baseline in all tested optimization modes (-Xint,
-XX:TieredStopAtLevel=1-3), as well as on C2 if the intrinsics are
disabled.
Webrev: http://cr.openjdk.java.net/~redestad/8203352/open.00/
Bug: https://bugs.openjdk.java.net/browse/JDK-8203352
Correctness is checked by existing tests, mainly
test/jdk/java/lang/Integer|Long/BitTwiddle.java
I think the Long version needs some adjustment.
The old code correctly handled the case when 32nd bit is the highest bit
set.
However, the in the new code such a value will be cast to a negative
int, and all the checks at lines 1774-1777 will fail.
We may want to add such test case to the existing tests.
With kind regards,
Ivan
/Claes
--
With kind regards,
Ivan Gerasimov