|
| 1 | +#include "test-qsort-common.h" |
| 2 | + |
| 3 | +template <typename T> |
| 4 | +class avx512_sort_partialrange : public ::testing::Test { |
| 5 | +}; |
| 6 | +TYPED_TEST_SUITE_P(avx512_sort_partialrange); |
| 7 | + |
| 8 | +TYPED_TEST_P(avx512_sort_partialrange, test_arrsizes) |
| 9 | +{ |
| 10 | + int64_t arrsize = 1024; |
| 11 | + int64_t nranges = 500; |
| 12 | + |
| 13 | + if (cpu_has_avx512bw()) { |
| 14 | + if ((sizeof(TypeParam) == 2) && (!cpu_has_avx512_vbmi2())) { |
| 15 | + GTEST_SKIP() << "Skipping this test, it requires avx512_vbmi2"; |
| 16 | + } |
| 17 | + std::vector<TypeParam> arr; |
| 18 | + std::vector<TypeParam> sortedarr; |
| 19 | + std::vector<TypeParam> prsortedarr; |
| 20 | + /* Random array */ |
| 21 | + arr = get_uniform_rand_array<TypeParam>(arrsize); |
| 22 | + sortedarr = arr; |
| 23 | + /* Sort with std::sort for comparison */ |
| 24 | + std::sort(sortedarr.begin(), sortedarr.end()); |
| 25 | + |
| 26 | + int64_t lb, ub; |
| 27 | + std::vector<int64_t> inds; |
| 28 | + for (size_t ii = 0; ii < nranges; ++ii) { |
| 29 | + prsortedarr = arr; |
| 30 | + |
| 31 | + /* Pick a random start and end for the range */ |
| 32 | + inds = get_uniform_rand_array<int64_t>(2, arrsize, 1); |
| 33 | + std::sort(inds.begin(), inds.end()); |
| 34 | + lb = inds[0], ub = inds[1]; |
| 35 | + |
| 36 | + /* Sort the range and verify all the required elements match the presorted set */ |
| 37 | + avx512_qsort_partialrange<TypeParam>(lb, ub, prsortedarr.data(), prsortedarr.size()); |
| 38 | + for (size_t k = (lb-1); k < ub; ++k) { |
| 39 | + ASSERT_EQ(sortedarr[k], prsortedarr[k]); |
| 40 | + } |
| 41 | + |
| 42 | + prsortedarr.clear(); |
| 43 | + } |
| 44 | + |
| 45 | + arr.clear(); |
| 46 | + sortedarr.clear(); |
| 47 | + } |
| 48 | + else { |
| 49 | + GTEST_SKIP() << "Skipping this test, it requires avx512bw"; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +REGISTER_TYPED_TEST_SUITE_P(avx512_sort_partialrange, test_arrsizes); |
0 commit comments