From f4e4db43f9442d3aa11f96292c09b1a627ace3df Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Sat, 27 Sep 2025 01:43:55 +0200 Subject: [PATCH] 4096-wise thiersort2 --- thiersort2.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/thiersort2.h b/thiersort2.h index d22e711..bcc93d7 100644 --- a/thiersort2.h +++ b/thiersort2.h @@ -42,7 +42,7 @@ static inline uint32_t witch_bucket(uint32_t key) { uint32_t witch_base = (key <= 2) ? 0 : (as.u >> 23) - 128; // 0, [127..159] -> [0..31] // return witch_base * 8 + ((as.u >> (23 - 3)) & 7); // 0..255 - return witch_base * 64 + ((as.u >> (23 - 6)) & 63); // 0..2047 + return witch_base * 128 + ((as.u >> (23 - 7)) & 127); // 0..2047 /* Alternative (but I measure it being worse): return (as.u >> 23); */ @@ -57,8 +57,8 @@ static inline uint32_t witch_bucket(uint32_t key) { * @param rstate Create with sch_rand_state rstate = schwab_rand_state(junk_uint32_t); */ static inline void thiersort2(uint32_t *arr, uint32_t *temparr, int n, sch_rand_state *rstate) { - int bucket[2048]; /* Inclusive */ - int bucket_end[2048]; /* Not inclusive */ + int bucket[4096]; /* Inclusive */ + int bucket_end[4096]; /* Not inclusive */ /* Check if need to sort at all - needed for invariants later */ if(n < 2) { @@ -67,7 +67,7 @@ static inline void thiersort2(uint32_t *arr, uint32_t *temparr, int n, sch_rand_ /* Count */ #pragma GCC unroll 64 - for(int i = 0; i < 2048; ++i) { + for(int i = 0; i < 4096; ++i) { bucket[i] = 0; } #pragma GCC unroll 64 @@ -78,14 +78,14 @@ static inline void thiersort2(uint32_t *arr, uint32_t *temparr, int n, sch_rand_ /* Prefix sum (like in Magyarsort) */ uint32_t prev = 0; #pragma GCC unroll 4 - for (int i = 0; i < 2048; i++) { + for (int i = 0; i < 4096; i++) { bucket[i] += prev; prev = bucket[i]; } /* Save end-offsets */ #pragma GCC unroll 64 - for(int i = 0; i < 2048; ++i) { + for(int i = 0; i < 4096; ++i) { bucket_end[i] = bucket[i]; } @@ -102,7 +102,7 @@ static inline void thiersort2(uint32_t *arr, uint32_t *temparr, int n, sch_rand_ /* temparr -> arr each bucket and sort them in-place */ #pragma GCC unroll 64 - for(int b = 0; b < 2048; ++b) { + for(int b = 0; b < 4096; ++b) { int begin = bucket[b]; int end = bucket_end[b];