forked from powturbo/TurboPFor-Integer-Compression
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfp.c
132 lines (112 loc) · 5.41 KB
/
fp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
Copyright (C) powturbo 2013-2017
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
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- homepage : https://sites.google.com/site/powturbo/
- github : https://github.com/powturbo
- twitter : https://twitter.com/powturbo
- email : powturbo [_AT_] gmail [_DOT_] com
**/
// "Floating Point Compression"
#pragma warning( disable : 4005)
#pragma warning( disable : 4090)
#pragma warning( disable : 4068)
#include "conf.h"
#include "vp4.h"
#include "fp.h"
#include "bitutil.h"
#define VSIZE 128
//#define ENC64(u,h) (u^h)
//#define DEC64(u,h) (u^h)
#define ENC64(u,h) zigzagenc64(u-h)
#define DEC64(u,h) zigzagdec64(u)+h
//---- Last value Predictor
unsigned char *fppenc64(uint64_t *in, unsigned n, unsigned char *out, uint64_t start) {
uint64_t *ip, h = 0, _p[VSIZE], *p;
unsigned char *op = out;
#define FE64(i) { uint64_t u = ip[i]; p[i] = ENC64(u, h); h = u; }
for(ip = (uint64_t *)in; ip != in + (n&~(VSIZE-1)); ) {
for(p = _p; p != &_p[VSIZE]; p+=4,ip+=4) { FE64(0); FE64(1); FE64(2); FE64(3); }
op = p4enc64(_p, VSIZE, op); __builtin_prefetch(ip+512, 0);
}
if(n = ((uint64_t *)in+n)-ip) {
for(p = _p; p != &_p[n]; p++,ip++) FE64(0);
op = p4enc64(_p, n, op);
}
return op;
}
unsigned char *fppdec64(unsigned char *in, unsigned n, uint64_t *out, uint64_t start) {
uint64_t *op, h = 0, _p[VSIZE+32],*p;
unsigned char *ip = in;
#define FD64(i) { uint64_t u = DEC64(p[i],h); op[i] = u; h = u; }
for(op = (uint64_t*)out; op != out+(n&~(VSIZE-1)); ) { __builtin_prefetch(ip+512, 0);
for(ip = p4dec64(ip, VSIZE, _p), p = _p; p != &_p[VSIZE]; p+=4,op+=4) { FD64(0); FD64(1); FD64(2); FD64(3); }
}
if(n = ((uint64_t *)out+n) - op)
for(ip = p4dec64(ip, n, _p), p = _p; p != &_p[n]; p++,op++) FD64(0);
return ip;
}
#define HBITS 13 //15
#define HASH64(_h_,_u_) (((_h_)<<5 ^ (_u_)>>50) & ((1u<<HBITS)-1))
//---- FCM: Finite Context Method Predictor
unsigned char *fpfcmenc64(uint64_t *in, unsigned n, unsigned char *out, uint64_t start) {
uint64_t *ip, htab[1<<HBITS] = {0}, h = 0, _p[VSIZE], *p;
unsigned char *op = out;
#define FE64(i) { uint64_t u = ip[i]; p[i] = ENC64(u, htab[h]); htab[h] = u; h = HASH64(h,u); }
for(ip = (uint64_t *)in; ip != in + (n&~(VSIZE-1)); ) {
for(p = _p; p != &_p[VSIZE]; p+=4,ip+=4) { FE64(0); FE64(1); FE64(2); FE64(3); }
op = p4enc64(_p, VSIZE, op); __builtin_prefetch(ip+512, 0);
}
if(n = ((uint64_t *)in+n)-ip) {
for(p = _p; p != &_p[n]; p++,ip++) FE64(0);
op = p4enc64(_p, n, op);
}
return op;
}
unsigned char *fpfcmdec64(unsigned char *in, unsigned n, uint64_t *out, uint64_t start) {
uint64_t *op, htab[1<<HBITS] = {0}, h = 0, _p[VSIZE+32],*p;
unsigned char *ip = in;
#define FD64(i) { uint64_t u = DEC64(p[i], htab[h]); op[i] = u; htab[h] = u; h = HASH64(h,u); }
for(op = (uint64_t*)out; op != out+(n&~(VSIZE-1)); ) { __builtin_prefetch(ip+512, 0);
for(ip = p4dec64(ip, VSIZE, _p), p = _p; p != &_p[VSIZE]; p+=4,op+=4) { FD64(0); FD64(1); FD64(2); FD64(3); }
}
if(n = ((uint64_t *)out+n) - op)
for(ip = p4dec64(ip, n, _p), p = _p; p != &_p[n]; p++,op++) FD64(0);
return ip;
}
// DFCM: Differential Finite Context Method Predictor
unsigned char *fpdfcmenc64(uint64_t *in, unsigned n, unsigned char *out, uint64_t start) {
unsigned char *op = out;
uint64_t _p[VSIZE+32], *ip, h = 0, *p, htab[1<<HBITS] = {0}; htab[0] = start ;
#define DE64(i) { uint64_t u = ip[i]; p[i] = ENC64(u, (htab[h]+start)); htab[h] = start = u - start; h = HASH64(h,start); start = u; }
for(ip = (uint64_t *)in; ip != in + (n&~(VSIZE-1)); ) {
for(p = _p; p != &_p[VSIZE]; p+=4,ip+=4) { DE64(0); DE64(1); DE64(2); DE64(3); }
op = p4enc64(_p, VSIZE, op); __builtin_prefetch(ip+512, 0);
}
if(n = ((uint64_t *)in+n)-ip) {
for(p = _p; p != &_p[n]; p++,ip++) DE64(0);
op = p4enc64(_p, n, op);
}
return op;
}
unsigned char *fpdfcmdec64(unsigned char *in, unsigned n, uint64_t *out, uint64_t start) {
unsigned char *ip = in;
uint64_t _p[VSIZE+32], *op, h = 0, *p, htab[1<<HBITS] = {0}; htab[0] = start;
#define DD64(i) { uint64_t u = DEC64(p[i], (htab[h]+start)); op[i] = u; htab[h] = start = u-start; h = HASH64(h,start); start = u; }
for(op = (uint64_t*)out; op != out+(n&~(VSIZE-1)); ) { __builtin_prefetch(ip+512, 0);
for(ip = p4dec64(ip, VSIZE, _p), p = _p; p != &_p[VSIZE]; p+=4,op+=4) { DD64(0); DD64(1); DD64(2); DD64(3); }
}
if(n = ((uint64_t *)out+n) - op)
for(ip = p4dec64(ip, n, _p), p = _p; p != &_p[n]; p++,op++) DD64(0);
return ip;
}