RFR: 8333382: [s390x] Move population_count implementation out of ad file
Amit Kumar
amitkumar at openjdk.org
Wed Jun 5 06:44:58 UTC 2024
On Sat, 1 Jun 2024 13:15:45 GMT, Amit Kumar <amitkumar at openjdk.org> wrote:
> We need to move popcnt instruction implementation out of s390.ad file as it is required to be required some methods present in [JDK-8331126.](https://bugs.openjdk.org/browse/JDK-8331126)
>
>
> When the miscellaneous-instruction-extensions facility 3 is not installed or bit 0 of the M3
> field is zero, a count of the number of one bits in each of the eight bytes of general register
> R2 is placed into the corresponding byte of general register R1. Each byte of general register
> R1 is an 8-bit binary integer in the range of 0-8.
>
>
>
> When the miscellaneous-instruction-extensions facility 3 is installed and bit 0 of the M3 field
> is one, a count of the total number of one bits in the 64-bit general register R2 is placed into
> general register R1. The result is a 64-bit unsigned integer in the range 0 to 64.
>
>
> Performed tier1 test on fastdebug build and didn't see any regression.
These are the benchmark results from custom benchmark:
Without the Patch:
Benchmark Mode Cnt Score Error Units
PopCount.fineTest avgt 20 1608179.360 ± 140304.896 ns/op
With the Patch:
Benchmark Mode Cnt Score Error Units
PopCount.fineTest avgt 20 762352.534 ± 84070.285 ns/op
This is the benchmark:
package org.openjdk.bench.vm.runtime;
import org.openjdk.jmh.annotations.*;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
@Warmup(iterations = 1, time = 1)
@Measurement(iterations = 4, time = 1)
@Fork(value = 5)
public class PopCount {
public Random rand = new Random();
int numTests = 100_000;
int[] testNumbers = new int[numTests];
@Setup
public void warmup() {
long l1 = 1, l2 = 2, l3 = 3, l4 = 4, l5 = 5, l6 = 6, l7 = 7, l8 = 9, l9 = 9, l10 = 10;
for (long i = 0; i < numTests; i++) {
l1 ^= Long.bitCount(l1) + i;
l2 ^= Long.bitCount(l2) + i;
l3 ^= Long.bitCount(l3) + i;
l4 ^= Long.bitCount(l4) + i;
l5 ^= Long.bitCount(l5) + i;
l6 ^= Long.bitCount(l6) + i;
l7 ^= Long.bitCount(l7) + i;
l8 ^= Long.bitCount(l8) + i;
l9 ^= Long.bitCount(l9) + i;
l10 ^= Long.bitCount(l10) + i;
}
long x = l1 + l2 + l3 + l4 + l5 + l6 + l7 + l8 + l9 + l10;
}
@Benchmark
public long fineTest() {
long l1 = 1, l2 = 2, l3 = 3, l4 = 4, l5 = 5, l6 = 6, l7 = 7, l8 = 9, l9 = 9, l10 = 10;
for (long i = 0; i < numTests; i++) {
l1 ^= Long.bitCount(l1) + i;
l2 ^= Long.bitCount(l2) + i;
l3 ^= Long.bitCount(l3) + i;
l4 ^= Long.bitCount(l4) + i;
l5 ^= Long.bitCount(l5) + i;
l6 ^= Long.bitCount(l6) + i;
l7 ^= Long.bitCount(l7) + i;
l8 ^= Long.bitCount(l8) + i;
l9 ^= Long.bitCount(l9) + i;
l10 ^= Long.bitCount(l10) + i;
}
return l1 + l2 + l3 + l4 + l5 + l6 + l7 + l8 + l9 + l10;
}
}
@RealLucy 👀
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19509#issuecomment-2149000386
More information about the hotspot-dev
mailing list