more ILP in some nearly sorted bucket parts in spsort - rand still not good so much

This commit is contained in:
Richard Thier 2022-08-16 18:59:18 +02:00
parent 4bed99751f
commit f8793f71ab
2 changed files with 14 additions and 12 deletions

View File

@ -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;
}

View File

@ -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());