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

8290034: Auto vectorize reverse bit operations. #9535

Closed
wants to merge 4 commits into from

Conversation

jatin-bhateja
Copy link
Member

@jatin-bhateja jatin-bhateja commented Jul 18, 2022

Summary of changes:

  • Intrinsify scalar bit reverse APIs to emit efficient instruction sequence for X86 targets with and w/o GFNI feature.
  • Handle auto-vectorization of Integer/Long.reverse bit operations.
  • Backend implementation for these were added with 4th incubation of VectorAPIs.

Following are performance number for newly added JMH mocro benchmarks:-

No-GFNI(CLX):
=============
Baseline:
Benchmark         (size)  Mode  Cnt  Score   Error  Units
Integers.reverse     500  avgt    2  1.085          us/op
Longs.reverse        500  avgt    2  1.236          us/op
WithOpt:
Benchmark         (size)  Mode  Cnt  Score   Error  Units
Integers.reverse     500  avgt    2  0.104          us/op
Longs.reverse        500  avgt    2  0.255          us/op

With-GFNI(ICX):
===============
Baseline:
Benchmark         (size)  Mode  Cnt  Score   Error  Units
Integers.reverse     500  avgt    2  0.887          us/op
Longs.reverse        500  avgt    2  1.095          us/op

Without:
Benchmark         (size)  Mode  Cnt  Score   Error  Units
Integers.reverse     500  avgt    2  0.037          us/op
Longs.reverse        500  avgt    2  0.145          us/op

Kindly review and share feedback.

Best Regards,
Jatin


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

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9535

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

Using diff file

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

@jatin-bhateja
Copy link
Member Author

/label add hotspot-compiler-dev

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 18, 2022

👋 Welcome back jbhateja! 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 rfr Pull request is ready for review hotspot-compiler hotspot-compiler-dev@openjdk.org labels Jul 18, 2022
@openjdk
Copy link

openjdk bot commented Jul 18, 2022

@jatin-bhateja
The hotspot-compiler label was successfully added.

@mlbridge
Copy link

mlbridge bot commented Jul 18, 2022

Webrevs

Copy link

@XiaohongGong XiaohongGong left a comment

Choose a reason for hiding this comment

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

Common codes looks good to me. Just some style issues.

}
const TypeInt* t1int = t1->isa_int();
if (t1int && t1int->is_con()) {
jint res = reverse_bits(t1int->get_con());

Choose a reason for hiding this comment

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

There is one more space between res = reverse_bits

}

const Type* ReverseLNode::Value(PhaseGVN* phase) const {
const Type *t1 = phase->type( in(1) );

Choose a reason for hiding this comment

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

The same with "ReverseINode::Value"

}
const TypeLong* t1long = t1->isa_long();
if (t1long->is_con()) {
jint res = reverse_bits(t1long->get_con());

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

@vnkozlov vnkozlov 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 submitted testing.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Testing passed.

@openjdk
Copy link

openjdk bot commented Jul 21, 2022

@jatin-bhateja 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:

8290034: Auto vectorize reverse bit operations.

Reviewed-by: xgong, kvn

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

  • 348a052: 8290846: sun/tools/jstatd/JstatdTest* tests should use VM options
  • bc6a3c7: 8290739: Simplify storage of dump-time class information
  • 16a1275: 8290943: Fix several IR test issues on SVE after JDK-8289801
  • c1a3347: 8291358: Fix the "overridding" typo
  • 37b08c7: 8237913: G1CollectedHeap::heap_region_containing shouldn't be a template
  • dc74ea2: 8291048: x86: compiler/c2/irTests/TestAutoVectorization2DArray.java fails with lower SSE

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 openjdk bot added the ready Pull request is ready to be integrated label Jul 21, 2022
Copy link

@XiaohongGong XiaohongGong 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! Thanks!

@jatin-bhateja
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 28, 2022

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

  • 348a052: 8290846: sun/tools/jstatd/JstatdTest* tests should use VM options
  • bc6a3c7: 8290739: Simplify storage of dump-time class information
  • 16a1275: 8290943: Fix several IR test issues on SVE after JDK-8289801
  • c1a3347: 8291358: Fix the "overridding" typo
  • 37b08c7: 8237913: G1CollectedHeap::heap_region_containing shouldn't be a template
  • dc74ea2: 8291048: x86: compiler/c2/irTests/TestAutoVectorization2DArray.java fails with lower SSE

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jul 28, 2022

@jatin-bhateja Pushed as commit 5d82d67.

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

@@ -1899,3 +1899,50 @@ const Type* SqrtFNode::Value(PhaseGVN* phase) const {
if( f < 0.0f ) return Type::FLOAT;
return TypeF::make( (float)sqrt( (double)f ) );
}

static jlong reverse_bits(jlong val) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is wrong and/or misnamed.
It should be called reverse_bits_in_bytes.

}
const TypeInt* t1int = t1->isa_int();
if (t1int && t1int->is_con()) {
jint res = reverse_bits(t1int->get_con());
Copy link
Contributor

Choose a reason for hiding this comment

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

This is clearly wrong, if I understand correctly that ReverseI is an intrinsic for Integer::reverse, which reverses not only bits in bytes but also the bytes themselves.

Also, it seems noxious (IIUC) because it widens t1int's con to 64 bits with sign extension, does some sort of 64-bit reversal operation, and then chops off the high order bits assigning to res.

The root cause here is that reverse_bits should be properly factored out and maintained in its own modular header file, akin to utilities/powerOfTwo.hpp. I suggest utilities/moveBits.hpp, to hold bits-in-bytes reversal, byte reversal, full reversal, compress/expand (with which it should be grouped) and who knows what other future permutations.

I say it's a root cause in that something randomly coded in the bowels of subnode.cpp cannot be properly reviewed in isolation, especially if it is misnamed.

Also, the nearly identical use of the HD algorithm in code/compressedStream.cpp should use the new version in the header file.

The new hand-written assembly code for this changeset should refer the reader to utilities/moveBits.hpp as well.

@jatin-bhateja jatin-bhateja deleted the JDK-8290034 branch January 20, 2023 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
4 participants