RFR: 8373613: PEXT/PDEP intrinsics cause performance regression on AMD pre-Zen 3 CPUs

Jasmine Karthikeyan jkarthikeyan at openjdk.org
Wed Feb 25 11:02:24 UTC 2026


On Thu, 19 Feb 2026 03:22:16 GMT, Alessandro Autiero <duke at openjdk.org> wrote:

> The `Integer/Long.compress()` and `Integer/Long.expand()` intrinsics (added in JDK 19 by JDK-8283893) unconditionally use BMI2 PEXT/PDEP instructions on all BMI2-capable x86 CPUs. However, AMD processors before Zen 3 (Family < 0x19) and Zhaoxin CPUs implement PEXT/PDEP via microcode with ~18-cycle  latency, making the intrinsified path 1.4-2.4x slower than the Java software fallback.
> 
> This patch introduces a `CPU_FAST_BMI2` feature flag that distinguishes CPUs with native hardware PEXT/PDEP support (Intel Haswell+, AMD Zen 3+) from those with slow microcoded implementations. The `Op_CompressBits`/`Op_ExpandBits` match rules in `x86.ad` are gated on this new flag instead of the general `supports_bmi2()`, so CPUs without fast hardware support fall back to the Java implementation. C2 IR tests are updated to use the new `fast_bmi2` CPU feature predicate.

This is looking good! I just have a small comment about the CPU feature declaration. Also, the copyright years on the files need to be updated to 2026.

src/hotspot/cpu/x86/vm_version_x86.hpp line 458:

> 456:     decl(AVX10_2,           avx10_2,           64) /* AVX10 512 bit vector ISA Version 2 support*/ \
> 457:     decl(HYBRID,            hybrid,            65) /* Hybrid architecture */ \
> 458:     decl(FAST_BMI2,         fast_bmi2,         66) /* Native Hardware support for PEXT/PDEP BMI2 instructions */

You'll also need to add `"fast_bmi2"` to the list of well-known CPU features in [CPUInfoTest.java](https://github.com/openjdk/jdk/blob/master/test/lib-test/jdk/test/whitebox/CPUInfoTest.java), as otherwise it would assert when encountering an unrecognized feature.

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

Changes requested by jkarthikeyan (Committer).

PR Review: https://git.openjdk.org/jdk/pull/29809#pullrequestreview-3850940626
PR Review Comment: https://git.openjdk.org/jdk/pull/29809#discussion_r2849932683


More information about the hotspot-dev mailing list