Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 6 commits into from

Conversation

Ilyagavrilin
Copy link

@Ilyagavrilin Ilyagavrilin commented Oct 13, 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

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8317971: RISC-V: implement copySignF/D and signumF/D intrinsics (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16186/head:pull/16186
$ git checkout pull/16186

Update a local copy of the PR:
$ git checkout pull/16186
$ git pull https://git.openjdk.org/jdk.git pull/16186/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16186

View PR using the GUI difftool:
$ git pr show -t 16186

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16186.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 13, 2023

👋 Welcome back igavrilin! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 13, 2023
@openjdk
Copy link

openjdk bot commented Oct 13, 2023

@Ilyagavrilin The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Oct 13, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 13, 2023

Webrevs

@Ilyagavrilin
Copy link
Author

/cc hotspot-compiler

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Oct 13, 2023
@openjdk
Copy link

openjdk bot commented Oct 13, 2023

@Ilyagavrilin
The hotspot-compiler label was successfully added.

Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments after a brief look.

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
@robehn
Copy link
Contributor

robehn commented Oct 17, 2023

Hey, I went ahead and create https://bugs.openjdk.org/browse/JDK-8318216.
So we can track these and not do double work.


// use floating-point 1.0 with a sign of input
is_double ? fsgnj_d(dst, one, src)
: fsgnj_s(dst, one, src);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the src argument contains zero? Math.signum(float/double) is supposed to return zero if the argument is zero [1].

[1] https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/Math.java#L2602

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to IEEE754, we can get positive or negative zero in the src register (also positive zero can be named as zero) , and these cases included to mask for the tmp1 (L1671-1676) and src value returned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the answer. I can approve this once my other comments are resolved.

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated change looks good. Thanks.
JMH data on hifive unmatched for reference:

Before:
Benchmark                 (seed)   Mode  Cnt      Score       Error   Units
MathBench.copySignDouble       0  thrpt    8  79728.042 ?  8211.438  ops/ms
MathBench.copySignFloat        0  thrpt    8  79516.930 ? 13163.477  ops/ms
MathBench.sigNumDouble         0  thrpt    8  58204.403 ?  6795.238  ops/ms
MathBench.signumFloat          0  thrpt    8  57882.056 ?  3635.354  ops/ms

After:
Benchmark                 (seed)   Mode  Cnt       Score       Error   Units
MathBench.copySignDouble       0  thrpt    8  104301.832 ?  7170.917  ops/ms
MathBench.copySignFloat        0  thrpt    8  103008.851 ? 11722.187  ops/ms
MathBench.signumDouble         0  thrpt    8   64465.030 ?  6849.148  ops/ms
MathBench.signumFloat          0  thrpt    8   63987.290 ?  4298.311  ops/ms

@openjdk
Copy link

openjdk bot commented Oct 19, 2023

@Ilyagavrilin This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

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

Reviewed-by: fyang, vkempik

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 109 new commits pushed to the master branch:

  • 4010642: 8077371: Binary files in JAXP test should be removed
  • fe52917: 8318457: Use prefix-less prepend methods directly to reduce branches in String concat expressions
  • 71c99a0: 8318448: Link PopupMenu/PopupMenuLocation.java failure to JDK-8259913
  • 2c23391: 8318101: Additional test cases for CSSAttributeEqualityBug
  • deadb9c: 8304684: Memory leak in DirectivesParser::set_option_flag
  • a03767c: 8318049: C2: assert(!failure) failed: Missed optimization opportunity in PhaseIterGVN
  • 848ecc1: 8318538: Add a way to obtain a strided var handle from a layout
  • b07da3a: 8317819: Scope should reflect lifetime of underying resource (mainline)
  • 6f1d896: 8318510: Serial: Remove TenuredGeneration::block_size
  • 8f4ebd8: 8317920: JDWP-agent sends broken exception event with onthrow option
  • ... and 99 more: https://git.openjdk.org/jdk/compare/6273ab97dc1a0d3c1f51ba94694d9594dd7593d4...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@RealFYang, @VladimirKempik) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 19, 2023
@Ilyagavrilin
Copy link
Author

Change branch inside signum, now dst always moves to src, so we can remove j(done);
Performance results:
Without intrinsic:

Benchmark               (seed)   Mode  Cnt      Score    Error   Units
MathBench.signumDouble       0  thrpt    8  35666.674 ±  6.317  ops/ms
MathBench.signumFloat        0  thrpt    8  34040.220 ± 13.783  ops/ms

With old version:

Benchmark               (seed)   Mode  Cnt      Score    Error   Units
MathBench.signumDouble       0  thrpt    8  41601.513 ± 16.570  ops/ms
MathBench.signumFloat        0  thrpt    8  39414.511 ± 28.290  ops/ms

With new version:

Benchmark               (seed)   Mode  Cnt      Score    Error   Units
MathBench.signumDouble       0  thrpt    8  44060.456 ± 12.483  ops/ms
MathBench.signumFloat        0  thrpt    8  40481.776 ± 28.512  ops/ms

Copy link

@VladimirKempik VladimirKempik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, last change is pretty similar to what was done here 00e16a6

Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still good. You might want to correct the remaining typo.

src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp Outdated Show resolved Hide resolved
@Ilyagavrilin
Copy link
Author

Still good. You might want to correct the remaining typo.

Thanks for review!

src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
src/hotspot/cpu/riscv/riscv.ad Outdated Show resolved Hide resolved
@Ilyagavrilin
Copy link
Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 20, 2023
@openjdk
Copy link

openjdk bot commented Oct 20, 2023

@Ilyagavrilin
Your change (at version b6e0b56) is now ready to be sponsored by a Committer.

@VladimirKempik
Copy link

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 20, 2023

Going to push as commit 5a97411.
Since your change was applied there have been 110 commits pushed to the master branch:

  • 9144287: 8318601: Remove javadoc text about restricted methods
  • 4010642: 8077371: Binary files in JAXP test should be removed
  • fe52917: 8318457: Use prefix-less prepend methods directly to reduce branches in String concat expressions
  • 71c99a0: 8318448: Link PopupMenu/PopupMenuLocation.java failure to JDK-8259913
  • 2c23391: 8318101: Additional test cases for CSSAttributeEqualityBug
  • deadb9c: 8304684: Memory leak in DirectivesParser::set_option_flag
  • a03767c: 8318049: C2: assert(!failure) failed: Missed optimization opportunity in PhaseIterGVN
  • 848ecc1: 8318538: Add a way to obtain a strided var handle from a layout
  • b07da3a: 8317819: Scope should reflect lifetime of underying resource (mainline)
  • 6f1d896: 8318510: Serial: Remove TenuredGeneration::block_size
  • ... and 100 more: https://git.openjdk.org/jdk/compare/6273ab97dc1a0d3c1f51ba94694d9594dd7593d4...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 20, 2023
@openjdk openjdk bot closed this Oct 20, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Oct 20, 2023
@openjdk
Copy link

openjdk bot commented Oct 20, 2023

@VladimirKempik @Ilyagavrilin Pushed as commit 5a97411.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org hotspot hotspot-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
5 participants