RFR: 8297715: RISC-V: C2: Use single-bit instructions from the Zbs extension

Fei Yang fyang at openjdk.org
Tue Nov 29 03:42:14 UTC 2022


The single-bit instructions from the Zbs extension provide a mechanism to set, clear,
invert, or extract a single bit in a register. The bit is specified by its index.

Especially, the single-bit extract (immediate) instruction 'bexti rd, rs1, shamt' performs:

  let index = shamt & (XLEN - 1);
  X(rd) = (X(rs1) >> index) & 1;


This instruction is a perfect match for following sub-graph in C2 when integer immediate 'mask' is power of 2:
'''
   Set dst (Conv2B (AndI src mask))
'''

Then we could optimize C2 JIT code for [1]:
Before:

  lhu  R28, [R11, #12]    # short, #@loadUS ! Field: com/sun/org/apache/xerces/internal/dom/NodeImpl.flags
  andi  R7, R28, #8       #@andI_reg_imm
  snez  R10, R7           #@convI2Bool


After:

  lhu  R28, [R11, #12]    # short, #@loadUS ! Field: com/sun/org/apache/xerces/internal/dom/NodeImpl.flags
  bexti  R10, R28, 3      #


Testing: Tier1-3 hotspot & jdk tested with QEMU (JTREG="VM_OPTIONS=-XX:+UnlockExperimentalVMOptions -XX:+UseZbs").

[1] https://github.com/openjdk/jdk/blob/master/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/NodeImpl.java#L1936

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

Commit messages:
 - 8297715: RISC-V: C2: Use single-bit instructions from the Zbs extension

Changes: https://git.openjdk.org/jdk/pull/11406/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11406&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8297715
  Stats: 26 lines in 4 files changed: 24 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/11406.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11406/head:pull/11406

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


More information about the hotspot-compiler-dev mailing list