TurboPFor: Elias fano encode/decode
This commit is contained in:
29
eliasfano.c
29
eliasfano.c
@ -90,7 +90,7 @@ static inline unsigned long long blsr(unsigned long long x) { return x & (x - 1)
|
|||||||
#undef EFANODEC
|
#undef EFANODEC
|
||||||
|
|
||||||
//----------------------
|
//----------------------
|
||||||
#define EFSIMD
|
#define VSIZE 128
|
||||||
#define BITPACK bitpack128v
|
#define BITPACK bitpack128v
|
||||||
#define BITUNPACK bitunpack128v
|
#define BITUNPACK bitunpack128v
|
||||||
#define EF_INC 1
|
#define EF_INC 1
|
||||||
@ -101,10 +101,6 @@ static inline unsigned long long blsr(unsigned long long x) { return x & (x - 1)
|
|||||||
#include __FILE__
|
#include __FILE__
|
||||||
#undef USIZE
|
#undef USIZE
|
||||||
|
|
||||||
/*#define USIZE 16
|
|
||||||
#include __FILE__
|
|
||||||
#undef USIZE*/
|
|
||||||
|
|
||||||
#undef EF_INC
|
#undef EF_INC
|
||||||
#undef EFANOENC
|
#undef EFANOENC
|
||||||
#undef EFANODEC
|
#undef EFANODEC
|
||||||
@ -117,14 +113,11 @@ static inline unsigned long long blsr(unsigned long long x) { return x & (x - 1)
|
|||||||
#define USIZE 32
|
#define USIZE 32
|
||||||
#include __FILE__
|
#include __FILE__
|
||||||
#undef USIZE
|
#undef USIZE
|
||||||
#undef EFSIMD
|
#undef VSIZE
|
||||||
|
|
||||||
/*#define USIZE 16
|
|
||||||
#include __FILE__
|
|
||||||
#undef USIZE*/
|
|
||||||
|
|
||||||
#else //--------------------------------------------- implementation ---------------------------------------------------------------
|
#else //--------------------------------------------- implementation ---------------------------------------------------------------
|
||||||
#define uint_t TEMPLATE3(uint, USIZE, _t)
|
#define uint_t TEMPLATE3(uint, USIZE, _t)
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wparentheses"
|
#pragma clang diagnostic ignored "-Wparentheses"
|
||||||
|
|
||||||
@ -145,11 +138,7 @@ unsigned char *TEMPLATE2(EFANOENC, USIZE)(uint_t *__restrict in, unsigned n, uns
|
|||||||
}
|
}
|
||||||
while(i < n) pa[i] = EFE(in,i,start) & x, ++i;
|
while(i < n) pa[i] = EFE(in,i,start) & x, ++i;
|
||||||
*out = lb+1;
|
*out = lb+1;
|
||||||
op = TEMPLATE2(BITPACK,USIZE)(pa,
|
op = TEMPLATE2(BITPACK,USIZE)(pa, n, out+1, lb);
|
||||||
#ifndef EFSIMD
|
|
||||||
n,
|
|
||||||
#endif
|
|
||||||
out+1, lb);
|
|
||||||
|
|
||||||
memset(op, 0, hl);
|
memset(op, 0, hl);
|
||||||
for(i = 0; i != n&~3; ) {
|
for(i = 0; i != n&~3; ) {
|
||||||
@ -163,7 +152,9 @@ unsigned char *TEMPLATE2(EFANOENC, USIZE)(uint_t *__restrict in, unsigned n, uns
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *TEMPLATE2(EFANODEC, USIZE)(unsigned char *__restrict in, unsigned n, uint_t *__restrict out, uint_t start) {
|
unsigned char *TEMPLATE2(EFANODEC, USIZE)(unsigned char *__restrict in, unsigned n, uint_t *__restrict out, uint_t start) {
|
||||||
if(!n) return in;
|
|
||||||
|
if(!n) return out;
|
||||||
|
|
||||||
unsigned char *ip = in;
|
unsigned char *ip = in;
|
||||||
unsigned i,j,lb = *ip++;
|
unsigned i,j,lb = *ip++;
|
||||||
bit_t b;
|
bit_t b;
|
||||||
@ -181,11 +172,7 @@ unsigned char *TEMPLATE2(EFANODEC, USIZE)(unsigned char *__restrict in, unsigned
|
|||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
ip = TEMPLATE2(BITUNPACK,USIZE)(ip,
|
ip = TEMPLATE2(BITUNPACK,USIZE)(ip, n, out, --lb);
|
||||||
#ifndef EFSIMD
|
|
||||||
n,
|
|
||||||
#endif
|
|
||||||
out, --lb);
|
|
||||||
for(i=j=0;; j += sizeof(bit_t)*8)
|
for(i=j=0;; j += sizeof(bit_t)*8)
|
||||||
for(b = *(bit_t *)(ip+(j>>3)); ; ) {
|
for(b = *(bit_t *)(ip+(j>>3)); ; ) {
|
||||||
if(!b) break; out[i] += ((uint_t)(j+ctz64(b)-i) << lb) + start+i*EF_INC; b = blsr(b); i++;
|
if(!b) break; out[i] += ((uint_t)(j+ctz64(b)-i) << lb) + start+i*EF_INC; b = blsr(b); i++;
|
||||||
|
Reference in New Issue
Block a user