From d61d1e72d291a4dbeb9197844a44897ac4027db9 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Tue, 6 May 2025 02:30:44 +0200 Subject: [PATCH] try simpler branchless at cost of extra swaps - seems slower for me --- qsort.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/qsort.h b/qsort.h index c69c9fc..14dc9cc 100644 --- a/qsort.h +++ b/qsort.h @@ -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; }