Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/xss-common-argsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ X86_SIMD_SORT_INLINE void xss_argsort(T *arr,
bool hasnan = false,
bool descending = false)
{
/* TODO optimization: on 32-bit, use full_vector for 32-bit dtype */

using vectype = typename std::conditional<sizeof(T) == sizeof(int32_t),
half_vector<T>,
full_vector<T>>::type;
Expand All @@ -607,6 +607,7 @@ X86_SIMD_SORT_INLINE void xss_argsort(T *arr,
full_vector<arrsize_t>>::type;

if (arrsize > 1) {
/* simdargsort does not work for float/double arrays with nan */
if constexpr (xss::fp::is_floating_point_v<T>) {
if ((hasnan) && (array_has_nan<vectype>(arr, arrsize))) {
std_argsort_withnan(arr, arg, 0, arrsize);
Expand All @@ -618,6 +619,11 @@ X86_SIMD_SORT_INLINE void xss_argsort(T *arr,
}
UNUSED(hasnan);

/* early exit for already sorted arrays: float/double with nan never reach here*/
auto comp = descending ? Comparator<vectype, true>::STDSortComparator
: Comparator<vectype, false>::STDSortComparator;
if (std::is_sorted(arr, arr + arrsize, comp)) { return; }

#ifdef XSS_COMPILE_OPENMP

bool use_parallel = arrsize > 10000;
Expand Down