2048-wise thiersort2
This commit is contained in:
parent
dcef96fee8
commit
76001efd98
14
thiersort2.h
14
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 * 16 + ((as.u >> (23 - 4)) & 15); // 0..255
|
||||
return witch_base * 64 + ((as.u >> (23 - 6)) & 63); // 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[512]; /* Inclusive */
|
||||
int bucket_end[512]; /* Not inclusive */
|
||||
int bucket[2048]; /* Inclusive */
|
||||
int bucket_end[2048]; /* 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 < 512; ++i) {
|
||||
for(int i = 0; i < 2048; ++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 < 512; i++) {
|
||||
for (int i = 0; i < 2048; i++) {
|
||||
bucket[i] += prev;
|
||||
prev = bucket[i];
|
||||
}
|
||||
|
||||
/* Save end-offsets */
|
||||
#pragma GCC unroll 64
|
||||
for(int i = 0; i < 512; ++i) {
|
||||
for(int i = 0; i < 2048; ++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 < 512; ++b) {
|
||||
for(int b = 0; b < 2048; ++b) {
|
||||
int begin = bucket[b];
|
||||
int end = bucket_end[b];
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user