RFR: 8318158: RISC-V: implement roundD/roundF intrinsics

Olga Mikhaltsova omikhaltcova at openjdk.org
Wed Nov 8 16:36:59 UTC 2023


On Thu, 26 Oct 2023 17:20:49 GMT, Olga Mikhaltsova <omikhaltcova at openjdk.org> wrote:

> Please, review this Implementation of the roundD/roundF intrinsics for RISC-V platform.
> As shown below the output for RISC-V instructions and Java methods differs only for NaN argument.
> 
>                                                   RISC-V                            Java
>                                         (FCVT.W.S)    (FCVT.L.D)  (long round(double a)) (int round(float a))
> Minimum valid input (after rounding)     −2^31         −2^63         Long.MIN_VALUE       Integer.MIN_VALUE
> Maximum valid input (after rounding)      2^31 − 1      2^63 − 1     Long.MAX_VALUE       Integer.MAX_VALUE
> Output for out-of-range negative input   −2^31         −2^63         Long.MIN_VALUE       Integer.MIN_VALUE
> Output for −∞                            −2^31         −2^63         Long.MIN_VALUE       Integer.MIN_VALUE
> Output for out-of-range positive input    2^31 − 1      2^63 - 1     Long.MAX_VALUE       Integer.MAX_VALUE
> Output for +∞                             2^31 − 1      2^63 - 1     Long.MAX_VALUE       Integer.MAX_VALUE
> Output for NaN                            2^31 − 1      2^63 - 1           0                      0
> 
> The benchmark shows the following performance improvement:
> 
> **Before**
> 
> Benchmark                              (TESTSIZE)   Mode  Cnt  Score   Error   Units
> FpRoundingBenchmark.test_round_double        2048  thrpt   15  4.675 ± 0.259  ops/ms
> FpRoundingBenchmark.test_round_float         2048  thrpt   15  4.549 ± 0.210  ops/ms
> 
> 
> **After**
> 
> Benchmark                              (TESTSIZE)   Mode  Cnt   Score   Error   Units
> FpRoundingBenchmark.test_round_double        2048  thrpt   15  10.483 ± 0.681  ops/ms
> FpRoundingBenchmark.test_round_float         2048  thrpt   15  10.475 ± 0.480  ops/ms
> 
> 
> Testing: tier1 tests successfully passed on a RISC-V HiFive board with Linux.

Yes, you are both right, this is incorrect implementation. I compared the output of the assembler instructions fcvt.w.s/fcvt.l.d and Java Math.round(), paying attention to the range mentioned above. The results are different. Thank you for pointing me out this mistake!

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

PR Comment: https://git.openjdk.org/jdk/pull/16382#issuecomment-1802252694


More information about the hotspot-dev mailing list