4096-wise thiersort2
This commit is contained in:
parent
76001efd98
commit
f4e4db43f9
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]
|
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 * 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):
|
/* Alternative (but I measure it being worse):
|
||||||
return (as.u >> 23);
|
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);
|
* @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) {
|
static inline void thiersort2(uint32_t *arr, uint32_t *temparr, int n, sch_rand_state *rstate) {
|
||||||
int bucket[2048]; /* Inclusive */
|
int bucket[4096]; /* Inclusive */
|
||||||
int bucket_end[2048]; /* Not inclusive */
|
int bucket_end[4096]; /* Not inclusive */
|
||||||
|
|
||||||
/* Check if need to sort at all - needed for invariants later */
|
/* Check if need to sort at all - needed for invariants later */
|
||||||
if(n < 2) {
|
if(n < 2) {
|
||||||
@ -67,7 +67,7 @@ static inline void thiersort2(uint32_t *arr, uint32_t *temparr, int n, sch_rand_
|
|||||||
|
|
||||||
/* Count */
|
/* Count */
|
||||||
#pragma GCC unroll 64
|
#pragma GCC unroll 64
|
||||||
for(int i = 0; i < 2048; ++i) {
|
for(int i = 0; i < 4096; ++i) {
|
||||||
bucket[i] = 0;
|
bucket[i] = 0;
|
||||||
}
|
}
|
||||||
#pragma GCC unroll 64
|
#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) */
|
/* Prefix sum (like in Magyarsort) */
|
||||||
uint32_t prev = 0;
|
uint32_t prev = 0;
|
||||||
#pragma GCC unroll 4
|
#pragma GCC unroll 4
|
||||||
for (int i = 0; i < 2048; i++) {
|
for (int i = 0; i < 4096; i++) {
|
||||||
bucket[i] += prev;
|
bucket[i] += prev;
|
||||||
prev = bucket[i];
|
prev = bucket[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save end-offsets */
|
/* Save end-offsets */
|
||||||
#pragma GCC unroll 64
|
#pragma GCC unroll 64
|
||||||
for(int i = 0; i < 2048; ++i) {
|
for(int i = 0; i < 4096; ++i) {
|
||||||
bucket_end[i] = bucket[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 */
|
/* temparr -> arr each bucket and sort them in-place */
|
||||||
#pragma GCC unroll 64
|
#pragma GCC unroll 64
|
||||||
for(int b = 0; b < 2048; ++b) {
|
for(int b = 0; b < 4096; ++b) {
|
||||||
int begin = bucket[b];
|
int begin = bucket[b];
|
||||||
int end = bucket_end[b];
|
int end = bucket_end[b];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user