Skip to content

Commit

Permalink
include/oneapi/dpl/pstl/hetero/dpcpp/parallel_backend_sycl_merge_sort…
Browse files Browse the repository at this point in the history
….h - avoid loops and condition checks for small data sizes in __subgroup_bubble_sorter::sort

Signed-off-by: Sergey Kopienko <[email protected]>
  • Loading branch information
SergeyKopienko committed Sep 24, 2024
1 parent 6869456 commit 57f9caf
Showing 1 changed file with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,39 @@ struct __subgroup_bubble_sorter
void
sort(const _StorageAcc& __storage_acc, _Compare __comp, std::uint32_t __start, std::uint32_t __end) const
{
bool __changed = true;
using _IndexType = std::make_signed_t<decltype(__end)>;

for (std::uint32_t i = __start; i < __end && __changed; ++i)
{
__changed = false;
_IndexType __n = __end - __start;

for (std::uint32_t j = __start + 1; j < __start + __end - i; ++j)
switch (__n)
{
case 0:
case 1:
break;
case 2:
{
auto& __first_item = __storage_acc[j - 1];
auto& __second_item = __storage_acc[j];
auto& __first_item = __storage_acc[__start];
auto& __second_item = __storage_acc[__start + 1];
if (__comp(__second_item, __first_item))
{
std::swap(__first_item, __second_item);
__changed = true;
}
}
break;
default:
do
{
_IndexType __new_n = 0;
for (_IndexType __i = 1; __i < __n; ++__i)
{
auto& __first_item = __storage_acc[__start + __i - 1];
auto& __second_item = __storage_acc[__start + __i];
if (__comp(__second_item, __first_item))
{
std::swap(__first_item, __second_item);
__new_n = __i;
}
}
__n = __new_n;
} while (__n > 1);
}
}
};
Expand Down

0 comments on commit 57f9caf

Please sign in to comment.