Skip to content

8318225: RISC-V: C2 UModI #16394

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

Closed
wants to merge 1 commit into from

Conversation

Hamlin-Li
Copy link

@Hamlin-Li Hamlin-Li commented Oct 27, 2023

Hi,
Can you review the change to add intrinsic for UModI and UModL?
( This is a quite similar patch to #16346, which addresses UDivI and UDivL, so for the performance consideration please also check the discussion in that pr. )
Thanks!

Tests

Functionality

Run tests successfully found via grep -nr test/jdk/ -we remainderUnsigned and grep -nr test/hotspot/ -we remainderUnsigned

Performance

Long

NOTE: for positive divisor, it's the common case; for negative divisor, it's a rare case

Before

LongDivMod.testRemainderUnsigned                 1024          mixed  avgt   10  21222.911 ± 57.735  ns/op
LongDivMod.testRemainderUnsigned                 1024       positive  avgt   10  28841.429 ±  6.294  ns/op
LongDivMod.testRemainderUnsigned                 1024       negative  avgt   10   7733.038 ±  3.856  ns/op

After

LongDivMod.testRemainderUnsigned                 1024          mixed  avgt   10  22666.448 ± 34.986  ns/op
LongDivMod.testRemainderUnsigned                 1024       positive  avgt   10  15967.846 ± 24.805  ns/op
LongDivMod.testRemainderUnsigned                 1024       negative  avgt   10  29507.865 ± 20.593  ns/op

Integer

Before

IntegerDivMod.testRemainderUnsigned                 1024          mixed  avgt   10  23396.475 ± 24.065  ns/op
IntegerDivMod.testRemainderUnsigned                 1024       positive  avgt   10  16796.796 ±  3.389  ns/op
IntegerDivMod.testRemainderUnsigned                 1024       negative  avgt   10  30159.407 ±  6.716  ns/op

After

IntegerDivMod.testRemainderUnsigned                 1024          mixed  avgt   10  23216.710 ± 14.351  ns/op
IntegerDivMod.testRemainderUnsigned                 1024       positive  avgt   10  16621.374 ±  3.203  ns/op
IntegerDivMod.testRemainderUnsigned                 1024       negative  avgt   10  30002.088 ± 41.212  ns/op


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

Issues

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16394

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 27, 2023

👋 Welcome back mli! 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 27, 2023
@openjdk
Copy link

openjdk bot commented Oct 27, 2023

@Hamlin-Li The following label will be automatically applied to this pull request:

  • hotspot

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

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Oct 27, 2023
@Hamlin-Li
Copy link
Author

/solves JDK-8318226

@mlbridge
Copy link

mlbridge bot commented Oct 27, 2023

Webrevs

@openjdk
Copy link

openjdk bot commented Oct 27, 2023

@Hamlin-Li
Adding additional issue to solves list: 8318226: RISC-V: C2 UModL.

@robehn
Copy link
Contributor

robehn commented Oct 27, 2023

Looks good, but these numbers:

LongDivMod.testRemainderUnsigned                 1024       negative  avgt   10     7733.038 ±  3.856  ns/op
IntegerDivMod.testRemainderUnsigned             1024       negative  avgt   10  30159.407 ±  6.716  ns/op

What up here ? How come in before case Long is 4-5x faster than Integer?

I don't see an explanation in other PR either ?

@Hamlin-Li
Copy link
Author

Hamlin-Li commented Oct 27, 2023

Good find.

Let me try to explain.

For l.l.Long, remainderUnsigned has a quick path for negative divisor (This was similar discussion about div case in #16346), it's much quicker than the case of positive divisor.

For j.l.Integer

    public static int remainderUnsigned(int dividend, int divisor) {
        // In lieu of tricky code, for now just use long arithmetic.
        return (int)(toUnsignedLong(dividend) % toUnsignedLong(divisor));
    }

it will call Long's rem, and the value of divisor passed to Long rem will be positive in the sense of Long.
To verify this, you can compare the Long's rem data before the patch, positive one is much lower than negative one.

LongDivMod.testRemainderUnsigned                 1024       positive  avgt   10  28841.429 ±  6.294  ns/op
LongDivMod.testRemainderUnsigned                 1024       negative  avgt   10   7733.038 ±  3.856  ns/op

Hope this answers your question.

@VladimirKempik
Copy link

VladimirKempik commented Oct 27, 2023

So, you win 45% on
LongDivMod.testRemainderUnsigned 1024 positive

but loose almost 4x on
LongDivMod.testRemainderUnsigned 1024 negative

Does this intrinsic ( for LONGs) make sense at all? or better leave it as is ?
Nevermind, I see #16346 (comment)

Copy link
Contributor

@robehn robehn left a comment

Choose a reason for hiding this comment

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

As you already discussed all other things in other PR, thanks!

@openjdk
Copy link

openjdk bot commented Oct 27, 2023

@Hamlin-Li 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:

8318225: RISC-V: C2 UModI
8318226: RISC-V: C2 UModL

Reviewed-by: luhenry, rehn, fyang

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 16 new commits pushed to the master branch:

  • 96bec35: 8316996: Catalog API Enhancement: add a factory method
  • d226014: 8318850: Duplicate code in the LCMSImageLayout
  • c593f8b: 8318091: Remove empty initIDs functions
  • 4f9f195: 8318753: hsdis binutils may place libs in lib64
  • 2915d74: 8318837: javac generates wrong ldc instruction for dynamic constant loads
  • ddd0716: 8317661: [REDO] store/load order not preserved when handling memory pool due to weakly ordered memory architecture of aarch64
  • 141dae8: 8318811: Compiler directives parser swallows a character after line comments
  • 667cca9: 8288899: java/util/concurrent/ExecutorService/CloseTest.java failed with "InterruptedException: sleep interrupted"
  • b9dcd4b: 8318964: Fix build failures caused by 8315097
  • d52a995: 8315097: Rename createJavaProcessBuilder
  • ... and 6 more: https://git.openjdk.org/jdk/compare/a9b31b587c7487b2222773debde1ce2227884959...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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 27, 2023
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.

And JMH result on hifive unmatched board for reference:
Before:

LongDivMod.testRemainderUnsigned                 1024          mixed  avgt   15  26377.726 ?  535.884  ns/op
LongDivMod.testRemainderUnsigned                 1024       positive  avgt   15  36251.980 ?   23.214  ns/op
LongDivMod.testRemainderUnsigned                 1024       negative  avgt   15   8441.098 ?    9.375  ns/op
IntegerDivMod.testRemainderUnsigned                 1024          mixed  avgt   15  28501.570 ?  14.628  ns/op
IntegerDivMod.testRemainderUnsigned                 1024       positive  avgt   15  20226.145 ?  19.112  ns/op
IntegerDivMod.testRemainderUnsigned                 1024       negative  avgt   15  37002.906 ?  34.361  ns/op

After:

LongDivMod.testRemainderUnsigned                 1024          mixed  avgt   15  27140.089 ? 17.391  ns/op
LongDivMod.testRemainderUnsigned                 1024       positive  avgt   15  18772.742 ? 18.943  ns/op
LongDivMod.testRemainderUnsigned                 1024       negative  avgt   15  35780.310 ? 28.929  ns/op
IntegerDivMod.testRemainderUnsigned                 1024          mixed  avgt   15  27864.893 ? 15.551  ns/op
IntegerDivMod.testRemainderUnsigned                 1024       positive  avgt   15  19585.612 ? 17.651  ns/op
IntegerDivMod.testRemainderUnsigned                 1024       negative  avgt   15  36366.167 ? 18.933  ns/op

@Hamlin-Li
Copy link
Author

@RealFYang Thanks for testing!

@Hamlin-Li
Copy link
Author

/integrate
Thanks all for your reviewing.

@openjdk
Copy link

openjdk bot commented Oct 28, 2023

Going to push as commit 1ec0d02.
Since your change was applied there have been 16 commits pushed to the master branch:

  • 96bec35: 8316996: Catalog API Enhancement: add a factory method
  • d226014: 8318850: Duplicate code in the LCMSImageLayout
  • c593f8b: 8318091: Remove empty initIDs functions
  • 4f9f195: 8318753: hsdis binutils may place libs in lib64
  • 2915d74: 8318837: javac generates wrong ldc instruction for dynamic constant loads
  • ddd0716: 8317661: [REDO] store/load order not preserved when handling memory pool due to weakly ordered memory architecture of aarch64
  • 141dae8: 8318811: Compiler directives parser swallows a character after line comments
  • 667cca9: 8288899: java/util/concurrent/ExecutorService/CloseTest.java failed with "InterruptedException: sleep interrupted"
  • b9dcd4b: 8318964: Fix build failures caused by 8315097
  • d52a995: 8315097: Rename createJavaProcessBuilder
  • ... and 6 more: https://git.openjdk.org/jdk/compare/a9b31b587c7487b2222773debde1ce2227884959...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 28, 2023

@Hamlin-Li Pushed as commit 1ec0d02.

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

@Hamlin-Li Hamlin-Li deleted the remainderUnsigned branch February 27, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants