Skip to content

Conversation

@RealFYang
Copy link
Member

@RealFYang RealFYang commented Dec 18, 2024

Hi, please consider this cleanup change.

Currently, we have mixed use of addi and add(int64_t)/sub(int64_t). The former adds a 12-bit immediate while the latter
does not have a constraint on the immediate range. We should use addi when possible, which would help save one runtime check about the immediate range and avoid the use of one tmp register by the latter as well.

In order to make the code more readable, this also introduces helper routines subi/subiw and adapts callsites of addi/addiw with negative immediates.

 <Design of the RISC-V Instruction Set Architecture>:

 There is no SUBI instruction, because ADDI with a negative immediate is almost equivalent. The one
 exception arises from the asymmetry of the twos complement representation: SUBI with an immediate of
 -2048 would add 2048 to a register, which ADDI is incapable of.

Testing on Premier-P550 SBC running Ubuntu-24.04:

  • tier1-3 and gtest:all (release)
  • hotspot:tier1 (fastdebug)

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-8346478: RISC-V: Refactor add/sub assembler routines (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22804

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 18, 2024

👋 Welcome back fyang! 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
Copy link

openjdk bot commented Dec 18, 2024

@RealFYang 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:

8346478: RISC-V: Refactor add/sub assembler routines

Reviewed-by: fjiang, rehn, gcao

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

  • 8eddf67: 8346887: DrawFocusRect() may cause an assertion failure
  • a46ae70: 8339728: [Accessibility,Windows,JAWS] Bug in the getKeyChar method of the AccessBridge class
  • 97dd06c: 8347299: Add annotations to test cases in LicenseTest
  • 0a35ebf: 8347297: Skip the RuntimeImageSymbolicLinksTest test on Windows when it is executed outside of the jtreg
  • b3e8736: 8347296: WinInstallerUiTest fails in local test runs if the path to test work directory is longer that regular

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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
Copy link

openjdk bot commented Dec 18, 2024

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

  • hotspot
  • shenandoah

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 shenandoah shenandoah-dev@openjdk.org labels Dec 18, 2024
@RealFYang RealFYang marked this pull request as ready for review December 18, 2024 04:42
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 18, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 18, 2024

@RealFYang
Copy link
Member Author

/label remove shenandoah

@openjdk openjdk bot removed the shenandoah shenandoah-dev@openjdk.org label Dec 19, 2024
@openjdk
Copy link

openjdk bot commented Dec 19, 2024

@RealFYang
The shenandoah label was successfully removed.

@robehn
Copy link
Contributor

robehn commented Dec 20, 2024

Hey,

As we have instructions and and andi but in asm they are called andr and andi, I suggest we apply this to add/sub also?

@RealFYang
Copy link
Member Author

RealFYang commented Dec 20, 2024

Hey,

As we have instructions and and andi but in asm they are called andr and andi, I suggest we apply this to add/sub also?

Hi, that's exactly what I am thinking :-) I guess this might help with other naming issues as well.
I don't really like other macro-assember routine names such as MacroAssembler::ror_imm. I think it should be something simpler like MacroAssembler::ror. But we need to rename the Assembler::ror as Assembler::rorr first.

BTW: We cannot use names like and/xor/or because they are standard C++ operators. That's why we use andr/xorr/orr for RISC-V and other CPU platforms.

@RealFYang
Copy link
Member Author

RealFYang commented Dec 20, 2024

Let's take add for example, new proposal about the naming is:

Assembler::addr    ====> add two registers
Assembler::addi    ====> add one register and sign-extended 12-bit immediate

and

MacroAssembler::add(int64_t increment)    ====> add one register and any 64-bit immediate

Similar for rotate-right:

Assembler::rorr    ====> rotate right variable amount (Zbb)
Assembler::rori    ====> rotate right constant amount (sign-extended 12-bit immediate) (Zbb)

and

MacroAssembler::ror(Register amount)    ====> Use Zbb rorr if available and basic instructions otherwise
MacroAssembler::ror(uint32_t amount)    ====> Use Zbb rori if available and basic instructions otherwise

Let me know what you think. Thanks.

@robehn
Copy link
Contributor

robehn commented Dec 20, 2024

Yea, I think what you are suggesting seems good.

@RealFYang
Copy link
Member Author

RealFYang commented Dec 21, 2024

Yea, I think what you are suggesting seems good.

Thanks. I added one commit only handling naming of the rotate routines. I would keep this kind of change minimum unless we have similar issues like this. Also names like addr doesn't seem nice to me as it could be mis-interpreted as an abbreviation of address.

Copy link
Member

@zifeihan zifeihan 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 to me.

Copy link
Member

@feilongjiang feilongjiang 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! I have some minor comments.

@RealFYang
Copy link
Member Author

@feilongjiang @zifeihan : Thanks for the review!
@robehn : Are you OK with the latest version? Let me know if you have any further comments.

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.

Hey, sorry, I didn't understand/forgot over the holidays that you were waiting for me.

Yes, thanks!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 9, 2025
@RealFYang
Copy link
Member Author

Thanks all for the review!
/integrate

@openjdk
Copy link

openjdk bot commented Jan 9, 2025

Going to push as commit 8c87ea2.
Since your change was applied there have been 10 commits pushed to the master branch:

  • 765b9e6: 8346706: RISC-V: Add available registers to hs_err
  • d66737e: 8341097: GHA: Demote Mac x86 jobs to build only
  • dff5719: 8347126: gc/stress/TestStressG1Uncommit.java gets OOM-killed
  • 82e16ba: 8347268: [ubsan] logOutput.cpp:357:21: runtime error: applying non-zero offset 1 to null pointer
  • 33f9be8: 8347083: Incomplete logging in nsk/jvmti/ResourceExhausted/resexhausted00* tests
  • 8eddf67: 8346887: DrawFocusRect() may cause an assertion failure
  • a46ae70: 8339728: [Accessibility,Windows,JAWS] Bug in the getKeyChar method of the AccessBridge class
  • 97dd06c: 8347299: Add annotations to test cases in LicenseTest
  • 0a35ebf: 8347297: Skip the RuntimeImageSymbolicLinksTest test on Windows when it is executed outside of the jtreg
  • b3e8736: 8347296: WinInstallerUiTest fails in local test runs if the path to test work directory is longer that regular

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jan 9, 2025

@RealFYang Pushed as commit 8c87ea2.

💡 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

hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants