From f8793f71abc2dec030d8e92cfd9dc52f4c8a90fa Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Tue, 16 Aug 2022 18:59:18 +0200 Subject: [PATCH] more ILP in some nearly sorted bucket parts in spsort - rand still not good so much --- space_partitioning_sort/spsort.h | 22 ++++++++++++---------- ypsu.cpp | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/space_partitioning_sort/spsort.h b/space_partitioning_sort/spsort.h index 6482006..c406526 100644 --- a/space_partitioning_sort/spsort.h +++ b/space_partitioning_sort/spsort.h @@ -139,15 +139,18 @@ inline int internal_array_separate(uint32_t *t, int n, uint32_t mid) { int left = 0; int right = n - 1; while(left < right) { - bool lok = (t[left] < mid); - bool rok = (t[right] >= mid); - if(lok || rok) { - // HOT PATH - // Move heads until both in wrong location - left += lok; - right -= rok; - } else { - // REGULAR PATH + // Step over already good positioned values from left + while((left < right) && (t[left] < mid)) { + ++left; + } + + // Step over already good positioned values from right + while((left < right) && (t[right] >= mid)) { + --right; + } + + // Extra check needed for edge-case! + if(left < right) { // Both in wrong location - xchg them! auto tmp = t[right]; t[right] = t[left]; @@ -159,7 +162,6 @@ inline int internal_array_separate(uint32_t *t, int n, uint32_t mid) { // Edge-case increment if single elem happens in middle in the end left += ((left == right) && (t[left] < mid)); - return left; } diff --git a/ypsu.cpp b/ypsu.cpp index 2a1ae86..3b80e25 100644 --- a/ypsu.cpp +++ b/ypsu.cpp @@ -419,8 +419,8 @@ //int n = 64; // Uncomment this for profiling and alg! - measure_single(n); - return 0; + //measure_single(n); + //return 0; for (auto inputtype : inputtypes) { printf("%10s", inputtype.c_str());