RFR: 8346664: C2: Optimize mask check with constant offset [v3]

Matthias Ernst duke at openjdk.org
Mon Jan 20 08:41:41 UTC 2025


On Mon, 20 Jan 2025 08:15:27 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> Would it be possible to show the benchmarks mentioned in https://mail.openjdk.org/pipermail/panama-dev/2024-December/020835.html before and after this patch?

Of course. I've also added one that simply replicates the alignment check (see below):



Before:
Benchmark                       Mode  Cnt  Score   Error  Units
Alignment.findAligned           avgt    5  0.237 ± 0.023  ns/op
Alignment.findAlignedNext       avgt    5  0.377 ± 0.047  ns/op    <= #####
Alignment.findAlignedPlusOne    avgt    5  0.366 ± 0.021  ns/op    <= #####
Alignment.findUnaligned         avgt    5  0.237 ± 0.019  ns/op
Alignment.findUnalignedNext     avgt    5  0.240 ± 0.017  ns/op
Alignment.findUnalignedPlusOne  avgt    5  0.239 ± 0.008  ns/op
AndAddShift.isAligned       avgt    5  ≈ 10⁻⁷           ns/op
AndAddShift.isAlignedPlus1  avgt    5   0.153 ±  0.004  ns/op    <= #####

After:
Benchmark                       Mode  Cnt  Score   Error  Units
Alignment.findAligned           avgt    5  0.236 ± 0.029  ns/op
Alignment.findAlignedNext       avgt    5  0.238 ± 0.035  ns/op    <= #####
Alignment.findAlignedPlusOne    avgt    5  0.239 ± 0.034  ns/op    <= #####
Alignment.findUnaligned         avgt    5  0.235 ± 0.014  ns/op
Alignment.findUnalignedNext     avgt    5  0.240 ± 0.013  ns/op
Alignment.findUnalignedPlusOne  avgt    5  0.241 ± 0.015  ns/op
AndAddShift.isAligned       avgt    5  ≈ 10⁻⁷           ns/op
AndAddShift.isAlignedPlus1  avgt    5  ≈ 10⁻⁷           ns/op    <= #####



    private static boolean check(MemorySegment segment, long index) {
        return ((segment.address() + (index << 3L)) & 7L) == 0;
    }

    @Benchmark
    public void isAligned() {
        long size = segment.byteSize() / 8;
        for (long i = 0; i < size - 1; ++i) {
            if (!check(segment, i)) {
                throw new IllegalArgumentException();
            }
        }
    }

    @Benchmark
    public void isAlignedPlus1() {
        long size = segment.byteSize() / 8;
        for (long i = 0; i < size - 1; ++i) {
            if (!check(segment, i + 1)) {
                throw new IllegalArgumentException();
            }
        }
    }

-------------

PR Comment: https://git.openjdk.org/jdk/pull/22856#issuecomment-2601757857


More information about the hotspot-compiler-dev mailing list