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

Feilong Jiang fjiang at openjdk.org
Tue Nov 29 06:52:04 UTC 2022


On Tue, 29 Nov 2022 03:35:12 GMT, Fei Yang <fyang at openjdk.org> wrote:

> 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 C2 sub-graph when integer immediate 'mask' is power of 2:
> 
>   Set dst (Conv2B (AndI src mask))
> 
> 
> The effect is that we could then optimize C2 JIT code for methods like [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

Looks good.

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

Marked as reviewed by fjiang (Author).

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


More information about the hotspot-compiler-dev mailing list