RFR: 8317971: RISC-V: implement copySignF/D and signumF/D intrinsics

Ilya Gavrilin igavrilin at openjdk.org
Fri Oct 13 15:45:27 UTC 2023


Hi all, please review this changes into risc-v floating point copysign and signum intrinsics.
CopySign - returns first argument with the sign of second. On risc-v we have `fsgnj.x` instruction, which can implement this intrinsic.
Signum - returns input value if it is +/- 0.0 or NaN, otherwise 1.0 with the sign of input value returned.  On risc-v we can use `fclass.x` to specify type of input value and return appropriate value.

Tests:
Performance tests on t-head board:
With intrinsics:

Benchmark                 (seed)   Mode  Cnt      Score      Error   Units
MathBench.copySignDouble       0  thrpt    8  34156.580 ±   76.272  ops/ms
MathBench.copySignFloat        0  thrpt    8  34181.731 ±   38.182  ops/ms
MathBench.signumDouble         0  thrpt    8  31977.258 ± 1122.327  ops/ms
MathBench.signumFloat          0  thrpt    8  31836.852 ±   56.013  ops/ms

Intrinsics turned off (`-XX:+UnlockDiagnosticVMOptions -XX:-UseCopySignIntrinsic -XX:-UseSignumIntrinsic`):

Benchmark                 (seed)   Mode  Cnt      Score      Error   Units
MathBench.copySignDouble       0  thrpt    8  31000.996 ±  943.094  ops/ms
MathBench.copySignFloat        0  thrpt    8  30678.016 ±   28.087  ops/ms
MathBench.signumDouble         0  thrpt    8  25435.010 ± 2047.085  ops/ms
MathBench.signumFloat          0  thrpt    8  25257.058 ±   79.175  ops/ms

Regression tests: tier1, hotspot:tier2 on risc-v board.

Also, changed name of one micro test: before we had: `sigNumDouble` and `signumFloat` tests, they does not matches to `signum` or `sigNum`. Now we have similar part: `signum`.
Performance tests has been changed a bit, to check intrinsics result better, diff to modify tests:

diff --git a/test/micro/org/openjdk/bench/java/lang/MathBench.java b/test/micro/org/openjdk/bench/java/lang/MathBench.java
index 6cd1353907e..0bee25366bf 100644
--- a/test/micro/org/openjdk/bench/java/lang/MathBench.java
+++ b/test/micro/org/openjdk/bench/java/lang/MathBench.java
@@ -143,12 +143,12 @@ public double  ceilDouble() {
 
     @Benchmark
     public double  copySignDouble() {
-        return  Math.copySign(double81, doubleNegative12);
+        return  Math.copySign(double81, doubleNegative12) + Math.copySign(double81, double2) + Math.copySign(double4Dot1, doubleNegative12);
     }
 
     @Benchmark
     public float  copySignFloat() {
-        return  Math.copySign(floatNegative99, float1);
+        return  Math.copySign(floatNegative99, float1) + Math.copySign(eFloat, float1) + Math.copySign(eFloat, floatNegative99);
     }
 
     @Benchmark
@@ -472,12 +472,12 @@ public float  scalbFloatInt() {
 
     @Benchmark
     public double  sigNumDouble() {
-        return  Math.signum(double4Dot1);
+        return  Math.signum(double4Dot1) + Math.signum(doubleNegative12) + Math.signum(double81);
     }
 
     @Benchmark
     public double  signumFloat() {
-        return  Math.signum(floatNegative99);
+        return  Math.signum(floatNegative99) + Math.signum(float2) + Math.signum(float7);
     }
 
     @Benchmark

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

Commit messages:
 - Implement copySign and signum intrinsics

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

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


More information about the core-libs-dev mailing list