From ef9e4f799b4f73e9319264a82fc89e885ef455ac Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Wed, 1 Oct 2025 02:16:34 +0200 Subject: [PATCH] more uint->int, but these seem to make it slower a bit so will be reverted --- thiersort3.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/thiersort3.h b/thiersort3.h index e5df720..afa1d99 100644 --- a/thiersort3.h +++ b/thiersort3.h @@ -22,7 +22,7 @@ union th3_fu { typedef union th3_fu th3_fu; /** Tells from the key which bucket it is in. */ -static inline uint32_t witch_bucket3(uint32_t key) { +static inline int witch_bucket3(uint32_t key) { /* This is hackz to misuse int->float converter HEAVILY and IEE for bucketing */ /* https://en.wikipedia.org/wiki/Single-precision_floating-point_format */ @@ -35,7 +35,7 @@ static inline uint32_t witch_bucket3(uint32_t key) { th3_fu as; as.f = (float) key; - uint32_t witch_base = (key <= 2) ? 0 : (as.u >> 23) - 128; // 0, [127..159] -> [0..31] + int 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 /* All below ones were worse, because three-ways 28 bit sorting would just make unnecessary work at cost of some locality */ //return witch_base * 128 + ((as.u >> (23 - 7)) & 127); // 0..4095 @@ -50,7 +50,6 @@ static inline uint32_t witch_bucket3(uint32_t key) { * @param arr The array to sort, will contain result afterwards * @param temparr The temporary array with same size * @param n Number of elements in arr and temparr - * @param rstate Create with sch_rand_state rstate = schwab_rand_state(junk_uint32_t); */ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { int bucket[256]; /* Inclusive */ @@ -77,7 +76,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { } /* Prefix sum (like in Magyarsort) */ - uint32_t prev = 0; + int prev = 0; #pragma GCC unroll 4 for (int i = 0; i < 256; i++) { bucket[i] += prev; @@ -108,7 +107,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { #pragma GCC unroll 128 for(int i = 0; i < n; ++i) { uint32_t num = arr[i]; - uint32_t witch = witch_bucket3(num); + int witch = witch_bucket3(num); int offset = (--bucket[witch]); temparr[offset] = num; } @@ -127,7 +126,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { /* Use our specialized threepass */ /* - which does not use up all the bits */ /* - which does not allocate and copy back to arr here */ - uint32_t n = end - begin; + int n = end - begin; uint32_t *a = &(temparr[begin]); uint32_t *buf = &(arr[begin]); threepass_xb(a, buf, n); @@ -139,7 +138,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { #pragma GCC unroll 64 for(int i = 0; i < n; ++i) { uint32_t num = arr[i]; - uint32_t witch = witch_bucket3(num); + int witch = witch_bucket3(num); int offset = (num & (1 << 27)) ? (--bucket[witch]) : (bucket_leftend[witch]++); @@ -161,7 +160,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { /* Use our specialized threepass */ /* - which does not use up all the bits */ /* - which does not allocate and copy back to arr here */ - uint32_t n = lend - lbegin; + int n = lend - lbegin; uint32_t *a = &(temparr[lbegin]); uint32_t *buf = &(arr[lbegin]); threepass_xb(a, buf, n); @@ -172,7 +171,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) { /* Use our specialized threepass */ /* - which does not use up all the bits */ /* - which does not allocate and copy back to arr here */ - uint32_t n = rend - rbegin; + int n = rend - rbegin; uint32_t *a = &(temparr[rbegin]); uint32_t *buf = &(arr[rbegin]); threepass_xb(a, buf, n);