From 4c675015112127721038b58f50e5a93ae5448360 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Fri, 9 May 2025 03:51:37 +0200 Subject: [PATCH] schwab: full branchless parts on partitioning now - speed gain but minimal... need like 5-6 of these --- schwab_sort.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/schwab_sort.h b/schwab_sort.h index 9cd2846..038332e 100644 --- a/schwab_sort.h +++ b/schwab_sort.h @@ -158,18 +158,16 @@ static inline int schwab_partition( /* TODO: should be copy of whole element when not just uint32s! */ uint32_t curr = arr[b3]; - /* Half-branchless and half-goto trickery */ + /* Full branchless - see below for branch alternative */ int where = (curr < klo) ? 0 : ((curr < kmid) ? 1 : 2); int target = (curr < klo) ? b0 : ((curr < kmid) ? b1 : b2); arr[b3] = arr[b2]; - if(where == 2) goto auss; - arr[b2] = arr[b1]; - if(where == 1) goto auss; - arr[b1] = arr[b0]; -auss: + arr[b2] = (where == 2) ? arr[b2] : arr[b1]; + arr[b1] = (where == 1) ? arr[b1] : arr[b0]; + ++b2; b1 += (where < 2); b0 += (where < 1);