try simpler branchless at cost of extra swaps - seems slower for me

This commit is contained in:
Richard Thier 2025-05-06 02:30:44 +02:00
parent 0b864ad2f0
commit d61d1e72d2

View File

@ -259,9 +259,7 @@ static inline pret3 partition3_sp2(uint32_t array[], int low, int high, uint32_t
/* Handle left and find wrongly placed element */
while((array[jl] <= pivotval) && (jl <= jr)) {
int isNonPivot = (array[jl] != pivotval);
int nonSameIndex = (il + 1 != jl);
if(isNonPivot & nonSameIndex)
swapit(&array[il + 1], &array[jl]);
if(isNonPivot) swapit(&array[il + 1], &array[jl]);
il += isNonPivot;
++jl;
}
@ -269,9 +267,7 @@ static inline pret3 partition3_sp2(uint32_t array[], int low, int high, uint32_t
/* Handle right and find wrongly placed element */
while((array[jr] >= pivotval) && (jl <= jr)) {
int isNonPivot = (array[jr] != pivotval);
int nonSameIndex = (ir - 1 != jr);
if(isNonPivot & nonSameIndex)
swapit(&array[ir - 1], &array[jr]);
if(isNonPivot) swapit(&array[ir - 1], &array[jr]);
ir -= isNonPivot;
--jr;
}