From 6fa33b24b5fe998faa229c35faa5634ec622f63e Mon Sep 17 00:00:00 2001 From: powturbo Date: Thu, 28 May 2015 16:53:44 +0200 Subject: [PATCH] . --- vp4dc.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-) diff --git a/vp4dc.c b/vp4dc.c index 91047c0..373c23e 100644 --- a/vp4dc.c +++ b/vp4dc.c @@ -1,7 +1,7 @@ /** - Copyright (C) powturbo 2013-2014 + Copyright (C) powturbo 2013-2015 GPL v2 License - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -16,14 +16,13 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - email : powturbo [AT] gmail.com - - github : https://github.com/powturbo - homepage : https://sites.google.com/site/powturbo/ + - github : https://github.com/powturbo - twitter : https://twitter.com/powturbo - - vp4dd.c - "Integer Compression" Turbo PforDelta + - email : powturbo [_AT_] gmail [_DOT_] com **/ - +// vp4dd.c - "Integer Compression" Turbo PforDelta + #ifndef USIZE #include #include "conf.h" #include "bitpack.h" @@ -34,12 +33,91 @@ #include //------------------------------------------ #define P4DSIZE 128 //64 // -#define P4DENC p4denc +#define P4D p4d +#define P4DENC p4denc +#define P4DE p4de + +#define BITPACK bitpack #define USIZE 32 -#include "vp4dc_.h" +#include __FILE__ #undef USIZE #define USIZE 16 -#include "vp4dc_.h" +#include __FILE__ +#undef USIZE +#undef BITPACK +#undef P4DENC +#undef P4DE +#undef P4D +//------------------------------------------ +#define P4DSIZE 128 //64 // + +#define P4DENC p4dencv +#define P4DE p4dev +#define BITPACK bitpackv +#define USIZE 32 +#include __FILE__ +#undef USIZE + +/*#define USIZE 16 +#include __FILE__*/ + + #else +#define uint_t TEMPLATE3(uint, USIZE, _t) +#define P4DN (P4DSIZE/64) + + #ifdef P4D +unsigned TEMPLATE2(P4D, USIZE)(uint_t *__restrict in, unsigned n, unsigned *pbx) { + int i,b = 0; unsigned cnt[USIZE+1] = {0}; uint_t *ip; + + for(ip = in; ip < in+(n&~3); ) { + ++cnt[TEMPLATE2(bsr, USIZE)(*ip)]; b |= *ip++; + ++cnt[TEMPLATE2(bsr, USIZE)(*ip)]; b |= *ip++; + ++cnt[TEMPLATE2(bsr, USIZE)(*ip)]; b |= *ip++; + ++cnt[TEMPLATE2(bsr, USIZE)(*ip)]; b |= *ip++; + } + while(ip < in+n) ++cnt[TEMPLATE2(bsr, USIZE)(*ip)], b |= *ip++; + b = TEMPLATE2(bsr, USIZE)(b); + + unsigned bx = b, ml = PAD8(n*b)+1, x = cnt[b]; + for(i = b-1; i >= 0; --i) { + unsigned l = PAD8(n*i) + 2+P4DN*8+PAD8(x*(bx-i)); + if(unlikely(l < ml)) b = i, ml = l; x += cnt[i]; //if(x >= 64) break; + } + *pbx = bx - b; + return b; +} +#endif + +unsigned char *TEMPLATE2(P4DE, USIZE)(uint_t *__restrict in, unsigned n, unsigned char *__restrict out, unsigned b, unsigned bx) { + if(!bx) return TEMPLATE2(BITPACK, USIZE)(in, n, out, b); + + uint_t _in[P4DSIZE], inx[P4DSIZE*2]; + unsigned long long xmap[P4DN+1]; + unsigned miss[P4DSIZE],i, xn, msk = (1ull< msk; _in[i] = in[i] & msk; i++; + miss[xn] = i; xn += in[i] > msk; _in[i] = in[i] & msk; i++; + miss[xn] = i; xn += in[i] > msk; _in[i] = in[i] & msk; i++; + miss[xn] = i; xn += in[i] > msk; _in[i] = in[i] & msk; i++; + } + while(i != n) { miss[xn] = i; xn += in[i] > msk; _in[i] = in[i] & msk; i++; } + for(i = 0; i < xn; i++) { + unsigned c = miss[i]; + xmap[c>>6] |= (1ull << (c&0x3f)); + inx[i] = in[c] >> b; + } + out = TEMPLATE2(BITPACK, USIZE)(_in, n, out, b); + for(i=0;i < P4DN; i++) { *(unsigned long long *)out = xmap[i]; out += 8; } + return TEMPLATE2(bitpack, USIZE)(inx, xn, out, bx); +} + +unsigned char *TEMPLATE2(P4DENC, USIZE)(uint_t *__restrict in, unsigned n, unsigned char *__restrict out) { + unsigned bx,b = TEMPLATE2(p4d, USIZE)(in, n, &bx); + P4DSAVE(out, b, bx); + return TEMPLATE2(P4DE, USIZE)(in, n, out, b, bx); +} + #endif