-
Enhancement
-
Resolution: Unresolved
-
P4
-
24
Examples:
for (int i = fromIndex; i < end; i++) {
result = 31 * result + a[i];
}
@Benchmark
public int nativeSegmentJava() {
int result = 1;
for (long i = 0; i < ELEM_SIZE; i++) {
result = 31 * result + nativeSegment.get(JAVA_BYTE, i);
}
return result;
}
Basic idea, this reformulation:
result = result * 31^N + a[0] * 31^(N-1) + ... a[i] * 32^ (N-1-i) ... + a[N-2] * 31 + a[N-1]
All the values can thus be calculated in parallel.
This work would generallize the intrinsics we already have for strings:
https://bugs.openjdk.org/browse/JDK-8282664
https://github.com/openjdk/jdk/pull/10847
Other previous investigation:
https://inside.java/2021/01/27/extending-c2-autovectorization-capabilities/
A further generalization would to vectorize prefix-sums and more generally scans:
https://eme64.github.io/blog/2023/11/03/C2-AutoVectorizer-Improvement-Ideas.html
for (int i = fromIndex; i < end; i++) {
result = 31 * result + a[i];
}
@Benchmark
public int nativeSegmentJava() {
int result = 1;
for (long i = 0; i < ELEM_SIZE; i++) {
result = 31 * result + nativeSegment.get(JAVA_BYTE, i);
}
return result;
}
Basic idea, this reformulation:
result = result * 31^N + a[0] * 31^(N-1) + ... a[i] * 32^ (N-1-i) ... + a[N-2] * 31 + a[N-1]
All the values can thus be calculated in parallel.
This work would generallize the intrinsics we already have for strings:
https://bugs.openjdk.org/browse/JDK-8282664
https://github.com/openjdk/jdk/pull/10847
Other previous investigation:
https://inside.java/2021/01/27/extending-c2-autovectorization-capabilities/
A further generalization would to vectorize prefix-sums and more generally scans:
https://eme64.github.io/blog/2023/11/03/C2-AutoVectorizer-Improvement-Ideas.html
- relates to
-
JDK-8282664 Unroll by hand StringUTF16 and StringLatin1 polynomial hash loops
- Resolved
-
JDK-8294432 Add provisions to calculate hash values from MemorySegments
- Resolved