more uint->int, but these seem to make it slower a bit so will be reverted

This commit is contained in:
Richard Thier 2025-10-01 02:16:34 +02:00
parent 478d87e148
commit ef9e4f799b

View File

@ -22,7 +22,7 @@ union th3_fu {
typedef union th3_fu th3_fu; typedef union th3_fu th3_fu;
/** Tells from the key which bucket it is in. */ /** 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 */ /* This is hackz to misuse int->float converter HEAVILY and IEE for bucketing */
/* https://en.wikipedia.org/wiki/Single-precision_floating-point_format */ /* 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; th3_fu as;
as.f = (float) key; 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 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 */ /* 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 //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 arr The array to sort, will contain result afterwards
* @param temparr The temporary array with same size * @param temparr The temporary array with same size
* @param n Number of elements in arr and temparr * @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) { static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) {
int bucket[256]; /* Inclusive */ 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) */ /* Prefix sum (like in Magyarsort) */
uint32_t prev = 0; int prev = 0;
#pragma GCC unroll 4 #pragma GCC unroll 4
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
bucket[i] += prev; bucket[i] += prev;
@ -108,7 +107,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) {
#pragma GCC unroll 128 #pragma GCC unroll 128
for(int i = 0; i < n; ++i) { for(int i = 0; i < n; ++i) {
uint32_t num = arr[i]; uint32_t num = arr[i];
uint32_t witch = witch_bucket3(num); int witch = witch_bucket3(num);
int offset = (--bucket[witch]); int offset = (--bucket[witch]);
temparr[offset] = num; temparr[offset] = num;
} }
@ -127,7 +126,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) {
/* Use our specialized threepass */ /* Use our specialized threepass */
/* - which does not use up all the bits */ /* - which does not use up all the bits */
/* - which does not allocate and copy back to arr here */ /* - 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 *a = &(temparr[begin]);
uint32_t *buf = &(arr[begin]); uint32_t *buf = &(arr[begin]);
threepass_xb(a, buf, n); 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 #pragma GCC unroll 64
for(int i = 0; i < n; ++i) { for(int i = 0; i < n; ++i) {
uint32_t num = arr[i]; uint32_t num = arr[i];
uint32_t witch = witch_bucket3(num); int witch = witch_bucket3(num);
int offset = (num & (1 << 27)) ? int offset = (num & (1 << 27)) ?
(--bucket[witch]) : (--bucket[witch]) :
(bucket_leftend[witch]++); (bucket_leftend[witch]++);
@ -161,7 +160,7 @@ static inline void thiersort3(uint32_t *arr, uint32_t *temparr, int n) {
/* Use our specialized threepass */ /* Use our specialized threepass */
/* - which does not use up all the bits */ /* - which does not use up all the bits */
/* - which does not allocate and copy back to arr here */ /* - 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 *a = &(temparr[lbegin]);
uint32_t *buf = &(arr[lbegin]); uint32_t *buf = &(arr[lbegin]);
threepass_xb(a, buf, n); 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 */ /* Use our specialized threepass */
/* - which does not use up all the bits */ /* - which does not use up all the bits */
/* - which does not allocate and copy back to arr here */ /* - 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 *a = &(temparr[rbegin]);
uint32_t *buf = &(arr[rbegin]); uint32_t *buf = &(arr[rbegin]);
threepass_xb(a, buf, n); threepass_xb(a, buf, n);