File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -596,7 +596,7 @@ X86_SIMD_SORT_INLINE void xss_argsort(T *arr,
596596 bool hasnan = false ,
597597 bool descending = false )
598598{
599- /* TODO optimization: on 32-bit, use full_vector for 32-bit dtype */
599+
600600 using vectype = typename std::conditional<sizeof (T) == sizeof (int32_t ),
601601 half_vector<T>,
602602 full_vector<T>>::type;
@@ -607,6 +607,7 @@ X86_SIMD_SORT_INLINE void xss_argsort(T *arr,
607607 full_vector<arrsize_t >>::type;
608608
609609 if (arrsize > 1 ) {
610+ /* simdargsort does not work for float/double arrays with nan */
610611 if constexpr (xss::fp::is_floating_point_v<T>) {
611612 if ((hasnan) && (array_has_nan<vectype>(arr, arrsize))) {
612613 std_argsort_withnan (arr, arg, 0 , arrsize);
@@ -618,6 +619,11 @@ X86_SIMD_SORT_INLINE void xss_argsort(T *arr,
618619 }
619620 UNUSED (hasnan);
620621
622+ /* early exit for already sorted arrays: float/double with nan never reach here*/
623+ auto comp = descending ? Comparator<vectype, true >::STDSortComparator
624+ : Comparator<vectype, false >::STDSortComparator;
625+ if (std::is_sorted (arr, arr + arrsize, comp)) { return ; }
626+
621627#ifdef XSS_COMPILE_OPENMP
622628
623629 bool use_parallel = arrsize > 10000 ;
You can’t perform that action at this time.
0 commit comments