RFR: 8309130: x86_64 AVX512 intrinsics for Arrays.sort methods (int, long, float and double arrays) [v13]
Srinivas Vamsi Parasa
duke at openjdk.org
Tue Aug 1 17:42:54 UTC 2023
On Sun, 30 Jul 2023 08:24:20 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/Arrays.java line 100:
>>
>>> 98: else if (elemType == float.class) DualPivotQuicksort.sort((float[]) array, 0, fromIndex, toIndex);
>>> 99: else if (elemType == double.class) DualPivotQuicksort.sort((double[]) array, 0, fromIndex, toIndex);
>>> 100: else throw new UnsupportedOperationException("arraySort intrinsic not supported for this type: " + elemType.toString());
>>
>> I'm curious if there is a performance difference using switch pattern on element type that would generate an `invokedynamic typeSwitch` over the primitive array types e.g.:
>>
>> Suggestion:
>>
>> switch (array) {
>> case int[] arr -> DualPivotQuicksort.sort(arr, 0, fromIndex, toIndex);
>> case long[] arr -> DualPivotQuicksort.sort(arr, 0, fromIndex, toIndex);
>> case float[] arr -> DualPivotQuicksort.sort(arr, 0, fromIndex, toIndex);
>> case double[] arr -> DualPivotQuicksort.sort(arr, 0, fromIndex, toIndex);
>> default -> throw new UnsupportedOperationException(
>> "arraySort intrinsic not supported for this type: " + elemType);
>> }
>
> What is the reasoning behind this new public API? It doesn't follow the usual Java convention, which is to have overloads for each type. And it doesn't seem to provide anything not already provided by `Arrays.sort()`.
Hi Andrew, the reason for the public API is to make AVX512 sort available to other data structures like MemorySegment (including the ones backed by native heap). The API of the arraySort() AVX512 intrinsic is similar to the public API of ArraysSupport.vectorizedMismatch() which is used by MemorySegment.mismatch().
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14227#discussion_r1280953141
More information about the hotspot-compiler-dev
mailing list