zstdlib 0.1.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +9 -0
- data/Gemfile +3 -0
- data/README.md +96 -0
- data/Rakefile +29 -0
- data/ext/zstdlib/extconf.rb +53 -0
- data/ext/zstdlib/ruby/zlib-2.2/zlib.c +4659 -0
- data/ext/zstdlib/ruby/zlib-2.3/zlib.c +4686 -0
- data/ext/zstdlib/ruby/zlib-2.4/zlib.c +4843 -0
- data/ext/zstdlib/ruby/zlib-2.5/zlib.c +4848 -0
- data/ext/zstdlib/ruby/zlib-2.6/zlib.c +4890 -0
- data/ext/zstdlib/zlib-1.2.11/adler32.c +186 -0
- data/ext/zstdlib/zlib-1.2.11/compress.c +86 -0
- data/ext/zstdlib/zlib-1.2.11/crc32.c +442 -0
- data/ext/zstdlib/zlib-1.2.11/crc32.h +441 -0
- data/ext/zstdlib/zlib-1.2.11/deflate.c +2163 -0
- data/ext/zstdlib/zlib-1.2.11/deflate.h +349 -0
- data/ext/zstdlib/zlib-1.2.11/gzclose.c +25 -0
- data/ext/zstdlib/zlib-1.2.11/gzguts.h +218 -0
- data/ext/zstdlib/zlib-1.2.11/gzlib.c +637 -0
- data/ext/zstdlib/zlib-1.2.11/gzread.c +654 -0
- data/ext/zstdlib/zlib-1.2.11/gzwrite.c +665 -0
- data/ext/zstdlib/zlib-1.2.11/infback.c +640 -0
- data/ext/zstdlib/zlib-1.2.11/inffast.c +323 -0
- data/ext/zstdlib/zlib-1.2.11/inffast.h +11 -0
- data/ext/zstdlib/zlib-1.2.11/inffixed.h +94 -0
- data/ext/zstdlib/zlib-1.2.11/inflate.c +1561 -0
- data/ext/zstdlib/zlib-1.2.11/inflate.h +125 -0
- data/ext/zstdlib/zlib-1.2.11/inftrees.c +304 -0
- data/ext/zstdlib/zlib-1.2.11/inftrees.h +62 -0
- data/ext/zstdlib/zlib-1.2.11/trees.c +1203 -0
- data/ext/zstdlib/zlib-1.2.11/trees.h +128 -0
- data/ext/zstdlib/zlib-1.2.11/uncompr.c +93 -0
- data/ext/zstdlib/zlib-1.2.11/zconf.h +534 -0
- data/ext/zstdlib/zlib-1.2.11/zlib.h +1912 -0
- data/ext/zstdlib/zlib-1.2.11/zutil.c +325 -0
- data/ext/zstdlib/zlib-1.2.11/zutil.h +271 -0
- data/ext/zstdlib/zlib.mk +14 -0
- data/ext/zstdlib/zlibwrapper/zlibwrapper.c +14 -0
- data/ext/zstdlib/zlibwrapper.mk +14 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/bitstream.h +455 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/compiler.h +140 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/cpu.h +215 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/debug.c +44 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/debug.h +134 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/entropy_common.c +236 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.c +54 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.h +76 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/fse.h +708 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/fse_decompress.c +309 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/huf.h +358 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/mem.h +380 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/pool.c +340 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/pool.h +84 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/threading.c +75 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/threading.h +123 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.c +876 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.h +305 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_common.c +83 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_errors.h +93 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_internal.h +266 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/fse_compress.c +721 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.c +203 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.h +95 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/huf_compress.c +798 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress.c +4290 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress_internal.h +860 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.c +499 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.h +38 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.c +391 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.h +37 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.c +1106 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.h +67 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.c +597 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.h +105 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.c +1217 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.h +56 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.c +2107 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.h +174 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/huf_decompress.c +1232 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.c +240 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.h +44 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress.c +1672 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.c +1307 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.h +59 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_internal.h +168 -0
- data/ext/zstdlib/zstd-1.3.8/lib/zstd.h +1766 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzclose.c +28 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzcompatibility.h +68 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzguts.h +227 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzlib.c +640 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzread.c +670 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzwrite.c +671 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.c +1105 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.h +88 -0
- data/ext/zstdlib/zstd.mk +14 -0
- data/lib/2.2/zstdlib.so +0 -0
- data/lib/2.3/zstdlib.so +0 -0
- data/lib/2.4/zstdlib.so +0 -0
- data/lib/2.5/zstdlib.so +0 -0
- data/lib/2.6/zstdlib.so +0 -0
- data/lib/zstdlib.rb +6 -0
- data/test/zstdlib_test.rb +21 -0
- metadata +205 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2018-present, Facebook, Inc.
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* This source code is licensed under both the BSD-style license (found in the
|
6
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
+
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
9
|
+
*/
|
10
|
+
|
11
|
+
#ifndef ZSTD_COMMON_CPU_H
|
12
|
+
#define ZSTD_COMMON_CPU_H
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Implementation taken from folly/CpuId.h
|
16
|
+
* https://github.com/facebook/folly/blob/master/folly/CpuId.h
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <string.h>
|
20
|
+
|
21
|
+
#include "mem.h"
|
22
|
+
|
23
|
+
#ifdef _MSC_VER
|
24
|
+
#include <intrin.h>
|
25
|
+
#endif
|
26
|
+
|
27
|
+
typedef struct {
|
28
|
+
U32 f1c;
|
29
|
+
U32 f1d;
|
30
|
+
U32 f7b;
|
31
|
+
U32 f7c;
|
32
|
+
} ZSTD_cpuid_t;
|
33
|
+
|
34
|
+
MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
|
35
|
+
U32 f1c = 0;
|
36
|
+
U32 f1d = 0;
|
37
|
+
U32 f7b = 0;
|
38
|
+
U32 f7c = 0;
|
39
|
+
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
40
|
+
int reg[4];
|
41
|
+
__cpuid((int*)reg, 0);
|
42
|
+
{
|
43
|
+
int const n = reg[0];
|
44
|
+
if (n >= 1) {
|
45
|
+
__cpuid((int*)reg, 1);
|
46
|
+
f1c = (U32)reg[2];
|
47
|
+
f1d = (U32)reg[3];
|
48
|
+
}
|
49
|
+
if (n >= 7) {
|
50
|
+
__cpuidex((int*)reg, 7, 0);
|
51
|
+
f7b = (U32)reg[1];
|
52
|
+
f7c = (U32)reg[2];
|
53
|
+
}
|
54
|
+
}
|
55
|
+
#elif defined(__i386__) && defined(__PIC__) && !defined(__clang__) && defined(__GNUC__)
|
56
|
+
/* The following block like the normal cpuid branch below, but gcc
|
57
|
+
* reserves ebx for use of its pic register so we must specially
|
58
|
+
* handle the save and restore to avoid clobbering the register
|
59
|
+
*/
|
60
|
+
U32 n;
|
61
|
+
__asm__(
|
62
|
+
"pushl %%ebx\n\t"
|
63
|
+
"cpuid\n\t"
|
64
|
+
"popl %%ebx\n\t"
|
65
|
+
: "=a"(n)
|
66
|
+
: "a"(0)
|
67
|
+
: "ecx", "edx");
|
68
|
+
if (n >= 1) {
|
69
|
+
U32 f1a;
|
70
|
+
__asm__(
|
71
|
+
"pushl %%ebx\n\t"
|
72
|
+
"cpuid\n\t"
|
73
|
+
"popl %%ebx\n\t"
|
74
|
+
: "=a"(f1a), "=c"(f1c), "=d"(f1d)
|
75
|
+
: "a"(1));
|
76
|
+
}
|
77
|
+
if (n >= 7) {
|
78
|
+
__asm__(
|
79
|
+
"pushl %%ebx\n\t"
|
80
|
+
"cpuid\n\t"
|
81
|
+
"movl %%ebx, %%eax\n\t"
|
82
|
+
"popl %%ebx"
|
83
|
+
: "=a"(f7b), "=c"(f7c)
|
84
|
+
: "a"(7), "c"(0)
|
85
|
+
: "edx");
|
86
|
+
}
|
87
|
+
#elif defined(__x86_64__) || defined(_M_X64) || defined(__i386__)
|
88
|
+
U32 n;
|
89
|
+
__asm__("cpuid" : "=a"(n) : "a"(0) : "ebx", "ecx", "edx");
|
90
|
+
if (n >= 1) {
|
91
|
+
U32 f1a;
|
92
|
+
__asm__("cpuid" : "=a"(f1a), "=c"(f1c), "=d"(f1d) : "a"(1) : "ebx");
|
93
|
+
}
|
94
|
+
if (n >= 7) {
|
95
|
+
U32 f7a;
|
96
|
+
__asm__("cpuid"
|
97
|
+
: "=a"(f7a), "=b"(f7b), "=c"(f7c)
|
98
|
+
: "a"(7), "c"(0)
|
99
|
+
: "edx");
|
100
|
+
}
|
101
|
+
#endif
|
102
|
+
{
|
103
|
+
ZSTD_cpuid_t cpuid;
|
104
|
+
cpuid.f1c = f1c;
|
105
|
+
cpuid.f1d = f1d;
|
106
|
+
cpuid.f7b = f7b;
|
107
|
+
cpuid.f7c = f7c;
|
108
|
+
return cpuid;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
#define X(name, r, bit) \
|
113
|
+
MEM_STATIC int ZSTD_cpuid_##name(ZSTD_cpuid_t const cpuid) { \
|
114
|
+
return ((cpuid.r) & (1U << bit)) != 0; \
|
115
|
+
}
|
116
|
+
|
117
|
+
/* cpuid(1): Processor Info and Feature Bits. */
|
118
|
+
#define C(name, bit) X(name, f1c, bit)
|
119
|
+
C(sse3, 0)
|
120
|
+
C(pclmuldq, 1)
|
121
|
+
C(dtes64, 2)
|
122
|
+
C(monitor, 3)
|
123
|
+
C(dscpl, 4)
|
124
|
+
C(vmx, 5)
|
125
|
+
C(smx, 6)
|
126
|
+
C(eist, 7)
|
127
|
+
C(tm2, 8)
|
128
|
+
C(ssse3, 9)
|
129
|
+
C(cnxtid, 10)
|
130
|
+
C(fma, 12)
|
131
|
+
C(cx16, 13)
|
132
|
+
C(xtpr, 14)
|
133
|
+
C(pdcm, 15)
|
134
|
+
C(pcid, 17)
|
135
|
+
C(dca, 18)
|
136
|
+
C(sse41, 19)
|
137
|
+
C(sse42, 20)
|
138
|
+
C(x2apic, 21)
|
139
|
+
C(movbe, 22)
|
140
|
+
C(popcnt, 23)
|
141
|
+
C(tscdeadline, 24)
|
142
|
+
C(aes, 25)
|
143
|
+
C(xsave, 26)
|
144
|
+
C(osxsave, 27)
|
145
|
+
C(avx, 28)
|
146
|
+
C(f16c, 29)
|
147
|
+
C(rdrand, 30)
|
148
|
+
#undef C
|
149
|
+
#define D(name, bit) X(name, f1d, bit)
|
150
|
+
D(fpu, 0)
|
151
|
+
D(vme, 1)
|
152
|
+
D(de, 2)
|
153
|
+
D(pse, 3)
|
154
|
+
D(tsc, 4)
|
155
|
+
D(msr, 5)
|
156
|
+
D(pae, 6)
|
157
|
+
D(mce, 7)
|
158
|
+
D(cx8, 8)
|
159
|
+
D(apic, 9)
|
160
|
+
D(sep, 11)
|
161
|
+
D(mtrr, 12)
|
162
|
+
D(pge, 13)
|
163
|
+
D(mca, 14)
|
164
|
+
D(cmov, 15)
|
165
|
+
D(pat, 16)
|
166
|
+
D(pse36, 17)
|
167
|
+
D(psn, 18)
|
168
|
+
D(clfsh, 19)
|
169
|
+
D(ds, 21)
|
170
|
+
D(acpi, 22)
|
171
|
+
D(mmx, 23)
|
172
|
+
D(fxsr, 24)
|
173
|
+
D(sse, 25)
|
174
|
+
D(sse2, 26)
|
175
|
+
D(ss, 27)
|
176
|
+
D(htt, 28)
|
177
|
+
D(tm, 29)
|
178
|
+
D(pbe, 31)
|
179
|
+
#undef D
|
180
|
+
|
181
|
+
/* cpuid(7): Extended Features. */
|
182
|
+
#define B(name, bit) X(name, f7b, bit)
|
183
|
+
B(bmi1, 3)
|
184
|
+
B(hle, 4)
|
185
|
+
B(avx2, 5)
|
186
|
+
B(smep, 7)
|
187
|
+
B(bmi2, 8)
|
188
|
+
B(erms, 9)
|
189
|
+
B(invpcid, 10)
|
190
|
+
B(rtm, 11)
|
191
|
+
B(mpx, 14)
|
192
|
+
B(avx512f, 16)
|
193
|
+
B(avx512dq, 17)
|
194
|
+
B(rdseed, 18)
|
195
|
+
B(adx, 19)
|
196
|
+
B(smap, 20)
|
197
|
+
B(avx512ifma, 21)
|
198
|
+
B(pcommit, 22)
|
199
|
+
B(clflushopt, 23)
|
200
|
+
B(clwb, 24)
|
201
|
+
B(avx512pf, 26)
|
202
|
+
B(avx512er, 27)
|
203
|
+
B(avx512cd, 28)
|
204
|
+
B(sha, 29)
|
205
|
+
B(avx512bw, 30)
|
206
|
+
B(avx512vl, 31)
|
207
|
+
#undef B
|
208
|
+
#define C(name, bit) X(name, f7c, bit)
|
209
|
+
C(prefetchwt1, 0)
|
210
|
+
C(avx512vbmi, 1)
|
211
|
+
#undef C
|
212
|
+
|
213
|
+
#undef X
|
214
|
+
|
215
|
+
#endif /* ZSTD_COMMON_CPU_H */
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/* ******************************************************************
|
2
|
+
debug
|
3
|
+
Part of FSE library
|
4
|
+
Copyright (C) 2013-present, Yann Collet.
|
5
|
+
|
6
|
+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
7
|
+
|
8
|
+
Redistribution and use in source and binary forms, with or without
|
9
|
+
modification, are permitted provided that the following conditions are
|
10
|
+
met:
|
11
|
+
|
12
|
+
* Redistributions of source code must retain the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer.
|
14
|
+
* Redistributions in binary form must reproduce the above
|
15
|
+
copyright notice, this list of conditions and the following disclaimer
|
16
|
+
in the documentation and/or other materials provided with the
|
17
|
+
distribution.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
You can contact the author at :
|
32
|
+
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
33
|
+
****************************************************************** */
|
34
|
+
|
35
|
+
|
36
|
+
/*
|
37
|
+
* This module only hosts one global variable
|
38
|
+
* which can be used to dynamically influence the verbosity of traces,
|
39
|
+
* such as DEBUGLOG and RAWLOG
|
40
|
+
*/
|
41
|
+
|
42
|
+
#include "debug.h"
|
43
|
+
|
44
|
+
int g_debuglevel = DEBUGLEVEL;
|
@@ -0,0 +1,134 @@
|
|
1
|
+
/* ******************************************************************
|
2
|
+
debug
|
3
|
+
Part of FSE library
|
4
|
+
Copyright (C) 2013-present, Yann Collet.
|
5
|
+
|
6
|
+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
7
|
+
|
8
|
+
Redistribution and use in source and binary forms, with or without
|
9
|
+
modification, are permitted provided that the following conditions are
|
10
|
+
met:
|
11
|
+
|
12
|
+
* Redistributions of source code must retain the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer.
|
14
|
+
* Redistributions in binary form must reproduce the above
|
15
|
+
copyright notice, this list of conditions and the following disclaimer
|
16
|
+
in the documentation and/or other materials provided with the
|
17
|
+
distribution.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
20
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
21
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
22
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
25
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
26
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
27
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
You can contact the author at :
|
32
|
+
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
33
|
+
****************************************************************** */
|
34
|
+
|
35
|
+
|
36
|
+
/*
|
37
|
+
* The purpose of this header is to enable debug functions.
|
38
|
+
* They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
|
39
|
+
* and DEBUG_STATIC_ASSERT() for compile-time.
|
40
|
+
*
|
41
|
+
* By default, DEBUGLEVEL==0, which means run-time debug is disabled.
|
42
|
+
*
|
43
|
+
* Level 1 enables assert() only.
|
44
|
+
* Starting level 2, traces can be generated and pushed to stderr.
|
45
|
+
* The higher the level, the more verbose the traces.
|
46
|
+
*
|
47
|
+
* It's possible to dynamically adjust level using variable g_debug_level,
|
48
|
+
* which is only declared if DEBUGLEVEL>=2,
|
49
|
+
* and is a global variable, not multi-thread protected (use with care)
|
50
|
+
*/
|
51
|
+
|
52
|
+
#ifndef DEBUG_H_12987983217
|
53
|
+
#define DEBUG_H_12987983217
|
54
|
+
|
55
|
+
#if defined (__cplusplus)
|
56
|
+
extern "C" {
|
57
|
+
#endif
|
58
|
+
|
59
|
+
|
60
|
+
/* static assert is triggered at compile time, leaving no runtime artefact.
|
61
|
+
* static assert only works with compile-time constants.
|
62
|
+
* Also, this variant can only be used inside a function. */
|
63
|
+
#define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
|
64
|
+
|
65
|
+
|
66
|
+
/* DEBUGLEVEL is expected to be defined externally,
|
67
|
+
* typically through compiler command line.
|
68
|
+
* Value must be a number. */
|
69
|
+
#ifndef DEBUGLEVEL
|
70
|
+
# define DEBUGLEVEL 0
|
71
|
+
#endif
|
72
|
+
|
73
|
+
|
74
|
+
/* DEBUGFILE can be defined externally,
|
75
|
+
* typically through compiler command line.
|
76
|
+
* note : currently useless.
|
77
|
+
* Value must be stderr or stdout */
|
78
|
+
#ifndef DEBUGFILE
|
79
|
+
# define DEBUGFILE stderr
|
80
|
+
#endif
|
81
|
+
|
82
|
+
|
83
|
+
/* recommended values for DEBUGLEVEL :
|
84
|
+
* 0 : release mode, no debug, all run-time checks disabled
|
85
|
+
* 1 : enables assert() only, no display
|
86
|
+
* 2 : reserved, for currently active debug path
|
87
|
+
* 3 : events once per object lifetime (CCtx, CDict, etc.)
|
88
|
+
* 4 : events once per frame
|
89
|
+
* 5 : events once per block
|
90
|
+
* 6 : events once per sequence (verbose)
|
91
|
+
* 7+: events at every position (*very* verbose)
|
92
|
+
*
|
93
|
+
* It's generally inconvenient to output traces > 5.
|
94
|
+
* In which case, it's possible to selectively trigger high verbosity levels
|
95
|
+
* by modifying g_debug_level.
|
96
|
+
*/
|
97
|
+
|
98
|
+
#if (DEBUGLEVEL>=1)
|
99
|
+
# include <assert.h>
|
100
|
+
#else
|
101
|
+
# ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
|
102
|
+
# define assert(condition) ((void)0) /* disable assert (default) */
|
103
|
+
# endif
|
104
|
+
#endif
|
105
|
+
|
106
|
+
#if (DEBUGLEVEL>=2)
|
107
|
+
# include <stdio.h>
|
108
|
+
extern int g_debuglevel; /* the variable is only declared,
|
109
|
+
it actually lives in debug.c,
|
110
|
+
and is shared by the whole process.
|
111
|
+
It's not thread-safe.
|
112
|
+
It's useful when enabling very verbose levels
|
113
|
+
on selective conditions (such as position in src) */
|
114
|
+
|
115
|
+
# define RAWLOG(l, ...) { \
|
116
|
+
if (l<=g_debuglevel) { \
|
117
|
+
fprintf(stderr, __VA_ARGS__); \
|
118
|
+
} }
|
119
|
+
# define DEBUGLOG(l, ...) { \
|
120
|
+
if (l<=g_debuglevel) { \
|
121
|
+
fprintf(stderr, __FILE__ ": " __VA_ARGS__); \
|
122
|
+
fprintf(stderr, " \n"); \
|
123
|
+
} }
|
124
|
+
#else
|
125
|
+
# define RAWLOG(l, ...) {} /* disabled */
|
126
|
+
# define DEBUGLOG(l, ...) {} /* disabled */
|
127
|
+
#endif
|
128
|
+
|
129
|
+
|
130
|
+
#if defined (__cplusplus)
|
131
|
+
}
|
132
|
+
#endif
|
133
|
+
|
134
|
+
#endif /* DEBUG_H_12987983217 */
|
@@ -0,0 +1,236 @@
|
|
1
|
+
/*
|
2
|
+
Common functions of New Generation Entropy library
|
3
|
+
Copyright (C) 2016, Yann Collet.
|
4
|
+
|
5
|
+
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
8
|
+
modification, are permitted provided that the following conditions are
|
9
|
+
met:
|
10
|
+
|
11
|
+
* Redistributions of source code must retain the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer.
|
13
|
+
* Redistributions in binary form must reproduce the above
|
14
|
+
copyright notice, this list of conditions and the following disclaimer
|
15
|
+
in the documentation and/or other materials provided with the
|
16
|
+
distribution.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
|
30
|
+
You can contact the author at :
|
31
|
+
- FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
32
|
+
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
33
|
+
*************************************************************************** */
|
34
|
+
|
35
|
+
/* *************************************
|
36
|
+
* Dependencies
|
37
|
+
***************************************/
|
38
|
+
#include "mem.h"
|
39
|
+
#include "error_private.h" /* ERR_*, ERROR */
|
40
|
+
#define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
|
41
|
+
#include "fse.h"
|
42
|
+
#define HUF_STATIC_LINKING_ONLY /* HUF_TABLELOG_ABSOLUTEMAX */
|
43
|
+
#include "huf.h"
|
44
|
+
|
45
|
+
|
46
|
+
/*=== Version ===*/
|
47
|
+
unsigned FSE_versionNumber(void) { return FSE_VERSION_NUMBER; }
|
48
|
+
|
49
|
+
|
50
|
+
/*=== Error Management ===*/
|
51
|
+
unsigned FSE_isError(size_t code) { return ERR_isError(code); }
|
52
|
+
const char* FSE_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
53
|
+
|
54
|
+
unsigned HUF_isError(size_t code) { return ERR_isError(code); }
|
55
|
+
const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
56
|
+
|
57
|
+
|
58
|
+
/*-**************************************************************
|
59
|
+
* FSE NCount encoding-decoding
|
60
|
+
****************************************************************/
|
61
|
+
size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
62
|
+
const void* headerBuffer, size_t hbSize)
|
63
|
+
{
|
64
|
+
const BYTE* const istart = (const BYTE*) headerBuffer;
|
65
|
+
const BYTE* const iend = istart + hbSize;
|
66
|
+
const BYTE* ip = istart;
|
67
|
+
int nbBits;
|
68
|
+
int remaining;
|
69
|
+
int threshold;
|
70
|
+
U32 bitStream;
|
71
|
+
int bitCount;
|
72
|
+
unsigned charnum = 0;
|
73
|
+
int previous0 = 0;
|
74
|
+
|
75
|
+
if (hbSize < 4) {
|
76
|
+
/* This function only works when hbSize >= 4 */
|
77
|
+
char buffer[4];
|
78
|
+
memset(buffer, 0, sizeof(buffer));
|
79
|
+
memcpy(buffer, headerBuffer, hbSize);
|
80
|
+
{ size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr,
|
81
|
+
buffer, sizeof(buffer));
|
82
|
+
if (FSE_isError(countSize)) return countSize;
|
83
|
+
if (countSize > hbSize) return ERROR(corruption_detected);
|
84
|
+
return countSize;
|
85
|
+
} }
|
86
|
+
assert(hbSize >= 4);
|
87
|
+
|
88
|
+
/* init */
|
89
|
+
memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */
|
90
|
+
bitStream = MEM_readLE32(ip);
|
91
|
+
nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */
|
92
|
+
if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
|
93
|
+
bitStream >>= 4;
|
94
|
+
bitCount = 4;
|
95
|
+
*tableLogPtr = nbBits;
|
96
|
+
remaining = (1<<nbBits)+1;
|
97
|
+
threshold = 1<<nbBits;
|
98
|
+
nbBits++;
|
99
|
+
|
100
|
+
while ((remaining>1) & (charnum<=*maxSVPtr)) {
|
101
|
+
if (previous0) {
|
102
|
+
unsigned n0 = charnum;
|
103
|
+
while ((bitStream & 0xFFFF) == 0xFFFF) {
|
104
|
+
n0 += 24;
|
105
|
+
if (ip < iend-5) {
|
106
|
+
ip += 2;
|
107
|
+
bitStream = MEM_readLE32(ip) >> bitCount;
|
108
|
+
} else {
|
109
|
+
bitStream >>= 16;
|
110
|
+
bitCount += 16;
|
111
|
+
} }
|
112
|
+
while ((bitStream & 3) == 3) {
|
113
|
+
n0 += 3;
|
114
|
+
bitStream >>= 2;
|
115
|
+
bitCount += 2;
|
116
|
+
}
|
117
|
+
n0 += bitStream & 3;
|
118
|
+
bitCount += 2;
|
119
|
+
if (n0 > *maxSVPtr) return ERROR(maxSymbolValue_tooSmall);
|
120
|
+
while (charnum < n0) normalizedCounter[charnum++] = 0;
|
121
|
+
if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
122
|
+
assert((bitCount >> 3) <= 3); /* For first condition to work */
|
123
|
+
ip += bitCount>>3;
|
124
|
+
bitCount &= 7;
|
125
|
+
bitStream = MEM_readLE32(ip) >> bitCount;
|
126
|
+
} else {
|
127
|
+
bitStream >>= 2;
|
128
|
+
} }
|
129
|
+
{ int const max = (2*threshold-1) - remaining;
|
130
|
+
int count;
|
131
|
+
|
132
|
+
if ((bitStream & (threshold-1)) < (U32)max) {
|
133
|
+
count = bitStream & (threshold-1);
|
134
|
+
bitCount += nbBits-1;
|
135
|
+
} else {
|
136
|
+
count = bitStream & (2*threshold-1);
|
137
|
+
if (count >= threshold) count -= max;
|
138
|
+
bitCount += nbBits;
|
139
|
+
}
|
140
|
+
|
141
|
+
count--; /* extra accuracy */
|
142
|
+
remaining -= count < 0 ? -count : count; /* -1 means +1 */
|
143
|
+
normalizedCounter[charnum++] = (short)count;
|
144
|
+
previous0 = !count;
|
145
|
+
while (remaining < threshold) {
|
146
|
+
nbBits--;
|
147
|
+
threshold >>= 1;
|
148
|
+
}
|
149
|
+
|
150
|
+
if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
151
|
+
ip += bitCount>>3;
|
152
|
+
bitCount &= 7;
|
153
|
+
} else {
|
154
|
+
bitCount -= (int)(8 * (iend - 4 - ip));
|
155
|
+
ip = iend - 4;
|
156
|
+
}
|
157
|
+
bitStream = MEM_readLE32(ip) >> (bitCount & 31);
|
158
|
+
} } /* while ((remaining>1) & (charnum<=*maxSVPtr)) */
|
159
|
+
if (remaining != 1) return ERROR(corruption_detected);
|
160
|
+
if (bitCount > 32) return ERROR(corruption_detected);
|
161
|
+
*maxSVPtr = charnum-1;
|
162
|
+
|
163
|
+
ip += (bitCount+7)>>3;
|
164
|
+
return ip-istart;
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
/*! HUF_readStats() :
|
169
|
+
Read compact Huffman tree, saved by HUF_writeCTable().
|
170
|
+
`huffWeight` is destination buffer.
|
171
|
+
`rankStats` is assumed to be a table of at least HUF_TABLELOG_MAX U32.
|
172
|
+
@return : size read from `src` , or an error Code .
|
173
|
+
Note : Needed by HUF_readCTable() and HUF_readDTableX?() .
|
174
|
+
*/
|
175
|
+
size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
176
|
+
U32* nbSymbolsPtr, U32* tableLogPtr,
|
177
|
+
const void* src, size_t srcSize)
|
178
|
+
{
|
179
|
+
U32 weightTotal;
|
180
|
+
const BYTE* ip = (const BYTE*) src;
|
181
|
+
size_t iSize;
|
182
|
+
size_t oSize;
|
183
|
+
|
184
|
+
if (!srcSize) return ERROR(srcSize_wrong);
|
185
|
+
iSize = ip[0];
|
186
|
+
/* memset(huffWeight, 0, hwSize); *//* is not necessary, even though some analyzer complain ... */
|
187
|
+
|
188
|
+
if (iSize >= 128) { /* special header */
|
189
|
+
oSize = iSize - 127;
|
190
|
+
iSize = ((oSize+1)/2);
|
191
|
+
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
192
|
+
if (oSize >= hwSize) return ERROR(corruption_detected);
|
193
|
+
ip += 1;
|
194
|
+
{ U32 n;
|
195
|
+
for (n=0; n<oSize; n+=2) {
|
196
|
+
huffWeight[n] = ip[n/2] >> 4;
|
197
|
+
huffWeight[n+1] = ip[n/2] & 15;
|
198
|
+
} } }
|
199
|
+
else { /* header compressed with FSE (normal case) */
|
200
|
+
FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)]; /* 6 is max possible tableLog for HUF header (maybe even 5, to be tested) */
|
201
|
+
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
202
|
+
oSize = FSE_decompress_wksp(huffWeight, hwSize-1, ip+1, iSize, fseWorkspace, 6); /* max (hwSize-1) values decoded, as last one is implied */
|
203
|
+
if (FSE_isError(oSize)) return oSize;
|
204
|
+
}
|
205
|
+
|
206
|
+
/* collect weight stats */
|
207
|
+
memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
|
208
|
+
weightTotal = 0;
|
209
|
+
{ U32 n; for (n=0; n<oSize; n++) {
|
210
|
+
if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
211
|
+
rankStats[huffWeight[n]]++;
|
212
|
+
weightTotal += (1 << huffWeight[n]) >> 1;
|
213
|
+
} }
|
214
|
+
if (weightTotal == 0) return ERROR(corruption_detected);
|
215
|
+
|
216
|
+
/* get last non-null symbol weight (implied, total must be 2^n) */
|
217
|
+
{ U32 const tableLog = BIT_highbit32(weightTotal) + 1;
|
218
|
+
if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
219
|
+
*tableLogPtr = tableLog;
|
220
|
+
/* determine last weight */
|
221
|
+
{ U32 const total = 1 << tableLog;
|
222
|
+
U32 const rest = total - weightTotal;
|
223
|
+
U32 const verif = 1 << BIT_highbit32(rest);
|
224
|
+
U32 const lastWeight = BIT_highbit32(rest) + 1;
|
225
|
+
if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */
|
226
|
+
huffWeight[oSize] = (BYTE)lastWeight;
|
227
|
+
rankStats[lastWeight]++;
|
228
|
+
} }
|
229
|
+
|
230
|
+
/* check tree construction validity */
|
231
|
+
if ((rankStats[1] < 2) || (rankStats[1] & 1)) return ERROR(corruption_detected); /* by construction : at least 2 elts of rank 1, must be even */
|
232
|
+
|
233
|
+
/* results */
|
234
|
+
*nbSymbolsPtr = (U32)(oSize+1);
|
235
|
+
return iSize+1;
|
236
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* This source code is licensed under both the BSD-style license (found in the
|
6
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
+
* in the COPYING file in the root directory of this source tree).
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
9
|
+
*/
|
10
|
+
|
11
|
+
/* The purpose of this file is to have a single list of error strings embedded in binary */
|
12
|
+
|
13
|
+
#include "error_private.h"
|
14
|
+
|
15
|
+
const char* ERR_getErrorString(ERR_enum code)
|
16
|
+
{
|
17
|
+
#ifdef ZSTD_STRIP_ERROR_STRINGS
|
18
|
+
(void)code;
|
19
|
+
return "Error strings stripped";
|
20
|
+
#else
|
21
|
+
static const char* const notErrorCode = "Unspecified error code";
|
22
|
+
switch( code )
|
23
|
+
{
|
24
|
+
case PREFIX(no_error): return "No error detected";
|
25
|
+
case PREFIX(GENERIC): return "Error (generic)";
|
26
|
+
case PREFIX(prefix_unknown): return "Unknown frame descriptor";
|
27
|
+
case PREFIX(version_unsupported): return "Version not supported";
|
28
|
+
case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
|
29
|
+
case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
|
30
|
+
case PREFIX(corruption_detected): return "Corrupted block detected";
|
31
|
+
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
|
32
|
+
case PREFIX(parameter_unsupported): return "Unsupported parameter";
|
33
|
+
case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
|
34
|
+
case PREFIX(init_missing): return "Context should be init first";
|
35
|
+
case PREFIX(memory_allocation): return "Allocation error : not enough memory";
|
36
|
+
case PREFIX(workSpace_tooSmall): return "workSpace buffer is not large enough";
|
37
|
+
case PREFIX(stage_wrong): return "Operation not authorized at current processing stage";
|
38
|
+
case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
|
39
|
+
case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
|
40
|
+
case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
|
41
|
+
case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
|
42
|
+
case PREFIX(dictionary_wrong): return "Dictionary mismatch";
|
43
|
+
case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
|
44
|
+
case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
|
45
|
+
case PREFIX(srcSize_wrong): return "Src size is incorrect";
|
46
|
+
case PREFIX(dstBuffer_null): return "Operation on NULL destination buffer";
|
47
|
+
/* following error codes are not stable and may be removed or changed in a future version */
|
48
|
+
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
|
49
|
+
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
|
50
|
+
case PREFIX(maxCode):
|
51
|
+
default: return notErrorCode;
|
52
|
+
}
|
53
|
+
#endif
|
54
|
+
}
|