Skip to content

Commit 34c2798

Browse files
author
Raghuveer Devulapalli
committed
generalize key-value sort for all 64-bit combinations
1 parent 472c7d0 commit 34c2798

File tree

3 files changed

+13
-32
lines changed

3 files changed

+13
-32
lines changed

src/avx512-64bit-keyvaluesort.hpp

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -439,34 +439,20 @@ void qsort_64bit_(type1_t *keys,
439439
}
440440
}
441441

442-
template <>
443-
void avx512_qsort_kv<int64_t>(int64_t *keys, uint64_t *indexes, int64_t arrsize)
442+
template <typename T1, typename T2>
443+
void avx512_qsort_kv(T1 *keys, T2 *indexes, int64_t arrsize)
444444
{
445445
if (arrsize > 1) {
446-
qsort_64bit_<zmm_vector<int64_t>, zmm_vector<uint64_t>>(
447-
keys, indexes, 0, arrsize - 1, 2 * (int64_t)log2(arrsize));
448-
}
449-
}
450-
451-
template <>
452-
void avx512_qsort_kv<uint64_t>(uint64_t *keys,
453-
uint64_t *indexes,
454-
int64_t arrsize)
455-
{
456-
if (arrsize > 1) {
457-
qsort_64bit_<zmm_vector<uint64_t>, zmm_vector<uint64_t>>(
458-
keys, indexes, 0, arrsize - 1, 2 * (int64_t)log2(arrsize));
459-
}
460-
}
461-
462-
template <>
463-
void avx512_qsort_kv<double>(double *keys, uint64_t *indexes, int64_t arrsize)
464-
{
465-
if (arrsize > 1) {
466-
int64_t nan_count = replace_nan_with_inf<zmm_vector<double>>(keys, arrsize);
467-
qsort_64bit_<zmm_vector<double>, zmm_vector<uint64_t>>(
468-
keys, indexes, 0, arrsize - 1, 2 * (int64_t)log2(arrsize));
469-
replace_inf_with_nan(keys, arrsize, nan_count);
446+
if constexpr (std::is_floating_point_v<T1>) {
447+
int64_t nan_count = replace_nan_with_inf<zmm_vector<double>>(keys, arrsize);
448+
qsort_64bit_<zmm_vector<T1>, zmm_vector<T2>>(
449+
keys, indexes, 0, arrsize - 1, 2 * (int64_t)log2(arrsize));
450+
replace_inf_with_nan(keys, arrsize, nan_count);
451+
}
452+
else {
453+
qsort_64bit_<zmm_vector<T1>, zmm_vector<T2>>(
454+
keys, indexes, 0, arrsize - 1, 2 * (int64_t)log2(arrsize));
455+
}
470456
}
471457
}
472458
#endif // AVX512_QSORT_64BIT_KV

src/avx512-common-qsort.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,4 @@ inline void avx512_partial_qsort_fp16(uint16_t *arr, int64_t k, int64_t arrsize,
726726
avx512_qselect_fp16(arr, k - 1, arrsize, hasnan);
727727
avx512_qsort_fp16(arr, k - 1);
728728
}
729-
730-
// key-value sort routines
731-
template <typename T>
732-
void avx512_qsort_kv(T *keys, uint64_t *indexes, int64_t arrsize);
733-
734729
#endif // AVX512_QSORT_COMMON

tests/test-keyvalue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ TYPED_TEST_P(KeyValueSort, test_64bit_random_data)
5454
std::sort(sortedarr.begin(),
5555
sortedarr.end(),
5656
compare<TypeParam, uint64_t>);
57-
avx512_qsort_kv<TypeParam>(keys.data(), values.data(), keys.size());
57+
avx512_qsort_kv(keys.data(), values.data(), keys.size());
5858
for (size_t i = 0; i < keys.size(); i++) {
5959
ASSERT_EQ(keys[i], sortedarr[i].key);
6060
ASSERT_EQ(values[i], sortedarr[i].value);

0 commit comments

Comments
 (0)