Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-13 Thread Martin Buchholz
Approved! There was a lot of benchmarking work, so I'd like to see the jmh benchmark checked in. Especially since the exact variant we eventually settled on is not in Hacker's Delight. On Mon, Aug 13, 2018 at 12:09 PM, Ivan Gerasimov wrote: > Okay, your last variant is the winner :) > > Here's

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-13 Thread Ivan Gerasimov
Okay, your last variant is the winner :) Here's the updated webrev, benchmark and the graphs: http://cr.openjdk.java.net/~igerasim/8209171/02/webrev/ http://cr.openjdk.java.net/~igerasim/8209171/02/bench/int/MyBenchmark.java

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-13 Thread Martin Buchholz
On Mon, Aug 13, 2018 at 10:10 AM, Ivan Gerasimov wrote: > Hi Martin! > > Good point about the command line flags, thanks! > > These variants are close to numberOfTrailingZeros_07 that I've already > tested, though you did better by saving one arithmetic operation at the > return line! > > Right.

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-13 Thread Ivan Gerasimov
Hi Martin! Good point about the command line flags, thanks! These variants are close to numberOfTrailingZeros_07 that I've already tested, though you did better by saving one arithmetic operation at the return line! I'll rerun the benchmarks. With kind regards, Ivan On 8/13/18 7:56 AM,

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-13 Thread Martin Buchholz
The number of plausible variants is astonishing! --- Your use of -client and -server is outdated, which explains why you get the same results for both (-client is ignored). I'm not sure what's blessed by hotspot team, but for C1 I use -XX:+TieredCompilation -XX:TieredStopAtLevel=1 and for C2 I

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-13 Thread Ivan Gerasimov
On 8/12/18 10:57 AM, Martin Buchholz wrote: If delegating to nlz is the winner so far, we should be able to do at least as well by inlining nlz into ntz and then looking for more optimizations. Following this strategy leads naturally to static int ntz_inlineNlz2(int i) { i &= -i;

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-12 Thread Martin Buchholz
Here's an example of a microbenchmark that uses multiple random inputs simulating various typical populations: https://github.com/google/caliper/blob/master/caliper-examples/src/main/java/examples/Utf8Benchmark.java

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-12 Thread Martin Buchholz
If delegating to nlz is the winner so far, we should be able to do at least as well by inlining nlz into ntz and then looking for more optimizations. Following this strategy leads naturally to static int ntz_inlineNlz2(int i) { i &= -i; if (i <= 0) return 32 - (i >>> 31);

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-12 Thread Ivan Gerasimov
Hi Martin! On 8/11/18 5:54 PM, Martin Buchholz wrote: Hi Ivan, Oh the allure of bit-twiddling! Yes :) I'm skeptical that ntz should ever delegate to nlz, and not only because of the overhead of a wrapper, but because small numbers are more common, and we can take that into account when

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-11 Thread Martin Buchholz
Hi Ivan, Oh the allure of bit-twiddling! I'm skeptical that ntz should ever delegate to nlz, and not only because of the overhead of a wrapper, but because small numbers are more common, and we can take that into account when implementing ntz. At least add "1" to the set of numbers to

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-10 Thread Ivan Gerasimov
Thanks Martin! On 8/9/18 5:42 PM, Martin Buchholz wrote: On Thu, Aug 9, 2018 at 5:27 PM, Ivan Gerasimov mailto:ivan.gerasi...@oracle.com>> wrote: I did not use the intrinsified variants of numberOfLeadingZeros in the benchmark. Oops! Should have looked more closely! Did you know

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-09 Thread Martin Buchholz
On Thu, Aug 9, 2018 at 5:27 PM, Ivan Gerasimov wrote: > I did not use the intrinsified variants of numberOfLeadingZeros in the > benchmark. > Oops! Should have looked more closely! Did you know about http://www.hackersdelight.org/hdcodetxt/ntz.c.txt

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-09 Thread Ivan Gerasimov
Hi Martin! Thanks for taking a look! On 8/9/18 5:13 PM, Martin Buchholz wrote: On Thu, Aug 9, 2018 at 4:15 PM, Ivan Gerasimov mailto:ivan.gerasi...@oracle.com>> wrote: Hello! Integer.numberOfTrailingZeros() and Long.numberOfTrailingZeros() are intrinsified by Hotspot, so the

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-09 Thread Martin Buchholz
On Thu, Aug 9, 2018 at 4:15 PM, Ivan Gerasimov wrote: > Hello! > > Integer.numberOfTrailingZeros() and Long.numberOfTrailingZeros() are > intrinsified by Hotspot, so the Java implementation of these is not too > important. > However, they still can be improved by a tiny bit :) > > Could you

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-09 Thread Ivan Gerasimov
Hi Joe! On 8/9/18 4:20 PM, Joseph D. Darcy wrote: Hi Ivan, On which platforms were the benchmark numbers collected? Ah, yes, should have mentioned that. macOS 10.13.5 High Sierra, processor 3.1 GHz Intel Core i7 With kind regards, Ivan Thanks, -Joe On 8/9/2018 4:15 PM, Ivan Gerasimov

Re: RFR 8209171 : Simplify Java implementation of Integer/Long.numberOfTrailingZeros()

2018-08-09 Thread Joseph D. Darcy
Hi Ivan, On which platforms were the benchmark numbers collected? Thanks, -Joe On 8/9/2018 4:15 PM, Ivan Gerasimov wrote: Hello! Integer.numberOfTrailingZeros() and Long.numberOfTrailingZeros() are intrinsified by Hotspot, so the Java implementation of these is not too important.