RFR: 8318227: RISC-V: C2 ConvHF2F

Hamlin Li mli at openjdk.org
Fri Nov 24 17:45:04 UTC 2023


On Fri, 24 Nov 2023 10:32:04 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> Hi,
>> Can you review the patch to add ConvHF2F intrinsic to JDK for riscv?
>> Thanks!
>> 
>> (By latest kernel patch, `#define		RISCV_HWPROBE_EXT_ZFH		(1 << 27)`
>> https://lore.kernel.org/lkml/20231114141256.126749-11-cleger@rivosinc.com/)
>> 
>> ## Test
>> ### Functionality
>> #### hotspot tests
>> test/hotspot/jtreg/compiler/intrinsics/ 
>> test/hotspot/jtreg/compiler/c2/irTests
>> 
>> #### jdk tests
>> test/jdk/java/lang/Float/Binary16Conversion*.java
>> 
>> ### Performance
>> tested on licheepi.
>> 
>> #### with UseZfh enabled
>> (i.e. enable the intrinsic)
>> 
>> Benchmark                                     (size)  Mode  Cnt      Score     Error  Units
>> Fp16ConversionBenchmark.float16ToFloat          2048  avgt   10   4659.796 ?  13.262  ns/op
>> Fp16ConversionBenchmark.float16ToFloatMemory    2048  avgt   10     22.957 ?   0.098  ns/op
>> 
>> 
>> #### with UseZfh disabled
>> (i.e. disable the intrinsic)
>> 
>> Benchmark                                     (size)  Mode  Cnt      Score    Error  Units
>> Fp16ConversionBenchmark.float16ToFloat          2048  avgt   10  22930.591 ? 72.595  ns/op
>> Fp16ConversionBenchmark.float16ToFloatMemory    2048  avgt   10     25.970 ?  0.063  ns/op
>
> src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp line 1691:
> 
>> 1689:   fmv_h_x(dst, src);
>> 1690:   fcvt_s_h(dst, dst);
>> 1691:   j(done);
> 
> Since `Nan`s are exceptional inputs, it would be beneficial to move the handling below to an out-of-line stub.

Thanks for the suggestion, it make sense.

Just I'm not sure if there is a straight way to implement it currently. Following is what I've done, but blocked, please help to share your opinion.
 
To jump to stub code to process NaN case, the stub code need to use specific register for `src` and `dst`, as `dst` is a FloatRegister, so need a way to specify a float register when matching `ConvHF2F` in ad file. I tried to add a `fRegF_F10` to enable specify a float register, but it does not work well. Some error occurs for fastdebug version:


----------System.out:(47/2030)----------
Start ...
o558  SubF  === _ o515 o559  [[ o557 ]]

--N: o558  SubF  === _ o515 o559  [[ o557 ]]

   --N: o515  MoveI2F  === _ o681  [[ o470 o484 o620 o620 o618 o579 o558 o530 o434 4 10 10 ]]
   FREGF  0  FREGF
   FREGF_F10  0  FREGF_F10

   --N: o559  ConvHF2F  === _ o560  [[ o558 ]]  #float
   FREGF_F10  100  convHF2F_reg_reg

      --N: o560  RShiftI  === _ o561 o209  [[ o559 o434 4 ]]
      IREGI  0  IREGI
      IREGINOSP  0  IREGINOSP
      IREGI_R10  0  IREGI_R10
      IREGI_R11  0  IREGI_R11
      IREGI_R12  0  IREGI_R12
      IREGI_R13  0  IREGI_R13
      IREGI_R14  0  IREGI_R14
      IREGIORL2I  0  IREGI
      IREGIORL  0  IREGI
      IREGILNP  0  IREGI
      IREGILNPNOSP  0  IREGINOSP

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/hamlin/workspace/repos/github/jdk/src/hotspot/share/opto/matcher.cpp:1727), pid=2212108, tid=2212156
#  assert(false) failed: bad AD file

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16802#discussion_r1404562196


More information about the hotspot-dev mailing list