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,
596
596
bool hasnan = false ,
597
597
bool descending = false )
598
598
{
599
- /* TODO optimization: on 32-bit, use full_vector for 32-bit dtype */
599
+
600
600
using vectype = typename std::conditional<sizeof (T) == sizeof (int32_t ),
601
601
half_vector<T>,
602
602
full_vector<T>>::type;
@@ -607,6 +607,7 @@ X86_SIMD_SORT_INLINE void xss_argsort(T *arr,
607
607
full_vector<arrsize_t >>::type;
608
608
609
609
if (arrsize > 1 ) {
610
+ /* simdargsort does not work for float/double arrays with nan */
610
611
if constexpr (xss::fp::is_floating_point_v<T>) {
611
612
if ((hasnan) && (array_has_nan<vectype>(arr, arrsize))) {
612
613
std_argsort_withnan (arr, arg, 0 , arrsize);
@@ -618,6 +619,11 @@ X86_SIMD_SORT_INLINE void xss_argsort(T *arr,
618
619
}
619
620
UNUSED (hasnan);
620
621
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
+
621
627
#ifdef XSS_COMPILE_OPENMP
622
628
623
629
bool use_parallel = arrsize > 10000 ;
You can’t perform that action at this time.
0 commit comments