RFR: 8373613: Disable PEXT/PDEP intrinsics on CPUs with slow microcoded implementations

Alessandro Autiero duke at openjdk.org
Thu Feb 19 03:29:36 UTC 2026


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.

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

Commit messages:
 - x86: updated docs for compute_fast_bmi2
 - x86: modified TestBitShuffleOpers to require fast_bmi2 instead of bmi2 CPU flag
 - x86: modified VMVersion::supports_fast_bmi2 to use the newly added CPU flag, moved fast bmi2 detection logic to vm_version_x86.cpp
 - x86: added CPU flag FAST_BMI2 and modified C2 tests to use the new flag
 - x86: modify match_rule_supported logic in x86.ad for operations Op_CompressBits and Op_ExpandBits to check for VM_Version::supports_fast_bmi2() instead of VM_Version::supports_bmi2()
 - x86: add supports_fast_bmi2() to gate PEXT/PDEP performance

Changes: https://git.openjdk.org/jdk/pull/29809/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29809&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8373613
  Stats: 72 lines in 5 files changed: 52 ins; 0 del; 20 mod
  Patch: https://git.openjdk.org/jdk/pull/29809.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/29809/head:pull/29809

PR: https://git.openjdk.org/jdk/pull/29809


More information about the hotspot-dev mailing list