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

Fast Path StringCoding.countPostives and hasNegative for Power #21597

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

luke-li-2003
Copy link
Contributor

Fast path the StringCoding methods countPositives and hasNegative on Power, since their logics are similar, they can be implemented by a single instrinsic.

@luke-li-2003
Copy link
Contributor Author

Still a draft PR since I need to figure out a good way to deal with shorter arrays.

@luke-li-2003
Copy link
Contributor Author

… Power

Fast path the StringCoding methods countPositives and hasNegative on
Power, since their logics are similar, they can be implemented by a single
instrinsic.

Signed-off-by: Luke Li <[email protected]>
@luke-li-2003
Copy link
Contributor Author

luke-li-2003 commented Apr 8, 2025

For reference, this is what we are dealing with:

On jdk21+:

    public static boolean hasNegatives(byte[] ba, int off, int len) {
        return countPositives(ba, off, len) != len;
    }

    @IntrinsicCandidate
    public static int countPositives(byte[] ba, int off, int len) {
        int limit = off + len;
        for (int i = off; i < limit; i++) {
            if (ba[i] < 0) {
                return i - off;
            }
        }
        return len;
    }

Before jdk21:

    public static boolean hasNegatives(byte[] ba, int off, int len) {
        for (int i = off; i < off + len; i++) {
            if (ba[i] < 0) {
                return true;
            }
        }
        return false;
    }

@luke-li-2003
Copy link
Contributor Author

Performance: as outlined before it is not doing well for arrays shorter than byte[16]

build byte[1] 4 8 16 30 50 100
nightly 1100 325 217 107 34 19 14
fast path 478 175 97 40 41 144 77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant