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

8282389: Add new vector operations to count leading and trailing zeros. #176

Closed
wants to merge 3 commits into from

Conversation

swati-sha
Copy link
Contributor

@swati-sha swati-sha commented Feb 25, 2022

Hi All,

Added support for new vector operations CLZ (count number of leading zeros) and CTZ (could number of trailing zeros) for all the integral vector types(Byte/Short/Integer/Long).
Added validation and performance tests corresponding the these operations in existing VectorAPI JTREG/JMH suite.

Kindly review and share your feedback.

Thanks and Regards,
Swati Sharma
Intel


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Issue

  • JDK-8282389: Add new vector operations to count leading and trailing zeros.

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/panama-vector pull/176/head:pull/176
$ git checkout pull/176

Update a local copy of the PR:
$ git checkout pull/176
$ git pull https://git.openjdk.java.net/panama-vector pull/176/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 176

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/panama-vector/pull/176.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 25, 2022

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

@swati-sha
Copy link
Contributor Author

/label add panama-dev

@openjdk openjdk bot added the rfr label Feb 25, 2022
@openjdk
Copy link

openjdk bot commented Feb 25, 2022

@swati-sha
The label panama is not a valid label.
These labels are valid:

@mlbridge
Copy link

mlbridge bot commented Feb 25, 2022

Webrevs

Copy link
Member

@jatin-bhateja jatin-bhateja left a comment

Choose a reason for hiding this comment

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

LGTM.

@jatin-bhateja
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Feb 28, 2022

@swati-sha 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:

8282389: Add new vector operations to count leading and trailing zeros.

Reviewed-by: jbhateja, psandoz

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 1 new commit pushed to the vectorIntrinsics branch:

  • d829111: Fix compilation error in perf reduction tests

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

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 (@jatin-bhateja, @PaulSandoz) 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 label Feb 28, 2022
@openjdk
Copy link

openjdk bot commented Feb 28, 2022

@jatin-bhateja The change author (@swati-sha) must issue an integrate command before the integration can be sponsored.

@@ -1626,6 +1628,8 @@ DoubleVector abs() {





Copy link
Member

Choose a reason for hiding this comment

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

Please remove these lines.

Comment on lines 58 to 59
VECTOR_OP_CTZ = 29,
VECTOR_OP_CLZ = 30,

Choose a reason for hiding this comment

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

Seems weird, could you please either move these two to the end of this enum or set the number to "4, 5"?

@@ -1788,6 +1794,14 @@ static int bitCount(byte a) {
return Integer.bitCount((int)a & 0xFF);
}

static int numberOfTrailingZeros(byte a) {
return a != 0 ? Integer.numberOfTrailingZeros(a) : 8;

Choose a reason for hiding this comment

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

Integer.numberOfTrailingZeros((int)a & 0xFF) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it not return incorrect value for a=0.

Copy link
Member

Choose a reason for hiding this comment

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

This could be Integer.numberOfTrailingZeros(a | 0x100);

Copy link
Member

Choose a reason for hiding this comment

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

And I think what he meant was the calculation of the numberOfLeadingZeros below

Copy link
Member

@jatin-bhateja jatin-bhateja Mar 3, 2022

Choose a reason for hiding this comment

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

numberOfTrailingZeros

Having a special case for zero will be better from performance perspective in slow path.
We may incur one additional comparison but given that C2 will intrinsify at a VectorSupport.unaryOp level it will not hurt compiled code performance but special handlings improve fallback code performance.

@XiaohongGong
Copy link

Could you please update the copyright year to "2022" for all the modified files? Thanks!

@@ -5310,6 +5318,92 @@ static void BIT_COUNTMaskedByte128VectorTests(IntFunction<byte[]> fa,




static byte CTZ(byte a) {
return (byte)(CTZ_scalar(a));

Choose a reason for hiding this comment

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

Why not directly return (byte) (a != 0 ? Integer.numberOfTrailingZeros(a) : 8); in this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To keep minimal changes in the test generation template, we want to keep one interface which caters to all the primitive types.

@@ -452,6 +452,10 @@ static boolean opKind(Operator op, int bit) {
public static final Unary NEG = unary("NEG", "-a", VectorSupport.VECTOR_OP_NEG, VO_ALL|VO_SPECIAL);
/** Produce {@code bitCount(a)} */
public static final Unary BIT_COUNT = unary("BIT_COUNT", "bitCount", VectorSupport.VECTOR_OP_BIT_COUNT, VO_NOFP);
/** Produce {@code numberOfTrailingZeros(a)} */
public static final Unary CTZ = unary("CTZ", "numberOfTrailingZeros", VectorSupport.VECTOR_OP_CTZ, VO_NOFP);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be more verbose in the names, as they will not be well understood by developers. Specifically TRAILING_ZEROS_COUNT and LEADING_ZEROS_COUNT, and be consistent in other places. Internally we could shorten to VECTOR_OP_TZ_COUNT etc. to reduce the horizontal width.

@swati-sha
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor label Mar 6, 2022
@openjdk
Copy link

openjdk bot commented Mar 6, 2022

@swati-sha
Your change (at version 4304bc3) is now ready to be sponsored by a Committer.

@jatin-bhateja
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Mar 6, 2022

Going to push as commit 801f1fd.
Since your change was applied there has been 1 commit pushed to the vectorIntrinsics branch:

  • d829111: Fix compilation error in perf reduction tests

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated label Mar 6, 2022
@openjdk openjdk bot closed this Mar 6, 2022
@openjdk
Copy link

openjdk bot commented Mar 6, 2022

@jatin-bhateja @swati-sha Pushed as commit 801f1fd.

💡 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
Development

Successfully merging this pull request may close these issues.

6 participants