line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
Copyright 2016 Eric Biggers |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person |
5
|
|
|
|
|
|
|
obtaining a copy of this software and associated documentation files |
6
|
|
|
|
|
|
|
(the "Software"), to deal in the Software without restriction, |
7
|
|
|
|
|
|
|
including without limitation the rights to use, copy, modify, merge, |
8
|
|
|
|
|
|
|
publish, distribute, sublicense, and/or sell copies of the Software, |
9
|
|
|
|
|
|
|
and to permit persons to whom the Software is furnished to do so, |
10
|
|
|
|
|
|
|
subject to the following conditions: |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be |
13
|
|
|
|
|
|
|
included in all copies or substantial portions of the Software. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
16
|
|
|
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
17
|
|
|
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
18
|
|
|
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
19
|
|
|
|
|
|
|
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
20
|
|
|
|
|
|
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
21
|
|
|
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
|
|
|
|
SOFTWARE. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
*/ |
25
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/adler32.c */ |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
32
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
37
|
|
|
|
|
|
|
#endif |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
40
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
41
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
42
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
43
|
|
|
|
|
|
|
#else |
44
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
45
|
|
|
|
|
|
|
#endif |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
49
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
50
|
|
|
|
|
|
|
#else |
51
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
52
|
|
|
|
|
|
|
#endif |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
60
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
66
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#include |
69
|
|
|
|
|
|
|
#include |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#ifdef __cplusplus |
72
|
|
|
|
|
|
|
extern "C" { |
73
|
|
|
|
|
|
|
#endif |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
76
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
77
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
81
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
82
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
83
|
|
|
|
|
|
|
# else |
84
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
85
|
|
|
|
|
|
|
# endif |
86
|
|
|
|
|
|
|
#endif |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
struct libdeflate_compressor; |
93
|
|
|
|
|
|
|
struct libdeflate_options; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
97
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
101
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
102
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
106
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
107
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
108
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
112
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
113
|
|
|
|
|
|
|
size_t in_nbytes); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
117
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
118
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
119
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
123
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
124
|
|
|
|
|
|
|
size_t in_nbytes); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
128
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
129
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
130
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
134
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
135
|
|
|
|
|
|
|
size_t in_nbytes); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
139
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
146
|
|
|
|
|
|
|
struct libdeflate_options; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
150
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
154
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
enum libdeflate_result { |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
169
|
|
|
|
|
|
|
}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
173
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
174
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
175
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
176
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
180
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
181
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
182
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
183
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
184
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
188
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
189
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
190
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
191
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
195
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
196
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
197
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
198
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
199
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
203
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
204
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
205
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
206
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
210
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
211
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
212
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
213
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
214
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
218
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
226
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
231
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
239
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
240
|
|
|
|
|
|
|
void (*free_func)(void *)); |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
struct libdeflate_options { |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
size_t sizeof_options; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
250
|
|
|
|
|
|
|
void (*free_func)(void *); |
251
|
|
|
|
|
|
|
}; |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
#ifdef __cplusplus |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
#endif |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
#endif |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
#include |
261
|
|
|
|
|
|
|
#include |
262
|
|
|
|
|
|
|
#include |
263
|
|
|
|
|
|
|
#ifdef _MSC_VER |
264
|
|
|
|
|
|
|
# include |
265
|
|
|
|
|
|
|
# include |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
271
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
272
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
273
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
276
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
277
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
278
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
279
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
280
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
281
|
|
|
|
|
|
|
#endif |
282
|
|
|
|
|
|
|
#ifndef FREESTANDING |
283
|
|
|
|
|
|
|
# include |
284
|
|
|
|
|
|
|
#endif |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
292
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
293
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
294
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
295
|
|
|
|
|
|
|
#ifdef _MSC_VER |
296
|
|
|
|
|
|
|
# if defined(_M_X64) |
297
|
|
|
|
|
|
|
# define ARCH_X86_64 |
298
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
299
|
|
|
|
|
|
|
# define ARCH_X86_32 |
300
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
301
|
|
|
|
|
|
|
# define ARCH_ARM64 |
302
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
303
|
|
|
|
|
|
|
# define ARCH_ARM32 |
304
|
|
|
|
|
|
|
# endif |
305
|
|
|
|
|
|
|
#else |
306
|
|
|
|
|
|
|
# if defined(__x86_64__) |
307
|
|
|
|
|
|
|
# define ARCH_X86_64 |
308
|
|
|
|
|
|
|
# elif defined(__i386__) |
309
|
|
|
|
|
|
|
# define ARCH_X86_32 |
310
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
311
|
|
|
|
|
|
|
# define ARCH_ARM64 |
312
|
|
|
|
|
|
|
# elif defined(__arm__) |
313
|
|
|
|
|
|
|
# define ARCH_ARM32 |
314
|
|
|
|
|
|
|
# endif |
315
|
|
|
|
|
|
|
#endif |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
typedef uint8_t u8; |
323
|
|
|
|
|
|
|
typedef uint16_t u16; |
324
|
|
|
|
|
|
|
typedef uint32_t u32; |
325
|
|
|
|
|
|
|
typedef uint64_t u64; |
326
|
|
|
|
|
|
|
typedef int8_t s8; |
327
|
|
|
|
|
|
|
typedef int16_t s16; |
328
|
|
|
|
|
|
|
typedef int32_t s32; |
329
|
|
|
|
|
|
|
typedef int64_t s64; |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
#ifdef _MSC_VER |
333
|
|
|
|
|
|
|
# ifdef _WIN64 |
334
|
|
|
|
|
|
|
typedef long long ssize_t; |
335
|
|
|
|
|
|
|
# else |
336
|
|
|
|
|
|
|
typedef long ssize_t; |
337
|
|
|
|
|
|
|
# endif |
338
|
|
|
|
|
|
|
#endif |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
355
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
356
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
357
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
358
|
|
|
|
|
|
|
#else |
359
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
360
|
|
|
|
|
|
|
#endif |
361
|
|
|
|
|
|
|
#ifdef __clang__ |
362
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
363
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
364
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
365
|
|
|
|
|
|
|
# else |
366
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
367
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
368
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
369
|
|
|
|
|
|
|
# endif |
370
|
|
|
|
|
|
|
#else |
371
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
372
|
|
|
|
|
|
|
#endif |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
#ifndef __has_attribute |
376
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
377
|
|
|
|
|
|
|
#endif |
378
|
|
|
|
|
|
|
#ifndef __has_builtin |
379
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
380
|
|
|
|
|
|
|
#endif |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
#ifdef _MSC_VER |
384
|
|
|
|
|
|
|
# define inline __inline |
385
|
|
|
|
|
|
|
#endif |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
389
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
390
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
391
|
|
|
|
|
|
|
# define forceinline __forceinline |
392
|
|
|
|
|
|
|
#else |
393
|
|
|
|
|
|
|
# define forceinline inline |
394
|
|
|
|
|
|
|
#endif |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
398
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
399
|
|
|
|
|
|
|
#else |
400
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
401
|
|
|
|
|
|
|
#endif |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
405
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
406
|
|
|
|
|
|
|
# define restrict __restrict__ |
407
|
|
|
|
|
|
|
# else |
408
|
|
|
|
|
|
|
# define restrict |
409
|
|
|
|
|
|
|
# endif |
410
|
|
|
|
|
|
|
#endif |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
414
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
415
|
|
|
|
|
|
|
#else |
416
|
|
|
|
|
|
|
# define likely(expr) (expr) |
417
|
|
|
|
|
|
|
#endif |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
421
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
422
|
|
|
|
|
|
|
#else |
423
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
424
|
|
|
|
|
|
|
#endif |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
#undef prefetchr |
428
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
429
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
430
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
431
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
432
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
433
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
434
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
435
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
436
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
437
|
|
|
|
|
|
|
# endif |
438
|
|
|
|
|
|
|
#endif |
439
|
|
|
|
|
|
|
#ifndef prefetchr |
440
|
|
|
|
|
|
|
# define prefetchr(addr) |
441
|
|
|
|
|
|
|
#endif |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
#undef prefetchw |
445
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
446
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
447
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
448
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
449
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
450
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
451
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
452
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
453
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
454
|
|
|
|
|
|
|
# endif |
455
|
|
|
|
|
|
|
#endif |
456
|
|
|
|
|
|
|
#ifndef prefetchw |
457
|
|
|
|
|
|
|
# define prefetchw(addr) |
458
|
|
|
|
|
|
|
#endif |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
#undef _aligned_attribute |
462
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
463
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
464
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
465
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
466
|
|
|
|
|
|
|
#endif |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
470
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
471
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
472
|
|
|
|
|
|
|
#else |
473
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
474
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
475
|
|
|
|
|
|
|
#endif |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
482
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
483
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
484
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
485
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
486
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
487
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
495
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
496
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
497
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
498
|
|
|
|
|
|
|
#else |
499
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
500
|
|
|
|
|
|
|
{ |
501
|
|
|
|
|
|
|
union { |
502
|
|
|
|
|
|
|
u32 w; |
503
|
|
|
|
|
|
|
u8 b; |
504
|
|
|
|
|
|
|
} u; |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
u.w = 1; |
507
|
|
|
|
|
|
|
return u.b; |
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
#endif |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
513
|
|
|
|
|
|
|
{ |
514
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
515
|
24
|
|
|
|
|
|
return __builtin_bswap16(v); |
516
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
517
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
518
|
|
|
|
|
|
|
#else |
519
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
520
|
|
|
|
|
|
|
#endif |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
525
|
|
|
|
|
|
|
{ |
526
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
527
|
24
|
|
|
|
|
|
return __builtin_bswap32(v); |
528
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
529
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
530
|
|
|
|
|
|
|
#else |
531
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
532
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
533
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
534
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
535
|
|
|
|
|
|
|
#endif |
536
|
|
|
|
|
|
|
} |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
540
|
|
|
|
|
|
|
{ |
541
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
542
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
543
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
544
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
545
|
|
|
|
|
|
|
#else |
546
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
547
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
548
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
549
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
550
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
551
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
552
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
553
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
554
|
|
|
|
|
|
|
#endif |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
558
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
559
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
560
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
561
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
562
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
570
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
571
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
572
|
|
|
|
|
|
|
defined(__wasm__)) |
573
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
574
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
575
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
576
|
|
|
|
|
|
|
#else |
577
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
578
|
|
|
|
|
|
|
#endif |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
#ifdef FREESTANDING |
583
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
584
|
|
|
|
|
|
|
#else |
585
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
586
|
|
|
|
|
|
|
#endif |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
591
|
|
|
|
|
|
|
static forceinline type \ |
592
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
593
|
|
|
|
|
|
|
{ \ |
594
|
|
|
|
|
|
|
type v; \ |
595
|
|
|
|
|
|
|
\ |
596
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
597
|
|
|
|
|
|
|
return v; \ |
598
|
|
|
|
|
|
|
} \ |
599
|
|
|
|
|
|
|
\ |
600
|
|
|
|
|
|
|
static forceinline void \ |
601
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
602
|
|
|
|
|
|
|
{ \ |
603
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
604
|
|
|
|
|
|
|
} |
605
|
|
|
|
|
|
|
|
606
|
12
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
607
|
128476
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
608
|
11015
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
609
|
298975
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
#undef MEMCOPY |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
614
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
static forceinline u16 |
619
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
620
|
|
|
|
|
|
|
{ |
621
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
622
|
0
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
623
|
|
|
|
|
|
|
else |
624
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
static forceinline u16 |
628
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
629
|
|
|
|
|
|
|
{ |
630
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
631
|
12
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
632
|
|
|
|
|
|
|
else |
633
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
634
|
|
|
|
|
|
|
} |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
static forceinline u32 |
637
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
638
|
|
|
|
|
|
|
{ |
639
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
640
|
86219
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
641
|
|
|
|
|
|
|
else |
642
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
643
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
644
|
|
|
|
|
|
|
} |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
static forceinline u32 |
647
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
648
|
|
|
|
|
|
|
{ |
649
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
650
|
12
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
651
|
|
|
|
|
|
|
else |
652
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
653
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
static forceinline u64 |
657
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
658
|
|
|
|
|
|
|
{ |
659
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
660
|
11015
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
661
|
|
|
|
|
|
|
else |
662
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
663
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
664
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
665
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
static forceinline machine_word_t |
669
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
670
|
|
|
|
|
|
|
{ |
671
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
672
|
|
|
|
|
|
|
if (WORDBITS == 32) |
673
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
674
|
|
|
|
|
|
|
else |
675
|
11015
|
|
|
|
|
|
return get_unaligned_le64(p); |
676
|
|
|
|
|
|
|
} |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
static forceinline void |
681
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
682
|
|
|
|
|
|
|
{ |
683
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
684
|
0
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
685
|
|
|
|
|
|
|
} else { |
686
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
687
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
688
|
|
|
|
|
|
|
} |
689
|
|
|
|
|
|
|
} |
690
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
static forceinline void |
692
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
693
|
|
|
|
|
|
|
{ |
694
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
695
|
24
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
696
|
|
|
|
|
|
|
} else { |
697
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
698
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
699
|
|
|
|
|
|
|
} |
700
|
|
|
|
|
|
|
} |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
static forceinline void |
703
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
704
|
|
|
|
|
|
|
{ |
705
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
706
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
707
|
|
|
|
|
|
|
} else { |
708
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
709
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
710
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
711
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
static forceinline void |
716
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
717
|
|
|
|
|
|
|
{ |
718
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
719
|
12
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
720
|
|
|
|
|
|
|
} else { |
721
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
722
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
723
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
724
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
725
|
|
|
|
|
|
|
} |
726
|
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
static forceinline void |
729
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
730
|
|
|
|
|
|
|
{ |
731
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
732
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
733
|
|
|
|
|
|
|
} else { |
734
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
735
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
736
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
737
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
738
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
739
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
740
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
741
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
742
|
|
|
|
|
|
|
} |
743
|
|
|
|
|
|
|
} |
744
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
static forceinline void |
746
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
747
|
|
|
|
|
|
|
{ |
748
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
749
|
|
|
|
|
|
|
if (WORDBITS == 32) |
750
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
751
|
|
|
|
|
|
|
else |
752
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
753
|
|
|
|
|
|
|
} |
754
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
static forceinline unsigned |
762
|
|
|
|
|
|
|
bsr32(u32 v) |
763
|
|
|
|
|
|
|
{ |
764
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
765
|
12249
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
766
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
767
|
|
|
|
|
|
|
unsigned long i; |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
770
|
|
|
|
|
|
|
return i; |
771
|
|
|
|
|
|
|
#else |
772
|
|
|
|
|
|
|
unsigned i = 0; |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
775
|
|
|
|
|
|
|
i++; |
776
|
|
|
|
|
|
|
return i; |
777
|
|
|
|
|
|
|
#endif |
778
|
|
|
|
|
|
|
} |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
static forceinline unsigned |
781
|
|
|
|
|
|
|
bsr64(u64 v) |
782
|
|
|
|
|
|
|
{ |
783
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
784
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
785
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
786
|
|
|
|
|
|
|
unsigned long i; |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
789
|
|
|
|
|
|
|
return i; |
790
|
|
|
|
|
|
|
#else |
791
|
|
|
|
|
|
|
unsigned i = 0; |
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
794
|
|
|
|
|
|
|
i++; |
795
|
|
|
|
|
|
|
return i; |
796
|
|
|
|
|
|
|
#endif |
797
|
|
|
|
|
|
|
} |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
static forceinline unsigned |
800
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
801
|
|
|
|
|
|
|
{ |
802
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
803
|
|
|
|
|
|
|
if (WORDBITS == 32) |
804
|
|
|
|
|
|
|
return bsr32(v); |
805
|
|
|
|
|
|
|
else |
806
|
|
|
|
|
|
|
return bsr64(v); |
807
|
|
|
|
|
|
|
} |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
static forceinline unsigned |
812
|
|
|
|
|
|
|
bsf32(u32 v) |
813
|
|
|
|
|
|
|
{ |
814
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
815
|
|
|
|
|
|
|
return __builtin_ctz(v); |
816
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
817
|
|
|
|
|
|
|
unsigned long i; |
818
|
|
|
|
|
|
|
|
819
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
820
|
|
|
|
|
|
|
return i; |
821
|
|
|
|
|
|
|
#else |
822
|
|
|
|
|
|
|
unsigned i = 0; |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
825
|
|
|
|
|
|
|
i++; |
826
|
|
|
|
|
|
|
return i; |
827
|
|
|
|
|
|
|
#endif |
828
|
|
|
|
|
|
|
} |
829
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
static forceinline unsigned |
831
|
|
|
|
|
|
|
bsf64(u64 v) |
832
|
|
|
|
|
|
|
{ |
833
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
834
|
2632
|
|
|
|
|
|
return __builtin_ctzll(v); |
835
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
836
|
|
|
|
|
|
|
unsigned long i; |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
839
|
|
|
|
|
|
|
return i; |
840
|
|
|
|
|
|
|
#else |
841
|
|
|
|
|
|
|
unsigned i = 0; |
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
844
|
|
|
|
|
|
|
i++; |
845
|
|
|
|
|
|
|
return i; |
846
|
|
|
|
|
|
|
#endif |
847
|
|
|
|
|
|
|
} |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
static forceinline unsigned |
850
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
851
|
|
|
|
|
|
|
{ |
852
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
853
|
|
|
|
|
|
|
if (WORDBITS == 32) |
854
|
|
|
|
|
|
|
return bsf32(v); |
855
|
|
|
|
|
|
|
else |
856
|
2632
|
|
|
|
|
|
return bsf64(v); |
857
|
|
|
|
|
|
|
} |
858
|
|
|
|
|
|
|
|
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
#undef rbit32 |
861
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
862
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
863
|
|
|
|
|
|
|
static forceinline u32 |
864
|
|
|
|
|
|
|
rbit32(u32 v) |
865
|
|
|
|
|
|
|
{ |
866
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
867
|
|
|
|
|
|
|
return v; |
868
|
|
|
|
|
|
|
} |
869
|
|
|
|
|
|
|
#define rbit32 rbit32 |
870
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
871
|
|
|
|
|
|
|
static forceinline u32 |
872
|
|
|
|
|
|
|
rbit32(u32 v) |
873
|
|
|
|
|
|
|
{ |
874
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
875
|
|
|
|
|
|
|
return v; |
876
|
|
|
|
|
|
|
} |
877
|
|
|
|
|
|
|
#define rbit32 rbit32 |
878
|
|
|
|
|
|
|
#endif |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
#endif |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
|
883
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
884
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
887
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
890
|
|
|
|
|
|
|
size_t alignment, size_t size); |
891
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
#ifdef FREESTANDING |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
896
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
899
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
900
|
|
|
|
|
|
|
|
901
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
902
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
905
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
908
|
|
|
|
|
|
|
#else |
909
|
|
|
|
|
|
|
#include |
910
|
|
|
|
|
|
|
#endif |
911
|
|
|
|
|
|
|
|
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
914
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
915
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
916
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
917
|
|
|
|
|
|
|
#else |
918
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
919
|
|
|
|
|
|
|
#endif |
920
|
|
|
|
|
|
|
|
921
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
922
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
923
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
924
|
|
|
|
|
|
|
|
925
|
|
|
|
|
|
|
#endif |
926
|
|
|
|
|
|
|
|
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
|
929
|
|
|
|
|
|
|
#define DIVISOR 65521 |
930
|
|
|
|
|
|
|
|
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
#define MAX_CHUNK_LEN 5552 |
933
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
static u32 MAYBE_UNUSED |
935
|
0
|
|
|
|
|
|
adler32_generic(u32 adler, const u8 *p, size_t len) |
936
|
|
|
|
|
|
|
{ |
937
|
0
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
938
|
0
|
|
|
|
|
|
u32 s2 = adler >> 16; |
939
|
0
|
|
|
|
|
|
const u8 * const end = p + len; |
940
|
|
|
|
|
|
|
|
941
|
0
|
0
|
|
|
|
|
while (p != end) { |
942
|
0
|
|
|
|
|
|
size_t chunk_len = MIN(end - p, MAX_CHUNK_LEN); |
943
|
0
|
|
|
|
|
|
const u8 *chunk_end = p + chunk_len; |
944
|
0
|
|
|
|
|
|
size_t num_unrolled_iterations = chunk_len / 4; |
945
|
|
|
|
|
|
|
|
946
|
0
|
0
|
|
|
|
|
while (num_unrolled_iterations--) { |
947
|
0
|
|
|
|
|
|
s1 += *p++; |
948
|
0
|
|
|
|
|
|
s2 += s1; |
949
|
0
|
|
|
|
|
|
s1 += *p++; |
950
|
0
|
|
|
|
|
|
s2 += s1; |
951
|
0
|
|
|
|
|
|
s1 += *p++; |
952
|
0
|
|
|
|
|
|
s2 += s1; |
953
|
0
|
|
|
|
|
|
s1 += *p++; |
954
|
0
|
|
|
|
|
|
s2 += s1; |
955
|
|
|
|
|
|
|
} |
956
|
0
|
0
|
|
|
|
|
while (p != chunk_end) { |
957
|
0
|
|
|
|
|
|
s1 += *p++; |
958
|
0
|
|
|
|
|
|
s2 += s1; |
959
|
|
|
|
|
|
|
} |
960
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
961
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
962
|
|
|
|
|
|
|
} |
963
|
|
|
|
|
|
|
|
964
|
0
|
|
|
|
|
|
return (s2 << 16) | s1; |
965
|
|
|
|
|
|
|
} |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
|
968
|
|
|
|
|
|
|
#undef DEFAULT_IMPL |
969
|
|
|
|
|
|
|
#undef arch_select_adler32_func |
970
|
|
|
|
|
|
|
typedef u32 (*adler32_func_t)(u32 adler, const u8 *p, size_t len); |
971
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
972
|
|
|
|
|
|
|
/* # include "arm/adler32_impl.h" */ |
973
|
|
|
|
|
|
|
|
974
|
|
|
|
|
|
|
|
975
|
|
|
|
|
|
|
#ifndef LIB_ARM_ADLER32_IMPL_H |
976
|
|
|
|
|
|
|
#define LIB_ARM_ADLER32_IMPL_H |
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
979
|
|
|
|
|
|
|
|
980
|
|
|
|
|
|
|
|
981
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
982
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
988
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
989
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
993
|
|
|
|
|
|
|
#endif |
994
|
|
|
|
|
|
|
|
995
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
996
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
997
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
998
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
999
|
|
|
|
|
|
|
#else |
1000
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
1001
|
|
|
|
|
|
|
#endif |
1002
|
|
|
|
|
|
|
|
1003
|
|
|
|
|
|
|
|
1004
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
1005
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
1006
|
|
|
|
|
|
|
#else |
1007
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
1008
|
|
|
|
|
|
|
#endif |
1009
|
|
|
|
|
|
|
|
1010
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
1011
|
|
|
|
|
|
|
|
1012
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
1013
|
|
|
|
|
|
|
|
1014
|
|
|
|
|
|
|
|
1015
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
1016
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
1017
|
|
|
|
|
|
|
|
1018
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
1022
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
#include |
1025
|
|
|
|
|
|
|
#include |
1026
|
|
|
|
|
|
|
|
1027
|
|
|
|
|
|
|
#ifdef __cplusplus |
1028
|
|
|
|
|
|
|
extern "C" { |
1029
|
|
|
|
|
|
|
#endif |
1030
|
|
|
|
|
|
|
|
1031
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
1032
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
1033
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
|
1036
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
1037
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
1038
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
1039
|
|
|
|
|
|
|
# else |
1040
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
1041
|
|
|
|
|
|
|
# endif |
1042
|
|
|
|
|
|
|
#endif |
1043
|
|
|
|
|
|
|
|
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
|
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
struct libdeflate_compressor; |
1049
|
|
|
|
|
|
|
struct libdeflate_options; |
1050
|
|
|
|
|
|
|
|
1051
|
|
|
|
|
|
|
|
1052
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
1053
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
1054
|
|
|
|
|
|
|
|
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
1057
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
1058
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
1059
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
|
1061
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1062
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
1063
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1064
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
1065
|
|
|
|
|
|
|
|
1066
|
|
|
|
|
|
|
|
1067
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1068
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
1069
|
|
|
|
|
|
|
size_t in_nbytes); |
1070
|
|
|
|
|
|
|
|
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1073
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
1074
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1075
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
|
1078
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1079
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
1080
|
|
|
|
|
|
|
size_t in_nbytes); |
1081
|
|
|
|
|
|
|
|
1082
|
|
|
|
|
|
|
|
1083
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1084
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
1085
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1086
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
1087
|
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1090
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
1091
|
|
|
|
|
|
|
size_t in_nbytes); |
1092
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
|
1094
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
1095
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
|
1100
|
|
|
|
|
|
|
|
1101
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
1102
|
|
|
|
|
|
|
struct libdeflate_options; |
1103
|
|
|
|
|
|
|
|
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
1106
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
1107
|
|
|
|
|
|
|
|
1108
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
1110
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
1111
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
enum libdeflate_result { |
1114
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
|
1118
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
|
1124
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
1125
|
|
|
|
|
|
|
}; |
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
|
1128
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1129
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
1130
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1131
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1132
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1133
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1136
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
1137
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1138
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1139
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
1140
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1141
|
|
|
|
|
|
|
|
1142
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1144
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
1145
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1146
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1147
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
|
1150
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1151
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
1152
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1153
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1154
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
1155
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
|
1158
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1159
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
1160
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1161
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1162
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1163
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
|
1165
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1166
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
1167
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1168
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1169
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
1170
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1171
|
|
|
|
|
|
|
|
1172
|
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
1174
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
1175
|
|
|
|
|
|
|
|
1176
|
|
|
|
|
|
|
|
1177
|
|
|
|
|
|
|
|
1178
|
|
|
|
|
|
|
|
1179
|
|
|
|
|
|
|
|
1180
|
|
|
|
|
|
|
|
1181
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
1182
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
1183
|
|
|
|
|
|
|
|
1184
|
|
|
|
|
|
|
|
1185
|
|
|
|
|
|
|
|
1186
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
1187
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
1188
|
|
|
|
|
|
|
|
1189
|
|
|
|
|
|
|
|
1190
|
|
|
|
|
|
|
|
1191
|
|
|
|
|
|
|
|
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
|
1194
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
1195
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
1196
|
|
|
|
|
|
|
void (*free_func)(void *)); |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
|
1199
|
|
|
|
|
|
|
struct libdeflate_options { |
1200
|
|
|
|
|
|
|
|
1201
|
|
|
|
|
|
|
|
1202
|
|
|
|
|
|
|
size_t sizeof_options; |
1203
|
|
|
|
|
|
|
|
1204
|
|
|
|
|
|
|
|
1205
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
1206
|
|
|
|
|
|
|
void (*free_func)(void *); |
1207
|
|
|
|
|
|
|
}; |
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
#ifdef __cplusplus |
1210
|
|
|
|
|
|
|
} |
1211
|
|
|
|
|
|
|
#endif |
1212
|
|
|
|
|
|
|
|
1213
|
|
|
|
|
|
|
#endif |
1214
|
|
|
|
|
|
|
|
1215
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
#include |
1217
|
|
|
|
|
|
|
#include |
1218
|
|
|
|
|
|
|
#include |
1219
|
|
|
|
|
|
|
#ifdef _MSC_VER |
1220
|
|
|
|
|
|
|
# include |
1221
|
|
|
|
|
|
|
# include |
1222
|
|
|
|
|
|
|
|
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
1225
|
|
|
|
|
|
|
|
1226
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
1227
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
1228
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
1229
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
1230
|
|
|
|
|
|
|
|
1231
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
1232
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
1233
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
1234
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
1235
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
1236
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
1237
|
|
|
|
|
|
|
#endif |
1238
|
|
|
|
|
|
|
#ifndef FREESTANDING |
1239
|
|
|
|
|
|
|
# include |
1240
|
|
|
|
|
|
|
#endif |
1241
|
|
|
|
|
|
|
|
1242
|
|
|
|
|
|
|
|
1243
|
|
|
|
|
|
|
|
1244
|
|
|
|
|
|
|
|
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
1248
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
1249
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
1250
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
1251
|
|
|
|
|
|
|
#ifdef _MSC_VER |
1252
|
|
|
|
|
|
|
# if defined(_M_X64) |
1253
|
|
|
|
|
|
|
# define ARCH_X86_64 |
1254
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
1255
|
|
|
|
|
|
|
# define ARCH_X86_32 |
1256
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
1257
|
|
|
|
|
|
|
# define ARCH_ARM64 |
1258
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
1259
|
|
|
|
|
|
|
# define ARCH_ARM32 |
1260
|
|
|
|
|
|
|
# endif |
1261
|
|
|
|
|
|
|
#else |
1262
|
|
|
|
|
|
|
# if defined(__x86_64__) |
1263
|
|
|
|
|
|
|
# define ARCH_X86_64 |
1264
|
|
|
|
|
|
|
# elif defined(__i386__) |
1265
|
|
|
|
|
|
|
# define ARCH_X86_32 |
1266
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
1267
|
|
|
|
|
|
|
# define ARCH_ARM64 |
1268
|
|
|
|
|
|
|
# elif defined(__arm__) |
1269
|
|
|
|
|
|
|
# define ARCH_ARM32 |
1270
|
|
|
|
|
|
|
# endif |
1271
|
|
|
|
|
|
|
#endif |
1272
|
|
|
|
|
|
|
|
1273
|
|
|
|
|
|
|
|
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
|
1276
|
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
|
|
1278
|
|
|
|
|
|
|
typedef uint8_t u8; |
1279
|
|
|
|
|
|
|
typedef uint16_t u16; |
1280
|
|
|
|
|
|
|
typedef uint32_t u32; |
1281
|
|
|
|
|
|
|
typedef uint64_t u64; |
1282
|
|
|
|
|
|
|
typedef int8_t s8; |
1283
|
|
|
|
|
|
|
typedef int16_t s16; |
1284
|
|
|
|
|
|
|
typedef int32_t s32; |
1285
|
|
|
|
|
|
|
typedef int64_t s64; |
1286
|
|
|
|
|
|
|
|
1287
|
|
|
|
|
|
|
|
1288
|
|
|
|
|
|
|
#ifdef _MSC_VER |
1289
|
|
|
|
|
|
|
# ifdef _WIN64 |
1290
|
|
|
|
|
|
|
typedef long long ssize_t; |
1291
|
|
|
|
|
|
|
# else |
1292
|
|
|
|
|
|
|
typedef long ssize_t; |
1293
|
|
|
|
|
|
|
# endif |
1294
|
|
|
|
|
|
|
#endif |
1295
|
|
|
|
|
|
|
|
1296
|
|
|
|
|
|
|
|
1297
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
1298
|
|
|
|
|
|
|
|
1299
|
|
|
|
|
|
|
|
1300
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
1301
|
|
|
|
|
|
|
|
1302
|
|
|
|
|
|
|
|
1303
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
1304
|
|
|
|
|
|
|
|
1305
|
|
|
|
|
|
|
|
1306
|
|
|
|
|
|
|
|
1307
|
|
|
|
|
|
|
|
1308
|
|
|
|
|
|
|
|
1309
|
|
|
|
|
|
|
|
1310
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
1311
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
1312
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
1313
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
1314
|
|
|
|
|
|
|
#else |
1315
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
1316
|
|
|
|
|
|
|
#endif |
1317
|
|
|
|
|
|
|
#ifdef __clang__ |
1318
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
1319
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
1320
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
1321
|
|
|
|
|
|
|
# else |
1322
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
1323
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
1324
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
1325
|
|
|
|
|
|
|
# endif |
1326
|
|
|
|
|
|
|
#else |
1327
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
1328
|
|
|
|
|
|
|
#endif |
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
|
1331
|
|
|
|
|
|
|
#ifndef __has_attribute |
1332
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
1333
|
|
|
|
|
|
|
#endif |
1334
|
|
|
|
|
|
|
#ifndef __has_builtin |
1335
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
1336
|
|
|
|
|
|
|
#endif |
1337
|
|
|
|
|
|
|
|
1338
|
|
|
|
|
|
|
|
1339
|
|
|
|
|
|
|
#ifdef _MSC_VER |
1340
|
|
|
|
|
|
|
# define inline __inline |
1341
|
|
|
|
|
|
|
#endif |
1342
|
|
|
|
|
|
|
|
1343
|
|
|
|
|
|
|
|
1344
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
1345
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
1346
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1347
|
|
|
|
|
|
|
# define forceinline __forceinline |
1348
|
|
|
|
|
|
|
#else |
1349
|
|
|
|
|
|
|
# define forceinline inline |
1350
|
|
|
|
|
|
|
#endif |
1351
|
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
|
|
1353
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
1354
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
1355
|
|
|
|
|
|
|
#else |
1356
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
1357
|
|
|
|
|
|
|
#endif |
1358
|
|
|
|
|
|
|
|
1359
|
|
|
|
|
|
|
|
1360
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
1361
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
1362
|
|
|
|
|
|
|
# define restrict __restrict__ |
1363
|
|
|
|
|
|
|
# else |
1364
|
|
|
|
|
|
|
# define restrict |
1365
|
|
|
|
|
|
|
# endif |
1366
|
|
|
|
|
|
|
#endif |
1367
|
|
|
|
|
|
|
|
1368
|
|
|
|
|
|
|
|
1369
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
1370
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
1371
|
|
|
|
|
|
|
#else |
1372
|
|
|
|
|
|
|
# define likely(expr) (expr) |
1373
|
|
|
|
|
|
|
#endif |
1374
|
|
|
|
|
|
|
|
1375
|
|
|
|
|
|
|
|
1376
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
1377
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
1378
|
|
|
|
|
|
|
#else |
1379
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
1380
|
|
|
|
|
|
|
#endif |
1381
|
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
|
1383
|
|
|
|
|
|
|
#undef prefetchr |
1384
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
1385
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
1386
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1387
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
1388
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
1389
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
1390
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
1391
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
1392
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
1393
|
|
|
|
|
|
|
# endif |
1394
|
|
|
|
|
|
|
#endif |
1395
|
|
|
|
|
|
|
#ifndef prefetchr |
1396
|
|
|
|
|
|
|
# define prefetchr(addr) |
1397
|
|
|
|
|
|
|
#endif |
1398
|
|
|
|
|
|
|
|
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
#undef prefetchw |
1401
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
1402
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
1403
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1404
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
1405
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
1406
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
1407
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
1408
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
1409
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
1410
|
|
|
|
|
|
|
# endif |
1411
|
|
|
|
|
|
|
#endif |
1412
|
|
|
|
|
|
|
#ifndef prefetchw |
1413
|
|
|
|
|
|
|
# define prefetchw(addr) |
1414
|
|
|
|
|
|
|
#endif |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
|
1417
|
|
|
|
|
|
|
#undef _aligned_attribute |
1418
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
1419
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
1420
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1421
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
1422
|
|
|
|
|
|
|
#endif |
1423
|
|
|
|
|
|
|
|
1424
|
|
|
|
|
|
|
|
1425
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
1426
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
1427
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
1428
|
|
|
|
|
|
|
#else |
1429
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
1430
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
1431
|
|
|
|
|
|
|
#endif |
1432
|
|
|
|
|
|
|
|
1433
|
|
|
|
|
|
|
|
1434
|
|
|
|
|
|
|
|
1435
|
|
|
|
|
|
|
|
1436
|
|
|
|
|
|
|
|
1437
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
1438
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
1439
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
1440
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
1441
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
1442
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
1443
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
1444
|
|
|
|
|
|
|
|
1445
|
|
|
|
|
|
|
|
1446
|
|
|
|
|
|
|
|
1447
|
|
|
|
|
|
|
|
1448
|
|
|
|
|
|
|
|
1449
|
|
|
|
|
|
|
|
1450
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
1451
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
1452
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1453
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
1454
|
|
|
|
|
|
|
#else |
1455
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
1456
|
|
|
|
|
|
|
{ |
1457
|
|
|
|
|
|
|
union { |
1458
|
|
|
|
|
|
|
u32 w; |
1459
|
|
|
|
|
|
|
u8 b; |
1460
|
|
|
|
|
|
|
} u; |
1461
|
|
|
|
|
|
|
|
1462
|
|
|
|
|
|
|
u.w = 1; |
1463
|
|
|
|
|
|
|
return u.b; |
1464
|
|
|
|
|
|
|
} |
1465
|
|
|
|
|
|
|
#endif |
1466
|
|
|
|
|
|
|
|
1467
|
|
|
|
|
|
|
|
1468
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
1469
|
|
|
|
|
|
|
{ |
1470
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
1471
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
1472
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1473
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
1474
|
|
|
|
|
|
|
#else |
1475
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
1476
|
|
|
|
|
|
|
#endif |
1477
|
|
|
|
|
|
|
} |
1478
|
|
|
|
|
|
|
|
1479
|
|
|
|
|
|
|
|
1480
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
1481
|
|
|
|
|
|
|
{ |
1482
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
1483
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
1484
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1485
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
1486
|
|
|
|
|
|
|
#else |
1487
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
1488
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
1489
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
1490
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
1491
|
|
|
|
|
|
|
#endif |
1492
|
|
|
|
|
|
|
} |
1493
|
|
|
|
|
|
|
|
1494
|
|
|
|
|
|
|
|
1495
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
1496
|
|
|
|
|
|
|
{ |
1497
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
1498
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
1499
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1500
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
1501
|
|
|
|
|
|
|
#else |
1502
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
1503
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
1504
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
1505
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
1506
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
1507
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
1508
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
1509
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
1510
|
|
|
|
|
|
|
#endif |
1511
|
|
|
|
|
|
|
} |
1512
|
|
|
|
|
|
|
|
1513
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
1514
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
1515
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
1516
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
1517
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
1518
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
1519
|
|
|
|
|
|
|
|
1520
|
|
|
|
|
|
|
|
1521
|
|
|
|
|
|
|
|
1522
|
|
|
|
|
|
|
|
1523
|
|
|
|
|
|
|
|
1524
|
|
|
|
|
|
|
|
1525
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
1526
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
1527
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
1528
|
|
|
|
|
|
|
defined(__wasm__)) |
1529
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
1530
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1531
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
1532
|
|
|
|
|
|
|
#else |
1533
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
1534
|
|
|
|
|
|
|
#endif |
1535
|
|
|
|
|
|
|
|
1536
|
|
|
|
|
|
|
|
1537
|
|
|
|
|
|
|
|
1538
|
|
|
|
|
|
|
#ifdef FREESTANDING |
1539
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
1540
|
|
|
|
|
|
|
#else |
1541
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
1542
|
|
|
|
|
|
|
#endif |
1543
|
|
|
|
|
|
|
|
1544
|
|
|
|
|
|
|
|
1545
|
|
|
|
|
|
|
|
1546
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
1547
|
|
|
|
|
|
|
static forceinline type \ |
1548
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
1549
|
|
|
|
|
|
|
{ \ |
1550
|
|
|
|
|
|
|
type v; \ |
1551
|
|
|
|
|
|
|
\ |
1552
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
1553
|
|
|
|
|
|
|
return v; \ |
1554
|
|
|
|
|
|
|
} \ |
1555
|
|
|
|
|
|
|
\ |
1556
|
|
|
|
|
|
|
static forceinline void \ |
1557
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
1558
|
|
|
|
|
|
|
{ \ |
1559
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
1560
|
|
|
|
|
|
|
} |
1561
|
|
|
|
|
|
|
|
1562
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
1563
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
1564
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
1565
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
1566
|
|
|
|
|
|
|
|
1567
|
|
|
|
|
|
|
#undef MEMCOPY |
1568
|
|
|
|
|
|
|
|
1569
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
1570
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
1571
|
|
|
|
|
|
|
|
1572
|
|
|
|
|
|
|
|
1573
|
|
|
|
|
|
|
|
1574
|
|
|
|
|
|
|
static forceinline u16 |
1575
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
1576
|
|
|
|
|
|
|
{ |
1577
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1578
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
1579
|
|
|
|
|
|
|
else |
1580
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
1581
|
|
|
|
|
|
|
} |
1582
|
|
|
|
|
|
|
|
1583
|
|
|
|
|
|
|
static forceinline u16 |
1584
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
1585
|
|
|
|
|
|
|
{ |
1586
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1587
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
1588
|
|
|
|
|
|
|
else |
1589
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
1590
|
|
|
|
|
|
|
} |
1591
|
|
|
|
|
|
|
|
1592
|
|
|
|
|
|
|
static forceinline u32 |
1593
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
1594
|
|
|
|
|
|
|
{ |
1595
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1596
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
1597
|
|
|
|
|
|
|
else |
1598
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
1599
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
1600
|
|
|
|
|
|
|
} |
1601
|
|
|
|
|
|
|
|
1602
|
|
|
|
|
|
|
static forceinline u32 |
1603
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
1604
|
|
|
|
|
|
|
{ |
1605
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1606
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
1607
|
|
|
|
|
|
|
else |
1608
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
1609
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
1610
|
|
|
|
|
|
|
} |
1611
|
|
|
|
|
|
|
|
1612
|
|
|
|
|
|
|
static forceinline u64 |
1613
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
1614
|
|
|
|
|
|
|
{ |
1615
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1616
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
1617
|
|
|
|
|
|
|
else |
1618
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
1619
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
1620
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
1621
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
1622
|
|
|
|
|
|
|
} |
1623
|
|
|
|
|
|
|
|
1624
|
|
|
|
|
|
|
static forceinline machine_word_t |
1625
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
1626
|
|
|
|
|
|
|
{ |
1627
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
1628
|
|
|
|
|
|
|
if (WORDBITS == 32) |
1629
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
1630
|
|
|
|
|
|
|
else |
1631
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
1632
|
|
|
|
|
|
|
} |
1633
|
|
|
|
|
|
|
|
1634
|
|
|
|
|
|
|
|
1635
|
|
|
|
|
|
|
|
1636
|
|
|
|
|
|
|
static forceinline void |
1637
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
1638
|
|
|
|
|
|
|
{ |
1639
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1640
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
1641
|
|
|
|
|
|
|
} else { |
1642
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
1643
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
1644
|
|
|
|
|
|
|
} |
1645
|
|
|
|
|
|
|
} |
1646
|
|
|
|
|
|
|
|
1647
|
|
|
|
|
|
|
static forceinline void |
1648
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
1649
|
|
|
|
|
|
|
{ |
1650
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1651
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
1652
|
|
|
|
|
|
|
} else { |
1653
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
1654
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
1655
|
|
|
|
|
|
|
} |
1656
|
|
|
|
|
|
|
} |
1657
|
|
|
|
|
|
|
|
1658
|
|
|
|
|
|
|
static forceinline void |
1659
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
1660
|
|
|
|
|
|
|
{ |
1661
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1662
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
1663
|
|
|
|
|
|
|
} else { |
1664
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
1665
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
1666
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
1667
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
1668
|
|
|
|
|
|
|
} |
1669
|
|
|
|
|
|
|
} |
1670
|
|
|
|
|
|
|
|
1671
|
|
|
|
|
|
|
static forceinline void |
1672
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
1673
|
|
|
|
|
|
|
{ |
1674
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1675
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
1676
|
|
|
|
|
|
|
} else { |
1677
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
1678
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
1679
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
1680
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
1681
|
|
|
|
|
|
|
} |
1682
|
|
|
|
|
|
|
} |
1683
|
|
|
|
|
|
|
|
1684
|
|
|
|
|
|
|
static forceinline void |
1685
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
1686
|
|
|
|
|
|
|
{ |
1687
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1688
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
1689
|
|
|
|
|
|
|
} else { |
1690
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
1691
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
1692
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
1693
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
1694
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
1695
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
1696
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
1697
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
1698
|
|
|
|
|
|
|
} |
1699
|
|
|
|
|
|
|
} |
1700
|
|
|
|
|
|
|
|
1701
|
|
|
|
|
|
|
static forceinline void |
1702
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
1703
|
|
|
|
|
|
|
{ |
1704
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
1705
|
|
|
|
|
|
|
if (WORDBITS == 32) |
1706
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
1707
|
|
|
|
|
|
|
else |
1708
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
1709
|
|
|
|
|
|
|
} |
1710
|
|
|
|
|
|
|
|
1711
|
|
|
|
|
|
|
|
1712
|
|
|
|
|
|
|
|
1713
|
|
|
|
|
|
|
|
1714
|
|
|
|
|
|
|
|
1715
|
|
|
|
|
|
|
|
1716
|
|
|
|
|
|
|
|
1717
|
|
|
|
|
|
|
static forceinline unsigned |
1718
|
|
|
|
|
|
|
bsr32(u32 v) |
1719
|
|
|
|
|
|
|
{ |
1720
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
1721
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
1722
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1723
|
|
|
|
|
|
|
unsigned long i; |
1724
|
|
|
|
|
|
|
|
1725
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
1726
|
|
|
|
|
|
|
return i; |
1727
|
|
|
|
|
|
|
#else |
1728
|
|
|
|
|
|
|
unsigned i = 0; |
1729
|
|
|
|
|
|
|
|
1730
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
1731
|
|
|
|
|
|
|
i++; |
1732
|
|
|
|
|
|
|
return i; |
1733
|
|
|
|
|
|
|
#endif |
1734
|
|
|
|
|
|
|
} |
1735
|
|
|
|
|
|
|
|
1736
|
|
|
|
|
|
|
static forceinline unsigned |
1737
|
|
|
|
|
|
|
bsr64(u64 v) |
1738
|
|
|
|
|
|
|
{ |
1739
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
1740
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
1741
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
1742
|
|
|
|
|
|
|
unsigned long i; |
1743
|
|
|
|
|
|
|
|
1744
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
1745
|
|
|
|
|
|
|
return i; |
1746
|
|
|
|
|
|
|
#else |
1747
|
|
|
|
|
|
|
unsigned i = 0; |
1748
|
|
|
|
|
|
|
|
1749
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
1750
|
|
|
|
|
|
|
i++; |
1751
|
|
|
|
|
|
|
return i; |
1752
|
|
|
|
|
|
|
#endif |
1753
|
|
|
|
|
|
|
} |
1754
|
|
|
|
|
|
|
|
1755
|
|
|
|
|
|
|
static forceinline unsigned |
1756
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
1757
|
|
|
|
|
|
|
{ |
1758
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
1759
|
|
|
|
|
|
|
if (WORDBITS == 32) |
1760
|
|
|
|
|
|
|
return bsr32(v); |
1761
|
|
|
|
|
|
|
else |
1762
|
|
|
|
|
|
|
return bsr64(v); |
1763
|
|
|
|
|
|
|
} |
1764
|
|
|
|
|
|
|
|
1765
|
|
|
|
|
|
|
|
1766
|
|
|
|
|
|
|
|
1767
|
|
|
|
|
|
|
static forceinline unsigned |
1768
|
|
|
|
|
|
|
bsf32(u32 v) |
1769
|
|
|
|
|
|
|
{ |
1770
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
1771
|
|
|
|
|
|
|
return __builtin_ctz(v); |
1772
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1773
|
|
|
|
|
|
|
unsigned long i; |
1774
|
|
|
|
|
|
|
|
1775
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
1776
|
|
|
|
|
|
|
return i; |
1777
|
|
|
|
|
|
|
#else |
1778
|
|
|
|
|
|
|
unsigned i = 0; |
1779
|
|
|
|
|
|
|
|
1780
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
1781
|
|
|
|
|
|
|
i++; |
1782
|
|
|
|
|
|
|
return i; |
1783
|
|
|
|
|
|
|
#endif |
1784
|
|
|
|
|
|
|
} |
1785
|
|
|
|
|
|
|
|
1786
|
|
|
|
|
|
|
static forceinline unsigned |
1787
|
|
|
|
|
|
|
bsf64(u64 v) |
1788
|
|
|
|
|
|
|
{ |
1789
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
1790
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
1791
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
1792
|
|
|
|
|
|
|
unsigned long i; |
1793
|
|
|
|
|
|
|
|
1794
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
1795
|
|
|
|
|
|
|
return i; |
1796
|
|
|
|
|
|
|
#else |
1797
|
|
|
|
|
|
|
unsigned i = 0; |
1798
|
|
|
|
|
|
|
|
1799
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
1800
|
|
|
|
|
|
|
i++; |
1801
|
|
|
|
|
|
|
return i; |
1802
|
|
|
|
|
|
|
#endif |
1803
|
|
|
|
|
|
|
} |
1804
|
|
|
|
|
|
|
|
1805
|
|
|
|
|
|
|
static forceinline unsigned |
1806
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
1807
|
|
|
|
|
|
|
{ |
1808
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
1809
|
|
|
|
|
|
|
if (WORDBITS == 32) |
1810
|
|
|
|
|
|
|
return bsf32(v); |
1811
|
|
|
|
|
|
|
else |
1812
|
|
|
|
|
|
|
return bsf64(v); |
1813
|
|
|
|
|
|
|
} |
1814
|
|
|
|
|
|
|
|
1815
|
|
|
|
|
|
|
|
1816
|
|
|
|
|
|
|
#undef rbit32 |
1817
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
1818
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
1819
|
|
|
|
|
|
|
static forceinline u32 |
1820
|
|
|
|
|
|
|
rbit32(u32 v) |
1821
|
|
|
|
|
|
|
{ |
1822
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
1823
|
|
|
|
|
|
|
return v; |
1824
|
|
|
|
|
|
|
} |
1825
|
|
|
|
|
|
|
#define rbit32 rbit32 |
1826
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
1827
|
|
|
|
|
|
|
static forceinline u32 |
1828
|
|
|
|
|
|
|
rbit32(u32 v) |
1829
|
|
|
|
|
|
|
{ |
1830
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
1831
|
|
|
|
|
|
|
return v; |
1832
|
|
|
|
|
|
|
} |
1833
|
|
|
|
|
|
|
#define rbit32 rbit32 |
1834
|
|
|
|
|
|
|
#endif |
1835
|
|
|
|
|
|
|
|
1836
|
|
|
|
|
|
|
#endif |
1837
|
|
|
|
|
|
|
|
1838
|
|
|
|
|
|
|
|
1839
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
1840
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
1841
|
|
|
|
|
|
|
|
1842
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
1843
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
1844
|
|
|
|
|
|
|
|
1845
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
1846
|
|
|
|
|
|
|
size_t alignment, size_t size); |
1847
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
1848
|
|
|
|
|
|
|
|
1849
|
|
|
|
|
|
|
#ifdef FREESTANDING |
1850
|
|
|
|
|
|
|
|
1851
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
1852
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
1853
|
|
|
|
|
|
|
|
1854
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
1855
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
1856
|
|
|
|
|
|
|
|
1857
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
1858
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
1859
|
|
|
|
|
|
|
|
1860
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
1861
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
1862
|
|
|
|
|
|
|
|
1863
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
1864
|
|
|
|
|
|
|
#else |
1865
|
|
|
|
|
|
|
#include |
1866
|
|
|
|
|
|
|
#endif |
1867
|
|
|
|
|
|
|
|
1868
|
|
|
|
|
|
|
|
1869
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
1870
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
1871
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
1872
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
1873
|
|
|
|
|
|
|
#else |
1874
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
1875
|
|
|
|
|
|
|
#endif |
1876
|
|
|
|
|
|
|
|
1877
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
1878
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
1879
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
1880
|
|
|
|
|
|
|
|
1881
|
|
|
|
|
|
|
#endif |
1882
|
|
|
|
|
|
|
|
1883
|
|
|
|
|
|
|
|
1884
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
1885
|
|
|
|
|
|
|
|
1886
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
1887
|
|
|
|
|
|
|
|
1888
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
1889
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
1890
|
|
|
|
|
|
|
(defined(__linux__) || \ |
1891
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
1892
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
1893
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
1894
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
1895
|
|
|
|
|
|
|
#endif |
1896
|
|
|
|
|
|
|
|
1897
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
1898
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
1899
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
1900
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
1901
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
1902
|
|
|
|
|
|
|
|
1903
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
1904
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
1905
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
1906
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
1907
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
1908
|
|
|
|
|
|
|
|
1909
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
1910
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
1911
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
1912
|
|
|
|
|
|
|
|
1913
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
1914
|
|
|
|
|
|
|
|
1915
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
1916
|
|
|
|
|
|
|
{ |
1917
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
1918
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
1919
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
1920
|
|
|
|
|
|
|
} |
1921
|
|
|
|
|
|
|
#else |
1922
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
1923
|
|
|
|
|
|
|
#endif |
1924
|
|
|
|
|
|
|
|
1925
|
|
|
|
|
|
|
|
1926
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
1927
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
1928
|
|
|
|
|
|
|
#else |
1929
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
1930
|
|
|
|
|
|
|
#endif |
1931
|
|
|
|
|
|
|
|
1932
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
1933
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
1934
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
1935
|
|
|
|
|
|
|
#else |
1936
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
1937
|
|
|
|
|
|
|
#endif |
1938
|
|
|
|
|
|
|
|
1939
|
|
|
|
|
|
|
|
1940
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
1941
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
1942
|
|
|
|
|
|
|
#else |
1943
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
1944
|
|
|
|
|
|
|
#endif |
1945
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
1946
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
1947
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
1948
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
1949
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
1950
|
|
|
|
|
|
|
\ |
1951
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
1952
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
1953
|
|
|
|
|
|
|
|
1954
|
|
|
|
|
|
|
# ifdef _MSC_VER |
1955
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
1956
|
|
|
|
|
|
|
# else |
1957
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
1958
|
|
|
|
|
|
|
# endif |
1959
|
|
|
|
|
|
|
#else |
1960
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
1961
|
|
|
|
|
|
|
#endif |
1962
|
|
|
|
|
|
|
|
1963
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
1964
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
1965
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
1966
|
|
|
|
|
|
|
#else |
1967
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
1968
|
|
|
|
|
|
|
#endif |
1969
|
|
|
|
|
|
|
|
1970
|
|
|
|
|
|
|
|
1971
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
1972
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
1973
|
|
|
|
|
|
|
#else |
1974
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
1975
|
|
|
|
|
|
|
#endif |
1976
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
1977
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
1978
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
1979
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
1980
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
1981
|
|
|
|
|
|
|
|
1982
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
1983
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
1984
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
1985
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
1986
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
1987
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
1988
|
|
|
|
|
|
|
# endif |
1989
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
1990
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
1991
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
1992
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
1993
|
|
|
|
|
|
|
# endif |
1994
|
|
|
|
|
|
|
#endif |
1995
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
1996
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
1997
|
|
|
|
|
|
|
#endif |
1998
|
|
|
|
|
|
|
|
1999
|
|
|
|
|
|
|
|
2000
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
2001
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
2002
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
2003
|
|
|
|
|
|
|
# else |
2004
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
2005
|
|
|
|
|
|
|
# endif |
2006
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
2007
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
2008
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
2009
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
2010
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
2011
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
2012
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
2013
|
|
|
|
|
|
|
#else |
2014
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
2015
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
2016
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
2017
|
|
|
|
|
|
|
#endif |
2018
|
|
|
|
|
|
|
|
2019
|
|
|
|
|
|
|
|
2020
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
2021
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
2022
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
2023
|
|
|
|
|
|
|
# else |
2024
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
2025
|
|
|
|
|
|
|
# endif |
2026
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
2027
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
2028
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
2029
|
|
|
|
|
|
|
defined(_MSC_VER))) |
2030
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
2031
|
|
|
|
|
|
|
# else |
2032
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
2033
|
|
|
|
|
|
|
# endif |
2034
|
|
|
|
|
|
|
#else |
2035
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
2036
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
2037
|
|
|
|
|
|
|
#endif |
2038
|
|
|
|
|
|
|
|
2039
|
|
|
|
|
|
|
|
2040
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
2041
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
2042
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
2043
|
|
|
|
|
|
|
#endif |
2044
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
2045
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
2046
|
|
|
|
|
|
|
#endif |
2047
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
2048
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
2049
|
|
|
|
|
|
|
#endif |
2050
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
2051
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
2052
|
|
|
|
|
|
|
# include |
2053
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
2054
|
|
|
|
|
|
|
#endif |
2055
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
2056
|
|
|
|
|
|
|
# include |
2057
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
2058
|
|
|
|
|
|
|
#endif |
2059
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
2060
|
|
|
|
|
|
|
# include |
2061
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
2062
|
|
|
|
|
|
|
#endif |
2063
|
|
|
|
|
|
|
|
2064
|
|
|
|
|
|
|
#endif |
2065
|
|
|
|
|
|
|
|
2066
|
|
|
|
|
|
|
#endif |
2067
|
|
|
|
|
|
|
|
2068
|
|
|
|
|
|
|
|
2069
|
|
|
|
|
|
|
|
2070
|
|
|
|
|
|
|
#if HAVE_NEON_INTRIN && CPU_IS_LITTLE_ENDIAN() |
2071
|
|
|
|
|
|
|
# define adler32_neon adler32_neon |
2072
|
|
|
|
|
|
|
# define FUNCNAME adler32_neon |
2073
|
|
|
|
|
|
|
# define FUNCNAME_CHUNK adler32_neon_chunk |
2074
|
|
|
|
|
|
|
# define IMPL_ALIGNMENT 16 |
2075
|
|
|
|
|
|
|
# define IMPL_SEGMENT_LEN 64 |
2076
|
|
|
|
|
|
|
|
2077
|
|
|
|
|
|
|
# define IMPL_MAX_CHUNK_LEN (64 * (0xFFFF / 0xFF)) |
2078
|
|
|
|
|
|
|
# if HAVE_NEON_NATIVE |
2079
|
|
|
|
|
|
|
# define ATTRIBUTES |
2080
|
|
|
|
|
|
|
# else |
2081
|
|
|
|
|
|
|
# ifdef ARCH_ARM32 |
2082
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("fpu=neon") |
2083
|
|
|
|
|
|
|
# else |
2084
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+simd") |
2085
|
|
|
|
|
|
|
# endif |
2086
|
|
|
|
|
|
|
# endif |
2087
|
|
|
|
|
|
|
# include |
2088
|
|
|
|
|
|
|
static forceinline ATTRIBUTES void |
2089
|
|
|
|
|
|
|
adler32_neon_chunk(const uint8x16_t *p, const uint8x16_t * const end, |
2090
|
|
|
|
|
|
|
u32 *s1, u32 *s2) |
2091
|
|
|
|
|
|
|
{ |
2092
|
|
|
|
|
|
|
static const u16 _aligned_attribute(16) mults[64] = { |
2093
|
|
|
|
|
|
|
64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, |
2094
|
|
|
|
|
|
|
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, |
2095
|
|
|
|
|
|
|
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, |
2096
|
|
|
|
|
|
|
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, |
2097
|
|
|
|
|
|
|
}; |
2098
|
|
|
|
|
|
|
const uint16x8_t mults_a = vld1q_u16(&mults[0]); |
2099
|
|
|
|
|
|
|
const uint16x8_t mults_b = vld1q_u16(&mults[8]); |
2100
|
|
|
|
|
|
|
const uint16x8_t mults_c = vld1q_u16(&mults[16]); |
2101
|
|
|
|
|
|
|
const uint16x8_t mults_d = vld1q_u16(&mults[24]); |
2102
|
|
|
|
|
|
|
const uint16x8_t mults_e = vld1q_u16(&mults[32]); |
2103
|
|
|
|
|
|
|
const uint16x8_t mults_f = vld1q_u16(&mults[40]); |
2104
|
|
|
|
|
|
|
const uint16x8_t mults_g = vld1q_u16(&mults[48]); |
2105
|
|
|
|
|
|
|
const uint16x8_t mults_h = vld1q_u16(&mults[56]); |
2106
|
|
|
|
|
|
|
|
2107
|
|
|
|
|
|
|
uint32x4_t v_s1 = vdupq_n_u32(0); |
2108
|
|
|
|
|
|
|
uint32x4_t v_s2 = vdupq_n_u32(0); |
2109
|
|
|
|
|
|
|
|
2110
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_a = vdupq_n_u16(0); |
2111
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_b = vdupq_n_u16(0); |
2112
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_c = vdupq_n_u16(0); |
2113
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_d = vdupq_n_u16(0); |
2114
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_e = vdupq_n_u16(0); |
2115
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_f = vdupq_n_u16(0); |
2116
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_g = vdupq_n_u16(0); |
2117
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_h = vdupq_n_u16(0); |
2118
|
|
|
|
|
|
|
|
2119
|
|
|
|
|
|
|
do { |
2120
|
|
|
|
|
|
|
|
2121
|
|
|
|
|
|
|
const uint8x16_t bytes1 = *p++; |
2122
|
|
|
|
|
|
|
const uint8x16_t bytes2 = *p++; |
2123
|
|
|
|
|
|
|
const uint8x16_t bytes3 = *p++; |
2124
|
|
|
|
|
|
|
const uint8x16_t bytes4 = *p++; |
2125
|
|
|
|
|
|
|
uint16x8_t tmp; |
2126
|
|
|
|
|
|
|
|
2127
|
|
|
|
|
|
|
|
2128
|
|
|
|
|
|
|
v_s2 = vaddq_u32(v_s2, v_s1); |
2129
|
|
|
|
|
|
|
|
2130
|
|
|
|
|
|
|
|
2131
|
|
|
|
|
|
|
tmp = vpaddlq_u8(bytes1); |
2132
|
|
|
|
|
|
|
v_byte_sums_a = vaddw_u8(v_byte_sums_a, vget_low_u8(bytes1)); |
2133
|
|
|
|
|
|
|
v_byte_sums_b = vaddw_u8(v_byte_sums_b, vget_high_u8(bytes1)); |
2134
|
|
|
|
|
|
|
tmp = vpadalq_u8(tmp, bytes2); |
2135
|
|
|
|
|
|
|
v_byte_sums_c = vaddw_u8(v_byte_sums_c, vget_low_u8(bytes2)); |
2136
|
|
|
|
|
|
|
v_byte_sums_d = vaddw_u8(v_byte_sums_d, vget_high_u8(bytes2)); |
2137
|
|
|
|
|
|
|
tmp = vpadalq_u8(tmp, bytes3); |
2138
|
|
|
|
|
|
|
v_byte_sums_e = vaddw_u8(v_byte_sums_e, vget_low_u8(bytes3)); |
2139
|
|
|
|
|
|
|
v_byte_sums_f = vaddw_u8(v_byte_sums_f, vget_high_u8(bytes3)); |
2140
|
|
|
|
|
|
|
tmp = vpadalq_u8(tmp, bytes4); |
2141
|
|
|
|
|
|
|
v_byte_sums_g = vaddw_u8(v_byte_sums_g, vget_low_u8(bytes4)); |
2142
|
|
|
|
|
|
|
v_byte_sums_h = vaddw_u8(v_byte_sums_h, vget_high_u8(bytes4)); |
2143
|
|
|
|
|
|
|
v_s1 = vpadalq_u16(v_s1, tmp); |
2144
|
|
|
|
|
|
|
|
2145
|
|
|
|
|
|
|
} while (p != end); |
2146
|
|
|
|
|
|
|
|
2147
|
|
|
|
|
|
|
|
2148
|
|
|
|
|
|
|
#ifdef ARCH_ARM32 |
2149
|
|
|
|
|
|
|
# define umlal2(a, b, c) vmlal_u16((a), vget_high_u16(b), vget_high_u16(c)) |
2150
|
|
|
|
|
|
|
#else |
2151
|
|
|
|
|
|
|
# define umlal2 vmlal_high_u16 |
2152
|
|
|
|
|
|
|
#endif |
2153
|
|
|
|
|
|
|
v_s2 = vqshlq_n_u32(v_s2, 6); |
2154
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_a), vget_low_u16(mults_a)); |
2155
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_a, mults_a); |
2156
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_b), vget_low_u16(mults_b)); |
2157
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_b, mults_b); |
2158
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_c), vget_low_u16(mults_c)); |
2159
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_c, mults_c); |
2160
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_d), vget_low_u16(mults_d)); |
2161
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_d, mults_d); |
2162
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_e), vget_low_u16(mults_e)); |
2163
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_e, mults_e); |
2164
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_f), vget_low_u16(mults_f)); |
2165
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_f, mults_f); |
2166
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_g), vget_low_u16(mults_g)); |
2167
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_g, mults_g); |
2168
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_h), vget_low_u16(mults_h)); |
2169
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_h, mults_h); |
2170
|
|
|
|
|
|
|
#undef umlal2 |
2171
|
|
|
|
|
|
|
|
2172
|
|
|
|
|
|
|
|
2173
|
|
|
|
|
|
|
#ifdef ARCH_ARM32 |
2174
|
|
|
|
|
|
|
*s1 += vgetq_lane_u32(v_s1, 0) + vgetq_lane_u32(v_s1, 1) + |
2175
|
|
|
|
|
|
|
vgetq_lane_u32(v_s1, 2) + vgetq_lane_u32(v_s1, 3); |
2176
|
|
|
|
|
|
|
*s2 += vgetq_lane_u32(v_s2, 0) + vgetq_lane_u32(v_s2, 1) + |
2177
|
|
|
|
|
|
|
vgetq_lane_u32(v_s2, 2) + vgetq_lane_u32(v_s2, 3); |
2178
|
|
|
|
|
|
|
#else |
2179
|
|
|
|
|
|
|
*s1 += vaddvq_u32(v_s1); |
2180
|
|
|
|
|
|
|
*s2 += vaddvq_u32(v_s2); |
2181
|
|
|
|
|
|
|
#endif |
2182
|
|
|
|
|
|
|
} |
2183
|
|
|
|
|
|
|
/* #include "adler32_vec_template.h" */ |
2184
|
|
|
|
|
|
|
|
2185
|
|
|
|
|
|
|
|
2186
|
|
|
|
|
|
|
|
2187
|
|
|
|
|
|
|
|
2188
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
2189
|
|
|
|
|
|
|
FUNCNAME(u32 adler, const u8 *p, size_t len) |
2190
|
|
|
|
|
|
|
{ |
2191
|
|
|
|
|
|
|
const size_t max_chunk_len = |
2192
|
|
|
|
|
|
|
MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) - |
2193
|
|
|
|
|
|
|
(MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) % IMPL_SEGMENT_LEN); |
2194
|
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
2195
|
|
|
|
|
|
|
u32 s2 = adler >> 16; |
2196
|
|
|
|
|
|
|
const u8 * const end = p + len; |
2197
|
|
|
|
|
|
|
const u8 *vend; |
2198
|
|
|
|
|
|
|
|
2199
|
|
|
|
|
|
|
|
2200
|
|
|
|
|
|
|
if (p != end && (uintptr_t)p % IMPL_ALIGNMENT) { |
2201
|
|
|
|
|
|
|
do { |
2202
|
|
|
|
|
|
|
s1 += *p++; |
2203
|
|
|
|
|
|
|
s2 += s1; |
2204
|
|
|
|
|
|
|
} while (p != end && (uintptr_t)p % IMPL_ALIGNMENT); |
2205
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2206
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2207
|
|
|
|
|
|
|
} |
2208
|
|
|
|
|
|
|
|
2209
|
|
|
|
|
|
|
|
2210
|
|
|
|
|
|
|
STATIC_ASSERT(IMPL_SEGMENT_LEN % IMPL_ALIGNMENT == 0); |
2211
|
|
|
|
|
|
|
vend = end - ((size_t)(end - p) % IMPL_SEGMENT_LEN); |
2212
|
|
|
|
|
|
|
while (p != vend) { |
2213
|
|
|
|
|
|
|
size_t chunk_len = MIN((size_t)(vend - p), max_chunk_len); |
2214
|
|
|
|
|
|
|
|
2215
|
|
|
|
|
|
|
s2 += s1 * chunk_len; |
2216
|
|
|
|
|
|
|
|
2217
|
|
|
|
|
|
|
FUNCNAME_CHUNK((const void *)p, (const void *)(p + chunk_len), |
2218
|
|
|
|
|
|
|
&s1, &s2); |
2219
|
|
|
|
|
|
|
|
2220
|
|
|
|
|
|
|
p += chunk_len; |
2221
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2222
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2223
|
|
|
|
|
|
|
} |
2224
|
|
|
|
|
|
|
|
2225
|
|
|
|
|
|
|
|
2226
|
|
|
|
|
|
|
if (p != end) { |
2227
|
|
|
|
|
|
|
do { |
2228
|
|
|
|
|
|
|
s1 += *p++; |
2229
|
|
|
|
|
|
|
s2 += s1; |
2230
|
|
|
|
|
|
|
} while (p != end); |
2231
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2232
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2233
|
|
|
|
|
|
|
} |
2234
|
|
|
|
|
|
|
|
2235
|
|
|
|
|
|
|
return (s2 << 16) | s1; |
2236
|
|
|
|
|
|
|
} |
2237
|
|
|
|
|
|
|
|
2238
|
|
|
|
|
|
|
#undef FUNCNAME |
2239
|
|
|
|
|
|
|
#undef FUNCNAME_CHUNK |
2240
|
|
|
|
|
|
|
#undef ATTRIBUTES |
2241
|
|
|
|
|
|
|
#undef IMPL_ALIGNMENT |
2242
|
|
|
|
|
|
|
#undef IMPL_SEGMENT_LEN |
2243
|
|
|
|
|
|
|
#undef IMPL_MAX_CHUNK_LEN |
2244
|
|
|
|
|
|
|
|
2245
|
|
|
|
|
|
|
#endif |
2246
|
|
|
|
|
|
|
|
2247
|
|
|
|
|
|
|
|
2248
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && CPU_IS_LITTLE_ENDIAN() |
2249
|
|
|
|
|
|
|
# define adler32_neon_dotprod adler32_neon_dotprod |
2250
|
|
|
|
|
|
|
# define FUNCNAME adler32_neon_dotprod |
2251
|
|
|
|
|
|
|
# define FUNCNAME_CHUNK adler32_neon_dotprod_chunk |
2252
|
|
|
|
|
|
|
# define IMPL_ALIGNMENT 16 |
2253
|
|
|
|
|
|
|
# define IMPL_SEGMENT_LEN 64 |
2254
|
|
|
|
|
|
|
# define IMPL_MAX_CHUNK_LEN MAX_CHUNK_LEN |
2255
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE |
2256
|
|
|
|
|
|
|
# define ATTRIBUTES |
2257
|
|
|
|
|
|
|
# else |
2258
|
|
|
|
|
|
|
# ifdef __clang__ |
2259
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("dotprod") |
2260
|
|
|
|
|
|
|
|
2261
|
|
|
|
|
|
|
# elif defined(__ARM_FEATURE_JCVT) |
2262
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+dotprod") |
2263
|
|
|
|
|
|
|
# else |
2264
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8.2-a+dotprod") |
2265
|
|
|
|
|
|
|
# endif |
2266
|
|
|
|
|
|
|
# endif |
2267
|
|
|
|
|
|
|
# include |
2268
|
|
|
|
|
|
|
static forceinline ATTRIBUTES void |
2269
|
|
|
|
|
|
|
adler32_neon_dotprod_chunk(const uint8x16_t *p, const uint8x16_t * const end, |
2270
|
|
|
|
|
|
|
u32 *s1, u32 *s2) |
2271
|
|
|
|
|
|
|
{ |
2272
|
|
|
|
|
|
|
static const u8 _aligned_attribute(16) mults[64] = { |
2273
|
|
|
|
|
|
|
64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, |
2274
|
|
|
|
|
|
|
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, |
2275
|
|
|
|
|
|
|
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, |
2276
|
|
|
|
|
|
|
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, |
2277
|
|
|
|
|
|
|
}; |
2278
|
|
|
|
|
|
|
const uint8x16_t mults_a = vld1q_u8(&mults[0]); |
2279
|
|
|
|
|
|
|
const uint8x16_t mults_b = vld1q_u8(&mults[16]); |
2280
|
|
|
|
|
|
|
const uint8x16_t mults_c = vld1q_u8(&mults[32]); |
2281
|
|
|
|
|
|
|
const uint8x16_t mults_d = vld1q_u8(&mults[48]); |
2282
|
|
|
|
|
|
|
const uint8x16_t ones = vdupq_n_u8(1); |
2283
|
|
|
|
|
|
|
uint32x4_t v_s1_a = vdupq_n_u32(0); |
2284
|
|
|
|
|
|
|
uint32x4_t v_s1_b = vdupq_n_u32(0); |
2285
|
|
|
|
|
|
|
uint32x4_t v_s1_c = vdupq_n_u32(0); |
2286
|
|
|
|
|
|
|
uint32x4_t v_s1_d = vdupq_n_u32(0); |
2287
|
|
|
|
|
|
|
uint32x4_t v_s2_a = vdupq_n_u32(0); |
2288
|
|
|
|
|
|
|
uint32x4_t v_s2_b = vdupq_n_u32(0); |
2289
|
|
|
|
|
|
|
uint32x4_t v_s2_c = vdupq_n_u32(0); |
2290
|
|
|
|
|
|
|
uint32x4_t v_s2_d = vdupq_n_u32(0); |
2291
|
|
|
|
|
|
|
uint32x4_t v_s1_sums_a = vdupq_n_u32(0); |
2292
|
|
|
|
|
|
|
uint32x4_t v_s1_sums_b = vdupq_n_u32(0); |
2293
|
|
|
|
|
|
|
uint32x4_t v_s1_sums_c = vdupq_n_u32(0); |
2294
|
|
|
|
|
|
|
uint32x4_t v_s1_sums_d = vdupq_n_u32(0); |
2295
|
|
|
|
|
|
|
uint32x4_t v_s1; |
2296
|
|
|
|
|
|
|
uint32x4_t v_s2; |
2297
|
|
|
|
|
|
|
uint32x4_t v_s1_sums; |
2298
|
|
|
|
|
|
|
|
2299
|
|
|
|
|
|
|
do { |
2300
|
|
|
|
|
|
|
uint8x16_t bytes_a = *p++; |
2301
|
|
|
|
|
|
|
uint8x16_t bytes_b = *p++; |
2302
|
|
|
|
|
|
|
uint8x16_t bytes_c = *p++; |
2303
|
|
|
|
|
|
|
uint8x16_t bytes_d = *p++; |
2304
|
|
|
|
|
|
|
|
2305
|
|
|
|
|
|
|
v_s1_sums_a = vaddq_u32(v_s1_sums_a, v_s1_a); |
2306
|
|
|
|
|
|
|
v_s1_a = vdotq_u32(v_s1_a, bytes_a, ones); |
2307
|
|
|
|
|
|
|
v_s2_a = vdotq_u32(v_s2_a, bytes_a, mults_a); |
2308
|
|
|
|
|
|
|
|
2309
|
|
|
|
|
|
|
v_s1_sums_b = vaddq_u32(v_s1_sums_b, v_s1_b); |
2310
|
|
|
|
|
|
|
v_s1_b = vdotq_u32(v_s1_b, bytes_b, ones); |
2311
|
|
|
|
|
|
|
v_s2_b = vdotq_u32(v_s2_b, bytes_b, mults_b); |
2312
|
|
|
|
|
|
|
|
2313
|
|
|
|
|
|
|
v_s1_sums_c = vaddq_u32(v_s1_sums_c, v_s1_c); |
2314
|
|
|
|
|
|
|
v_s1_c = vdotq_u32(v_s1_c, bytes_c, ones); |
2315
|
|
|
|
|
|
|
v_s2_c = vdotq_u32(v_s2_c, bytes_c, mults_c); |
2316
|
|
|
|
|
|
|
|
2317
|
|
|
|
|
|
|
v_s1_sums_d = vaddq_u32(v_s1_sums_d, v_s1_d); |
2318
|
|
|
|
|
|
|
v_s1_d = vdotq_u32(v_s1_d, bytes_d, ones); |
2319
|
|
|
|
|
|
|
v_s2_d = vdotq_u32(v_s2_d, bytes_d, mults_d); |
2320
|
|
|
|
|
|
|
} while (p != end); |
2321
|
|
|
|
|
|
|
|
2322
|
|
|
|
|
|
|
v_s1 = vaddq_u32(vaddq_u32(v_s1_a, v_s1_b), vaddq_u32(v_s1_c, v_s1_d)); |
2323
|
|
|
|
|
|
|
v_s2 = vaddq_u32(vaddq_u32(v_s2_a, v_s2_b), vaddq_u32(v_s2_c, v_s2_d)); |
2324
|
|
|
|
|
|
|
v_s1_sums = vaddq_u32(vaddq_u32(v_s1_sums_a, v_s1_sums_b), |
2325
|
|
|
|
|
|
|
vaddq_u32(v_s1_sums_c, v_s1_sums_d)); |
2326
|
|
|
|
|
|
|
v_s2 = vaddq_u32(v_s2, vqshlq_n_u32(v_s1_sums, 6)); |
2327
|
|
|
|
|
|
|
|
2328
|
|
|
|
|
|
|
*s1 += vaddvq_u32(v_s1); |
2329
|
|
|
|
|
|
|
*s2 += vaddvq_u32(v_s2); |
2330
|
|
|
|
|
|
|
} |
2331
|
|
|
|
|
|
|
/* #include "arm-../adler32_vec_template.h" */ |
2332
|
|
|
|
|
|
|
|
2333
|
|
|
|
|
|
|
|
2334
|
|
|
|
|
|
|
|
2335
|
|
|
|
|
|
|
|
2336
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
2337
|
|
|
|
|
|
|
FUNCNAME(u32 adler, const u8 *p, size_t len) |
2338
|
|
|
|
|
|
|
{ |
2339
|
|
|
|
|
|
|
const size_t max_chunk_len = |
2340
|
|
|
|
|
|
|
MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) - |
2341
|
|
|
|
|
|
|
(MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) % IMPL_SEGMENT_LEN); |
2342
|
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
2343
|
|
|
|
|
|
|
u32 s2 = adler >> 16; |
2344
|
|
|
|
|
|
|
const u8 * const end = p + len; |
2345
|
|
|
|
|
|
|
const u8 *vend; |
2346
|
|
|
|
|
|
|
|
2347
|
|
|
|
|
|
|
|
2348
|
|
|
|
|
|
|
if (p != end && (uintptr_t)p % IMPL_ALIGNMENT) { |
2349
|
|
|
|
|
|
|
do { |
2350
|
|
|
|
|
|
|
s1 += *p++; |
2351
|
|
|
|
|
|
|
s2 += s1; |
2352
|
|
|
|
|
|
|
} while (p != end && (uintptr_t)p % IMPL_ALIGNMENT); |
2353
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2354
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2355
|
|
|
|
|
|
|
} |
2356
|
|
|
|
|
|
|
|
2357
|
|
|
|
|
|
|
|
2358
|
|
|
|
|
|
|
STATIC_ASSERT(IMPL_SEGMENT_LEN % IMPL_ALIGNMENT == 0); |
2359
|
|
|
|
|
|
|
vend = end - ((size_t)(end - p) % IMPL_SEGMENT_LEN); |
2360
|
|
|
|
|
|
|
while (p != vend) { |
2361
|
|
|
|
|
|
|
size_t chunk_len = MIN((size_t)(vend - p), max_chunk_len); |
2362
|
|
|
|
|
|
|
|
2363
|
|
|
|
|
|
|
s2 += s1 * chunk_len; |
2364
|
|
|
|
|
|
|
|
2365
|
|
|
|
|
|
|
FUNCNAME_CHUNK((const void *)p, (const void *)(p + chunk_len), |
2366
|
|
|
|
|
|
|
&s1, &s2); |
2367
|
|
|
|
|
|
|
|
2368
|
|
|
|
|
|
|
p += chunk_len; |
2369
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2370
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2371
|
|
|
|
|
|
|
} |
2372
|
|
|
|
|
|
|
|
2373
|
|
|
|
|
|
|
|
2374
|
|
|
|
|
|
|
if (p != end) { |
2375
|
|
|
|
|
|
|
do { |
2376
|
|
|
|
|
|
|
s1 += *p++; |
2377
|
|
|
|
|
|
|
s2 += s1; |
2378
|
|
|
|
|
|
|
} while (p != end); |
2379
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2380
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2381
|
|
|
|
|
|
|
} |
2382
|
|
|
|
|
|
|
|
2383
|
|
|
|
|
|
|
return (s2 << 16) | s1; |
2384
|
|
|
|
|
|
|
} |
2385
|
|
|
|
|
|
|
|
2386
|
|
|
|
|
|
|
#undef FUNCNAME |
2387
|
|
|
|
|
|
|
#undef FUNCNAME_CHUNK |
2388
|
|
|
|
|
|
|
#undef ATTRIBUTES |
2389
|
|
|
|
|
|
|
#undef IMPL_ALIGNMENT |
2390
|
|
|
|
|
|
|
#undef IMPL_SEGMENT_LEN |
2391
|
|
|
|
|
|
|
#undef IMPL_MAX_CHUNK_LEN |
2392
|
|
|
|
|
|
|
|
2393
|
|
|
|
|
|
|
#endif |
2394
|
|
|
|
|
|
|
|
2395
|
|
|
|
|
|
|
#if defined(adler32_neon_dotprod) && HAVE_DOTPROD_NATIVE |
2396
|
|
|
|
|
|
|
#define DEFAULT_IMPL adler32_neon_dotprod |
2397
|
|
|
|
|
|
|
#else |
2398
|
|
|
|
|
|
|
static inline adler32_func_t |
2399
|
|
|
|
|
|
|
arch_select_adler32_func(void) |
2400
|
|
|
|
|
|
|
{ |
2401
|
|
|
|
|
|
|
const u32 features MAYBE_UNUSED = get_arm_cpu_features(); |
2402
|
|
|
|
|
|
|
|
2403
|
|
|
|
|
|
|
#ifdef adler32_neon_dotprod |
2404
|
|
|
|
|
|
|
if (HAVE_NEON(features) && HAVE_DOTPROD(features)) |
2405
|
|
|
|
|
|
|
return adler32_neon_dotprod; |
2406
|
|
|
|
|
|
|
#endif |
2407
|
|
|
|
|
|
|
#ifdef adler32_neon |
2408
|
|
|
|
|
|
|
if (HAVE_NEON(features)) |
2409
|
|
|
|
|
|
|
return adler32_neon; |
2410
|
|
|
|
|
|
|
#endif |
2411
|
|
|
|
|
|
|
return NULL; |
2412
|
|
|
|
|
|
|
} |
2413
|
|
|
|
|
|
|
#define arch_select_adler32_func arch_select_adler32_func |
2414
|
|
|
|
|
|
|
#endif |
2415
|
|
|
|
|
|
|
|
2416
|
|
|
|
|
|
|
#endif |
2417
|
|
|
|
|
|
|
|
2418
|
|
|
|
|
|
|
#elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
2419
|
|
|
|
|
|
|
/* # include "x86/adler32_impl.h" */ |
2420
|
|
|
|
|
|
|
|
2421
|
|
|
|
|
|
|
|
2422
|
|
|
|
|
|
|
#ifndef LIB_X86_ADLER32_IMPL_H |
2423
|
|
|
|
|
|
|
#define LIB_X86_ADLER32_IMPL_H |
2424
|
|
|
|
|
|
|
|
2425
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
2426
|
|
|
|
|
|
|
|
2427
|
|
|
|
|
|
|
|
2428
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
2429
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
2430
|
|
|
|
|
|
|
|
2431
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
2432
|
|
|
|
|
|
|
|
2433
|
|
|
|
|
|
|
|
2434
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
2435
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
2436
|
|
|
|
|
|
|
|
2437
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
2438
|
|
|
|
|
|
|
|
2439
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
2440
|
|
|
|
|
|
|
#endif |
2441
|
|
|
|
|
|
|
|
2442
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
2443
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
2444
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
2445
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
2446
|
|
|
|
|
|
|
#else |
2447
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
2448
|
|
|
|
|
|
|
#endif |
2449
|
|
|
|
|
|
|
|
2450
|
|
|
|
|
|
|
|
2451
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
2452
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
2453
|
|
|
|
|
|
|
#else |
2454
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
2455
|
|
|
|
|
|
|
#endif |
2456
|
|
|
|
|
|
|
|
2457
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
2458
|
|
|
|
|
|
|
|
2459
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
2460
|
|
|
|
|
|
|
|
2461
|
|
|
|
|
|
|
|
2462
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
2463
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
2464
|
|
|
|
|
|
|
|
2465
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
2466
|
|
|
|
|
|
|
|
2467
|
|
|
|
|
|
|
|
2468
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
2469
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
2470
|
|
|
|
|
|
|
|
2471
|
|
|
|
|
|
|
#include |
2472
|
|
|
|
|
|
|
#include |
2473
|
|
|
|
|
|
|
|
2474
|
|
|
|
|
|
|
#ifdef __cplusplus |
2475
|
|
|
|
|
|
|
extern "C" { |
2476
|
|
|
|
|
|
|
#endif |
2477
|
|
|
|
|
|
|
|
2478
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
2479
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
2480
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
2481
|
|
|
|
|
|
|
|
2482
|
|
|
|
|
|
|
|
2483
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
2484
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
2485
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
2486
|
|
|
|
|
|
|
# else |
2487
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
2488
|
|
|
|
|
|
|
# endif |
2489
|
|
|
|
|
|
|
#endif |
2490
|
|
|
|
|
|
|
|
2491
|
|
|
|
|
|
|
|
2492
|
|
|
|
|
|
|
|
2493
|
|
|
|
|
|
|
|
2494
|
|
|
|
|
|
|
|
2495
|
|
|
|
|
|
|
struct libdeflate_compressor; |
2496
|
|
|
|
|
|
|
struct libdeflate_options; |
2497
|
|
|
|
|
|
|
|
2498
|
|
|
|
|
|
|
|
2499
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
2500
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
2501
|
|
|
|
|
|
|
|
2502
|
|
|
|
|
|
|
|
2503
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
2504
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
2505
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
2506
|
|
|
|
|
|
|
|
2507
|
|
|
|
|
|
|
|
2508
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2509
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
2510
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2511
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
2512
|
|
|
|
|
|
|
|
2513
|
|
|
|
|
|
|
|
2514
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2515
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
2516
|
|
|
|
|
|
|
size_t in_nbytes); |
2517
|
|
|
|
|
|
|
|
2518
|
|
|
|
|
|
|
|
2519
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2520
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
2521
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2522
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
2523
|
|
|
|
|
|
|
|
2524
|
|
|
|
|
|
|
|
2525
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2526
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
2527
|
|
|
|
|
|
|
size_t in_nbytes); |
2528
|
|
|
|
|
|
|
|
2529
|
|
|
|
|
|
|
|
2530
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2531
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
2532
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2533
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
2534
|
|
|
|
|
|
|
|
2535
|
|
|
|
|
|
|
|
2536
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2537
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
2538
|
|
|
|
|
|
|
size_t in_nbytes); |
2539
|
|
|
|
|
|
|
|
2540
|
|
|
|
|
|
|
|
2541
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
2542
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
2543
|
|
|
|
|
|
|
|
2544
|
|
|
|
|
|
|
|
2545
|
|
|
|
|
|
|
|
2546
|
|
|
|
|
|
|
|
2547
|
|
|
|
|
|
|
|
2548
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
2549
|
|
|
|
|
|
|
struct libdeflate_options; |
2550
|
|
|
|
|
|
|
|
2551
|
|
|
|
|
|
|
|
2552
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
2553
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
2554
|
|
|
|
|
|
|
|
2555
|
|
|
|
|
|
|
|
2556
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
2557
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
2558
|
|
|
|
|
|
|
|
2559
|
|
|
|
|
|
|
|
2560
|
|
|
|
|
|
|
enum libdeflate_result { |
2561
|
|
|
|
|
|
|
|
2562
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
2563
|
|
|
|
|
|
|
|
2564
|
|
|
|
|
|
|
|
2565
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
2566
|
|
|
|
|
|
|
|
2567
|
|
|
|
|
|
|
|
2568
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
2569
|
|
|
|
|
|
|
|
2570
|
|
|
|
|
|
|
|
2571
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
2572
|
|
|
|
|
|
|
}; |
2573
|
|
|
|
|
|
|
|
2574
|
|
|
|
|
|
|
|
2575
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2576
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
2577
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2578
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2579
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2580
|
|
|
|
|
|
|
|
2581
|
|
|
|
|
|
|
|
2582
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2583
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
2584
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2585
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2586
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
2587
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2588
|
|
|
|
|
|
|
|
2589
|
|
|
|
|
|
|
|
2590
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2591
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
2592
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2593
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2594
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2595
|
|
|
|
|
|
|
|
2596
|
|
|
|
|
|
|
|
2597
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2598
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
2599
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2600
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2601
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
2602
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2603
|
|
|
|
|
|
|
|
2604
|
|
|
|
|
|
|
|
2605
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2606
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
2607
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2608
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2609
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2610
|
|
|
|
|
|
|
|
2611
|
|
|
|
|
|
|
|
2612
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2613
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
2614
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2615
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2616
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
2617
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2618
|
|
|
|
|
|
|
|
2619
|
|
|
|
|
|
|
|
2620
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
2621
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
2622
|
|
|
|
|
|
|
|
2623
|
|
|
|
|
|
|
|
2624
|
|
|
|
|
|
|
|
2625
|
|
|
|
|
|
|
|
2626
|
|
|
|
|
|
|
|
2627
|
|
|
|
|
|
|
|
2628
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
2629
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
2630
|
|
|
|
|
|
|
|
2631
|
|
|
|
|
|
|
|
2632
|
|
|
|
|
|
|
|
2633
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
2634
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
2635
|
|
|
|
|
|
|
|
2636
|
|
|
|
|
|
|
|
2637
|
|
|
|
|
|
|
|
2638
|
|
|
|
|
|
|
|
2639
|
|
|
|
|
|
|
|
2640
|
|
|
|
|
|
|
|
2641
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
2642
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
2643
|
|
|
|
|
|
|
void (*free_func)(void *)); |
2644
|
|
|
|
|
|
|
|
2645
|
|
|
|
|
|
|
|
2646
|
|
|
|
|
|
|
struct libdeflate_options { |
2647
|
|
|
|
|
|
|
|
2648
|
|
|
|
|
|
|
|
2649
|
|
|
|
|
|
|
size_t sizeof_options; |
2650
|
|
|
|
|
|
|
|
2651
|
|
|
|
|
|
|
|
2652
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
2653
|
|
|
|
|
|
|
void (*free_func)(void *); |
2654
|
|
|
|
|
|
|
}; |
2655
|
|
|
|
|
|
|
|
2656
|
|
|
|
|
|
|
#ifdef __cplusplus |
2657
|
|
|
|
|
|
|
} |
2658
|
|
|
|
|
|
|
#endif |
2659
|
|
|
|
|
|
|
|
2660
|
|
|
|
|
|
|
#endif |
2661
|
|
|
|
|
|
|
|
2662
|
|
|
|
|
|
|
|
2663
|
|
|
|
|
|
|
#include |
2664
|
|
|
|
|
|
|
#include |
2665
|
|
|
|
|
|
|
#include |
2666
|
|
|
|
|
|
|
#ifdef _MSC_VER |
2667
|
|
|
|
|
|
|
# include |
2668
|
|
|
|
|
|
|
# include |
2669
|
|
|
|
|
|
|
|
2670
|
|
|
|
|
|
|
|
2671
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
2672
|
|
|
|
|
|
|
|
2673
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
2674
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
2675
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
2676
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
2677
|
|
|
|
|
|
|
|
2678
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
2679
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
2680
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
2681
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
2682
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
2683
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
2684
|
|
|
|
|
|
|
#endif |
2685
|
|
|
|
|
|
|
#ifndef FREESTANDING |
2686
|
|
|
|
|
|
|
# include |
2687
|
|
|
|
|
|
|
#endif |
2688
|
|
|
|
|
|
|
|
2689
|
|
|
|
|
|
|
|
2690
|
|
|
|
|
|
|
|
2691
|
|
|
|
|
|
|
|
2692
|
|
|
|
|
|
|
|
2693
|
|
|
|
|
|
|
|
2694
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
2695
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
2696
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
2697
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
2698
|
|
|
|
|
|
|
#ifdef _MSC_VER |
2699
|
|
|
|
|
|
|
# if defined(_M_X64) |
2700
|
|
|
|
|
|
|
# define ARCH_X86_64 |
2701
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
2702
|
|
|
|
|
|
|
# define ARCH_X86_32 |
2703
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
2704
|
|
|
|
|
|
|
# define ARCH_ARM64 |
2705
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
2706
|
|
|
|
|
|
|
# define ARCH_ARM32 |
2707
|
|
|
|
|
|
|
# endif |
2708
|
|
|
|
|
|
|
#else |
2709
|
|
|
|
|
|
|
# if defined(__x86_64__) |
2710
|
|
|
|
|
|
|
# define ARCH_X86_64 |
2711
|
|
|
|
|
|
|
# elif defined(__i386__) |
2712
|
|
|
|
|
|
|
# define ARCH_X86_32 |
2713
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
2714
|
|
|
|
|
|
|
# define ARCH_ARM64 |
2715
|
|
|
|
|
|
|
# elif defined(__arm__) |
2716
|
|
|
|
|
|
|
# define ARCH_ARM32 |
2717
|
|
|
|
|
|
|
# endif |
2718
|
|
|
|
|
|
|
#endif |
2719
|
|
|
|
|
|
|
|
2720
|
|
|
|
|
|
|
|
2721
|
|
|
|
|
|
|
|
2722
|
|
|
|
|
|
|
|
2723
|
|
|
|
|
|
|
|
2724
|
|
|
|
|
|
|
|
2725
|
|
|
|
|
|
|
typedef uint8_t u8; |
2726
|
|
|
|
|
|
|
typedef uint16_t u16; |
2727
|
|
|
|
|
|
|
typedef uint32_t u32; |
2728
|
|
|
|
|
|
|
typedef uint64_t u64; |
2729
|
|
|
|
|
|
|
typedef int8_t s8; |
2730
|
|
|
|
|
|
|
typedef int16_t s16; |
2731
|
|
|
|
|
|
|
typedef int32_t s32; |
2732
|
|
|
|
|
|
|
typedef int64_t s64; |
2733
|
|
|
|
|
|
|
|
2734
|
|
|
|
|
|
|
|
2735
|
|
|
|
|
|
|
#ifdef _MSC_VER |
2736
|
|
|
|
|
|
|
# ifdef _WIN64 |
2737
|
|
|
|
|
|
|
typedef long long ssize_t; |
2738
|
|
|
|
|
|
|
# else |
2739
|
|
|
|
|
|
|
typedef long ssize_t; |
2740
|
|
|
|
|
|
|
# endif |
2741
|
|
|
|
|
|
|
#endif |
2742
|
|
|
|
|
|
|
|
2743
|
|
|
|
|
|
|
|
2744
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
2745
|
|
|
|
|
|
|
|
2746
|
|
|
|
|
|
|
|
2747
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
2748
|
|
|
|
|
|
|
|
2749
|
|
|
|
|
|
|
|
2750
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
2751
|
|
|
|
|
|
|
|
2752
|
|
|
|
|
|
|
|
2753
|
|
|
|
|
|
|
|
2754
|
|
|
|
|
|
|
|
2755
|
|
|
|
|
|
|
|
2756
|
|
|
|
|
|
|
|
2757
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
2758
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
2759
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
2760
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
2761
|
|
|
|
|
|
|
#else |
2762
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
2763
|
|
|
|
|
|
|
#endif |
2764
|
|
|
|
|
|
|
#ifdef __clang__ |
2765
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
2766
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
2767
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
2768
|
|
|
|
|
|
|
# else |
2769
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
2770
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
2771
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
2772
|
|
|
|
|
|
|
# endif |
2773
|
|
|
|
|
|
|
#else |
2774
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
2775
|
|
|
|
|
|
|
#endif |
2776
|
|
|
|
|
|
|
|
2777
|
|
|
|
|
|
|
|
2778
|
|
|
|
|
|
|
#ifndef __has_attribute |
2779
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
2780
|
|
|
|
|
|
|
#endif |
2781
|
|
|
|
|
|
|
#ifndef __has_builtin |
2782
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
2783
|
|
|
|
|
|
|
#endif |
2784
|
|
|
|
|
|
|
|
2785
|
|
|
|
|
|
|
|
2786
|
|
|
|
|
|
|
#ifdef _MSC_VER |
2787
|
|
|
|
|
|
|
# define inline __inline |
2788
|
|
|
|
|
|
|
#endif |
2789
|
|
|
|
|
|
|
|
2790
|
|
|
|
|
|
|
|
2791
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
2792
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
2793
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2794
|
|
|
|
|
|
|
# define forceinline __forceinline |
2795
|
|
|
|
|
|
|
#else |
2796
|
|
|
|
|
|
|
# define forceinline inline |
2797
|
|
|
|
|
|
|
#endif |
2798
|
|
|
|
|
|
|
|
2799
|
|
|
|
|
|
|
|
2800
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
2801
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
2802
|
|
|
|
|
|
|
#else |
2803
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
2804
|
|
|
|
|
|
|
#endif |
2805
|
|
|
|
|
|
|
|
2806
|
|
|
|
|
|
|
|
2807
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
2808
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
2809
|
|
|
|
|
|
|
# define restrict __restrict__ |
2810
|
|
|
|
|
|
|
# else |
2811
|
|
|
|
|
|
|
# define restrict |
2812
|
|
|
|
|
|
|
# endif |
2813
|
|
|
|
|
|
|
#endif |
2814
|
|
|
|
|
|
|
|
2815
|
|
|
|
|
|
|
|
2816
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
2817
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
2818
|
|
|
|
|
|
|
#else |
2819
|
|
|
|
|
|
|
# define likely(expr) (expr) |
2820
|
|
|
|
|
|
|
#endif |
2821
|
|
|
|
|
|
|
|
2822
|
|
|
|
|
|
|
|
2823
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
2824
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
2825
|
|
|
|
|
|
|
#else |
2826
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
2827
|
|
|
|
|
|
|
#endif |
2828
|
|
|
|
|
|
|
|
2829
|
|
|
|
|
|
|
|
2830
|
|
|
|
|
|
|
#undef prefetchr |
2831
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
2832
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
2833
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2834
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
2835
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
2836
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
2837
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
2838
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
2839
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
2840
|
|
|
|
|
|
|
# endif |
2841
|
|
|
|
|
|
|
#endif |
2842
|
|
|
|
|
|
|
#ifndef prefetchr |
2843
|
|
|
|
|
|
|
# define prefetchr(addr) |
2844
|
|
|
|
|
|
|
#endif |
2845
|
|
|
|
|
|
|
|
2846
|
|
|
|
|
|
|
|
2847
|
|
|
|
|
|
|
#undef prefetchw |
2848
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
2849
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
2850
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2851
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
2852
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
2853
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
2854
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
2855
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
2856
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
2857
|
|
|
|
|
|
|
# endif |
2858
|
|
|
|
|
|
|
#endif |
2859
|
|
|
|
|
|
|
#ifndef prefetchw |
2860
|
|
|
|
|
|
|
# define prefetchw(addr) |
2861
|
|
|
|
|
|
|
#endif |
2862
|
|
|
|
|
|
|
|
2863
|
|
|
|
|
|
|
|
2864
|
|
|
|
|
|
|
#undef _aligned_attribute |
2865
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
2866
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
2867
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2868
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
2869
|
|
|
|
|
|
|
#endif |
2870
|
|
|
|
|
|
|
|
2871
|
|
|
|
|
|
|
|
2872
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
2873
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
2874
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
2875
|
|
|
|
|
|
|
#else |
2876
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
2877
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
2878
|
|
|
|
|
|
|
#endif |
2879
|
|
|
|
|
|
|
|
2880
|
|
|
|
|
|
|
|
2881
|
|
|
|
|
|
|
|
2882
|
|
|
|
|
|
|
|
2883
|
|
|
|
|
|
|
|
2884
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
2885
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
2886
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
2887
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
2888
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
2889
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
2890
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
2891
|
|
|
|
|
|
|
|
2892
|
|
|
|
|
|
|
|
2893
|
|
|
|
|
|
|
|
2894
|
|
|
|
|
|
|
|
2895
|
|
|
|
|
|
|
|
2896
|
|
|
|
|
|
|
|
2897
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
2898
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
2899
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2900
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
2901
|
|
|
|
|
|
|
#else |
2902
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
2903
|
|
|
|
|
|
|
{ |
2904
|
|
|
|
|
|
|
union { |
2905
|
|
|
|
|
|
|
u32 w; |
2906
|
|
|
|
|
|
|
u8 b; |
2907
|
|
|
|
|
|
|
} u; |
2908
|
|
|
|
|
|
|
|
2909
|
|
|
|
|
|
|
u.w = 1; |
2910
|
|
|
|
|
|
|
return u.b; |
2911
|
|
|
|
|
|
|
} |
2912
|
|
|
|
|
|
|
#endif |
2913
|
|
|
|
|
|
|
|
2914
|
|
|
|
|
|
|
|
2915
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
2916
|
|
|
|
|
|
|
{ |
2917
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
2918
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
2919
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2920
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
2921
|
|
|
|
|
|
|
#else |
2922
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
2923
|
|
|
|
|
|
|
#endif |
2924
|
|
|
|
|
|
|
} |
2925
|
|
|
|
|
|
|
|
2926
|
|
|
|
|
|
|
|
2927
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
2928
|
|
|
|
|
|
|
{ |
2929
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
2930
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
2931
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2932
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
2933
|
|
|
|
|
|
|
#else |
2934
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
2935
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
2936
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
2937
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
2938
|
|
|
|
|
|
|
#endif |
2939
|
|
|
|
|
|
|
} |
2940
|
|
|
|
|
|
|
|
2941
|
|
|
|
|
|
|
|
2942
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
2943
|
|
|
|
|
|
|
{ |
2944
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
2945
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
2946
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2947
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
2948
|
|
|
|
|
|
|
#else |
2949
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
2950
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
2951
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
2952
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
2953
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
2954
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
2955
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
2956
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
2957
|
|
|
|
|
|
|
#endif |
2958
|
|
|
|
|
|
|
} |
2959
|
|
|
|
|
|
|
|
2960
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
2961
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
2962
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
2963
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
2964
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
2965
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
2966
|
|
|
|
|
|
|
|
2967
|
|
|
|
|
|
|
|
2968
|
|
|
|
|
|
|
|
2969
|
|
|
|
|
|
|
|
2970
|
|
|
|
|
|
|
|
2971
|
|
|
|
|
|
|
|
2972
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
2973
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
2974
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
2975
|
|
|
|
|
|
|
defined(__wasm__)) |
2976
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
2977
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2978
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
2979
|
|
|
|
|
|
|
#else |
2980
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
2981
|
|
|
|
|
|
|
#endif |
2982
|
|
|
|
|
|
|
|
2983
|
|
|
|
|
|
|
|
2984
|
|
|
|
|
|
|
|
2985
|
|
|
|
|
|
|
#ifdef FREESTANDING |
2986
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
2987
|
|
|
|
|
|
|
#else |
2988
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
2989
|
|
|
|
|
|
|
#endif |
2990
|
|
|
|
|
|
|
|
2991
|
|
|
|
|
|
|
|
2992
|
|
|
|
|
|
|
|
2993
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
2994
|
|
|
|
|
|
|
static forceinline type \ |
2995
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
2996
|
|
|
|
|
|
|
{ \ |
2997
|
|
|
|
|
|
|
type v; \ |
2998
|
|
|
|
|
|
|
\ |
2999
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
3000
|
|
|
|
|
|
|
return v; \ |
3001
|
|
|
|
|
|
|
} \ |
3002
|
|
|
|
|
|
|
\ |
3003
|
|
|
|
|
|
|
static forceinline void \ |
3004
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
3005
|
|
|
|
|
|
|
{ \ |
3006
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
3007
|
|
|
|
|
|
|
} |
3008
|
|
|
|
|
|
|
|
3009
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
3010
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
3011
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
3012
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
3013
|
|
|
|
|
|
|
|
3014
|
|
|
|
|
|
|
#undef MEMCOPY |
3015
|
|
|
|
|
|
|
|
3016
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
3017
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
3018
|
|
|
|
|
|
|
|
3019
|
|
|
|
|
|
|
|
3020
|
|
|
|
|
|
|
|
3021
|
|
|
|
|
|
|
static forceinline u16 |
3022
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
3023
|
|
|
|
|
|
|
{ |
3024
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
3025
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
3026
|
|
|
|
|
|
|
else |
3027
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
3028
|
|
|
|
|
|
|
} |
3029
|
|
|
|
|
|
|
|
3030
|
|
|
|
|
|
|
static forceinline u16 |
3031
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
3032
|
|
|
|
|
|
|
{ |
3033
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
3034
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
3035
|
|
|
|
|
|
|
else |
3036
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
3037
|
|
|
|
|
|
|
} |
3038
|
|
|
|
|
|
|
|
3039
|
|
|
|
|
|
|
static forceinline u32 |
3040
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
3041
|
|
|
|
|
|
|
{ |
3042
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
3043
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
3044
|
|
|
|
|
|
|
else |
3045
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
3046
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
3047
|
|
|
|
|
|
|
} |
3048
|
|
|
|
|
|
|
|
3049
|
|
|
|
|
|
|
static forceinline u32 |
3050
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
3051
|
|
|
|
|
|
|
{ |
3052
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
3053
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
3054
|
|
|
|
|
|
|
else |
3055
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
3056
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
3057
|
|
|
|
|
|
|
} |
3058
|
|
|
|
|
|
|
|
3059
|
|
|
|
|
|
|
static forceinline u64 |
3060
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
3061
|
|
|
|
|
|
|
{ |
3062
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
3063
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
3064
|
|
|
|
|
|
|
else |
3065
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
3066
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
3067
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
3068
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
3069
|
|
|
|
|
|
|
} |
3070
|
|
|
|
|
|
|
|
3071
|
|
|
|
|
|
|
static forceinline machine_word_t |
3072
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
3073
|
|
|
|
|
|
|
{ |
3074
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
3075
|
|
|
|
|
|
|
if (WORDBITS == 32) |
3076
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
3077
|
|
|
|
|
|
|
else |
3078
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
3079
|
|
|
|
|
|
|
} |
3080
|
|
|
|
|
|
|
|
3081
|
|
|
|
|
|
|
|
3082
|
|
|
|
|
|
|
|
3083
|
|
|
|
|
|
|
static forceinline void |
3084
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
3085
|
|
|
|
|
|
|
{ |
3086
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3087
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
3088
|
|
|
|
|
|
|
} else { |
3089
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
3090
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
3091
|
|
|
|
|
|
|
} |
3092
|
|
|
|
|
|
|
} |
3093
|
|
|
|
|
|
|
|
3094
|
|
|
|
|
|
|
static forceinline void |
3095
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
3096
|
|
|
|
|
|
|
{ |
3097
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3098
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
3099
|
|
|
|
|
|
|
} else { |
3100
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
3101
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
3102
|
|
|
|
|
|
|
} |
3103
|
|
|
|
|
|
|
} |
3104
|
|
|
|
|
|
|
|
3105
|
|
|
|
|
|
|
static forceinline void |
3106
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
3107
|
|
|
|
|
|
|
{ |
3108
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3109
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
3110
|
|
|
|
|
|
|
} else { |
3111
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
3112
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
3113
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
3114
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
3115
|
|
|
|
|
|
|
} |
3116
|
|
|
|
|
|
|
} |
3117
|
|
|
|
|
|
|
|
3118
|
|
|
|
|
|
|
static forceinline void |
3119
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
3120
|
|
|
|
|
|
|
{ |
3121
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3122
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
3123
|
|
|
|
|
|
|
} else { |
3124
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
3125
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
3126
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
3127
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
3128
|
|
|
|
|
|
|
} |
3129
|
|
|
|
|
|
|
} |
3130
|
|
|
|
|
|
|
|
3131
|
|
|
|
|
|
|
static forceinline void |
3132
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
3133
|
|
|
|
|
|
|
{ |
3134
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3135
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
3136
|
|
|
|
|
|
|
} else { |
3137
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
3138
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
3139
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
3140
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
3141
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
3142
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
3143
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
3144
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
3145
|
|
|
|
|
|
|
} |
3146
|
|
|
|
|
|
|
} |
3147
|
|
|
|
|
|
|
|
3148
|
|
|
|
|
|
|
static forceinline void |
3149
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
3150
|
|
|
|
|
|
|
{ |
3151
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
3152
|
|
|
|
|
|
|
if (WORDBITS == 32) |
3153
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
3154
|
|
|
|
|
|
|
else |
3155
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
3156
|
|
|
|
|
|
|
} |
3157
|
|
|
|
|
|
|
|
3158
|
|
|
|
|
|
|
|
3159
|
|
|
|
|
|
|
|
3160
|
|
|
|
|
|
|
|
3161
|
|
|
|
|
|
|
|
3162
|
|
|
|
|
|
|
|
3163
|
|
|
|
|
|
|
|
3164
|
|
|
|
|
|
|
static forceinline unsigned |
3165
|
|
|
|
|
|
|
bsr32(u32 v) |
3166
|
|
|
|
|
|
|
{ |
3167
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
3168
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
3169
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
3170
|
|
|
|
|
|
|
unsigned long i; |
3171
|
|
|
|
|
|
|
|
3172
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
3173
|
|
|
|
|
|
|
return i; |
3174
|
|
|
|
|
|
|
#else |
3175
|
|
|
|
|
|
|
unsigned i = 0; |
3176
|
|
|
|
|
|
|
|
3177
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
3178
|
|
|
|
|
|
|
i++; |
3179
|
|
|
|
|
|
|
return i; |
3180
|
|
|
|
|
|
|
#endif |
3181
|
|
|
|
|
|
|
} |
3182
|
|
|
|
|
|
|
|
3183
|
|
|
|
|
|
|
static forceinline unsigned |
3184
|
|
|
|
|
|
|
bsr64(u64 v) |
3185
|
|
|
|
|
|
|
{ |
3186
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
3187
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
3188
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
3189
|
|
|
|
|
|
|
unsigned long i; |
3190
|
|
|
|
|
|
|
|
3191
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
3192
|
|
|
|
|
|
|
return i; |
3193
|
|
|
|
|
|
|
#else |
3194
|
|
|
|
|
|
|
unsigned i = 0; |
3195
|
|
|
|
|
|
|
|
3196
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
3197
|
|
|
|
|
|
|
i++; |
3198
|
|
|
|
|
|
|
return i; |
3199
|
|
|
|
|
|
|
#endif |
3200
|
|
|
|
|
|
|
} |
3201
|
|
|
|
|
|
|
|
3202
|
|
|
|
|
|
|
static forceinline unsigned |
3203
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
3204
|
|
|
|
|
|
|
{ |
3205
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
3206
|
|
|
|
|
|
|
if (WORDBITS == 32) |
3207
|
|
|
|
|
|
|
return bsr32(v); |
3208
|
|
|
|
|
|
|
else |
3209
|
|
|
|
|
|
|
return bsr64(v); |
3210
|
|
|
|
|
|
|
} |
3211
|
|
|
|
|
|
|
|
3212
|
|
|
|
|
|
|
|
3213
|
|
|
|
|
|
|
|
3214
|
|
|
|
|
|
|
static forceinline unsigned |
3215
|
|
|
|
|
|
|
bsf32(u32 v) |
3216
|
|
|
|
|
|
|
{ |
3217
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
3218
|
|
|
|
|
|
|
return __builtin_ctz(v); |
3219
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
3220
|
|
|
|
|
|
|
unsigned long i; |
3221
|
|
|
|
|
|
|
|
3222
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
3223
|
|
|
|
|
|
|
return i; |
3224
|
|
|
|
|
|
|
#else |
3225
|
|
|
|
|
|
|
unsigned i = 0; |
3226
|
|
|
|
|
|
|
|
3227
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
3228
|
|
|
|
|
|
|
i++; |
3229
|
|
|
|
|
|
|
return i; |
3230
|
|
|
|
|
|
|
#endif |
3231
|
|
|
|
|
|
|
} |
3232
|
|
|
|
|
|
|
|
3233
|
|
|
|
|
|
|
static forceinline unsigned |
3234
|
|
|
|
|
|
|
bsf64(u64 v) |
3235
|
|
|
|
|
|
|
{ |
3236
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
3237
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
3238
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
3239
|
|
|
|
|
|
|
unsigned long i; |
3240
|
|
|
|
|
|
|
|
3241
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
3242
|
|
|
|
|
|
|
return i; |
3243
|
|
|
|
|
|
|
#else |
3244
|
|
|
|
|
|
|
unsigned i = 0; |
3245
|
|
|
|
|
|
|
|
3246
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
3247
|
|
|
|
|
|
|
i++; |
3248
|
|
|
|
|
|
|
return i; |
3249
|
|
|
|
|
|
|
#endif |
3250
|
|
|
|
|
|
|
} |
3251
|
|
|
|
|
|
|
|
3252
|
|
|
|
|
|
|
static forceinline unsigned |
3253
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
3254
|
|
|
|
|
|
|
{ |
3255
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
3256
|
|
|
|
|
|
|
if (WORDBITS == 32) |
3257
|
|
|
|
|
|
|
return bsf32(v); |
3258
|
|
|
|
|
|
|
else |
3259
|
|
|
|
|
|
|
return bsf64(v); |
3260
|
|
|
|
|
|
|
} |
3261
|
|
|
|
|
|
|
|
3262
|
|
|
|
|
|
|
|
3263
|
|
|
|
|
|
|
#undef rbit32 |
3264
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
3265
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
3266
|
|
|
|
|
|
|
static forceinline u32 |
3267
|
|
|
|
|
|
|
rbit32(u32 v) |
3268
|
|
|
|
|
|
|
{ |
3269
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
3270
|
|
|
|
|
|
|
return v; |
3271
|
|
|
|
|
|
|
} |
3272
|
|
|
|
|
|
|
#define rbit32 rbit32 |
3273
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
3274
|
|
|
|
|
|
|
static forceinline u32 |
3275
|
|
|
|
|
|
|
rbit32(u32 v) |
3276
|
|
|
|
|
|
|
{ |
3277
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
3278
|
|
|
|
|
|
|
return v; |
3279
|
|
|
|
|
|
|
} |
3280
|
|
|
|
|
|
|
#define rbit32 rbit32 |
3281
|
|
|
|
|
|
|
#endif |
3282
|
|
|
|
|
|
|
|
3283
|
|
|
|
|
|
|
#endif |
3284
|
|
|
|
|
|
|
|
3285
|
|
|
|
|
|
|
|
3286
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
3287
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
3288
|
|
|
|
|
|
|
|
3289
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
3290
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
3291
|
|
|
|
|
|
|
|
3292
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
3293
|
|
|
|
|
|
|
size_t alignment, size_t size); |
3294
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
3295
|
|
|
|
|
|
|
|
3296
|
|
|
|
|
|
|
#ifdef FREESTANDING |
3297
|
|
|
|
|
|
|
|
3298
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
3299
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
3300
|
|
|
|
|
|
|
|
3301
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
3302
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
3303
|
|
|
|
|
|
|
|
3304
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
3305
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
3306
|
|
|
|
|
|
|
|
3307
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
3308
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
3309
|
|
|
|
|
|
|
|
3310
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
3311
|
|
|
|
|
|
|
#else |
3312
|
|
|
|
|
|
|
#include |
3313
|
|
|
|
|
|
|
#endif |
3314
|
|
|
|
|
|
|
|
3315
|
|
|
|
|
|
|
|
3316
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
3317
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
3318
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
3319
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
3320
|
|
|
|
|
|
|
#else |
3321
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
3322
|
|
|
|
|
|
|
#endif |
3323
|
|
|
|
|
|
|
|
3324
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
3325
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
3326
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
3327
|
|
|
|
|
|
|
|
3328
|
|
|
|
|
|
|
#endif |
3329
|
|
|
|
|
|
|
|
3330
|
|
|
|
|
|
|
|
3331
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
3332
|
|
|
|
|
|
|
|
3333
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
3334
|
|
|
|
|
|
|
|
3335
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
3336
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
3337
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
3338
|
|
|
|
|
|
|
#endif |
3339
|
|
|
|
|
|
|
|
3340
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
3341
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
3342
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
3343
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
3344
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
3345
|
|
|
|
|
|
|
|
3346
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
3347
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
3348
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
3349
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
3350
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
3351
|
|
|
|
|
|
|
|
3352
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
3353
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
3354
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
3355
|
|
|
|
|
|
|
|
3356
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
3357
|
|
|
|
|
|
|
|
3358
|
5
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
3359
|
|
|
|
|
|
|
{ |
3360
|
5
|
100
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
3361
|
2
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
3362
|
5
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
3363
|
|
|
|
|
|
|
} |
3364
|
|
|
|
|
|
|
#else |
3365
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
3366
|
|
|
|
|
|
|
#endif |
3367
|
|
|
|
|
|
|
|
3368
|
|
|
|
|
|
|
|
3369
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
3370
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
3371
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
3372
|
|
|
|
|
|
|
#else |
3373
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
3374
|
|
|
|
|
|
|
#endif |
3375
|
|
|
|
|
|
|
|
3376
|
|
|
|
|
|
|
|
3377
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
3378
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
3379
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
3380
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
3381
|
|
|
|
|
|
|
#else |
3382
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
3383
|
|
|
|
|
|
|
#endif |
3384
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
3385
|
|
|
|
|
|
|
|
3386
|
|
|
|
|
|
|
|
3387
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
3388
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
3389
|
|
|
|
|
|
|
#else |
3390
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
3391
|
|
|
|
|
|
|
#endif |
3392
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
3393
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
3394
|
|
|
|
|
|
|
defined(_MSC_VER))) |
3395
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
3396
|
|
|
|
|
|
|
#else |
3397
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
3398
|
|
|
|
|
|
|
#endif |
3399
|
|
|
|
|
|
|
|
3400
|
|
|
|
|
|
|
|
3401
|
|
|
|
|
|
|
#ifdef __AVX__ |
3402
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
3403
|
|
|
|
|
|
|
#else |
3404
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
3405
|
|
|
|
|
|
|
#endif |
3406
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
3407
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
3408
|
|
|
|
|
|
|
defined(_MSC_VER))) |
3409
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
3410
|
|
|
|
|
|
|
#else |
3411
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
3412
|
|
|
|
|
|
|
#endif |
3413
|
|
|
|
|
|
|
|
3414
|
|
|
|
|
|
|
|
3415
|
|
|
|
|
|
|
#ifdef __AVX2__ |
3416
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
3417
|
|
|
|
|
|
|
#else |
3418
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
3419
|
|
|
|
|
|
|
#endif |
3420
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
3421
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
3422
|
|
|
|
|
|
|
defined(_MSC_VER))) |
3423
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
3424
|
|
|
|
|
|
|
#else |
3425
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
3426
|
|
|
|
|
|
|
#endif |
3427
|
|
|
|
|
|
|
|
3428
|
|
|
|
|
|
|
|
3429
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
3430
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
3431
|
|
|
|
|
|
|
#else |
3432
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
3433
|
|
|
|
|
|
|
#endif |
3434
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
3435
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
3436
|
|
|
|
|
|
|
defined(_MSC_VER))) |
3437
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
3438
|
|
|
|
|
|
|
#else |
3439
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
3440
|
|
|
|
|
|
|
#endif |
3441
|
|
|
|
|
|
|
|
3442
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1930 |
3443
|
|
|
|
|
|
|
# undef HAVE_BMI2_NATIVE |
3444
|
|
|
|
|
|
|
# undef HAVE_BMI2_INTRIN |
3445
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
3446
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
3447
|
|
|
|
|
|
|
#endif |
3448
|
|
|
|
|
|
|
|
3449
|
|
|
|
|
|
|
#endif |
3450
|
|
|
|
|
|
|
|
3451
|
|
|
|
|
|
|
#endif |
3452
|
|
|
|
|
|
|
|
3453
|
|
|
|
|
|
|
|
3454
|
|
|
|
|
|
|
|
3455
|
|
|
|
|
|
|
|
3456
|
|
|
|
|
|
|
#define ADLER32_FINISH_VEC_CHUNK_128(s1, s2, v_s1, v_s2) \ |
3457
|
|
|
|
|
|
|
{ \ |
3458
|
|
|
|
|
|
|
__m128i s1_last = (v_s1), s2_last = (v_s2); \ |
3459
|
|
|
|
|
|
|
\ |
3460
|
|
|
|
|
|
|
\ |
3461
|
|
|
|
|
|
|
s2_last = _mm_add_epi32(s2_last, _mm_shuffle_epi32(s2_last, 0x31)); \ |
3462
|
|
|
|
|
|
|
s1_last = _mm_add_epi32(s1_last, _mm_shuffle_epi32(s1_last, 0x02)); \ |
3463
|
|
|
|
|
|
|
s2_last = _mm_add_epi32(s2_last, _mm_shuffle_epi32(s2_last, 0x02)); \ |
3464
|
|
|
|
|
|
|
\ |
3465
|
|
|
|
|
|
|
*(s1) += (u32)_mm_cvtsi128_si32(s1_last); \ |
3466
|
|
|
|
|
|
|
*(s2) += (u32)_mm_cvtsi128_si32(s2_last); \ |
3467
|
|
|
|
|
|
|
} |
3468
|
|
|
|
|
|
|
|
3469
|
|
|
|
|
|
|
#define ADLER32_FINISH_VEC_CHUNK_256(s1, s2, v_s1, v_s2) \ |
3470
|
|
|
|
|
|
|
{ \ |
3471
|
|
|
|
|
|
|
__m128i s1_128bit, s2_128bit; \ |
3472
|
|
|
|
|
|
|
\ |
3473
|
|
|
|
|
|
|
\ |
3474
|
|
|
|
|
|
|
s1_128bit = _mm_add_epi32(_mm256_extracti128_si256((v_s1), 0), \ |
3475
|
|
|
|
|
|
|
_mm256_extracti128_si256((v_s1), 1)); \ |
3476
|
|
|
|
|
|
|
s2_128bit = _mm_add_epi32(_mm256_extracti128_si256((v_s2), 0), \ |
3477
|
|
|
|
|
|
|
_mm256_extracti128_si256((v_s2), 1)); \ |
3478
|
|
|
|
|
|
|
\ |
3479
|
|
|
|
|
|
|
ADLER32_FINISH_VEC_CHUNK_128((s1), (s2), s1_128bit, s2_128bit); \ |
3480
|
|
|
|
|
|
|
} |
3481
|
|
|
|
|
|
|
|
3482
|
|
|
|
|
|
|
|
3483
|
|
|
|
|
|
|
#if GCC_PREREQ(1, 0) |
3484
|
|
|
|
|
|
|
# define GCC_UPDATE_VARS(a, b, c, d, e, f) \ |
3485
|
|
|
|
|
|
|
__asm__("" : "+x" (a), "+x" (b), "+x" (c), "+x" (d), "+x" (e), "+x" (f)) |
3486
|
|
|
|
|
|
|
#else |
3487
|
|
|
|
|
|
|
# define GCC_UPDATE_VARS(a, b, c, d, e, f) \ |
3488
|
|
|
|
|
|
|
(void)a, (void)b, (void)c, (void)d, (void)e, (void)f |
3489
|
|
|
|
|
|
|
#endif |
3490
|
|
|
|
|
|
|
|
3491
|
|
|
|
|
|
|
|
3492
|
|
|
|
|
|
|
#if HAVE_SSE2_INTRIN |
3493
|
|
|
|
|
|
|
# define adler32_sse2 adler32_sse2 |
3494
|
|
|
|
|
|
|
# define FUNCNAME adler32_sse2 |
3495
|
|
|
|
|
|
|
# define FUNCNAME_CHUNK adler32_sse2_chunk |
3496
|
|
|
|
|
|
|
# define IMPL_ALIGNMENT 16 |
3497
|
|
|
|
|
|
|
# define IMPL_SEGMENT_LEN 32 |
3498
|
|
|
|
|
|
|
|
3499
|
|
|
|
|
|
|
# define IMPL_MAX_CHUNK_LEN (32 * (0x7FFF / 0xFF)) |
3500
|
|
|
|
|
|
|
# if HAVE_SSE2_NATIVE |
3501
|
|
|
|
|
|
|
# define ATTRIBUTES |
3502
|
|
|
|
|
|
|
# else |
3503
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("sse2") |
3504
|
|
|
|
|
|
|
# endif |
3505
|
|
|
|
|
|
|
# include |
3506
|
|
|
|
|
|
|
static forceinline ATTRIBUTES void |
3507
|
|
|
|
|
|
|
adler32_sse2_chunk(const __m128i *p, const __m128i *const end, u32 *s1, u32 *s2) |
3508
|
|
|
|
|
|
|
{ |
3509
|
24
|
|
|
|
|
|
const __m128i zeroes = _mm_setzero_si128(); |
3510
|
24
|
|
|
|
|
|
const __m128i mults_a = |
3511
|
|
|
|
|
|
|
_mm_setr_epi16(32, 31, 30, 29, 28, 27, 26, 25); |
3512
|
24
|
|
|
|
|
|
const __m128i mults_b = |
3513
|
|
|
|
|
|
|
_mm_setr_epi16(24, 23, 22, 21, 20, 19, 18, 17); |
3514
|
24
|
|
|
|
|
|
const __m128i mults_c = |
3515
|
|
|
|
|
|
|
_mm_setr_epi16(16, 15, 14, 13, 12, 11, 10, 9); |
3516
|
24
|
|
|
|
|
|
const __m128i mults_d = |
3517
|
|
|
|
|
|
|
_mm_setr_epi16(8, 7, 6, 5, 4, 3, 2, 1); |
3518
|
|
|
|
|
|
|
|
3519
|
|
|
|
|
|
|
|
3520
|
24
|
|
|
|
|
|
__m128i v_s1 = zeroes; |
3521
|
|
|
|
|
|
|
|
3522
|
|
|
|
|
|
|
|
3523
|
24
|
|
|
|
|
|
__m128i v_s2 = zeroes; |
3524
|
|
|
|
|
|
|
|
3525
|
|
|
|
|
|
|
|
3526
|
24
|
|
|
|
|
|
__m128i v_byte_sums_a = zeroes; |
3527
|
24
|
|
|
|
|
|
__m128i v_byte_sums_b = zeroes; |
3528
|
24
|
|
|
|
|
|
__m128i v_byte_sums_c = zeroes; |
3529
|
24
|
|
|
|
|
|
__m128i v_byte_sums_d = zeroes; |
3530
|
|
|
|
|
|
|
|
3531
|
|
|
|
|
|
|
do { |
3532
|
|
|
|
|
|
|
|
3533
|
1272
|
|
|
|
|
|
const __m128i bytes1 = *p++; |
3534
|
1272
|
|
|
|
|
|
const __m128i bytes2 = *p++; |
3535
|
|
|
|
|
|
|
|
3536
|
|
|
|
|
|
|
|
3537
|
1272
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, v_s1); |
3538
|
|
|
|
|
|
|
|
3539
|
|
|
|
|
|
|
|
3540
|
2544
|
|
|
|
|
|
v_s1 = _mm_add_epi32(v_s1, _mm_sad_epu8(bytes1, zeroes)); |
3541
|
2544
|
|
|
|
|
|
v_s1 = _mm_add_epi32(v_s1, _mm_sad_epu8(bytes2, zeroes)); |
3542
|
|
|
|
|
|
|
|
3543
|
|
|
|
|
|
|
|
3544
|
2544
|
|
|
|
|
|
v_byte_sums_a = _mm_add_epi16( |
3545
|
|
|
|
|
|
|
v_byte_sums_a, _mm_unpacklo_epi8(bytes1, zeroes)); |
3546
|
2544
|
|
|
|
|
|
v_byte_sums_b = _mm_add_epi16( |
3547
|
|
|
|
|
|
|
v_byte_sums_b, _mm_unpackhi_epi8(bytes1, zeroes)); |
3548
|
2544
|
|
|
|
|
|
v_byte_sums_c = _mm_add_epi16( |
3549
|
|
|
|
|
|
|
v_byte_sums_c, _mm_unpacklo_epi8(bytes2, zeroes)); |
3550
|
2544
|
|
|
|
|
|
v_byte_sums_d = _mm_add_epi16( |
3551
|
|
|
|
|
|
|
v_byte_sums_d, _mm_unpackhi_epi8(bytes2, zeroes)); |
3552
|
|
|
|
|
|
|
|
3553
|
1272
|
|
|
|
|
|
GCC_UPDATE_VARS(v_s1, v_s2, v_byte_sums_a, v_byte_sums_b, |
3554
|
|
|
|
|
|
|
v_byte_sums_c, v_byte_sums_d); |
3555
|
1272
|
100
|
|
|
|
|
} while (p != end); |
3556
|
|
|
|
|
|
|
|
3557
|
|
|
|
|
|
|
|
3558
|
24
|
|
|
|
|
|
v_s2 = _mm_slli_epi32(v_s2, 5); |
3559
|
48
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(v_byte_sums_a, mults_a)); |
3560
|
48
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(v_byte_sums_b, mults_b)); |
3561
|
48
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(v_byte_sums_c, mults_c)); |
3562
|
48
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(v_byte_sums_d, mults_d)); |
3563
|
|
|
|
|
|
|
|
3564
|
|
|
|
|
|
|
|
3565
|
72
|
|
|
|
|
|
ADLER32_FINISH_VEC_CHUNK_128(s1, s2, v_s1, v_s2); |
3566
|
|
|
|
|
|
|
} |
3567
|
|
|
|
|
|
|
/* #include "adler32_vec_template.h" */ |
3568
|
|
|
|
|
|
|
|
3569
|
|
|
|
|
|
|
|
3570
|
|
|
|
|
|
|
|
3571
|
|
|
|
|
|
|
|
3572
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
3573
|
24
|
|
|
|
|
|
FUNCNAME(u32 adler, const u8 *p, size_t len) |
3574
|
|
|
|
|
|
|
{ |
3575
|
24
|
|
|
|
|
|
const size_t max_chunk_len = |
3576
|
|
|
|
|
|
|
MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) - |
3577
|
|
|
|
|
|
|
(MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) % IMPL_SEGMENT_LEN); |
3578
|
24
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
3579
|
24
|
|
|
|
|
|
u32 s2 = adler >> 16; |
3580
|
24
|
|
|
|
|
|
const u8 * const end = p + len; |
3581
|
|
|
|
|
|
|
const u8 *vend; |
3582
|
|
|
|
|
|
|
|
3583
|
|
|
|
|
|
|
|
3584
|
24
|
50
|
|
|
|
|
if (p != end && (uintptr_t)p % IMPL_ALIGNMENT) { |
|
|
50
|
|
|
|
|
|
3585
|
|
|
|
|
|
|
do { |
3586
|
0
|
|
|
|
|
|
s1 += *p++; |
3587
|
0
|
|
|
|
|
|
s2 += s1; |
3588
|
0
|
0
|
|
|
|
|
} while (p != end && (uintptr_t)p % IMPL_ALIGNMENT); |
|
|
0
|
|
|
|
|
|
3589
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
3590
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
3591
|
|
|
|
|
|
|
} |
3592
|
|
|
|
|
|
|
|
3593
|
|
|
|
|
|
|
|
3594
|
|
|
|
|
|
|
STATIC_ASSERT(IMPL_SEGMENT_LEN % IMPL_ALIGNMENT == 0); |
3595
|
24
|
|
|
|
|
|
vend = end - ((size_t)(end - p) % IMPL_SEGMENT_LEN); |
3596
|
48
|
100
|
|
|
|
|
while (p != vend) { |
3597
|
24
|
|
|
|
|
|
size_t chunk_len = MIN((size_t)(vend - p), max_chunk_len); |
3598
|
|
|
|
|
|
|
|
3599
|
24
|
|
|
|
|
|
s2 += s1 * chunk_len; |
3600
|
|
|
|
|
|
|
|
3601
|
24
|
|
|
|
|
|
FUNCNAME_CHUNK((const void *)p, (const void *)(p + chunk_len), |
3602
|
|
|
|
|
|
|
&s1, &s2); |
3603
|
|
|
|
|
|
|
|
3604
|
24
|
|
|
|
|
|
p += chunk_len; |
3605
|
24
|
|
|
|
|
|
s1 %= DIVISOR; |
3606
|
24
|
|
|
|
|
|
s2 %= DIVISOR; |
3607
|
|
|
|
|
|
|
} |
3608
|
|
|
|
|
|
|
|
3609
|
|
|
|
|
|
|
|
3610
|
24
|
50
|
|
|
|
|
if (p != end) { |
3611
|
|
|
|
|
|
|
do { |
3612
|
96
|
|
|
|
|
|
s1 += *p++; |
3613
|
96
|
|
|
|
|
|
s2 += s1; |
3614
|
96
|
100
|
|
|
|
|
} while (p != end); |
3615
|
24
|
|
|
|
|
|
s1 %= DIVISOR; |
3616
|
24
|
|
|
|
|
|
s2 %= DIVISOR; |
3617
|
|
|
|
|
|
|
} |
3618
|
|
|
|
|
|
|
|
3619
|
24
|
|
|
|
|
|
return (s2 << 16) | s1; |
3620
|
|
|
|
|
|
|
} |
3621
|
|
|
|
|
|
|
|
3622
|
|
|
|
|
|
|
#undef FUNCNAME |
3623
|
|
|
|
|
|
|
#undef FUNCNAME_CHUNK |
3624
|
|
|
|
|
|
|
#undef ATTRIBUTES |
3625
|
|
|
|
|
|
|
#undef IMPL_ALIGNMENT |
3626
|
|
|
|
|
|
|
#undef IMPL_SEGMENT_LEN |
3627
|
|
|
|
|
|
|
#undef IMPL_MAX_CHUNK_LEN |
3628
|
|
|
|
|
|
|
|
3629
|
|
|
|
|
|
|
#endif |
3630
|
|
|
|
|
|
|
|
3631
|
|
|
|
|
|
|
|
3632
|
|
|
|
|
|
|
#if HAVE_AVX2_INTRIN |
3633
|
|
|
|
|
|
|
# define adler32_avx2 adler32_avx2 |
3634
|
|
|
|
|
|
|
# define FUNCNAME adler32_avx2 |
3635
|
|
|
|
|
|
|
# define FUNCNAME_CHUNK adler32_avx2_chunk |
3636
|
|
|
|
|
|
|
# define IMPL_ALIGNMENT 32 |
3637
|
|
|
|
|
|
|
# define IMPL_SEGMENT_LEN 64 |
3638
|
|
|
|
|
|
|
# define IMPL_MAX_CHUNK_LEN (64 * (0x7FFF / 0xFF)) |
3639
|
|
|
|
|
|
|
# if HAVE_AVX2_NATIVE |
3640
|
|
|
|
|
|
|
# define ATTRIBUTES |
3641
|
|
|
|
|
|
|
# else |
3642
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("avx2") |
3643
|
|
|
|
|
|
|
# endif |
3644
|
|
|
|
|
|
|
# include |
3645
|
|
|
|
|
|
|
|
3646
|
|
|
|
|
|
|
# if defined(__clang__) && defined(_MSC_VER) |
3647
|
|
|
|
|
|
|
# include |
3648
|
|
|
|
|
|
|
# include |
3649
|
|
|
|
|
|
|
# endif |
3650
|
|
|
|
|
|
|
static forceinline ATTRIBUTES void |
3651
|
|
|
|
|
|
|
adler32_avx2_chunk(const __m256i *p, const __m256i *const end, u32 *s1, u32 *s2) |
3652
|
|
|
|
|
|
|
{ |
3653
|
0
|
|
|
|
|
|
const __m256i zeroes = _mm256_setzero_si256(); |
3654
|
|
|
|
|
|
|
|
3655
|
0
|
|
|
|
|
|
const __m256i mults_a = |
3656
|
|
|
|
|
|
|
_mm256_setr_epi16(64, 63, 62, 61, 60, 59, 58, 57, |
3657
|
|
|
|
|
|
|
48, 47, 46, 45, 44, 43, 42, 41); |
3658
|
0
|
|
|
|
|
|
const __m256i mults_b = |
3659
|
|
|
|
|
|
|
_mm256_setr_epi16(56, 55, 54, 53, 52, 51, 50, 49, |
3660
|
|
|
|
|
|
|
40, 39, 38, 37, 36, 35, 34, 33); |
3661
|
0
|
|
|
|
|
|
const __m256i mults_c = |
3662
|
|
|
|
|
|
|
_mm256_setr_epi16(32, 31, 30, 29, 28, 27, 26, 25, |
3663
|
|
|
|
|
|
|
16, 15, 14, 13, 12, 11, 10, 9); |
3664
|
0
|
|
|
|
|
|
const __m256i mults_d = |
3665
|
|
|
|
|
|
|
_mm256_setr_epi16(24, 23, 22, 21, 20, 19, 18, 17, |
3666
|
|
|
|
|
|
|
8, 7, 6, 5, 4, 3, 2, 1); |
3667
|
0
|
|
|
|
|
|
__m256i v_s1 = zeroes; |
3668
|
0
|
|
|
|
|
|
__m256i v_s2 = zeroes; |
3669
|
0
|
|
|
|
|
|
__m256i v_byte_sums_a = zeroes; |
3670
|
0
|
|
|
|
|
|
__m256i v_byte_sums_b = zeroes; |
3671
|
0
|
|
|
|
|
|
__m256i v_byte_sums_c = zeroes; |
3672
|
0
|
|
|
|
|
|
__m256i v_byte_sums_d = zeroes; |
3673
|
|
|
|
|
|
|
|
3674
|
|
|
|
|
|
|
do { |
3675
|
0
|
|
|
|
|
|
const __m256i bytes1 = *p++; |
3676
|
0
|
|
|
|
|
|
const __m256i bytes2 = *p++; |
3677
|
|
|
|
|
|
|
|
3678
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, v_s1); |
3679
|
0
|
|
|
|
|
|
v_s1 = _mm256_add_epi32(v_s1, _mm256_sad_epu8(bytes1, zeroes)); |
3680
|
0
|
|
|
|
|
|
v_s1 = _mm256_add_epi32(v_s1, _mm256_sad_epu8(bytes2, zeroes)); |
3681
|
0
|
|
|
|
|
|
v_byte_sums_a = _mm256_add_epi16( |
3682
|
|
|
|
|
|
|
v_byte_sums_a, _mm256_unpacklo_epi8(bytes1, zeroes)); |
3683
|
0
|
|
|
|
|
|
v_byte_sums_b = _mm256_add_epi16( |
3684
|
|
|
|
|
|
|
v_byte_sums_b, _mm256_unpackhi_epi8(bytes1, zeroes)); |
3685
|
0
|
|
|
|
|
|
v_byte_sums_c = _mm256_add_epi16( |
3686
|
|
|
|
|
|
|
v_byte_sums_c, _mm256_unpacklo_epi8(bytes2, zeroes)); |
3687
|
0
|
|
|
|
|
|
v_byte_sums_d = _mm256_add_epi16( |
3688
|
|
|
|
|
|
|
v_byte_sums_d, _mm256_unpackhi_epi8(bytes2, zeroes)); |
3689
|
|
|
|
|
|
|
|
3690
|
0
|
|
|
|
|
|
GCC_UPDATE_VARS(v_s1, v_s2, v_byte_sums_a, v_byte_sums_b, |
3691
|
|
|
|
|
|
|
v_byte_sums_c, v_byte_sums_d); |
3692
|
0
|
0
|
|
|
|
|
} while (p != end); |
3693
|
|
|
|
|
|
|
|
3694
|
0
|
|
|
|
|
|
v_s2 = _mm256_slli_epi32(v_s2, 6); |
3695
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, _mm256_madd_epi16(v_byte_sums_a, mults_a)); |
3696
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, _mm256_madd_epi16(v_byte_sums_b, mults_b)); |
3697
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, _mm256_madd_epi16(v_byte_sums_c, mults_c)); |
3698
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, _mm256_madd_epi16(v_byte_sums_d, mults_d)); |
3699
|
0
|
|
|
|
|
|
ADLER32_FINISH_VEC_CHUNK_256(s1, s2, v_s1, v_s2); |
3700
|
|
|
|
|
|
|
} |
3701
|
|
|
|
|
|
|
/* #include "x86-../adler32_vec_template.h" */ |
3702
|
|
|
|
|
|
|
|
3703
|
|
|
|
|
|
|
|
3704
|
|
|
|
|
|
|
|
3705
|
|
|
|
|
|
|
|
3706
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
3707
|
0
|
|
|
|
|
|
FUNCNAME(u32 adler, const u8 *p, size_t len) |
3708
|
|
|
|
|
|
|
{ |
3709
|
0
|
|
|
|
|
|
const size_t max_chunk_len = |
3710
|
|
|
|
|
|
|
MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) - |
3711
|
|
|
|
|
|
|
(MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) % IMPL_SEGMENT_LEN); |
3712
|
0
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
3713
|
0
|
|
|
|
|
|
u32 s2 = adler >> 16; |
3714
|
0
|
|
|
|
|
|
const u8 * const end = p + len; |
3715
|
|
|
|
|
|
|
const u8 *vend; |
3716
|
|
|
|
|
|
|
|
3717
|
|
|
|
|
|
|
|
3718
|
0
|
0
|
|
|
|
|
if (p != end && (uintptr_t)p % IMPL_ALIGNMENT) { |
|
|
0
|
|
|
|
|
|
3719
|
|
|
|
|
|
|
do { |
3720
|
0
|
|
|
|
|
|
s1 += *p++; |
3721
|
0
|
|
|
|
|
|
s2 += s1; |
3722
|
0
|
0
|
|
|
|
|
} while (p != end && (uintptr_t)p % IMPL_ALIGNMENT); |
|
|
0
|
|
|
|
|
|
3723
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
3724
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
3725
|
|
|
|
|
|
|
} |
3726
|
|
|
|
|
|
|
|
3727
|
|
|
|
|
|
|
|
3728
|
|
|
|
|
|
|
STATIC_ASSERT(IMPL_SEGMENT_LEN % IMPL_ALIGNMENT == 0); |
3729
|
0
|
|
|
|
|
|
vend = end - ((size_t)(end - p) % IMPL_SEGMENT_LEN); |
3730
|
0
|
0
|
|
|
|
|
while (p != vend) { |
3731
|
0
|
|
|
|
|
|
size_t chunk_len = MIN((size_t)(vend - p), max_chunk_len); |
3732
|
|
|
|
|
|
|
|
3733
|
0
|
|
|
|
|
|
s2 += s1 * chunk_len; |
3734
|
|
|
|
|
|
|
|
3735
|
0
|
|
|
|
|
|
FUNCNAME_CHUNK((const void *)p, (const void *)(p + chunk_len), |
3736
|
|
|
|
|
|
|
&s1, &s2); |
3737
|
|
|
|
|
|
|
|
3738
|
0
|
|
|
|
|
|
p += chunk_len; |
3739
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
3740
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
3741
|
|
|
|
|
|
|
} |
3742
|
|
|
|
|
|
|
|
3743
|
|
|
|
|
|
|
|
3744
|
0
|
0
|
|
|
|
|
if (p != end) { |
3745
|
|
|
|
|
|
|
do { |
3746
|
0
|
|
|
|
|
|
s1 += *p++; |
3747
|
0
|
|
|
|
|
|
s2 += s1; |
3748
|
0
|
0
|
|
|
|
|
} while (p != end); |
3749
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
3750
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
3751
|
|
|
|
|
|
|
} |
3752
|
|
|
|
|
|
|
|
3753
|
0
|
|
|
|
|
|
return (s2 << 16) | s1; |
3754
|
|
|
|
|
|
|
} |
3755
|
|
|
|
|
|
|
|
3756
|
|
|
|
|
|
|
#undef FUNCNAME |
3757
|
|
|
|
|
|
|
#undef FUNCNAME_CHUNK |
3758
|
|
|
|
|
|
|
#undef ATTRIBUTES |
3759
|
|
|
|
|
|
|
#undef IMPL_ALIGNMENT |
3760
|
|
|
|
|
|
|
#undef IMPL_SEGMENT_LEN |
3761
|
|
|
|
|
|
|
#undef IMPL_MAX_CHUNK_LEN |
3762
|
|
|
|
|
|
|
|
3763
|
|
|
|
|
|
|
#endif |
3764
|
|
|
|
|
|
|
|
3765
|
|
|
|
|
|
|
#if defined(adler32_avx2) && HAVE_AVX2_NATIVE |
3766
|
|
|
|
|
|
|
#define DEFAULT_IMPL adler32_avx2 |
3767
|
|
|
|
|
|
|
#else |
3768
|
|
|
|
|
|
|
static inline adler32_func_t |
3769
|
1
|
|
|
|
|
|
arch_select_adler32_func(void) |
3770
|
|
|
|
|
|
|
{ |
3771
|
1
|
|
|
|
|
|
const u32 features MAYBE_UNUSED = get_x86_cpu_features(); |
3772
|
|
|
|
|
|
|
|
3773
|
|
|
|
|
|
|
#ifdef adler32_avx2 |
3774
|
1
|
50
|
|
|
|
|
if (HAVE_AVX2(features)) |
3775
|
0
|
|
|
|
|
|
return adler32_avx2; |
3776
|
|
|
|
|
|
|
#endif |
3777
|
|
|
|
|
|
|
#ifdef adler32_sse2 |
3778
|
|
|
|
|
|
|
if (HAVE_SSE2(features)) |
3779
|
1
|
|
|
|
|
|
return adler32_sse2; |
3780
|
|
|
|
|
|
|
#endif |
3781
|
|
|
|
|
|
|
return NULL; |
3782
|
|
|
|
|
|
|
} |
3783
|
|
|
|
|
|
|
#define arch_select_adler32_func arch_select_adler32_func |
3784
|
|
|
|
|
|
|
#endif |
3785
|
|
|
|
|
|
|
|
3786
|
|
|
|
|
|
|
#endif |
3787
|
|
|
|
|
|
|
|
3788
|
|
|
|
|
|
|
#endif |
3789
|
|
|
|
|
|
|
|
3790
|
|
|
|
|
|
|
#ifndef DEFAULT_IMPL |
3791
|
|
|
|
|
|
|
# define DEFAULT_IMPL adler32_generic |
3792
|
|
|
|
|
|
|
#endif |
3793
|
|
|
|
|
|
|
|
3794
|
|
|
|
|
|
|
#ifdef arch_select_adler32_func |
3795
|
|
|
|
|
|
|
static u32 adler32_dispatch_adler32(u32 adler, const u8 *p, size_t len); |
3796
|
|
|
|
|
|
|
|
3797
|
|
|
|
|
|
|
static volatile adler32_func_t adler32_impl = adler32_dispatch_adler32; |
3798
|
|
|
|
|
|
|
|
3799
|
|
|
|
|
|
|
|
3800
|
1
|
|
|
|
|
|
static u32 adler32_dispatch_adler32(u32 adler, const u8 *p, size_t len) |
3801
|
|
|
|
|
|
|
{ |
3802
|
1
|
|
|
|
|
|
adler32_func_t f = arch_select_adler32_func(); |
3803
|
|
|
|
|
|
|
|
3804
|
1
|
50
|
|
|
|
|
if (f == NULL) |
3805
|
0
|
|
|
|
|
|
f = DEFAULT_IMPL; |
3806
|
|
|
|
|
|
|
|
3807
|
1
|
|
|
|
|
|
adler32_impl = f; |
3808
|
1
|
|
|
|
|
|
return f(adler, p, len); |
3809
|
|
|
|
|
|
|
} |
3810
|
|
|
|
|
|
|
#else |
3811
|
|
|
|
|
|
|
|
3812
|
|
|
|
|
|
|
#define adler32_impl DEFAULT_IMPL |
3813
|
|
|
|
|
|
|
#endif |
3814
|
|
|
|
|
|
|
|
3815
|
|
|
|
|
|
|
LIBDEFLATEAPI u32 |
3816
|
24
|
|
|
|
|
|
libdeflate_adler32(u32 adler, const void *buffer, size_t len) |
3817
|
|
|
|
|
|
|
{ |
3818
|
24
|
50
|
|
|
|
|
if (buffer == NULL) |
3819
|
0
|
|
|
|
|
|
return 1; |
3820
|
24
|
|
|
|
|
|
return adler32_impl(adler, buffer, len); |
3821
|
|
|
|
|
|
|
} |
3822
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/crc32.c */ |
3823
|
|
|
|
|
|
|
|
3824
|
|
|
|
|
|
|
|
3825
|
|
|
|
|
|
|
|
3826
|
|
|
|
|
|
|
|
3827
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
3828
|
|
|
|
|
|
|
|
3829
|
|
|
|
|
|
|
|
3830
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
3831
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
3832
|
|
|
|
|
|
|
|
3833
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
3834
|
|
|
|
|
|
|
|
3835
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
3836
|
|
|
|
|
|
|
#endif |
3837
|
|
|
|
|
|
|
|
3838
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
3839
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
3840
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
3841
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
3842
|
|
|
|
|
|
|
#else |
3843
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
3844
|
|
|
|
|
|
|
#endif |
3845
|
|
|
|
|
|
|
|
3846
|
|
|
|
|
|
|
|
3847
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
3848
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
3849
|
|
|
|
|
|
|
#else |
3850
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
3851
|
|
|
|
|
|
|
#endif |
3852
|
|
|
|
|
|
|
|
3853
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
3854
|
|
|
|
|
|
|
|
3855
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
3856
|
|
|
|
|
|
|
|
3857
|
|
|
|
|
|
|
|
3858
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
3859
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
3860
|
|
|
|
|
|
|
|
3861
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
3862
|
|
|
|
|
|
|
|
3863
|
|
|
|
|
|
|
|
3864
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
3865
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
3866
|
|
|
|
|
|
|
|
3867
|
|
|
|
|
|
|
#include |
3868
|
|
|
|
|
|
|
#include |
3869
|
|
|
|
|
|
|
|
3870
|
|
|
|
|
|
|
#ifdef __cplusplus |
3871
|
|
|
|
|
|
|
extern "C" { |
3872
|
|
|
|
|
|
|
#endif |
3873
|
|
|
|
|
|
|
|
3874
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
3875
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
3876
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
3877
|
|
|
|
|
|
|
|
3878
|
|
|
|
|
|
|
|
3879
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
3880
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
3881
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
3882
|
|
|
|
|
|
|
# else |
3883
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
3884
|
|
|
|
|
|
|
# endif |
3885
|
|
|
|
|
|
|
#endif |
3886
|
|
|
|
|
|
|
|
3887
|
|
|
|
|
|
|
|
3888
|
|
|
|
|
|
|
|
3889
|
|
|
|
|
|
|
|
3890
|
|
|
|
|
|
|
|
3891
|
|
|
|
|
|
|
struct libdeflate_compressor; |
3892
|
|
|
|
|
|
|
struct libdeflate_options; |
3893
|
|
|
|
|
|
|
|
3894
|
|
|
|
|
|
|
|
3895
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
3896
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
3897
|
|
|
|
|
|
|
|
3898
|
|
|
|
|
|
|
|
3899
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
3900
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
3901
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
3902
|
|
|
|
|
|
|
|
3903
|
|
|
|
|
|
|
|
3904
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3905
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
3906
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3907
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
3908
|
|
|
|
|
|
|
|
3909
|
|
|
|
|
|
|
|
3910
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3911
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
3912
|
|
|
|
|
|
|
size_t in_nbytes); |
3913
|
|
|
|
|
|
|
|
3914
|
|
|
|
|
|
|
|
3915
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3916
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
3917
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3918
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
3919
|
|
|
|
|
|
|
|
3920
|
|
|
|
|
|
|
|
3921
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3922
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
3923
|
|
|
|
|
|
|
size_t in_nbytes); |
3924
|
|
|
|
|
|
|
|
3925
|
|
|
|
|
|
|
|
3926
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3927
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
3928
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3929
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
3930
|
|
|
|
|
|
|
|
3931
|
|
|
|
|
|
|
|
3932
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3933
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
3934
|
|
|
|
|
|
|
size_t in_nbytes); |
3935
|
|
|
|
|
|
|
|
3936
|
|
|
|
|
|
|
|
3937
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
3938
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
3939
|
|
|
|
|
|
|
|
3940
|
|
|
|
|
|
|
|
3941
|
|
|
|
|
|
|
|
3942
|
|
|
|
|
|
|
|
3943
|
|
|
|
|
|
|
|
3944
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
3945
|
|
|
|
|
|
|
struct libdeflate_options; |
3946
|
|
|
|
|
|
|
|
3947
|
|
|
|
|
|
|
|
3948
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
3949
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
3950
|
|
|
|
|
|
|
|
3951
|
|
|
|
|
|
|
|
3952
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
3953
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
3954
|
|
|
|
|
|
|
|
3955
|
|
|
|
|
|
|
|
3956
|
|
|
|
|
|
|
enum libdeflate_result { |
3957
|
|
|
|
|
|
|
|
3958
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
3959
|
|
|
|
|
|
|
|
3960
|
|
|
|
|
|
|
|
3961
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
3962
|
|
|
|
|
|
|
|
3963
|
|
|
|
|
|
|
|
3964
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
3965
|
|
|
|
|
|
|
|
3966
|
|
|
|
|
|
|
|
3967
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
3968
|
|
|
|
|
|
|
}; |
3969
|
|
|
|
|
|
|
|
3970
|
|
|
|
|
|
|
|
3971
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3972
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
3973
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3974
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3975
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3976
|
|
|
|
|
|
|
|
3977
|
|
|
|
|
|
|
|
3978
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3979
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
3980
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3981
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3982
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
3983
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3984
|
|
|
|
|
|
|
|
3985
|
|
|
|
|
|
|
|
3986
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3987
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
3988
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3989
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3990
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3991
|
|
|
|
|
|
|
|
3992
|
|
|
|
|
|
|
|
3993
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3994
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
3995
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3996
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3997
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
3998
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3999
|
|
|
|
|
|
|
|
4000
|
|
|
|
|
|
|
|
4001
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
4002
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
4003
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
4004
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
4005
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
4006
|
|
|
|
|
|
|
|
4007
|
|
|
|
|
|
|
|
4008
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
4009
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
4010
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
4011
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
4012
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
4013
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
4014
|
|
|
|
|
|
|
|
4015
|
|
|
|
|
|
|
|
4016
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
4017
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
4018
|
|
|
|
|
|
|
|
4019
|
|
|
|
|
|
|
|
4020
|
|
|
|
|
|
|
|
4021
|
|
|
|
|
|
|
|
4022
|
|
|
|
|
|
|
|
4023
|
|
|
|
|
|
|
|
4024
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
4025
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
4026
|
|
|
|
|
|
|
|
4027
|
|
|
|
|
|
|
|
4028
|
|
|
|
|
|
|
|
4029
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
4030
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
4031
|
|
|
|
|
|
|
|
4032
|
|
|
|
|
|
|
|
4033
|
|
|
|
|
|
|
|
4034
|
|
|
|
|
|
|
|
4035
|
|
|
|
|
|
|
|
4036
|
|
|
|
|
|
|
|
4037
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
4038
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
4039
|
|
|
|
|
|
|
void (*free_func)(void *)); |
4040
|
|
|
|
|
|
|
|
4041
|
|
|
|
|
|
|
|
4042
|
|
|
|
|
|
|
struct libdeflate_options { |
4043
|
|
|
|
|
|
|
|
4044
|
|
|
|
|
|
|
|
4045
|
|
|
|
|
|
|
size_t sizeof_options; |
4046
|
|
|
|
|
|
|
|
4047
|
|
|
|
|
|
|
|
4048
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
4049
|
|
|
|
|
|
|
void (*free_func)(void *); |
4050
|
|
|
|
|
|
|
}; |
4051
|
|
|
|
|
|
|
|
4052
|
|
|
|
|
|
|
#ifdef __cplusplus |
4053
|
|
|
|
|
|
|
} |
4054
|
|
|
|
|
|
|
#endif |
4055
|
|
|
|
|
|
|
|
4056
|
|
|
|
|
|
|
#endif |
4057
|
|
|
|
|
|
|
|
4058
|
|
|
|
|
|
|
|
4059
|
|
|
|
|
|
|
#include |
4060
|
|
|
|
|
|
|
#include |
4061
|
|
|
|
|
|
|
#include |
4062
|
|
|
|
|
|
|
#ifdef _MSC_VER |
4063
|
|
|
|
|
|
|
# include |
4064
|
|
|
|
|
|
|
# include |
4065
|
|
|
|
|
|
|
|
4066
|
|
|
|
|
|
|
|
4067
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
4068
|
|
|
|
|
|
|
|
4069
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
4070
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
4071
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
4072
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
4073
|
|
|
|
|
|
|
|
4074
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
4075
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
4076
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
4077
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
4078
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
4079
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
4080
|
|
|
|
|
|
|
#endif |
4081
|
|
|
|
|
|
|
#ifndef FREESTANDING |
4082
|
|
|
|
|
|
|
# include |
4083
|
|
|
|
|
|
|
#endif |
4084
|
|
|
|
|
|
|
|
4085
|
|
|
|
|
|
|
|
4086
|
|
|
|
|
|
|
|
4087
|
|
|
|
|
|
|
|
4088
|
|
|
|
|
|
|
|
4089
|
|
|
|
|
|
|
|
4090
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
4091
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
4092
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
4093
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
4094
|
|
|
|
|
|
|
#ifdef _MSC_VER |
4095
|
|
|
|
|
|
|
# if defined(_M_X64) |
4096
|
|
|
|
|
|
|
# define ARCH_X86_64 |
4097
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
4098
|
|
|
|
|
|
|
# define ARCH_X86_32 |
4099
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
4100
|
|
|
|
|
|
|
# define ARCH_ARM64 |
4101
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
4102
|
|
|
|
|
|
|
# define ARCH_ARM32 |
4103
|
|
|
|
|
|
|
# endif |
4104
|
|
|
|
|
|
|
#else |
4105
|
|
|
|
|
|
|
# if defined(__x86_64__) |
4106
|
|
|
|
|
|
|
# define ARCH_X86_64 |
4107
|
|
|
|
|
|
|
# elif defined(__i386__) |
4108
|
|
|
|
|
|
|
# define ARCH_X86_32 |
4109
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
4110
|
|
|
|
|
|
|
# define ARCH_ARM64 |
4111
|
|
|
|
|
|
|
# elif defined(__arm__) |
4112
|
|
|
|
|
|
|
# define ARCH_ARM32 |
4113
|
|
|
|
|
|
|
# endif |
4114
|
|
|
|
|
|
|
#endif |
4115
|
|
|
|
|
|
|
|
4116
|
|
|
|
|
|
|
|
4117
|
|
|
|
|
|
|
|
4118
|
|
|
|
|
|
|
|
4119
|
|
|
|
|
|
|
|
4120
|
|
|
|
|
|
|
|
4121
|
|
|
|
|
|
|
typedef uint8_t u8; |
4122
|
|
|
|
|
|
|
typedef uint16_t u16; |
4123
|
|
|
|
|
|
|
typedef uint32_t u32; |
4124
|
|
|
|
|
|
|
typedef uint64_t u64; |
4125
|
|
|
|
|
|
|
typedef int8_t s8; |
4126
|
|
|
|
|
|
|
typedef int16_t s16; |
4127
|
|
|
|
|
|
|
typedef int32_t s32; |
4128
|
|
|
|
|
|
|
typedef int64_t s64; |
4129
|
|
|
|
|
|
|
|
4130
|
|
|
|
|
|
|
|
4131
|
|
|
|
|
|
|
#ifdef _MSC_VER |
4132
|
|
|
|
|
|
|
# ifdef _WIN64 |
4133
|
|
|
|
|
|
|
typedef long long ssize_t; |
4134
|
|
|
|
|
|
|
# else |
4135
|
|
|
|
|
|
|
typedef long ssize_t; |
4136
|
|
|
|
|
|
|
# endif |
4137
|
|
|
|
|
|
|
#endif |
4138
|
|
|
|
|
|
|
|
4139
|
|
|
|
|
|
|
|
4140
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
4141
|
|
|
|
|
|
|
|
4142
|
|
|
|
|
|
|
|
4143
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
4144
|
|
|
|
|
|
|
|
4145
|
|
|
|
|
|
|
|
4146
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
4147
|
|
|
|
|
|
|
|
4148
|
|
|
|
|
|
|
|
4149
|
|
|
|
|
|
|
|
4150
|
|
|
|
|
|
|
|
4151
|
|
|
|
|
|
|
|
4152
|
|
|
|
|
|
|
|
4153
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
4154
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
4155
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
4156
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
4157
|
|
|
|
|
|
|
#else |
4158
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
4159
|
|
|
|
|
|
|
#endif |
4160
|
|
|
|
|
|
|
#ifdef __clang__ |
4161
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
4162
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
4163
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
4164
|
|
|
|
|
|
|
# else |
4165
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
4166
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
4167
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
4168
|
|
|
|
|
|
|
# endif |
4169
|
|
|
|
|
|
|
#else |
4170
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
4171
|
|
|
|
|
|
|
#endif |
4172
|
|
|
|
|
|
|
|
4173
|
|
|
|
|
|
|
|
4174
|
|
|
|
|
|
|
#ifndef __has_attribute |
4175
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
4176
|
|
|
|
|
|
|
#endif |
4177
|
|
|
|
|
|
|
#ifndef __has_builtin |
4178
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
4179
|
|
|
|
|
|
|
#endif |
4180
|
|
|
|
|
|
|
|
4181
|
|
|
|
|
|
|
|
4182
|
|
|
|
|
|
|
#ifdef _MSC_VER |
4183
|
|
|
|
|
|
|
# define inline __inline |
4184
|
|
|
|
|
|
|
#endif |
4185
|
|
|
|
|
|
|
|
4186
|
|
|
|
|
|
|
|
4187
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
4188
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
4189
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4190
|
|
|
|
|
|
|
# define forceinline __forceinline |
4191
|
|
|
|
|
|
|
#else |
4192
|
|
|
|
|
|
|
# define forceinline inline |
4193
|
|
|
|
|
|
|
#endif |
4194
|
|
|
|
|
|
|
|
4195
|
|
|
|
|
|
|
|
4196
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
4197
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
4198
|
|
|
|
|
|
|
#else |
4199
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
4200
|
|
|
|
|
|
|
#endif |
4201
|
|
|
|
|
|
|
|
4202
|
|
|
|
|
|
|
|
4203
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
4204
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
4205
|
|
|
|
|
|
|
# define restrict __restrict__ |
4206
|
|
|
|
|
|
|
# else |
4207
|
|
|
|
|
|
|
# define restrict |
4208
|
|
|
|
|
|
|
# endif |
4209
|
|
|
|
|
|
|
#endif |
4210
|
|
|
|
|
|
|
|
4211
|
|
|
|
|
|
|
|
4212
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
4213
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
4214
|
|
|
|
|
|
|
#else |
4215
|
|
|
|
|
|
|
# define likely(expr) (expr) |
4216
|
|
|
|
|
|
|
#endif |
4217
|
|
|
|
|
|
|
|
4218
|
|
|
|
|
|
|
|
4219
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
4220
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
4221
|
|
|
|
|
|
|
#else |
4222
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
4223
|
|
|
|
|
|
|
#endif |
4224
|
|
|
|
|
|
|
|
4225
|
|
|
|
|
|
|
|
4226
|
|
|
|
|
|
|
#undef prefetchr |
4227
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
4228
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
4229
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4230
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
4231
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
4232
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
4233
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
4234
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
4235
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
4236
|
|
|
|
|
|
|
# endif |
4237
|
|
|
|
|
|
|
#endif |
4238
|
|
|
|
|
|
|
#ifndef prefetchr |
4239
|
|
|
|
|
|
|
# define prefetchr(addr) |
4240
|
|
|
|
|
|
|
#endif |
4241
|
|
|
|
|
|
|
|
4242
|
|
|
|
|
|
|
|
4243
|
|
|
|
|
|
|
#undef prefetchw |
4244
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
4245
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
4246
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4247
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
4248
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
4249
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
4250
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
4251
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
4252
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
4253
|
|
|
|
|
|
|
# endif |
4254
|
|
|
|
|
|
|
#endif |
4255
|
|
|
|
|
|
|
#ifndef prefetchw |
4256
|
|
|
|
|
|
|
# define prefetchw(addr) |
4257
|
|
|
|
|
|
|
#endif |
4258
|
|
|
|
|
|
|
|
4259
|
|
|
|
|
|
|
|
4260
|
|
|
|
|
|
|
#undef _aligned_attribute |
4261
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
4262
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
4263
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4264
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
4265
|
|
|
|
|
|
|
#endif |
4266
|
|
|
|
|
|
|
|
4267
|
|
|
|
|
|
|
|
4268
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
4269
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
4270
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
4271
|
|
|
|
|
|
|
#else |
4272
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
4273
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
4274
|
|
|
|
|
|
|
#endif |
4275
|
|
|
|
|
|
|
|
4276
|
|
|
|
|
|
|
|
4277
|
|
|
|
|
|
|
|
4278
|
|
|
|
|
|
|
|
4279
|
|
|
|
|
|
|
|
4280
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
4281
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
4282
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
4283
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
4284
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
4285
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
4286
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
4287
|
|
|
|
|
|
|
|
4288
|
|
|
|
|
|
|
|
4289
|
|
|
|
|
|
|
|
4290
|
|
|
|
|
|
|
|
4291
|
|
|
|
|
|
|
|
4292
|
|
|
|
|
|
|
|
4293
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
4294
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
4295
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4296
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
4297
|
|
|
|
|
|
|
#else |
4298
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
4299
|
|
|
|
|
|
|
{ |
4300
|
|
|
|
|
|
|
union { |
4301
|
|
|
|
|
|
|
u32 w; |
4302
|
|
|
|
|
|
|
u8 b; |
4303
|
|
|
|
|
|
|
} u; |
4304
|
|
|
|
|
|
|
|
4305
|
|
|
|
|
|
|
u.w = 1; |
4306
|
|
|
|
|
|
|
return u.b; |
4307
|
|
|
|
|
|
|
} |
4308
|
|
|
|
|
|
|
#endif |
4309
|
|
|
|
|
|
|
|
4310
|
|
|
|
|
|
|
|
4311
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
4312
|
|
|
|
|
|
|
{ |
4313
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
4314
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
4315
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4316
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
4317
|
|
|
|
|
|
|
#else |
4318
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
4319
|
|
|
|
|
|
|
#endif |
4320
|
|
|
|
|
|
|
} |
4321
|
|
|
|
|
|
|
|
4322
|
|
|
|
|
|
|
|
4323
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
4324
|
|
|
|
|
|
|
{ |
4325
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
4326
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
4327
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4328
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
4329
|
|
|
|
|
|
|
#else |
4330
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
4331
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
4332
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
4333
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
4334
|
|
|
|
|
|
|
#endif |
4335
|
|
|
|
|
|
|
} |
4336
|
|
|
|
|
|
|
|
4337
|
|
|
|
|
|
|
|
4338
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
4339
|
|
|
|
|
|
|
{ |
4340
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
4341
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
4342
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4343
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
4344
|
|
|
|
|
|
|
#else |
4345
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
4346
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
4347
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
4348
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
4349
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
4350
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
4351
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
4352
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
4353
|
|
|
|
|
|
|
#endif |
4354
|
|
|
|
|
|
|
} |
4355
|
|
|
|
|
|
|
|
4356
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
4357
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
4358
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
4359
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
4360
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
4361
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
4362
|
|
|
|
|
|
|
|
4363
|
|
|
|
|
|
|
|
4364
|
|
|
|
|
|
|
|
4365
|
|
|
|
|
|
|
|
4366
|
|
|
|
|
|
|
|
4367
|
|
|
|
|
|
|
|
4368
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
4369
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
4370
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
4371
|
|
|
|
|
|
|
defined(__wasm__)) |
4372
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
4373
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4374
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
4375
|
|
|
|
|
|
|
#else |
4376
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
4377
|
|
|
|
|
|
|
#endif |
4378
|
|
|
|
|
|
|
|
4379
|
|
|
|
|
|
|
|
4380
|
|
|
|
|
|
|
|
4381
|
|
|
|
|
|
|
#ifdef FREESTANDING |
4382
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
4383
|
|
|
|
|
|
|
#else |
4384
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
4385
|
|
|
|
|
|
|
#endif |
4386
|
|
|
|
|
|
|
|
4387
|
|
|
|
|
|
|
|
4388
|
|
|
|
|
|
|
|
4389
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
4390
|
|
|
|
|
|
|
static forceinline type \ |
4391
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
4392
|
|
|
|
|
|
|
{ \ |
4393
|
|
|
|
|
|
|
type v; \ |
4394
|
|
|
|
|
|
|
\ |
4395
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
4396
|
|
|
|
|
|
|
return v; \ |
4397
|
|
|
|
|
|
|
} \ |
4398
|
|
|
|
|
|
|
\ |
4399
|
|
|
|
|
|
|
static forceinline void \ |
4400
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
4401
|
|
|
|
|
|
|
{ \ |
4402
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
4403
|
|
|
|
|
|
|
} |
4404
|
|
|
|
|
|
|
|
4405
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
4406
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
4407
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
4408
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
4409
|
|
|
|
|
|
|
|
4410
|
|
|
|
|
|
|
#undef MEMCOPY |
4411
|
|
|
|
|
|
|
|
4412
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
4413
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
4414
|
|
|
|
|
|
|
|
4415
|
|
|
|
|
|
|
|
4416
|
|
|
|
|
|
|
|
4417
|
|
|
|
|
|
|
static forceinline u16 |
4418
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
4419
|
|
|
|
|
|
|
{ |
4420
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4421
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
4422
|
|
|
|
|
|
|
else |
4423
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
4424
|
|
|
|
|
|
|
} |
4425
|
|
|
|
|
|
|
|
4426
|
|
|
|
|
|
|
static forceinline u16 |
4427
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
4428
|
|
|
|
|
|
|
{ |
4429
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4430
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
4431
|
|
|
|
|
|
|
else |
4432
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
4433
|
|
|
|
|
|
|
} |
4434
|
|
|
|
|
|
|
|
4435
|
|
|
|
|
|
|
static forceinline u32 |
4436
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
4437
|
|
|
|
|
|
|
{ |
4438
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4439
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
4440
|
|
|
|
|
|
|
else |
4441
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
4442
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
4443
|
|
|
|
|
|
|
} |
4444
|
|
|
|
|
|
|
|
4445
|
|
|
|
|
|
|
static forceinline u32 |
4446
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
4447
|
|
|
|
|
|
|
{ |
4448
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4449
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
4450
|
|
|
|
|
|
|
else |
4451
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
4452
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
4453
|
|
|
|
|
|
|
} |
4454
|
|
|
|
|
|
|
|
4455
|
|
|
|
|
|
|
static forceinline u64 |
4456
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
4457
|
|
|
|
|
|
|
{ |
4458
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4459
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
4460
|
|
|
|
|
|
|
else |
4461
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
4462
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
4463
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
4464
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
4465
|
|
|
|
|
|
|
} |
4466
|
|
|
|
|
|
|
|
4467
|
|
|
|
|
|
|
static forceinline machine_word_t |
4468
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
4469
|
|
|
|
|
|
|
{ |
4470
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
4471
|
|
|
|
|
|
|
if (WORDBITS == 32) |
4472
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
4473
|
|
|
|
|
|
|
else |
4474
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
4475
|
|
|
|
|
|
|
} |
4476
|
|
|
|
|
|
|
|
4477
|
|
|
|
|
|
|
|
4478
|
|
|
|
|
|
|
|
4479
|
|
|
|
|
|
|
static forceinline void |
4480
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
4481
|
|
|
|
|
|
|
{ |
4482
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4483
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
4484
|
|
|
|
|
|
|
} else { |
4485
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
4486
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
4487
|
|
|
|
|
|
|
} |
4488
|
|
|
|
|
|
|
} |
4489
|
|
|
|
|
|
|
|
4490
|
|
|
|
|
|
|
static forceinline void |
4491
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
4492
|
|
|
|
|
|
|
{ |
4493
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4494
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
4495
|
|
|
|
|
|
|
} else { |
4496
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
4497
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
4498
|
|
|
|
|
|
|
} |
4499
|
|
|
|
|
|
|
} |
4500
|
|
|
|
|
|
|
|
4501
|
|
|
|
|
|
|
static forceinline void |
4502
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
4503
|
|
|
|
|
|
|
{ |
4504
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4505
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
4506
|
|
|
|
|
|
|
} else { |
4507
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
4508
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
4509
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
4510
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
4511
|
|
|
|
|
|
|
} |
4512
|
|
|
|
|
|
|
} |
4513
|
|
|
|
|
|
|
|
4514
|
|
|
|
|
|
|
static forceinline void |
4515
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
4516
|
|
|
|
|
|
|
{ |
4517
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4518
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
4519
|
|
|
|
|
|
|
} else { |
4520
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
4521
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
4522
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
4523
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
4524
|
|
|
|
|
|
|
} |
4525
|
|
|
|
|
|
|
} |
4526
|
|
|
|
|
|
|
|
4527
|
|
|
|
|
|
|
static forceinline void |
4528
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
4529
|
|
|
|
|
|
|
{ |
4530
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4531
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
4532
|
|
|
|
|
|
|
} else { |
4533
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
4534
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
4535
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
4536
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
4537
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
4538
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
4539
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
4540
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
4541
|
|
|
|
|
|
|
} |
4542
|
|
|
|
|
|
|
} |
4543
|
|
|
|
|
|
|
|
4544
|
|
|
|
|
|
|
static forceinline void |
4545
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
4546
|
|
|
|
|
|
|
{ |
4547
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
4548
|
|
|
|
|
|
|
if (WORDBITS == 32) |
4549
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
4550
|
|
|
|
|
|
|
else |
4551
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
4552
|
|
|
|
|
|
|
} |
4553
|
|
|
|
|
|
|
|
4554
|
|
|
|
|
|
|
|
4555
|
|
|
|
|
|
|
|
4556
|
|
|
|
|
|
|
|
4557
|
|
|
|
|
|
|
|
4558
|
|
|
|
|
|
|
|
4559
|
|
|
|
|
|
|
|
4560
|
|
|
|
|
|
|
static forceinline unsigned |
4561
|
|
|
|
|
|
|
bsr32(u32 v) |
4562
|
|
|
|
|
|
|
{ |
4563
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
4564
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
4565
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4566
|
|
|
|
|
|
|
unsigned long i; |
4567
|
|
|
|
|
|
|
|
4568
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
4569
|
|
|
|
|
|
|
return i; |
4570
|
|
|
|
|
|
|
#else |
4571
|
|
|
|
|
|
|
unsigned i = 0; |
4572
|
|
|
|
|
|
|
|
4573
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
4574
|
|
|
|
|
|
|
i++; |
4575
|
|
|
|
|
|
|
return i; |
4576
|
|
|
|
|
|
|
#endif |
4577
|
|
|
|
|
|
|
} |
4578
|
|
|
|
|
|
|
|
4579
|
|
|
|
|
|
|
static forceinline unsigned |
4580
|
|
|
|
|
|
|
bsr64(u64 v) |
4581
|
|
|
|
|
|
|
{ |
4582
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
4583
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
4584
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
4585
|
|
|
|
|
|
|
unsigned long i; |
4586
|
|
|
|
|
|
|
|
4587
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
4588
|
|
|
|
|
|
|
return i; |
4589
|
|
|
|
|
|
|
#else |
4590
|
|
|
|
|
|
|
unsigned i = 0; |
4591
|
|
|
|
|
|
|
|
4592
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
4593
|
|
|
|
|
|
|
i++; |
4594
|
|
|
|
|
|
|
return i; |
4595
|
|
|
|
|
|
|
#endif |
4596
|
|
|
|
|
|
|
} |
4597
|
|
|
|
|
|
|
|
4598
|
|
|
|
|
|
|
static forceinline unsigned |
4599
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
4600
|
|
|
|
|
|
|
{ |
4601
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
4602
|
|
|
|
|
|
|
if (WORDBITS == 32) |
4603
|
|
|
|
|
|
|
return bsr32(v); |
4604
|
|
|
|
|
|
|
else |
4605
|
|
|
|
|
|
|
return bsr64(v); |
4606
|
|
|
|
|
|
|
} |
4607
|
|
|
|
|
|
|
|
4608
|
|
|
|
|
|
|
|
4609
|
|
|
|
|
|
|
|
4610
|
|
|
|
|
|
|
static forceinline unsigned |
4611
|
|
|
|
|
|
|
bsf32(u32 v) |
4612
|
|
|
|
|
|
|
{ |
4613
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
4614
|
|
|
|
|
|
|
return __builtin_ctz(v); |
4615
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4616
|
|
|
|
|
|
|
unsigned long i; |
4617
|
|
|
|
|
|
|
|
4618
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
4619
|
|
|
|
|
|
|
return i; |
4620
|
|
|
|
|
|
|
#else |
4621
|
|
|
|
|
|
|
unsigned i = 0; |
4622
|
|
|
|
|
|
|
|
4623
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
4624
|
|
|
|
|
|
|
i++; |
4625
|
|
|
|
|
|
|
return i; |
4626
|
|
|
|
|
|
|
#endif |
4627
|
|
|
|
|
|
|
} |
4628
|
|
|
|
|
|
|
|
4629
|
|
|
|
|
|
|
static forceinline unsigned |
4630
|
|
|
|
|
|
|
bsf64(u64 v) |
4631
|
|
|
|
|
|
|
{ |
4632
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
4633
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
4634
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
4635
|
|
|
|
|
|
|
unsigned long i; |
4636
|
|
|
|
|
|
|
|
4637
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
4638
|
|
|
|
|
|
|
return i; |
4639
|
|
|
|
|
|
|
#else |
4640
|
|
|
|
|
|
|
unsigned i = 0; |
4641
|
|
|
|
|
|
|
|
4642
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
4643
|
|
|
|
|
|
|
i++; |
4644
|
|
|
|
|
|
|
return i; |
4645
|
|
|
|
|
|
|
#endif |
4646
|
|
|
|
|
|
|
} |
4647
|
|
|
|
|
|
|
|
4648
|
|
|
|
|
|
|
static forceinline unsigned |
4649
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
4650
|
|
|
|
|
|
|
{ |
4651
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
4652
|
|
|
|
|
|
|
if (WORDBITS == 32) |
4653
|
|
|
|
|
|
|
return bsf32(v); |
4654
|
|
|
|
|
|
|
else |
4655
|
|
|
|
|
|
|
return bsf64(v); |
4656
|
|
|
|
|
|
|
} |
4657
|
|
|
|
|
|
|
|
4658
|
|
|
|
|
|
|
|
4659
|
|
|
|
|
|
|
#undef rbit32 |
4660
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
4661
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
4662
|
|
|
|
|
|
|
static forceinline u32 |
4663
|
|
|
|
|
|
|
rbit32(u32 v) |
4664
|
|
|
|
|
|
|
{ |
4665
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
4666
|
|
|
|
|
|
|
return v; |
4667
|
|
|
|
|
|
|
} |
4668
|
|
|
|
|
|
|
#define rbit32 rbit32 |
4669
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
4670
|
|
|
|
|
|
|
static forceinline u32 |
4671
|
|
|
|
|
|
|
rbit32(u32 v) |
4672
|
|
|
|
|
|
|
{ |
4673
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
4674
|
|
|
|
|
|
|
return v; |
4675
|
|
|
|
|
|
|
} |
4676
|
|
|
|
|
|
|
#define rbit32 rbit32 |
4677
|
|
|
|
|
|
|
#endif |
4678
|
|
|
|
|
|
|
|
4679
|
|
|
|
|
|
|
#endif |
4680
|
|
|
|
|
|
|
|
4681
|
|
|
|
|
|
|
|
4682
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
4683
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
4684
|
|
|
|
|
|
|
|
4685
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
4686
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
4687
|
|
|
|
|
|
|
|
4688
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
4689
|
|
|
|
|
|
|
size_t alignment, size_t size); |
4690
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
4691
|
|
|
|
|
|
|
|
4692
|
|
|
|
|
|
|
#ifdef FREESTANDING |
4693
|
|
|
|
|
|
|
|
4694
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
4695
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
4696
|
|
|
|
|
|
|
|
4697
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
4698
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
4699
|
|
|
|
|
|
|
|
4700
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
4701
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
4702
|
|
|
|
|
|
|
|
4703
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
4704
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
4705
|
|
|
|
|
|
|
|
4706
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
4707
|
|
|
|
|
|
|
#else |
4708
|
|
|
|
|
|
|
#include |
4709
|
|
|
|
|
|
|
#endif |
4710
|
|
|
|
|
|
|
|
4711
|
|
|
|
|
|
|
|
4712
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
4713
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
4714
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
4715
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
4716
|
|
|
|
|
|
|
#else |
4717
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
4718
|
|
|
|
|
|
|
#endif |
4719
|
|
|
|
|
|
|
|
4720
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
4721
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
4722
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
4723
|
|
|
|
|
|
|
|
4724
|
|
|
|
|
|
|
#endif |
4725
|
|
|
|
|
|
|
|
4726
|
|
|
|
|
|
|
/* #include "crc32_multipliers.h" */ |
4727
|
|
|
|
|
|
|
|
4728
|
|
|
|
|
|
|
|
4729
|
|
|
|
|
|
|
#define CRC32_1VECS_MULT_1 0xae689191 |
4730
|
|
|
|
|
|
|
#define CRC32_1VECS_MULT_2 0xccaa009e |
4731
|
|
|
|
|
|
|
#define CRC32_1VECS_MULTS { CRC32_1VECS_MULT_1, CRC32_1VECS_MULT_2 } |
4732
|
|
|
|
|
|
|
|
4733
|
|
|
|
|
|
|
#define CRC32_2VECS_MULT_1 0xf1da05aa |
4734
|
|
|
|
|
|
|
#define CRC32_2VECS_MULT_2 0x81256527 |
4735
|
|
|
|
|
|
|
#define CRC32_2VECS_MULTS { CRC32_2VECS_MULT_1, CRC32_2VECS_MULT_2 } |
4736
|
|
|
|
|
|
|
|
4737
|
|
|
|
|
|
|
#define CRC32_3VECS_MULT_1 0x3db1ecdc |
4738
|
|
|
|
|
|
|
#define CRC32_3VECS_MULT_2 0xaf449247 |
4739
|
|
|
|
|
|
|
#define CRC32_3VECS_MULTS { CRC32_3VECS_MULT_1, CRC32_3VECS_MULT_2 } |
4740
|
|
|
|
|
|
|
|
4741
|
|
|
|
|
|
|
#define CRC32_4VECS_MULT_1 0x8f352d95 |
4742
|
|
|
|
|
|
|
#define CRC32_4VECS_MULT_2 0x1d9513d7 |
4743
|
|
|
|
|
|
|
#define CRC32_4VECS_MULTS { CRC32_4VECS_MULT_1, CRC32_4VECS_MULT_2 } |
4744
|
|
|
|
|
|
|
|
4745
|
|
|
|
|
|
|
#define CRC32_5VECS_MULT_1 0x1c279815 |
4746
|
|
|
|
|
|
|
#define CRC32_5VECS_MULT_2 0xae0b5394 |
4747
|
|
|
|
|
|
|
#define CRC32_5VECS_MULTS { CRC32_5VECS_MULT_1, CRC32_5VECS_MULT_2 } |
4748
|
|
|
|
|
|
|
|
4749
|
|
|
|
|
|
|
#define CRC32_6VECS_MULT_1 0xdf068dc2 |
4750
|
|
|
|
|
|
|
#define CRC32_6VECS_MULT_2 0x57c54819 |
4751
|
|
|
|
|
|
|
#define CRC32_6VECS_MULTS { CRC32_6VECS_MULT_1, CRC32_6VECS_MULT_2 } |
4752
|
|
|
|
|
|
|
|
4753
|
|
|
|
|
|
|
#define CRC32_7VECS_MULT_1 0x31f8303f |
4754
|
|
|
|
|
|
|
#define CRC32_7VECS_MULT_2 0x0cbec0ed |
4755
|
|
|
|
|
|
|
#define CRC32_7VECS_MULTS { CRC32_7VECS_MULT_1, CRC32_7VECS_MULT_2 } |
4756
|
|
|
|
|
|
|
|
4757
|
|
|
|
|
|
|
#define CRC32_8VECS_MULT_1 0x33fff533 |
4758
|
|
|
|
|
|
|
#define CRC32_8VECS_MULT_2 0x910eeec1 |
4759
|
|
|
|
|
|
|
#define CRC32_8VECS_MULTS { CRC32_8VECS_MULT_1, CRC32_8VECS_MULT_2 } |
4760
|
|
|
|
|
|
|
|
4761
|
|
|
|
|
|
|
#define CRC32_9VECS_MULT_1 0x26b70c3d |
4762
|
|
|
|
|
|
|
#define CRC32_9VECS_MULT_2 0x3f41287a |
4763
|
|
|
|
|
|
|
#define CRC32_9VECS_MULTS { CRC32_9VECS_MULT_1, CRC32_9VECS_MULT_2 } |
4764
|
|
|
|
|
|
|
|
4765
|
|
|
|
|
|
|
#define CRC32_10VECS_MULT_1 0xe3543be0 |
4766
|
|
|
|
|
|
|
#define CRC32_10VECS_MULT_2 0x9026d5b1 |
4767
|
|
|
|
|
|
|
#define CRC32_10VECS_MULTS { CRC32_10VECS_MULT_1, CRC32_10VECS_MULT_2 } |
4768
|
|
|
|
|
|
|
|
4769
|
|
|
|
|
|
|
#define CRC32_11VECS_MULT_1 0x5a1bb05d |
4770
|
|
|
|
|
|
|
#define CRC32_11VECS_MULT_2 0xd1df2327 |
4771
|
|
|
|
|
|
|
#define CRC32_11VECS_MULTS { CRC32_11VECS_MULT_1, CRC32_11VECS_MULT_2 } |
4772
|
|
|
|
|
|
|
|
4773
|
|
|
|
|
|
|
#define CRC32_12VECS_MULT_1 0x596c8d81 |
4774
|
|
|
|
|
|
|
#define CRC32_12VECS_MULT_2 0xf5e48c85 |
4775
|
|
|
|
|
|
|
#define CRC32_12VECS_MULTS { CRC32_12VECS_MULT_1, CRC32_12VECS_MULT_2 } |
4776
|
|
|
|
|
|
|
|
4777
|
|
|
|
|
|
|
#define CRC32_FINAL_MULT 0xb8bc6765 |
4778
|
|
|
|
|
|
|
#define CRC32_BARRETT_CONSTANT_1 0x00000001f7011641ULL |
4779
|
|
|
|
|
|
|
#define CRC32_BARRETT_CONSTANT_2 0x00000001db710641ULL |
4780
|
|
|
|
|
|
|
#define CRC32_BARRETT_CONSTANTS { CRC32_BARRETT_CONSTANT_1, CRC32_BARRETT_CONSTANT_2 } |
4781
|
|
|
|
|
|
|
|
4782
|
|
|
|
|
|
|
#define CRC32_NUM_CHUNKS 4 |
4783
|
|
|
|
|
|
|
#define CRC32_MIN_VARIABLE_CHUNK_LEN 128UL |
4784
|
|
|
|
|
|
|
#define CRC32_MAX_VARIABLE_CHUNK_LEN 16384UL |
4785
|
|
|
|
|
|
|
|
4786
|
|
|
|
|
|
|
|
4787
|
|
|
|
|
|
|
static const u32 crc32_mults_for_chunklen[][CRC32_NUM_CHUNKS - 1] MAYBE_UNUSED = { |
4788
|
|
|
|
|
|
|
{ 0 }, |
4789
|
|
|
|
|
|
|
|
4790
|
|
|
|
|
|
|
{ 0xd31343ea , 0xe95c1271 , 0x910eeec1 , }, |
4791
|
|
|
|
|
|
|
|
4792
|
|
|
|
|
|
|
{ 0x1d6708a0 , 0x0c30f51d , 0xe95c1271 , }, |
4793
|
|
|
|
|
|
|
|
4794
|
|
|
|
|
|
|
{ 0xdb3839f3 , 0x1d6708a0 , 0xd31343ea , }, |
4795
|
|
|
|
|
|
|
|
4796
|
|
|
|
|
|
|
{ 0x1753ab84 , 0xbbf2f6d6 , 0x0c30f51d , }, |
4797
|
|
|
|
|
|
|
|
4798
|
|
|
|
|
|
|
{ 0x3796455c , 0xb8e0e4a8 , 0xc352f6de , }, |
4799
|
|
|
|
|
|
|
|
4800
|
|
|
|
|
|
|
{ 0x3954de39 , 0x1753ab84 , 0x1d6708a0 , }, |
4801
|
|
|
|
|
|
|
|
4802
|
|
|
|
|
|
|
{ 0x632d78c5 , 0x3fc33de4 , 0x9a1b53c8 , }, |
4803
|
|
|
|
|
|
|
|
4804
|
|
|
|
|
|
|
{ 0xa0decef3 , 0x7b4aa8b7 , 0xbbf2f6d6 , }, |
4805
|
|
|
|
|
|
|
|
4806
|
|
|
|
|
|
|
{ 0xe9c09bb0 , 0x3954de39 , 0xdb3839f3 , }, |
4807
|
|
|
|
|
|
|
|
4808
|
|
|
|
|
|
|
{ 0xd51917a4 , 0xcae68461 , 0xb8e0e4a8 , }, |
4809
|
|
|
|
|
|
|
|
4810
|
|
|
|
|
|
|
{ 0x154a8a62 , 0x41e7589c , 0x3e9a43cd , }, |
4811
|
|
|
|
|
|
|
|
4812
|
|
|
|
|
|
|
{ 0xf196555d , 0xa0decef3 , 0x1753ab84 , }, |
4813
|
|
|
|
|
|
|
|
4814
|
|
|
|
|
|
|
{ 0x8eec2999 , 0xefb0a128 , 0x6044fbb0 , }, |
4815
|
|
|
|
|
|
|
|
4816
|
|
|
|
|
|
|
{ 0x27892abf , 0x48d72bb1 , 0x3fc33de4 , }, |
4817
|
|
|
|
|
|
|
|
4818
|
|
|
|
|
|
|
{ 0x77bc2419 , 0xd51917a4 , 0x3796455c , }, |
4819
|
|
|
|
|
|
|
|
4820
|
|
|
|
|
|
|
{ 0xcea114a5 , 0x68c0a2c5 , 0x7b4aa8b7 , }, |
4821
|
|
|
|
|
|
|
|
4822
|
|
|
|
|
|
|
{ 0xa1077e85 , 0x188cc628 , 0x0c21f835 , }, |
4823
|
|
|
|
|
|
|
|
4824
|
|
|
|
|
|
|
{ 0xc5ed75e1 , 0xf196555d , 0x3954de39 , }, |
4825
|
|
|
|
|
|
|
|
4826
|
|
|
|
|
|
|
{ 0xca4fba3f , 0x0acfa26f , 0x6cb21510 , }, |
4827
|
|
|
|
|
|
|
|
4828
|
|
|
|
|
|
|
{ 0xcf5bcdc4 , 0x4fae7fc0 , 0xcae68461 , }, |
4829
|
|
|
|
|
|
|
|
4830
|
|
|
|
|
|
|
{ 0xf36b9d16 , 0x27892abf , 0x632d78c5 , }, |
4831
|
|
|
|
|
|
|
|
4832
|
|
|
|
|
|
|
{ 0xf76fd988 , 0xed5c39b1 , 0x41e7589c , }, |
4833
|
|
|
|
|
|
|
|
4834
|
|
|
|
|
|
|
{ 0x6c45d92e , 0xff809fcd , 0x0c46baec , }, |
4835
|
|
|
|
|
|
|
|
4836
|
|
|
|
|
|
|
{ 0x6116b82b , 0xcea114a5 , 0xa0decef3 , }, |
4837
|
|
|
|
|
|
|
|
4838
|
|
|
|
|
|
|
{ 0x4d9899bb , 0x9f9d8d9c , 0x53deb236 , }, |
4839
|
|
|
|
|
|
|
|
4840
|
|
|
|
|
|
|
{ 0x3e7c93b9 , 0x6666b805 , 0xefb0a128 , }, |
4841
|
|
|
|
|
|
|
|
4842
|
|
|
|
|
|
|
{ 0x388b20ac , 0xc5ed75e1 , 0xe9c09bb0 , }, |
4843
|
|
|
|
|
|
|
|
4844
|
|
|
|
|
|
|
{ 0x0956d953 , 0x97fbdb14 , 0x48d72bb1 , }, |
4845
|
|
|
|
|
|
|
|
4846
|
|
|
|
|
|
|
{ 0x55cb4dfe , 0x1b37c832 , 0xc07331b3 , }, |
4847
|
|
|
|
|
|
|
|
4848
|
|
|
|
|
|
|
{ 0x52222fea , 0xcf5bcdc4 , 0xd51917a4 , }, |
4849
|
|
|
|
|
|
|
|
4850
|
|
|
|
|
|
|
{ 0x0603989b , 0xb03c8112 , 0x5e04b9a5 , }, |
4851
|
|
|
|
|
|
|
|
4852
|
|
|
|
|
|
|
{ 0x4470c029 , 0x2339d155 , 0x68c0a2c5 , }, |
4853
|
|
|
|
|
|
|
|
4854
|
|
|
|
|
|
|
{ 0xb6f35093 , 0xf76fd988 , 0x154a8a62 , }, |
4855
|
|
|
|
|
|
|
|
4856
|
|
|
|
|
|
|
{ 0xc46805ba , 0x416f9449 , 0x188cc628 , }, |
4857
|
|
|
|
|
|
|
|
4858
|
|
|
|
|
|
|
{ 0xc3876592 , 0x4b809189 , 0xc35cf6e7 , }, |
4859
|
|
|
|
|
|
|
|
4860
|
|
|
|
|
|
|
{ 0x5b0c98b9 , 0x6116b82b , 0xf196555d , }, |
4861
|
|
|
|
|
|
|
|
4862
|
|
|
|
|
|
|
{ 0x30d13e5f , 0x4c5a315a , 0x8c224466 , }, |
4863
|
|
|
|
|
|
|
|
4864
|
|
|
|
|
|
|
{ 0x54afca53 , 0xbccfa2c1 , 0x0acfa26f , }, |
4865
|
|
|
|
|
|
|
|
4866
|
|
|
|
|
|
|
{ 0x93102436 , 0x3e7c93b9 , 0x8eec2999 , }, |
4867
|
|
|
|
|
|
|
|
4868
|
|
|
|
|
|
|
{ 0xbd2655a8 , 0x3e116c9d , 0x4fae7fc0 , }, |
4869
|
|
|
|
|
|
|
|
4870
|
|
|
|
|
|
|
{ 0x70cd7f26 , 0x408e57f2 , 0x1691be45 , }, |
4871
|
|
|
|
|
|
|
|
4872
|
|
|
|
|
|
|
{ 0x2d546c53 , 0x0956d953 , 0x27892abf , }, |
4873
|
|
|
|
|
|
|
|
4874
|
|
|
|
|
|
|
{ 0xb53410a8 , 0x42ebf0ad , 0x161f3c12 , }, |
4875
|
|
|
|
|
|
|
|
4876
|
|
|
|
|
|
|
{ 0x67a93f75 , 0xcf3233e4 , 0xed5c39b1 , }, |
4877
|
|
|
|
|
|
|
|
4878
|
|
|
|
|
|
|
{ 0x9830ac33 , 0x52222fea , 0x77bc2419 , }, |
4879
|
|
|
|
|
|
|
|
4880
|
|
|
|
|
|
|
{ 0xb0b6fc3e , 0x2fde73f8 , 0xff809fcd , }, |
4881
|
|
|
|
|
|
|
|
4882
|
|
|
|
|
|
|
{ 0x84170f16 , 0xced90d99 , 0x30de0f98 , }, |
4883
|
|
|
|
|
|
|
|
4884
|
|
|
|
|
|
|
{ 0xd7017a0c , 0x4470c029 , 0xcea114a5 , }, |
4885
|
|
|
|
|
|
|
|
4886
|
|
|
|
|
|
|
{ 0xadb25de6 , 0x84f40beb , 0x2b7e0e1b , }, |
4887
|
|
|
|
|
|
|
|
4888
|
|
|
|
|
|
|
{ 0x8282fddc , 0xec855937 , 0x9f9d8d9c , }, |
4889
|
|
|
|
|
|
|
|
4890
|
|
|
|
|
|
|
{ 0x46362bee , 0xc46805ba , 0xa1077e85 , }, |
4891
|
|
|
|
|
|
|
|
4892
|
|
|
|
|
|
|
{ 0xb9077a01 , 0xdf7a24ac , 0x6666b805 , }, |
4893
|
|
|
|
|
|
|
|
4894
|
|
|
|
|
|
|
{ 0xf51d9bc6 , 0x2b52dc39 , 0x7e774cf6 , }, |
4895
|
|
|
|
|
|
|
|
4896
|
|
|
|
|
|
|
{ 0x4ca19a29 , 0x5b0c98b9 , 0xc5ed75e1 , }, |
4897
|
|
|
|
|
|
|
|
4898
|
|
|
|
|
|
|
{ 0xdc0fc3fc , 0xb939fcdf , 0x3678fed2 , }, |
4899
|
|
|
|
|
|
|
|
4900
|
|
|
|
|
|
|
{ 0x63c3d167 , 0x70f9947d , 0x97fbdb14 , }, |
4901
|
|
|
|
|
|
|
|
4902
|
|
|
|
|
|
|
{ 0x5851d254 , 0x54afca53 , 0xca4fba3f , }, |
4903
|
|
|
|
|
|
|
|
4904
|
|
|
|
|
|
|
{ 0xfeacf2a1 , 0x7a3c0a6a , 0x1b37c832 , }, |
4905
|
|
|
|
|
|
|
|
4906
|
|
|
|
|
|
|
{ 0x93b7edc8 , 0x1fea4d2a , 0x58fa96ee , }, |
4907
|
|
|
|
|
|
|
|
4908
|
|
|
|
|
|
|
{ 0x5539e44a , 0xbd2655a8 , 0xcf5bcdc4 , }, |
4909
|
|
|
|
|
|
|
|
4910
|
|
|
|
|
|
|
{ 0xde32a3d2 , 0x4ff61aa1 , 0x6a6a3694 , }, |
4911
|
|
|
|
|
|
|
|
4912
|
|
|
|
|
|
|
{ 0xf0baeeb6 , 0x7ae2f6f4 , 0xb03c8112 , }, |
4913
|
|
|
|
|
|
|
|
4914
|
|
|
|
|
|
|
{ 0xbe15887f , 0x2d546c53 , 0xf36b9d16 , }, |
4915
|
|
|
|
|
|
|
|
4916
|
|
|
|
|
|
|
{ 0x64f34a05 , 0xe0ee5efe , 0x2339d155 , }, |
4917
|
|
|
|
|
|
|
|
4918
|
|
|
|
|
|
|
{ 0x1b6d1aea , 0xfeafb67c , 0x4fb001a8 , }, |
4919
|
|
|
|
|
|
|
|
4920
|
|
|
|
|
|
|
{ 0x82adb0b8 , 0x67a93f75 , 0xf76fd988 , }, |
4921
|
|
|
|
|
|
|
|
4922
|
|
|
|
|
|
|
{ 0x694587c7 , 0x3b34408b , 0xeccb2978 , }, |
4923
|
|
|
|
|
|
|
|
4924
|
|
|
|
|
|
|
{ 0xd2fc57c3 , 0x07fcf8c6 , 0x416f9449 , }, |
4925
|
|
|
|
|
|
|
|
4926
|
|
|
|
|
|
|
{ 0x9dd6837c , 0xb0b6fc3e , 0x6c45d92e , }, |
4927
|
|
|
|
|
|
|
|
4928
|
|
|
|
|
|
|
{ 0x3a9d1f97 , 0xefd033b2 , 0x4b809189 , }, |
4929
|
|
|
|
|
|
|
|
4930
|
|
|
|
|
|
|
{ 0x1eee1d2a , 0xf2a6e46e , 0x55b4c814 , }, |
4931
|
|
|
|
|
|
|
|
4932
|
|
|
|
|
|
|
{ 0xb57c7728 , 0xd7017a0c , 0x6116b82b , }, |
4933
|
|
|
|
|
|
|
|
4934
|
|
|
|
|
|
|
{ 0xf2fc5d61 , 0x242aac86 , 0x05245cf0 , }, |
4935
|
|
|
|
|
|
|
|
4936
|
|
|
|
|
|
|
{ 0x26387824 , 0xc15c4ca5 , 0x4c5a315a , }, |
4937
|
|
|
|
|
|
|
|
4938
|
|
|
|
|
|
|
{ 0x8c151e77 , 0x8282fddc , 0x4d9899bb , }, |
4939
|
|
|
|
|
|
|
|
4940
|
|
|
|
|
|
|
{ 0x8ea1f680 , 0xf5ff6cdd , 0xbccfa2c1 , }, |
4941
|
|
|
|
|
|
|
|
4942
|
|
|
|
|
|
|
{ 0xe8cf3d2a , 0x338b1fb1 , 0xeda61f70 , }, |
4943
|
|
|
|
|
|
|
|
4944
|
|
|
|
|
|
|
{ 0x21f15b59 , 0xb9077a01 , 0x3e7c93b9 , }, |
4945
|
|
|
|
|
|
|
|
4946
|
|
|
|
|
|
|
{ 0x6f68d64a , 0x901b0161 , 0xb9fd3537 , }, |
4947
|
|
|
|
|
|
|
|
4948
|
|
|
|
|
|
|
{ 0x71b74d95 , 0xf5ddd5ad , 0x3e116c9d , }, |
4949
|
|
|
|
|
|
|
|
4950
|
|
|
|
|
|
|
{ 0x4c2e7261 , 0x4ca19a29 , 0x388b20ac , }, |
4951
|
|
|
|
|
|
|
|
4952
|
|
|
|
|
|
|
{ 0x8a2d38e8 , 0xd27ee0a1 , 0x408e57f2 , }, |
4953
|
|
|
|
|
|
|
|
4954
|
|
|
|
|
|
|
{ 0x7e58ca17 , 0x69dfedd2 , 0x3a76805e , }, |
4955
|
|
|
|
|
|
|
|
4956
|
|
|
|
|
|
|
{ 0xf997967f , 0x63c3d167 , 0x0956d953 , }, |
4957
|
|
|
|
|
|
|
|
4958
|
|
|
|
|
|
|
{ 0x48215963 , 0x71e1dfe0 , 0x42a6d410 , }, |
4959
|
|
|
|
|
|
|
|
4960
|
|
|
|
|
|
|
{ 0xa704b94c , 0x679f198a , 0x42ebf0ad , }, |
4961
|
|
|
|
|
|
|
|
4962
|
|
|
|
|
|
|
{ 0x1d699056 , 0xfeacf2a1 , 0x55cb4dfe , }, |
4963
|
|
|
|
|
|
|
|
4964
|
|
|
|
|
|
|
{ 0x6800bcc5 , 0x16024f15 , 0xcf3233e4 , }, |
4965
|
|
|
|
|
|
|
|
4966
|
|
|
|
|
|
|
{ 0x2d48e4ca , 0xbe61582f , 0x46026283 , }, |
4967
|
|
|
|
|
|
|
|
4968
|
|
|
|
|
|
|
{ 0x4c4c2b55 , 0x5539e44a , 0x52222fea , }, |
4969
|
|
|
|
|
|
|
|
4970
|
|
|
|
|
|
|
{ 0xd8ce94cb , 0xbc613c26 , 0x33776b4b , }, |
4971
|
|
|
|
|
|
|
|
4972
|
|
|
|
|
|
|
{ 0xd0b5a02b , 0x490d3cc6 , 0x2fde73f8 , }, |
4973
|
|
|
|
|
|
|
|
4974
|
|
|
|
|
|
|
{ 0xa223f7ec , 0xf0baeeb6 , 0x0603989b , }, |
4975
|
|
|
|
|
|
|
|
4976
|
|
|
|
|
|
|
{ 0x58de337a , 0x3bf3d597 , 0xced90d99 , }, |
4977
|
|
|
|
|
|
|
|
4978
|
|
|
|
|
|
|
{ 0x37f5d8f4 , 0x4d5b699b , 0xd7262e5f , }, |
4979
|
|
|
|
|
|
|
|
4980
|
|
|
|
|
|
|
{ 0xfa8a435d , 0x64f34a05 , 0x4470c029 , }, |
4981
|
|
|
|
|
|
|
|
4982
|
|
|
|
|
|
|
{ 0x238709fe , 0x52e7458f , 0x9a174cd3 , }, |
4983
|
|
|
|
|
|
|
|
4984
|
|
|
|
|
|
|
{ 0x9e1ba6f5 , 0xef0272f7 , 0x84f40beb , }, |
4985
|
|
|
|
|
|
|
|
4986
|
|
|
|
|
|
|
{ 0xcd8b57fa , 0x82adb0b8 , 0xb6f35093 , }, |
4987
|
|
|
|
|
|
|
|
4988
|
|
|
|
|
|
|
{ 0x0aed142f , 0xb1650290 , 0xec855937 , }, |
4989
|
|
|
|
|
|
|
|
4990
|
|
|
|
|
|
|
{ 0xd1f064db , 0x6e7340d3 , 0x5c28cb52 , }, |
4991
|
|
|
|
|
|
|
|
4992
|
|
|
|
|
|
|
{ 0x464ac895 , 0xd2fc57c3 , 0xc46805ba , }, |
4993
|
|
|
|
|
|
|
|
4994
|
|
|
|
|
|
|
{ 0xa0e6beea , 0xcfeec3d0 , 0x0225d214 , }, |
4995
|
|
|
|
|
|
|
|
4996
|
|
|
|
|
|
|
{ 0x78703ce0 , 0xc60f6075 , 0xdf7a24ac , }, |
4997
|
|
|
|
|
|
|
|
4998
|
|
|
|
|
|
|
{ 0xfea48165 , 0x3a9d1f97 , 0xc3876592 , }, |
4999
|
|
|
|
|
|
|
|
5000
|
|
|
|
|
|
|
{ 0xdb89b8db , 0xa6172211 , 0x2b52dc39 , }, |
5001
|
|
|
|
|
|
|
|
5002
|
|
|
|
|
|
|
{ 0x7ca03731 , 0x1db42849 , 0xc5df246e , }, |
5003
|
|
|
|
|
|
|
|
5004
|
|
|
|
|
|
|
{ 0x8801d0aa , 0xb57c7728 , 0x5b0c98b9 , }, |
5005
|
|
|
|
|
|
|
|
5006
|
|
|
|
|
|
|
{ 0xf89cd7f0 , 0xcc396a0b , 0xdb799c51 , }, |
5007
|
|
|
|
|
|
|
|
5008
|
|
|
|
|
|
|
{ 0x1611a808 , 0xaeae6105 , 0xb939fcdf , }, |
5009
|
|
|
|
|
|
|
|
5010
|
|
|
|
|
|
|
{ 0xe3cdb888 , 0x26387824 , 0x30d13e5f , }, |
5011
|
|
|
|
|
|
|
|
5012
|
|
|
|
|
|
|
{ 0x552a4cf6 , 0xee2d04bb , 0x70f9947d , }, |
5013
|
|
|
|
|
|
|
|
5014
|
|
|
|
|
|
|
{ 0x85e248e9 , 0x0a79663f , 0x53339cf7 , }, |
5015
|
|
|
|
|
|
|
|
5016
|
|
|
|
|
|
|
{ 0x1c61c3e9 , 0x8ea1f680 , 0x54afca53 , }, |
5017
|
|
|
|
|
|
|
|
5018
|
|
|
|
|
|
|
{ 0xb14cfc2b , 0x2e073302 , 0x10897992 , }, |
5019
|
|
|
|
|
|
|
|
5020
|
|
|
|
|
|
|
{ 0x6ec444cc , 0x9e819f13 , 0x7a3c0a6a , }, |
5021
|
|
|
|
|
|
|
|
5022
|
|
|
|
|
|
|
{ 0xe2fa5f80 , 0x21f15b59 , 0x93102436 , }, |
5023
|
|
|
|
|
|
|
|
5024
|
|
|
|
|
|
|
{ 0x6d33f4c6 , 0x31a27455 , 0x1fea4d2a , }, |
5025
|
|
|
|
|
|
|
|
5026
|
|
|
|
|
|
|
{ 0xb6dec609 , 0x4d437056 , 0x42eb1e2a , }, |
5027
|
|
|
|
|
|
|
|
5028
|
|
|
|
|
|
|
{ 0x1846c518 , 0x71b74d95 , 0xbd2655a8 , }, |
5029
|
|
|
|
|
|
|
|
5030
|
|
|
|
|
|
|
{ 0x9f947f8a , 0x2b501619 , 0xa4924b0e , }, |
5031
|
|
|
|
|
|
|
|
5032
|
|
|
|
|
|
|
{ 0xb7442f4d , 0xba30a5d8 , 0x4ff61aa1 , }, |
5033
|
|
|
|
|
|
|
|
5034
|
|
|
|
|
|
|
{ 0xe2c93242 , 0x8a2d38e8 , 0x70cd7f26 , }, |
5035
|
|
|
|
|
|
|
|
5036
|
|
|
|
|
|
|
{ 0xcd6863df , 0x78fd88dc , 0x7ae2f6f4 , }, |
5037
|
|
|
|
|
|
|
|
5038
|
|
|
|
|
|
|
{ 0xd512001d , 0xe6612dff , 0x5c4d0ca9 , }, |
5039
|
|
|
|
|
|
|
|
5040
|
|
|
|
|
|
|
{ 0x4e8d6b6c , 0xf997967f , 0x2d546c53 , }, |
5041
|
|
|
|
|
|
|
|
5042
|
|
|
|
|
|
|
{ 0xfa653ba1 , 0xc99014d4 , 0xa0c9fd27 , }, |
5043
|
|
|
|
|
|
|
|
5044
|
|
|
|
|
|
|
{ 0x49893408 , 0x29c2448b , 0xe0ee5efe , }, |
5045
|
|
|
|
|
|
|
}; |
5046
|
|
|
|
|
|
|
|
5047
|
|
|
|
|
|
|
|
5048
|
|
|
|
|
|
|
#define CRC32_FIXED_CHUNK_LEN 32768UL |
5049
|
|
|
|
|
|
|
#define CRC32_FIXED_CHUNK_MULT_1 0x29c2448b |
5050
|
|
|
|
|
|
|
#define CRC32_FIXED_CHUNK_MULT_2 0x4b912f53 |
5051
|
|
|
|
|
|
|
#define CRC32_FIXED_CHUNK_MULT_3 0x454c93be |
5052
|
|
|
|
|
|
|
|
5053
|
|
|
|
|
|
|
/* #include "crc32_tables.h" */ |
5054
|
|
|
|
|
|
|
|
5055
|
|
|
|
|
|
|
|
5056
|
|
|
|
|
|
|
static const u32 crc32_slice1_table[] MAYBE_UNUSED = { |
5057
|
|
|
|
|
|
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, |
5058
|
|
|
|
|
|
|
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, |
5059
|
|
|
|
|
|
|
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, |
5060
|
|
|
|
|
|
|
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, |
5061
|
|
|
|
|
|
|
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
5062
|
|
|
|
|
|
|
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, |
5063
|
|
|
|
|
|
|
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, |
5064
|
|
|
|
|
|
|
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, |
5065
|
|
|
|
|
|
|
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, |
5066
|
|
|
|
|
|
|
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
5067
|
|
|
|
|
|
|
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, |
5068
|
|
|
|
|
|
|
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, |
5069
|
|
|
|
|
|
|
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, |
5070
|
|
|
|
|
|
|
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, |
5071
|
|
|
|
|
|
|
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
5072
|
|
|
|
|
|
|
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, |
5073
|
|
|
|
|
|
|
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, |
5074
|
|
|
|
|
|
|
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, |
5075
|
|
|
|
|
|
|
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, |
5076
|
|
|
|
|
|
|
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
5077
|
|
|
|
|
|
|
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, |
5078
|
|
|
|
|
|
|
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, |
5079
|
|
|
|
|
|
|
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, |
5080
|
|
|
|
|
|
|
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, |
5081
|
|
|
|
|
|
|
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
5082
|
|
|
|
|
|
|
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, |
5083
|
|
|
|
|
|
|
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, |
5084
|
|
|
|
|
|
|
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, |
5085
|
|
|
|
|
|
|
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, |
5086
|
|
|
|
|
|
|
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
5087
|
|
|
|
|
|
|
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, |
5088
|
|
|
|
|
|
|
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, |
5089
|
|
|
|
|
|
|
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, |
5090
|
|
|
|
|
|
|
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, |
5091
|
|
|
|
|
|
|
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
5092
|
|
|
|
|
|
|
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, |
5093
|
|
|
|
|
|
|
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, |
5094
|
|
|
|
|
|
|
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, |
5095
|
|
|
|
|
|
|
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, |
5096
|
|
|
|
|
|
|
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
5097
|
|
|
|
|
|
|
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, |
5098
|
|
|
|
|
|
|
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, |
5099
|
|
|
|
|
|
|
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, |
5100
|
|
|
|
|
|
|
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, |
5101
|
|
|
|
|
|
|
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
5102
|
|
|
|
|
|
|
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, |
5103
|
|
|
|
|
|
|
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, |
5104
|
|
|
|
|
|
|
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, |
5105
|
|
|
|
|
|
|
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, |
5106
|
|
|
|
|
|
|
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
5107
|
|
|
|
|
|
|
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, |
5108
|
|
|
|
|
|
|
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, |
5109
|
|
|
|
|
|
|
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, |
5110
|
|
|
|
|
|
|
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, |
5111
|
|
|
|
|
|
|
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
5112
|
|
|
|
|
|
|
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, |
5113
|
|
|
|
|
|
|
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, |
5114
|
|
|
|
|
|
|
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, |
5115
|
|
|
|
|
|
|
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, |
5116
|
|
|
|
|
|
|
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
5117
|
|
|
|
|
|
|
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, |
5118
|
|
|
|
|
|
|
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, |
5119
|
|
|
|
|
|
|
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, |
5120
|
|
|
|
|
|
|
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, |
5121
|
|
|
|
|
|
|
}; |
5122
|
|
|
|
|
|
|
|
5123
|
|
|
|
|
|
|
static const u32 crc32_slice8_table[] MAYBE_UNUSED = { |
5124
|
|
|
|
|
|
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, |
5125
|
|
|
|
|
|
|
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, |
5126
|
|
|
|
|
|
|
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, |
5127
|
|
|
|
|
|
|
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, |
5128
|
|
|
|
|
|
|
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
5129
|
|
|
|
|
|
|
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, |
5130
|
|
|
|
|
|
|
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, |
5131
|
|
|
|
|
|
|
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, |
5132
|
|
|
|
|
|
|
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, |
5133
|
|
|
|
|
|
|
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
5134
|
|
|
|
|
|
|
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, |
5135
|
|
|
|
|
|
|
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, |
5136
|
|
|
|
|
|
|
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, |
5137
|
|
|
|
|
|
|
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, |
5138
|
|
|
|
|
|
|
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
5139
|
|
|
|
|
|
|
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, |
5140
|
|
|
|
|
|
|
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, |
5141
|
|
|
|
|
|
|
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, |
5142
|
|
|
|
|
|
|
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, |
5143
|
|
|
|
|
|
|
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
5144
|
|
|
|
|
|
|
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, |
5145
|
|
|
|
|
|
|
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, |
5146
|
|
|
|
|
|
|
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, |
5147
|
|
|
|
|
|
|
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, |
5148
|
|
|
|
|
|
|
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
5149
|
|
|
|
|
|
|
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, |
5150
|
|
|
|
|
|
|
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, |
5151
|
|
|
|
|
|
|
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, |
5152
|
|
|
|
|
|
|
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, |
5153
|
|
|
|
|
|
|
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
5154
|
|
|
|
|
|
|
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, |
5155
|
|
|
|
|
|
|
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, |
5156
|
|
|
|
|
|
|
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, |
5157
|
|
|
|
|
|
|
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, |
5158
|
|
|
|
|
|
|
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
5159
|
|
|
|
|
|
|
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, |
5160
|
|
|
|
|
|
|
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, |
5161
|
|
|
|
|
|
|
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, |
5162
|
|
|
|
|
|
|
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, |
5163
|
|
|
|
|
|
|
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
5164
|
|
|
|
|
|
|
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, |
5165
|
|
|
|
|
|
|
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, |
5166
|
|
|
|
|
|
|
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, |
5167
|
|
|
|
|
|
|
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, |
5168
|
|
|
|
|
|
|
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
5169
|
|
|
|
|
|
|
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, |
5170
|
|
|
|
|
|
|
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, |
5171
|
|
|
|
|
|
|
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, |
5172
|
|
|
|
|
|
|
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, |
5173
|
|
|
|
|
|
|
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
5174
|
|
|
|
|
|
|
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, |
5175
|
|
|
|
|
|
|
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, |
5176
|
|
|
|
|
|
|
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, |
5177
|
|
|
|
|
|
|
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, |
5178
|
|
|
|
|
|
|
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
5179
|
|
|
|
|
|
|
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, |
5180
|
|
|
|
|
|
|
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, |
5181
|
|
|
|
|
|
|
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, |
5182
|
|
|
|
|
|
|
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, |
5183
|
|
|
|
|
|
|
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
5184
|
|
|
|
|
|
|
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, |
5185
|
|
|
|
|
|
|
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, |
5186
|
|
|
|
|
|
|
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, |
5187
|
|
|
|
|
|
|
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, |
5188
|
|
|
|
|
|
|
0x00000000, 0x191b3141, 0x32366282, 0x2b2d53c3, |
5189
|
|
|
|
|
|
|
0x646cc504, 0x7d77f445, 0x565aa786, 0x4f4196c7, |
5190
|
|
|
|
|
|
|
0xc8d98a08, 0xd1c2bb49, 0xfaefe88a, 0xe3f4d9cb, |
5191
|
|
|
|
|
|
|
0xacb54f0c, 0xb5ae7e4d, 0x9e832d8e, 0x87981ccf, |
5192
|
|
|
|
|
|
|
0x4ac21251, 0x53d92310, 0x78f470d3, 0x61ef4192, |
5193
|
|
|
|
|
|
|
0x2eaed755, 0x37b5e614, 0x1c98b5d7, 0x05838496, |
5194
|
|
|
|
|
|
|
0x821b9859, 0x9b00a918, 0xb02dfadb, 0xa936cb9a, |
5195
|
|
|
|
|
|
|
0xe6775d5d, 0xff6c6c1c, 0xd4413fdf, 0xcd5a0e9e, |
5196
|
|
|
|
|
|
|
0x958424a2, 0x8c9f15e3, 0xa7b24620, 0xbea97761, |
5197
|
|
|
|
|
|
|
0xf1e8e1a6, 0xe8f3d0e7, 0xc3de8324, 0xdac5b265, |
5198
|
|
|
|
|
|
|
0x5d5daeaa, 0x44469feb, 0x6f6bcc28, 0x7670fd69, |
5199
|
|
|
|
|
|
|
0x39316bae, 0x202a5aef, 0x0b07092c, 0x121c386d, |
5200
|
|
|
|
|
|
|
0xdf4636f3, 0xc65d07b2, 0xed705471, 0xf46b6530, |
5201
|
|
|
|
|
|
|
0xbb2af3f7, 0xa231c2b6, 0x891c9175, 0x9007a034, |
5202
|
|
|
|
|
|
|
0x179fbcfb, 0x0e848dba, 0x25a9de79, 0x3cb2ef38, |
5203
|
|
|
|
|
|
|
0x73f379ff, 0x6ae848be, 0x41c51b7d, 0x58de2a3c, |
5204
|
|
|
|
|
|
|
0xf0794f05, 0xe9627e44, 0xc24f2d87, 0xdb541cc6, |
5205
|
|
|
|
|
|
|
0x94158a01, 0x8d0ebb40, 0xa623e883, 0xbf38d9c2, |
5206
|
|
|
|
|
|
|
0x38a0c50d, 0x21bbf44c, 0x0a96a78f, 0x138d96ce, |
5207
|
|
|
|
|
|
|
0x5ccc0009, 0x45d73148, 0x6efa628b, 0x77e153ca, |
5208
|
|
|
|
|
|
|
0xbabb5d54, 0xa3a06c15, 0x888d3fd6, 0x91960e97, |
5209
|
|
|
|
|
|
|
0xded79850, 0xc7cca911, 0xece1fad2, 0xf5facb93, |
5210
|
|
|
|
|
|
|
0x7262d75c, 0x6b79e61d, 0x4054b5de, 0x594f849f, |
5211
|
|
|
|
|
|
|
0x160e1258, 0x0f152319, 0x243870da, 0x3d23419b, |
5212
|
|
|
|
|
|
|
0x65fd6ba7, 0x7ce65ae6, 0x57cb0925, 0x4ed03864, |
5213
|
|
|
|
|
|
|
0x0191aea3, 0x188a9fe2, 0x33a7cc21, 0x2abcfd60, |
5214
|
|
|
|
|
|
|
0xad24e1af, 0xb43fd0ee, 0x9f12832d, 0x8609b26c, |
5215
|
|
|
|
|
|
|
0xc94824ab, 0xd05315ea, 0xfb7e4629, 0xe2657768, |
5216
|
|
|
|
|
|
|
0x2f3f79f6, 0x362448b7, 0x1d091b74, 0x04122a35, |
5217
|
|
|
|
|
|
|
0x4b53bcf2, 0x52488db3, 0x7965de70, 0x607eef31, |
5218
|
|
|
|
|
|
|
0xe7e6f3fe, 0xfefdc2bf, 0xd5d0917c, 0xcccba03d, |
5219
|
|
|
|
|
|
|
0x838a36fa, 0x9a9107bb, 0xb1bc5478, 0xa8a76539, |
5220
|
|
|
|
|
|
|
0x3b83984b, 0x2298a90a, 0x09b5fac9, 0x10aecb88, |
5221
|
|
|
|
|
|
|
0x5fef5d4f, 0x46f46c0e, 0x6dd93fcd, 0x74c20e8c, |
5222
|
|
|
|
|
|
|
0xf35a1243, 0xea412302, 0xc16c70c1, 0xd8774180, |
5223
|
|
|
|
|
|
|
0x9736d747, 0x8e2de606, 0xa500b5c5, 0xbc1b8484, |
5224
|
|
|
|
|
|
|
0x71418a1a, 0x685abb5b, 0x4377e898, 0x5a6cd9d9, |
5225
|
|
|
|
|
|
|
0x152d4f1e, 0x0c367e5f, 0x271b2d9c, 0x3e001cdd, |
5226
|
|
|
|
|
|
|
0xb9980012, 0xa0833153, 0x8bae6290, 0x92b553d1, |
5227
|
|
|
|
|
|
|
0xddf4c516, 0xc4eff457, 0xefc2a794, 0xf6d996d5, |
5228
|
|
|
|
|
|
|
0xae07bce9, 0xb71c8da8, 0x9c31de6b, 0x852aef2a, |
5229
|
|
|
|
|
|
|
0xca6b79ed, 0xd37048ac, 0xf85d1b6f, 0xe1462a2e, |
5230
|
|
|
|
|
|
|
0x66de36e1, 0x7fc507a0, 0x54e85463, 0x4df36522, |
5231
|
|
|
|
|
|
|
0x02b2f3e5, 0x1ba9c2a4, 0x30849167, 0x299fa026, |
5232
|
|
|
|
|
|
|
0xe4c5aeb8, 0xfdde9ff9, 0xd6f3cc3a, 0xcfe8fd7b, |
5233
|
|
|
|
|
|
|
0x80a96bbc, 0x99b25afd, 0xb29f093e, 0xab84387f, |
5234
|
|
|
|
|
|
|
0x2c1c24b0, 0x350715f1, 0x1e2a4632, 0x07317773, |
5235
|
|
|
|
|
|
|
0x4870e1b4, 0x516bd0f5, 0x7a468336, 0x635db277, |
5236
|
|
|
|
|
|
|
0xcbfad74e, 0xd2e1e60f, 0xf9ccb5cc, 0xe0d7848d, |
5237
|
|
|
|
|
|
|
0xaf96124a, 0xb68d230b, 0x9da070c8, 0x84bb4189, |
5238
|
|
|
|
|
|
|
0x03235d46, 0x1a386c07, 0x31153fc4, 0x280e0e85, |
5239
|
|
|
|
|
|
|
0x674f9842, 0x7e54a903, 0x5579fac0, 0x4c62cb81, |
5240
|
|
|
|
|
|
|
0x8138c51f, 0x9823f45e, 0xb30ea79d, 0xaa1596dc, |
5241
|
|
|
|
|
|
|
0xe554001b, 0xfc4f315a, 0xd7626299, 0xce7953d8, |
5242
|
|
|
|
|
|
|
0x49e14f17, 0x50fa7e56, 0x7bd72d95, 0x62cc1cd4, |
5243
|
|
|
|
|
|
|
0x2d8d8a13, 0x3496bb52, 0x1fbbe891, 0x06a0d9d0, |
5244
|
|
|
|
|
|
|
0x5e7ef3ec, 0x4765c2ad, 0x6c48916e, 0x7553a02f, |
5245
|
|
|
|
|
|
|
0x3a1236e8, 0x230907a9, 0x0824546a, 0x113f652b, |
5246
|
|
|
|
|
|
|
0x96a779e4, 0x8fbc48a5, 0xa4911b66, 0xbd8a2a27, |
5247
|
|
|
|
|
|
|
0xf2cbbce0, 0xebd08da1, 0xc0fdde62, 0xd9e6ef23, |
5248
|
|
|
|
|
|
|
0x14bce1bd, 0x0da7d0fc, 0x268a833f, 0x3f91b27e, |
5249
|
|
|
|
|
|
|
0x70d024b9, 0x69cb15f8, 0x42e6463b, 0x5bfd777a, |
5250
|
|
|
|
|
|
|
0xdc656bb5, 0xc57e5af4, 0xee530937, 0xf7483876, |
5251
|
|
|
|
|
|
|
0xb809aeb1, 0xa1129ff0, 0x8a3fcc33, 0x9324fd72, |
5252
|
|
|
|
|
|
|
0x00000000, 0x01c26a37, 0x0384d46e, 0x0246be59, |
5253
|
|
|
|
|
|
|
0x0709a8dc, 0x06cbc2eb, 0x048d7cb2, 0x054f1685, |
5254
|
|
|
|
|
|
|
0x0e1351b8, 0x0fd13b8f, 0x0d9785d6, 0x0c55efe1, |
5255
|
|
|
|
|
|
|
0x091af964, 0x08d89353, 0x0a9e2d0a, 0x0b5c473d, |
5256
|
|
|
|
|
|
|
0x1c26a370, 0x1de4c947, 0x1fa2771e, 0x1e601d29, |
5257
|
|
|
|
|
|
|
0x1b2f0bac, 0x1aed619b, 0x18abdfc2, 0x1969b5f5, |
5258
|
|
|
|
|
|
|
0x1235f2c8, 0x13f798ff, 0x11b126a6, 0x10734c91, |
5259
|
|
|
|
|
|
|
0x153c5a14, 0x14fe3023, 0x16b88e7a, 0x177ae44d, |
5260
|
|
|
|
|
|
|
0x384d46e0, 0x398f2cd7, 0x3bc9928e, 0x3a0bf8b9, |
5261
|
|
|
|
|
|
|
0x3f44ee3c, 0x3e86840b, 0x3cc03a52, 0x3d025065, |
5262
|
|
|
|
|
|
|
0x365e1758, 0x379c7d6f, 0x35dac336, 0x3418a901, |
5263
|
|
|
|
|
|
|
0x3157bf84, 0x3095d5b3, 0x32d36bea, 0x331101dd, |
5264
|
|
|
|
|
|
|
0x246be590, 0x25a98fa7, 0x27ef31fe, 0x262d5bc9, |
5265
|
|
|
|
|
|
|
0x23624d4c, 0x22a0277b, 0x20e69922, 0x2124f315, |
5266
|
|
|
|
|
|
|
0x2a78b428, 0x2bbade1f, 0x29fc6046, 0x283e0a71, |
5267
|
|
|
|
|
|
|
0x2d711cf4, 0x2cb376c3, 0x2ef5c89a, 0x2f37a2ad, |
5268
|
|
|
|
|
|
|
0x709a8dc0, 0x7158e7f7, 0x731e59ae, 0x72dc3399, |
5269
|
|
|
|
|
|
|
0x7793251c, 0x76514f2b, 0x7417f172, 0x75d59b45, |
5270
|
|
|
|
|
|
|
0x7e89dc78, 0x7f4bb64f, 0x7d0d0816, 0x7ccf6221, |
5271
|
|
|
|
|
|
|
0x798074a4, 0x78421e93, 0x7a04a0ca, 0x7bc6cafd, |
5272
|
|
|
|
|
|
|
0x6cbc2eb0, 0x6d7e4487, 0x6f38fade, 0x6efa90e9, |
5273
|
|
|
|
|
|
|
0x6bb5866c, 0x6a77ec5b, 0x68315202, 0x69f33835, |
5274
|
|
|
|
|
|
|
0x62af7f08, 0x636d153f, 0x612bab66, 0x60e9c151, |
5275
|
|
|
|
|
|
|
0x65a6d7d4, 0x6464bde3, 0x662203ba, 0x67e0698d, |
5276
|
|
|
|
|
|
|
0x48d7cb20, 0x4915a117, 0x4b531f4e, 0x4a917579, |
5277
|
|
|
|
|
|
|
0x4fde63fc, 0x4e1c09cb, 0x4c5ab792, 0x4d98dda5, |
5278
|
|
|
|
|
|
|
0x46c49a98, 0x4706f0af, 0x45404ef6, 0x448224c1, |
5279
|
|
|
|
|
|
|
0x41cd3244, 0x400f5873, 0x4249e62a, 0x438b8c1d, |
5280
|
|
|
|
|
|
|
0x54f16850, 0x55330267, 0x5775bc3e, 0x56b7d609, |
5281
|
|
|
|
|
|
|
0x53f8c08c, 0x523aaabb, 0x507c14e2, 0x51be7ed5, |
5282
|
|
|
|
|
|
|
0x5ae239e8, 0x5b2053df, 0x5966ed86, 0x58a487b1, |
5283
|
|
|
|
|
|
|
0x5deb9134, 0x5c29fb03, 0x5e6f455a, 0x5fad2f6d, |
5284
|
|
|
|
|
|
|
0xe1351b80, 0xe0f771b7, 0xe2b1cfee, 0xe373a5d9, |
5285
|
|
|
|
|
|
|
0xe63cb35c, 0xe7fed96b, 0xe5b86732, 0xe47a0d05, |
5286
|
|
|
|
|
|
|
0xef264a38, 0xeee4200f, 0xeca29e56, 0xed60f461, |
5287
|
|
|
|
|
|
|
0xe82fe2e4, 0xe9ed88d3, 0xebab368a, 0xea695cbd, |
5288
|
|
|
|
|
|
|
0xfd13b8f0, 0xfcd1d2c7, 0xfe976c9e, 0xff5506a9, |
5289
|
|
|
|
|
|
|
0xfa1a102c, 0xfbd87a1b, 0xf99ec442, 0xf85cae75, |
5290
|
|
|
|
|
|
|
0xf300e948, 0xf2c2837f, 0xf0843d26, 0xf1465711, |
5291
|
|
|
|
|
|
|
0xf4094194, 0xf5cb2ba3, 0xf78d95fa, 0xf64fffcd, |
5292
|
|
|
|
|
|
|
0xd9785d60, 0xd8ba3757, 0xdafc890e, 0xdb3ee339, |
5293
|
|
|
|
|
|
|
0xde71f5bc, 0xdfb39f8b, 0xddf521d2, 0xdc374be5, |
5294
|
|
|
|
|
|
|
0xd76b0cd8, 0xd6a966ef, 0xd4efd8b6, 0xd52db281, |
5295
|
|
|
|
|
|
|
0xd062a404, 0xd1a0ce33, 0xd3e6706a, 0xd2241a5d, |
5296
|
|
|
|
|
|
|
0xc55efe10, 0xc49c9427, 0xc6da2a7e, 0xc7184049, |
5297
|
|
|
|
|
|
|
0xc25756cc, 0xc3953cfb, 0xc1d382a2, 0xc011e895, |
5298
|
|
|
|
|
|
|
0xcb4dafa8, 0xca8fc59f, 0xc8c97bc6, 0xc90b11f1, |
5299
|
|
|
|
|
|
|
0xcc440774, 0xcd866d43, 0xcfc0d31a, 0xce02b92d, |
5300
|
|
|
|
|
|
|
0x91af9640, 0x906dfc77, 0x922b422e, 0x93e92819, |
5301
|
|
|
|
|
|
|
0x96a63e9c, 0x976454ab, 0x9522eaf2, 0x94e080c5, |
5302
|
|
|
|
|
|
|
0x9fbcc7f8, 0x9e7eadcf, 0x9c381396, 0x9dfa79a1, |
5303
|
|
|
|
|
|
|
0x98b56f24, 0x99770513, 0x9b31bb4a, 0x9af3d17d, |
5304
|
|
|
|
|
|
|
0x8d893530, 0x8c4b5f07, 0x8e0de15e, 0x8fcf8b69, |
5305
|
|
|
|
|
|
|
0x8a809dec, 0x8b42f7db, 0x89044982, 0x88c623b5, |
5306
|
|
|
|
|
|
|
0x839a6488, 0x82580ebf, 0x801eb0e6, 0x81dcdad1, |
5307
|
|
|
|
|
|
|
0x8493cc54, 0x8551a663, 0x8717183a, 0x86d5720d, |
5308
|
|
|
|
|
|
|
0xa9e2d0a0, 0xa820ba97, 0xaa6604ce, 0xaba46ef9, |
5309
|
|
|
|
|
|
|
0xaeeb787c, 0xaf29124b, 0xad6fac12, 0xacadc625, |
5310
|
|
|
|
|
|
|
0xa7f18118, 0xa633eb2f, 0xa4755576, 0xa5b73f41, |
5311
|
|
|
|
|
|
|
0xa0f829c4, 0xa13a43f3, 0xa37cfdaa, 0xa2be979d, |
5312
|
|
|
|
|
|
|
0xb5c473d0, 0xb40619e7, 0xb640a7be, 0xb782cd89, |
5313
|
|
|
|
|
|
|
0xb2cddb0c, 0xb30fb13b, 0xb1490f62, 0xb08b6555, |
5314
|
|
|
|
|
|
|
0xbbd72268, 0xba15485f, 0xb853f606, 0xb9919c31, |
5315
|
|
|
|
|
|
|
0xbcde8ab4, 0xbd1ce083, 0xbf5a5eda, 0xbe9834ed, |
5316
|
|
|
|
|
|
|
0x00000000, 0xb8bc6765, 0xaa09c88b, 0x12b5afee, |
5317
|
|
|
|
|
|
|
0x8f629757, 0x37def032, 0x256b5fdc, 0x9dd738b9, |
5318
|
|
|
|
|
|
|
0xc5b428ef, 0x7d084f8a, 0x6fbde064, 0xd7018701, |
5319
|
|
|
|
|
|
|
0x4ad6bfb8, 0xf26ad8dd, 0xe0df7733, 0x58631056, |
5320
|
|
|
|
|
|
|
0x5019579f, 0xe8a530fa, 0xfa109f14, 0x42acf871, |
5321
|
|
|
|
|
|
|
0xdf7bc0c8, 0x67c7a7ad, 0x75720843, 0xcdce6f26, |
5322
|
|
|
|
|
|
|
0x95ad7f70, 0x2d111815, 0x3fa4b7fb, 0x8718d09e, |
5323
|
|
|
|
|
|
|
0x1acfe827, 0xa2738f42, 0xb0c620ac, 0x087a47c9, |
5324
|
|
|
|
|
|
|
0xa032af3e, 0x188ec85b, 0x0a3b67b5, 0xb28700d0, |
5325
|
|
|
|
|
|
|
0x2f503869, 0x97ec5f0c, 0x8559f0e2, 0x3de59787, |
5326
|
|
|
|
|
|
|
0x658687d1, 0xdd3ae0b4, 0xcf8f4f5a, 0x7733283f, |
5327
|
|
|
|
|
|
|
0xeae41086, 0x525877e3, 0x40edd80d, 0xf851bf68, |
5328
|
|
|
|
|
|
|
0xf02bf8a1, 0x48979fc4, 0x5a22302a, 0xe29e574f, |
5329
|
|
|
|
|
|
|
0x7f496ff6, 0xc7f50893, 0xd540a77d, 0x6dfcc018, |
5330
|
|
|
|
|
|
|
0x359fd04e, 0x8d23b72b, 0x9f9618c5, 0x272a7fa0, |
5331
|
|
|
|
|
|
|
0xbafd4719, 0x0241207c, 0x10f48f92, 0xa848e8f7, |
5332
|
|
|
|
|
|
|
0x9b14583d, 0x23a83f58, 0x311d90b6, 0x89a1f7d3, |
5333
|
|
|
|
|
|
|
0x1476cf6a, 0xaccaa80f, 0xbe7f07e1, 0x06c36084, |
5334
|
|
|
|
|
|
|
0x5ea070d2, 0xe61c17b7, 0xf4a9b859, 0x4c15df3c, |
5335
|
|
|
|
|
|
|
0xd1c2e785, 0x697e80e0, 0x7bcb2f0e, 0xc377486b, |
5336
|
|
|
|
|
|
|
0xcb0d0fa2, 0x73b168c7, 0x6104c729, 0xd9b8a04c, |
5337
|
|
|
|
|
|
|
0x446f98f5, 0xfcd3ff90, 0xee66507e, 0x56da371b, |
5338
|
|
|
|
|
|
|
0x0eb9274d, 0xb6054028, 0xa4b0efc6, 0x1c0c88a3, |
5339
|
|
|
|
|
|
|
0x81dbb01a, 0x3967d77f, 0x2bd27891, 0x936e1ff4, |
5340
|
|
|
|
|
|
|
0x3b26f703, 0x839a9066, 0x912f3f88, 0x299358ed, |
5341
|
|
|
|
|
|
|
0xb4446054, 0x0cf80731, 0x1e4da8df, 0xa6f1cfba, |
5342
|
|
|
|
|
|
|
0xfe92dfec, 0x462eb889, 0x549b1767, 0xec277002, |
5343
|
|
|
|
|
|
|
0x71f048bb, 0xc94c2fde, 0xdbf98030, 0x6345e755, |
5344
|
|
|
|
|
|
|
0x6b3fa09c, 0xd383c7f9, 0xc1366817, 0x798a0f72, |
5345
|
|
|
|
|
|
|
0xe45d37cb, 0x5ce150ae, 0x4e54ff40, 0xf6e89825, |
5346
|
|
|
|
|
|
|
0xae8b8873, 0x1637ef16, 0x048240f8, 0xbc3e279d, |
5347
|
|
|
|
|
|
|
0x21e91f24, 0x99557841, 0x8be0d7af, 0x335cb0ca, |
5348
|
|
|
|
|
|
|
0xed59b63b, 0x55e5d15e, 0x47507eb0, 0xffec19d5, |
5349
|
|
|
|
|
|
|
0x623b216c, 0xda874609, 0xc832e9e7, 0x708e8e82, |
5350
|
|
|
|
|
|
|
0x28ed9ed4, 0x9051f9b1, 0x82e4565f, 0x3a58313a, |
5351
|
|
|
|
|
|
|
0xa78f0983, 0x1f336ee6, 0x0d86c108, 0xb53aa66d, |
5352
|
|
|
|
|
|
|
0xbd40e1a4, 0x05fc86c1, 0x1749292f, 0xaff54e4a, |
5353
|
|
|
|
|
|
|
0x322276f3, 0x8a9e1196, 0x982bbe78, 0x2097d91d, |
5354
|
|
|
|
|
|
|
0x78f4c94b, 0xc048ae2e, 0xd2fd01c0, 0x6a4166a5, |
5355
|
|
|
|
|
|
|
0xf7965e1c, 0x4f2a3979, 0x5d9f9697, 0xe523f1f2, |
5356
|
|
|
|
|
|
|
0x4d6b1905, 0xf5d77e60, 0xe762d18e, 0x5fdeb6eb, |
5357
|
|
|
|
|
|
|
0xc2098e52, 0x7ab5e937, 0x680046d9, 0xd0bc21bc, |
5358
|
|
|
|
|
|
|
0x88df31ea, 0x3063568f, 0x22d6f961, 0x9a6a9e04, |
5359
|
|
|
|
|
|
|
0x07bda6bd, 0xbf01c1d8, 0xadb46e36, 0x15080953, |
5360
|
|
|
|
|
|
|
0x1d724e9a, 0xa5ce29ff, 0xb77b8611, 0x0fc7e174, |
5361
|
|
|
|
|
|
|
0x9210d9cd, 0x2aacbea8, 0x38191146, 0x80a57623, |
5362
|
|
|
|
|
|
|
0xd8c66675, 0x607a0110, 0x72cfaefe, 0xca73c99b, |
5363
|
|
|
|
|
|
|
0x57a4f122, 0xef189647, 0xfdad39a9, 0x45115ecc, |
5364
|
|
|
|
|
|
|
0x764dee06, 0xcef18963, 0xdc44268d, 0x64f841e8, |
5365
|
|
|
|
|
|
|
0xf92f7951, 0x41931e34, 0x5326b1da, 0xeb9ad6bf, |
5366
|
|
|
|
|
|
|
0xb3f9c6e9, 0x0b45a18c, 0x19f00e62, 0xa14c6907, |
5367
|
|
|
|
|
|
|
0x3c9b51be, 0x842736db, 0x96929935, 0x2e2efe50, |
5368
|
|
|
|
|
|
|
0x2654b999, 0x9ee8defc, 0x8c5d7112, 0x34e11677, |
5369
|
|
|
|
|
|
|
0xa9362ece, 0x118a49ab, 0x033fe645, 0xbb838120, |
5370
|
|
|
|
|
|
|
0xe3e09176, 0x5b5cf613, 0x49e959fd, 0xf1553e98, |
5371
|
|
|
|
|
|
|
0x6c820621, 0xd43e6144, 0xc68bceaa, 0x7e37a9cf, |
5372
|
|
|
|
|
|
|
0xd67f4138, 0x6ec3265d, 0x7c7689b3, 0xc4caeed6, |
5373
|
|
|
|
|
|
|
0x591dd66f, 0xe1a1b10a, 0xf3141ee4, 0x4ba87981, |
5374
|
|
|
|
|
|
|
0x13cb69d7, 0xab770eb2, 0xb9c2a15c, 0x017ec639, |
5375
|
|
|
|
|
|
|
0x9ca9fe80, 0x241599e5, 0x36a0360b, 0x8e1c516e, |
5376
|
|
|
|
|
|
|
0x866616a7, 0x3eda71c2, 0x2c6fde2c, 0x94d3b949, |
5377
|
|
|
|
|
|
|
0x090481f0, 0xb1b8e695, 0xa30d497b, 0x1bb12e1e, |
5378
|
|
|
|
|
|
|
0x43d23e48, 0xfb6e592d, 0xe9dbf6c3, 0x516791a6, |
5379
|
|
|
|
|
|
|
0xccb0a91f, 0x740cce7a, 0x66b96194, 0xde0506f1, |
5380
|
|
|
|
|
|
|
0x00000000, 0x3d6029b0, 0x7ac05360, 0x47a07ad0, |
5381
|
|
|
|
|
|
|
0xf580a6c0, 0xc8e08f70, 0x8f40f5a0, 0xb220dc10, |
5382
|
|
|
|
|
|
|
0x30704bc1, 0x0d106271, 0x4ab018a1, 0x77d03111, |
5383
|
|
|
|
|
|
|
0xc5f0ed01, 0xf890c4b1, 0xbf30be61, 0x825097d1, |
5384
|
|
|
|
|
|
|
0x60e09782, 0x5d80be32, 0x1a20c4e2, 0x2740ed52, |
5385
|
|
|
|
|
|
|
0x95603142, 0xa80018f2, 0xefa06222, 0xd2c04b92, |
5386
|
|
|
|
|
|
|
0x5090dc43, 0x6df0f5f3, 0x2a508f23, 0x1730a693, |
5387
|
|
|
|
|
|
|
0xa5107a83, 0x98705333, 0xdfd029e3, 0xe2b00053, |
5388
|
|
|
|
|
|
|
0xc1c12f04, 0xfca106b4, 0xbb017c64, 0x866155d4, |
5389
|
|
|
|
|
|
|
0x344189c4, 0x0921a074, 0x4e81daa4, 0x73e1f314, |
5390
|
|
|
|
|
|
|
0xf1b164c5, 0xccd14d75, 0x8b7137a5, 0xb6111e15, |
5391
|
|
|
|
|
|
|
0x0431c205, 0x3951ebb5, 0x7ef19165, 0x4391b8d5, |
5392
|
|
|
|
|
|
|
0xa121b886, 0x9c419136, 0xdbe1ebe6, 0xe681c256, |
5393
|
|
|
|
|
|
|
0x54a11e46, 0x69c137f6, 0x2e614d26, 0x13016496, |
5394
|
|
|
|
|
|
|
0x9151f347, 0xac31daf7, 0xeb91a027, 0xd6f18997, |
5395
|
|
|
|
|
|
|
0x64d15587, 0x59b17c37, 0x1e1106e7, 0x23712f57, |
5396
|
|
|
|
|
|
|
0x58f35849, 0x659371f9, 0x22330b29, 0x1f532299, |
5397
|
|
|
|
|
|
|
0xad73fe89, 0x9013d739, 0xd7b3ade9, 0xead38459, |
5398
|
|
|
|
|
|
|
0x68831388, 0x55e33a38, 0x124340e8, 0x2f236958, |
5399
|
|
|
|
|
|
|
0x9d03b548, 0xa0639cf8, 0xe7c3e628, 0xdaa3cf98, |
5400
|
|
|
|
|
|
|
0x3813cfcb, 0x0573e67b, 0x42d39cab, 0x7fb3b51b, |
5401
|
|
|
|
|
|
|
0xcd93690b, 0xf0f340bb, 0xb7533a6b, 0x8a3313db, |
5402
|
|
|
|
|
|
|
0x0863840a, 0x3503adba, 0x72a3d76a, 0x4fc3feda, |
5403
|
|
|
|
|
|
|
0xfde322ca, 0xc0830b7a, 0x872371aa, 0xba43581a, |
5404
|
|
|
|
|
|
|
0x9932774d, 0xa4525efd, 0xe3f2242d, 0xde920d9d, |
5405
|
|
|
|
|
|
|
0x6cb2d18d, 0x51d2f83d, 0x167282ed, 0x2b12ab5d, |
5406
|
|
|
|
|
|
|
0xa9423c8c, 0x9422153c, 0xd3826fec, 0xeee2465c, |
5407
|
|
|
|
|
|
|
0x5cc29a4c, 0x61a2b3fc, 0x2602c92c, 0x1b62e09c, |
5408
|
|
|
|
|
|
|
0xf9d2e0cf, 0xc4b2c97f, 0x8312b3af, 0xbe729a1f, |
5409
|
|
|
|
|
|
|
0x0c52460f, 0x31326fbf, 0x7692156f, 0x4bf23cdf, |
5410
|
|
|
|
|
|
|
0xc9a2ab0e, 0xf4c282be, 0xb362f86e, 0x8e02d1de, |
5411
|
|
|
|
|
|
|
0x3c220dce, 0x0142247e, 0x46e25eae, 0x7b82771e, |
5412
|
|
|
|
|
|
|
0xb1e6b092, 0x8c869922, 0xcb26e3f2, 0xf646ca42, |
5413
|
|
|
|
|
|
|
0x44661652, 0x79063fe2, 0x3ea64532, 0x03c66c82, |
5414
|
|
|
|
|
|
|
0x8196fb53, 0xbcf6d2e3, 0xfb56a833, 0xc6368183, |
5415
|
|
|
|
|
|
|
0x74165d93, 0x49767423, 0x0ed60ef3, 0x33b62743, |
5416
|
|
|
|
|
|
|
0xd1062710, 0xec660ea0, 0xabc67470, 0x96a65dc0, |
5417
|
|
|
|
|
|
|
0x248681d0, 0x19e6a860, 0x5e46d2b0, 0x6326fb00, |
5418
|
|
|
|
|
|
|
0xe1766cd1, 0xdc164561, 0x9bb63fb1, 0xa6d61601, |
5419
|
|
|
|
|
|
|
0x14f6ca11, 0x2996e3a1, 0x6e369971, 0x5356b0c1, |
5420
|
|
|
|
|
|
|
0x70279f96, 0x4d47b626, 0x0ae7ccf6, 0x3787e546, |
5421
|
|
|
|
|
|
|
0x85a73956, 0xb8c710e6, 0xff676a36, 0xc2074386, |
5422
|
|
|
|
|
|
|
0x4057d457, 0x7d37fde7, 0x3a978737, 0x07f7ae87, |
5423
|
|
|
|
|
|
|
0xb5d77297, 0x88b75b27, 0xcf1721f7, 0xf2770847, |
5424
|
|
|
|
|
|
|
0x10c70814, 0x2da721a4, 0x6a075b74, 0x576772c4, |
5425
|
|
|
|
|
|
|
0xe547aed4, 0xd8278764, 0x9f87fdb4, 0xa2e7d404, |
5426
|
|
|
|
|
|
|
0x20b743d5, 0x1dd76a65, 0x5a7710b5, 0x67173905, |
5427
|
|
|
|
|
|
|
0xd537e515, 0xe857cca5, 0xaff7b675, 0x92979fc5, |
5428
|
|
|
|
|
|
|
0xe915e8db, 0xd475c16b, 0x93d5bbbb, 0xaeb5920b, |
5429
|
|
|
|
|
|
|
0x1c954e1b, 0x21f567ab, 0x66551d7b, 0x5b3534cb, |
5430
|
|
|
|
|
|
|
0xd965a31a, 0xe4058aaa, 0xa3a5f07a, 0x9ec5d9ca, |
5431
|
|
|
|
|
|
|
0x2ce505da, 0x11852c6a, 0x562556ba, 0x6b457f0a, |
5432
|
|
|
|
|
|
|
0x89f57f59, 0xb49556e9, 0xf3352c39, 0xce550589, |
5433
|
|
|
|
|
|
|
0x7c75d999, 0x4115f029, 0x06b58af9, 0x3bd5a349, |
5434
|
|
|
|
|
|
|
0xb9853498, 0x84e51d28, 0xc34567f8, 0xfe254e48, |
5435
|
|
|
|
|
|
|
0x4c059258, 0x7165bbe8, 0x36c5c138, 0x0ba5e888, |
5436
|
|
|
|
|
|
|
0x28d4c7df, 0x15b4ee6f, 0x521494bf, 0x6f74bd0f, |
5437
|
|
|
|
|
|
|
0xdd54611f, 0xe03448af, 0xa794327f, 0x9af41bcf, |
5438
|
|
|
|
|
|
|
0x18a48c1e, 0x25c4a5ae, 0x6264df7e, 0x5f04f6ce, |
5439
|
|
|
|
|
|
|
0xed242ade, 0xd044036e, 0x97e479be, 0xaa84500e, |
5440
|
|
|
|
|
|
|
0x4834505d, 0x755479ed, 0x32f4033d, 0x0f942a8d, |
5441
|
|
|
|
|
|
|
0xbdb4f69d, 0x80d4df2d, 0xc774a5fd, 0xfa148c4d, |
5442
|
|
|
|
|
|
|
0x78441b9c, 0x4524322c, 0x028448fc, 0x3fe4614c, |
5443
|
|
|
|
|
|
|
0x8dc4bd5c, 0xb0a494ec, 0xf704ee3c, 0xca64c78c, |
5444
|
|
|
|
|
|
|
0x00000000, 0xcb5cd3a5, 0x4dc8a10b, 0x869472ae, |
5445
|
|
|
|
|
|
|
0x9b914216, 0x50cd91b3, 0xd659e31d, 0x1d0530b8, |
5446
|
|
|
|
|
|
|
0xec53826d, 0x270f51c8, 0xa19b2366, 0x6ac7f0c3, |
5447
|
|
|
|
|
|
|
0x77c2c07b, 0xbc9e13de, 0x3a0a6170, 0xf156b2d5, |
5448
|
|
|
|
|
|
|
0x03d6029b, 0xc88ad13e, 0x4e1ea390, 0x85427035, |
5449
|
|
|
|
|
|
|
0x9847408d, 0x531b9328, 0xd58fe186, 0x1ed33223, |
5450
|
|
|
|
|
|
|
0xef8580f6, 0x24d95353, 0xa24d21fd, 0x6911f258, |
5451
|
|
|
|
|
|
|
0x7414c2e0, 0xbf481145, 0x39dc63eb, 0xf280b04e, |
5452
|
|
|
|
|
|
|
0x07ac0536, 0xccf0d693, 0x4a64a43d, 0x81387798, |
5453
|
|
|
|
|
|
|
0x9c3d4720, 0x57619485, 0xd1f5e62b, 0x1aa9358e, |
5454
|
|
|
|
|
|
|
0xebff875b, 0x20a354fe, 0xa6372650, 0x6d6bf5f5, |
5455
|
|
|
|
|
|
|
0x706ec54d, 0xbb3216e8, 0x3da66446, 0xf6fab7e3, |
5456
|
|
|
|
|
|
|
0x047a07ad, 0xcf26d408, 0x49b2a6a6, 0x82ee7503, |
5457
|
|
|
|
|
|
|
0x9feb45bb, 0x54b7961e, 0xd223e4b0, 0x197f3715, |
5458
|
|
|
|
|
|
|
0xe82985c0, 0x23755665, 0xa5e124cb, 0x6ebdf76e, |
5459
|
|
|
|
|
|
|
0x73b8c7d6, 0xb8e41473, 0x3e7066dd, 0xf52cb578, |
5460
|
|
|
|
|
|
|
0x0f580a6c, 0xc404d9c9, 0x4290ab67, 0x89cc78c2, |
5461
|
|
|
|
|
|
|
0x94c9487a, 0x5f959bdf, 0xd901e971, 0x125d3ad4, |
5462
|
|
|
|
|
|
|
0xe30b8801, 0x28575ba4, 0xaec3290a, 0x659ffaaf, |
5463
|
|
|
|
|
|
|
0x789aca17, 0xb3c619b2, 0x35526b1c, 0xfe0eb8b9, |
5464
|
|
|
|
|
|
|
0x0c8e08f7, 0xc7d2db52, 0x4146a9fc, 0x8a1a7a59, |
5465
|
|
|
|
|
|
|
0x971f4ae1, 0x5c439944, 0xdad7ebea, 0x118b384f, |
5466
|
|
|
|
|
|
|
0xe0dd8a9a, 0x2b81593f, 0xad152b91, 0x6649f834, |
5467
|
|
|
|
|
|
|
0x7b4cc88c, 0xb0101b29, 0x36846987, 0xfdd8ba22, |
5468
|
|
|
|
|
|
|
0x08f40f5a, 0xc3a8dcff, 0x453cae51, 0x8e607df4, |
5469
|
|
|
|
|
|
|
0x93654d4c, 0x58399ee9, 0xdeadec47, 0x15f13fe2, |
5470
|
|
|
|
|
|
|
0xe4a78d37, 0x2ffb5e92, 0xa96f2c3c, 0x6233ff99, |
5471
|
|
|
|
|
|
|
0x7f36cf21, 0xb46a1c84, 0x32fe6e2a, 0xf9a2bd8f, |
5472
|
|
|
|
|
|
|
0x0b220dc1, 0xc07ede64, 0x46eaacca, 0x8db67f6f, |
5473
|
|
|
|
|
|
|
0x90b34fd7, 0x5bef9c72, 0xdd7beedc, 0x16273d79, |
5474
|
|
|
|
|
|
|
0xe7718fac, 0x2c2d5c09, 0xaab92ea7, 0x61e5fd02, |
5475
|
|
|
|
|
|
|
0x7ce0cdba, 0xb7bc1e1f, 0x31286cb1, 0xfa74bf14, |
5476
|
|
|
|
|
|
|
0x1eb014d8, 0xd5ecc77d, 0x5378b5d3, 0x98246676, |
5477
|
|
|
|
|
|
|
0x852156ce, 0x4e7d856b, 0xc8e9f7c5, 0x03b52460, |
5478
|
|
|
|
|
|
|
0xf2e396b5, 0x39bf4510, 0xbf2b37be, 0x7477e41b, |
5479
|
|
|
|
|
|
|
0x6972d4a3, 0xa22e0706, 0x24ba75a8, 0xefe6a60d, |
5480
|
|
|
|
|
|
|
0x1d661643, 0xd63ac5e6, 0x50aeb748, 0x9bf264ed, |
5481
|
|
|
|
|
|
|
0x86f75455, 0x4dab87f0, 0xcb3ff55e, 0x006326fb, |
5482
|
|
|
|
|
|
|
0xf135942e, 0x3a69478b, 0xbcfd3525, 0x77a1e680, |
5483
|
|
|
|
|
|
|
0x6aa4d638, 0xa1f8059d, 0x276c7733, 0xec30a496, |
5484
|
|
|
|
|
|
|
0x191c11ee, 0xd240c24b, 0x54d4b0e5, 0x9f886340, |
5485
|
|
|
|
|
|
|
0x828d53f8, 0x49d1805d, 0xcf45f2f3, 0x04192156, |
5486
|
|
|
|
|
|
|
0xf54f9383, 0x3e134026, 0xb8873288, 0x73dbe12d, |
5487
|
|
|
|
|
|
|
0x6eded195, 0xa5820230, 0x2316709e, 0xe84aa33b, |
5488
|
|
|
|
|
|
|
0x1aca1375, 0xd196c0d0, 0x5702b27e, 0x9c5e61db, |
5489
|
|
|
|
|
|
|
0x815b5163, 0x4a0782c6, 0xcc93f068, 0x07cf23cd, |
5490
|
|
|
|
|
|
|
0xf6999118, 0x3dc542bd, 0xbb513013, 0x700de3b6, |
5491
|
|
|
|
|
|
|
0x6d08d30e, 0xa65400ab, 0x20c07205, 0xeb9ca1a0, |
5492
|
|
|
|
|
|
|
0x11e81eb4, 0xdab4cd11, 0x5c20bfbf, 0x977c6c1a, |
5493
|
|
|
|
|
|
|
0x8a795ca2, 0x41258f07, 0xc7b1fda9, 0x0ced2e0c, |
5494
|
|
|
|
|
|
|
0xfdbb9cd9, 0x36e74f7c, 0xb0733dd2, 0x7b2fee77, |
5495
|
|
|
|
|
|
|
0x662adecf, 0xad760d6a, 0x2be27fc4, 0xe0beac61, |
5496
|
|
|
|
|
|
|
0x123e1c2f, 0xd962cf8a, 0x5ff6bd24, 0x94aa6e81, |
5497
|
|
|
|
|
|
|
0x89af5e39, 0x42f38d9c, 0xc467ff32, 0x0f3b2c97, |
5498
|
|
|
|
|
|
|
0xfe6d9e42, 0x35314de7, 0xb3a53f49, 0x78f9ecec, |
5499
|
|
|
|
|
|
|
0x65fcdc54, 0xaea00ff1, 0x28347d5f, 0xe368aefa, |
5500
|
|
|
|
|
|
|
0x16441b82, 0xdd18c827, 0x5b8cba89, 0x90d0692c, |
5501
|
|
|
|
|
|
|
0x8dd55994, 0x46898a31, 0xc01df89f, 0x0b412b3a, |
5502
|
|
|
|
|
|
|
0xfa1799ef, 0x314b4a4a, 0xb7df38e4, 0x7c83eb41, |
5503
|
|
|
|
|
|
|
0x6186dbf9, 0xaada085c, 0x2c4e7af2, 0xe712a957, |
5504
|
|
|
|
|
|
|
0x15921919, 0xdececabc, 0x585ab812, 0x93066bb7, |
5505
|
|
|
|
|
|
|
0x8e035b0f, 0x455f88aa, 0xc3cbfa04, 0x089729a1, |
5506
|
|
|
|
|
|
|
0xf9c19b74, 0x329d48d1, 0xb4093a7f, 0x7f55e9da, |
5507
|
|
|
|
|
|
|
0x6250d962, 0xa90c0ac7, 0x2f987869, 0xe4c4abcc, |
5508
|
|
|
|
|
|
|
0x00000000, 0xa6770bb4, 0x979f1129, 0x31e81a9d, |
5509
|
|
|
|
|
|
|
0xf44f2413, 0x52382fa7, 0x63d0353a, 0xc5a73e8e, |
5510
|
|
|
|
|
|
|
0x33ef4e67, 0x959845d3, 0xa4705f4e, 0x020754fa, |
5511
|
|
|
|
|
|
|
0xc7a06a74, 0x61d761c0, 0x503f7b5d, 0xf64870e9, |
5512
|
|
|
|
|
|
|
0x67de9cce, 0xc1a9977a, 0xf0418de7, 0x56368653, |
5513
|
|
|
|
|
|
|
0x9391b8dd, 0x35e6b369, 0x040ea9f4, 0xa279a240, |
5514
|
|
|
|
|
|
|
0x5431d2a9, 0xf246d91d, 0xc3aec380, 0x65d9c834, |
5515
|
|
|
|
|
|
|
0xa07ef6ba, 0x0609fd0e, 0x37e1e793, 0x9196ec27, |
5516
|
|
|
|
|
|
|
0xcfbd399c, 0x69ca3228, 0x582228b5, 0xfe552301, |
5517
|
|
|
|
|
|
|
0x3bf21d8f, 0x9d85163b, 0xac6d0ca6, 0x0a1a0712, |
5518
|
|
|
|
|
|
|
0xfc5277fb, 0x5a257c4f, 0x6bcd66d2, 0xcdba6d66, |
5519
|
|
|
|
|
|
|
0x081d53e8, 0xae6a585c, 0x9f8242c1, 0x39f54975, |
5520
|
|
|
|
|
|
|
0xa863a552, 0x0e14aee6, 0x3ffcb47b, 0x998bbfcf, |
5521
|
|
|
|
|
|
|
0x5c2c8141, 0xfa5b8af5, 0xcbb39068, 0x6dc49bdc, |
5522
|
|
|
|
|
|
|
0x9b8ceb35, 0x3dfbe081, 0x0c13fa1c, 0xaa64f1a8, |
5523
|
|
|
|
|
|
|
0x6fc3cf26, 0xc9b4c492, 0xf85cde0f, 0x5e2bd5bb, |
5524
|
|
|
|
|
|
|
0x440b7579, 0xe27c7ecd, 0xd3946450, 0x75e36fe4, |
5525
|
|
|
|
|
|
|
0xb044516a, 0x16335ade, 0x27db4043, 0x81ac4bf7, |
5526
|
|
|
|
|
|
|
0x77e43b1e, 0xd19330aa, 0xe07b2a37, 0x460c2183, |
5527
|
|
|
|
|
|
|
0x83ab1f0d, 0x25dc14b9, 0x14340e24, 0xb2430590, |
5528
|
|
|
|
|
|
|
0x23d5e9b7, 0x85a2e203, 0xb44af89e, 0x123df32a, |
5529
|
|
|
|
|
|
|
0xd79acda4, 0x71edc610, 0x4005dc8d, 0xe672d739, |
5530
|
|
|
|
|
|
|
0x103aa7d0, 0xb64dac64, 0x87a5b6f9, 0x21d2bd4d, |
5531
|
|
|
|
|
|
|
0xe47583c3, 0x42028877, 0x73ea92ea, 0xd59d995e, |
5532
|
|
|
|
|
|
|
0x8bb64ce5, 0x2dc14751, 0x1c295dcc, 0xba5e5678, |
5533
|
|
|
|
|
|
|
0x7ff968f6, 0xd98e6342, 0xe86679df, 0x4e11726b, |
5534
|
|
|
|
|
|
|
0xb8590282, 0x1e2e0936, 0x2fc613ab, 0x89b1181f, |
5535
|
|
|
|
|
|
|
0x4c162691, 0xea612d25, 0xdb8937b8, 0x7dfe3c0c, |
5536
|
|
|
|
|
|
|
0xec68d02b, 0x4a1fdb9f, 0x7bf7c102, 0xdd80cab6, |
5537
|
|
|
|
|
|
|
0x1827f438, 0xbe50ff8c, 0x8fb8e511, 0x29cfeea5, |
5538
|
|
|
|
|
|
|
0xdf879e4c, 0x79f095f8, 0x48188f65, 0xee6f84d1, |
5539
|
|
|
|
|
|
|
0x2bc8ba5f, 0x8dbfb1eb, 0xbc57ab76, 0x1a20a0c2, |
5540
|
|
|
|
|
|
|
0x8816eaf2, 0x2e61e146, 0x1f89fbdb, 0xb9fef06f, |
5541
|
|
|
|
|
|
|
0x7c59cee1, 0xda2ec555, 0xebc6dfc8, 0x4db1d47c, |
5542
|
|
|
|
|
|
|
0xbbf9a495, 0x1d8eaf21, 0x2c66b5bc, 0x8a11be08, |
5543
|
|
|
|
|
|
|
0x4fb68086, 0xe9c18b32, 0xd82991af, 0x7e5e9a1b, |
5544
|
|
|
|
|
|
|
0xefc8763c, 0x49bf7d88, 0x78576715, 0xde206ca1, |
5545
|
|
|
|
|
|
|
0x1b87522f, 0xbdf0599b, 0x8c184306, 0x2a6f48b2, |
5546
|
|
|
|
|
|
|
0xdc27385b, 0x7a5033ef, 0x4bb82972, 0xedcf22c6, |
5547
|
|
|
|
|
|
|
0x28681c48, 0x8e1f17fc, 0xbff70d61, 0x198006d5, |
5548
|
|
|
|
|
|
|
0x47abd36e, 0xe1dcd8da, 0xd034c247, 0x7643c9f3, |
5549
|
|
|
|
|
|
|
0xb3e4f77d, 0x1593fcc9, 0x247be654, 0x820cede0, |
5550
|
|
|
|
|
|
|
0x74449d09, 0xd23396bd, 0xe3db8c20, 0x45ac8794, |
5551
|
|
|
|
|
|
|
0x800bb91a, 0x267cb2ae, 0x1794a833, 0xb1e3a387, |
5552
|
|
|
|
|
|
|
0x20754fa0, 0x86024414, 0xb7ea5e89, 0x119d553d, |
5553
|
|
|
|
|
|
|
0xd43a6bb3, 0x724d6007, 0x43a57a9a, 0xe5d2712e, |
5554
|
|
|
|
|
|
|
0x139a01c7, 0xb5ed0a73, 0x840510ee, 0x22721b5a, |
5555
|
|
|
|
|
|
|
0xe7d525d4, 0x41a22e60, 0x704a34fd, 0xd63d3f49, |
5556
|
|
|
|
|
|
|
0xcc1d9f8b, 0x6a6a943f, 0x5b828ea2, 0xfdf58516, |
5557
|
|
|
|
|
|
|
0x3852bb98, 0x9e25b02c, 0xafcdaab1, 0x09baa105, |
5558
|
|
|
|
|
|
|
0xfff2d1ec, 0x5985da58, 0x686dc0c5, 0xce1acb71, |
5559
|
|
|
|
|
|
|
0x0bbdf5ff, 0xadcafe4b, 0x9c22e4d6, 0x3a55ef62, |
5560
|
|
|
|
|
|
|
0xabc30345, 0x0db408f1, 0x3c5c126c, 0x9a2b19d8, |
5561
|
|
|
|
|
|
|
0x5f8c2756, 0xf9fb2ce2, 0xc813367f, 0x6e643dcb, |
5562
|
|
|
|
|
|
|
0x982c4d22, 0x3e5b4696, 0x0fb35c0b, 0xa9c457bf, |
5563
|
|
|
|
|
|
|
0x6c636931, 0xca146285, 0xfbfc7818, 0x5d8b73ac, |
5564
|
|
|
|
|
|
|
0x03a0a617, 0xa5d7ada3, 0x943fb73e, 0x3248bc8a, |
5565
|
|
|
|
|
|
|
0xf7ef8204, 0x519889b0, 0x6070932d, 0xc6079899, |
5566
|
|
|
|
|
|
|
0x304fe870, 0x9638e3c4, 0xa7d0f959, 0x01a7f2ed, |
5567
|
|
|
|
|
|
|
0xc400cc63, 0x6277c7d7, 0x539fdd4a, 0xf5e8d6fe, |
5568
|
|
|
|
|
|
|
0x647e3ad9, 0xc209316d, 0xf3e12bf0, 0x55962044, |
5569
|
|
|
|
|
|
|
0x90311eca, 0x3646157e, 0x07ae0fe3, 0xa1d90457, |
5570
|
|
|
|
|
|
|
0x579174be, 0xf1e67f0a, 0xc00e6597, 0x66796e23, |
5571
|
|
|
|
|
|
|
0xa3de50ad, 0x05a95b19, 0x34414184, 0x92364a30, |
5572
|
|
|
|
|
|
|
0x00000000, 0xccaa009e, 0x4225077d, 0x8e8f07e3, |
5573
|
|
|
|
|
|
|
0x844a0efa, 0x48e00e64, 0xc66f0987, 0x0ac50919, |
5574
|
|
|
|
|
|
|
0xd3e51bb5, 0x1f4f1b2b, 0x91c01cc8, 0x5d6a1c56, |
5575
|
|
|
|
|
|
|
0x57af154f, 0x9b0515d1, 0x158a1232, 0xd92012ac, |
5576
|
|
|
|
|
|
|
0x7cbb312b, 0xb01131b5, 0x3e9e3656, 0xf23436c8, |
5577
|
|
|
|
|
|
|
0xf8f13fd1, 0x345b3f4f, 0xbad438ac, 0x767e3832, |
5578
|
|
|
|
|
|
|
0xaf5e2a9e, 0x63f42a00, 0xed7b2de3, 0x21d12d7d, |
5579
|
|
|
|
|
|
|
0x2b142464, 0xe7be24fa, 0x69312319, 0xa59b2387, |
5580
|
|
|
|
|
|
|
0xf9766256, 0x35dc62c8, 0xbb53652b, 0x77f965b5, |
5581
|
|
|
|
|
|
|
0x7d3c6cac, 0xb1966c32, 0x3f196bd1, 0xf3b36b4f, |
5582
|
|
|
|
|
|
|
0x2a9379e3, 0xe639797d, 0x68b67e9e, 0xa41c7e00, |
5583
|
|
|
|
|
|
|
0xaed97719, 0x62737787, 0xecfc7064, 0x205670fa, |
5584
|
|
|
|
|
|
|
0x85cd537d, 0x496753e3, 0xc7e85400, 0x0b42549e, |
5585
|
|
|
|
|
|
|
0x01875d87, 0xcd2d5d19, 0x43a25afa, 0x8f085a64, |
5586
|
|
|
|
|
|
|
0x562848c8, 0x9a824856, 0x140d4fb5, 0xd8a74f2b, |
5587
|
|
|
|
|
|
|
0xd2624632, 0x1ec846ac, 0x9047414f, 0x5ced41d1, |
5588
|
|
|
|
|
|
|
0x299dc2ed, 0xe537c273, 0x6bb8c590, 0xa712c50e, |
5589
|
|
|
|
|
|
|
0xadd7cc17, 0x617dcc89, 0xeff2cb6a, 0x2358cbf4, |
5590
|
|
|
|
|
|
|
0xfa78d958, 0x36d2d9c6, 0xb85dde25, 0x74f7debb, |
5591
|
|
|
|
|
|
|
0x7e32d7a2, 0xb298d73c, 0x3c17d0df, 0xf0bdd041, |
5592
|
|
|
|
|
|
|
0x5526f3c6, 0x998cf358, 0x1703f4bb, 0xdba9f425, |
5593
|
|
|
|
|
|
|
0xd16cfd3c, 0x1dc6fda2, 0x9349fa41, 0x5fe3fadf, |
5594
|
|
|
|
|
|
|
0x86c3e873, 0x4a69e8ed, 0xc4e6ef0e, 0x084cef90, |
5595
|
|
|
|
|
|
|
0x0289e689, 0xce23e617, 0x40ace1f4, 0x8c06e16a, |
5596
|
|
|
|
|
|
|
0xd0eba0bb, 0x1c41a025, 0x92cea7c6, 0x5e64a758, |
5597
|
|
|
|
|
|
|
0x54a1ae41, 0x980baedf, 0x1684a93c, 0xda2ea9a2, |
5598
|
|
|
|
|
|
|
0x030ebb0e, 0xcfa4bb90, 0x412bbc73, 0x8d81bced, |
5599
|
|
|
|
|
|
|
0x8744b5f4, 0x4beeb56a, 0xc561b289, 0x09cbb217, |
5600
|
|
|
|
|
|
|
0xac509190, 0x60fa910e, 0xee7596ed, 0x22df9673, |
5601
|
|
|
|
|
|
|
0x281a9f6a, 0xe4b09ff4, 0x6a3f9817, 0xa6959889, |
5602
|
|
|
|
|
|
|
0x7fb58a25, 0xb31f8abb, 0x3d908d58, 0xf13a8dc6, |
5603
|
|
|
|
|
|
|
0xfbff84df, 0x37558441, 0xb9da83a2, 0x7570833c, |
5604
|
|
|
|
|
|
|
0x533b85da, 0x9f918544, 0x111e82a7, 0xddb48239, |
5605
|
|
|
|
|
|
|
0xd7718b20, 0x1bdb8bbe, 0x95548c5d, 0x59fe8cc3, |
5606
|
|
|
|
|
|
|
0x80de9e6f, 0x4c749ef1, 0xc2fb9912, 0x0e51998c, |
5607
|
|
|
|
|
|
|
0x04949095, 0xc83e900b, 0x46b197e8, 0x8a1b9776, |
5608
|
|
|
|
|
|
|
0x2f80b4f1, 0xe32ab46f, 0x6da5b38c, 0xa10fb312, |
5609
|
|
|
|
|
|
|
0xabcaba0b, 0x6760ba95, 0xe9efbd76, 0x2545bde8, |
5610
|
|
|
|
|
|
|
0xfc65af44, 0x30cfafda, 0xbe40a839, 0x72eaa8a7, |
5611
|
|
|
|
|
|
|
0x782fa1be, 0xb485a120, 0x3a0aa6c3, 0xf6a0a65d, |
5612
|
|
|
|
|
|
|
0xaa4de78c, 0x66e7e712, 0xe868e0f1, 0x24c2e06f, |
5613
|
|
|
|
|
|
|
0x2e07e976, 0xe2ade9e8, 0x6c22ee0b, 0xa088ee95, |
5614
|
|
|
|
|
|
|
0x79a8fc39, 0xb502fca7, 0x3b8dfb44, 0xf727fbda, |
5615
|
|
|
|
|
|
|
0xfde2f2c3, 0x3148f25d, 0xbfc7f5be, 0x736df520, |
5616
|
|
|
|
|
|
|
0xd6f6d6a7, 0x1a5cd639, 0x94d3d1da, 0x5879d144, |
5617
|
|
|
|
|
|
|
0x52bcd85d, 0x9e16d8c3, 0x1099df20, 0xdc33dfbe, |
5618
|
|
|
|
|
|
|
0x0513cd12, 0xc9b9cd8c, 0x4736ca6f, 0x8b9ccaf1, |
5619
|
|
|
|
|
|
|
0x8159c3e8, 0x4df3c376, 0xc37cc495, 0x0fd6c40b, |
5620
|
|
|
|
|
|
|
0x7aa64737, 0xb60c47a9, 0x3883404a, 0xf42940d4, |
5621
|
|
|
|
|
|
|
0xfeec49cd, 0x32464953, 0xbcc94eb0, 0x70634e2e, |
5622
|
|
|
|
|
|
|
0xa9435c82, 0x65e95c1c, 0xeb665bff, 0x27cc5b61, |
5623
|
|
|
|
|
|
|
0x2d095278, 0xe1a352e6, 0x6f2c5505, 0xa386559b, |
5624
|
|
|
|
|
|
|
0x061d761c, 0xcab77682, 0x44387161, 0x889271ff, |
5625
|
|
|
|
|
|
|
0x825778e6, 0x4efd7878, 0xc0727f9b, 0x0cd87f05, |
5626
|
|
|
|
|
|
|
0xd5f86da9, 0x19526d37, 0x97dd6ad4, 0x5b776a4a, |
5627
|
|
|
|
|
|
|
0x51b26353, 0x9d1863cd, 0x1397642e, 0xdf3d64b0, |
5628
|
|
|
|
|
|
|
0x83d02561, 0x4f7a25ff, 0xc1f5221c, 0x0d5f2282, |
5629
|
|
|
|
|
|
|
0x079a2b9b, 0xcb302b05, 0x45bf2ce6, 0x89152c78, |
5630
|
|
|
|
|
|
|
0x50353ed4, 0x9c9f3e4a, 0x121039a9, 0xdeba3937, |
5631
|
|
|
|
|
|
|
0xd47f302e, 0x18d530b0, 0x965a3753, 0x5af037cd, |
5632
|
|
|
|
|
|
|
0xff6b144a, 0x33c114d4, 0xbd4e1337, 0x71e413a9, |
5633
|
|
|
|
|
|
|
0x7b211ab0, 0xb78b1a2e, 0x39041dcd, 0xf5ae1d53, |
5634
|
|
|
|
|
|
|
0x2c8e0fff, 0xe0240f61, 0x6eab0882, 0xa201081c, |
5635
|
|
|
|
|
|
|
0xa8c40105, 0x646e019b, 0xeae10678, 0x264b06e6, |
5636
|
|
|
|
|
|
|
}; |
5637
|
|
|
|
|
|
|
|
5638
|
|
|
|
|
|
|
|
5639
|
|
|
|
|
|
|
|
5640
|
|
|
|
|
|
|
static u32 MAYBE_UNUSED |
5641
|
29
|
|
|
|
|
|
crc32_slice8(u32 crc, const u8 *p, size_t len) |
5642
|
|
|
|
|
|
|
{ |
5643
|
29
|
|
|
|
|
|
const u8 * const end = p + len; |
5644
|
|
|
|
|
|
|
const u8 *end64; |
5645
|
|
|
|
|
|
|
|
5646
|
29
|
50
|
|
|
|
|
for (; ((uintptr_t)p & 7) && p != end; p++) |
|
|
0
|
|
|
|
|
|
5647
|
0
|
|
|
|
|
|
crc = (crc >> 8) ^ crc32_slice8_table[(u8)crc ^ *p]; |
5648
|
|
|
|
|
|
|
|
5649
|
29
|
|
|
|
|
|
end64 = p + ((end - p) & ~7); |
5650
|
23002
|
100
|
|
|
|
|
for (; p != end64; p += 8) { |
5651
|
22973
|
|
|
|
|
|
u32 v1 = le32_bswap(*(const u32 *)(p + 0)); |
5652
|
22973
|
|
|
|
|
|
u32 v2 = le32_bswap(*(const u32 *)(p + 4)); |
5653
|
|
|
|
|
|
|
|
5654
|
68919
|
|
|
|
|
|
crc = crc32_slice8_table[0x700 + (u8)((crc ^ v1) >> 0)] ^ |
5655
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x600 + (u8)((crc ^ v1) >> 8)] ^ |
5656
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x500 + (u8)((crc ^ v1) >> 16)] ^ |
5657
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x400 + (u8)((crc ^ v1) >> 24)] ^ |
5658
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x300 + (u8)(v2 >> 0)] ^ |
5659
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x200 + (u8)(v2 >> 8)] ^ |
5660
|
22973
|
|
|
|
|
|
crc32_slice8_table[0x100 + (u8)(v2 >> 16)] ^ |
5661
|
22973
|
|
|
|
|
|
crc32_slice8_table[0x000 + (u8)(v2 >> 24)]; |
5662
|
|
|
|
|
|
|
} |
5663
|
|
|
|
|
|
|
|
5664
|
160
|
100
|
|
|
|
|
for (; p != end; p++) |
5665
|
131
|
|
|
|
|
|
crc = (crc >> 8) ^ crc32_slice8_table[(u8)crc ^ *p]; |
5666
|
|
|
|
|
|
|
|
5667
|
29
|
|
|
|
|
|
return crc; |
5668
|
|
|
|
|
|
|
} |
5669
|
|
|
|
|
|
|
|
5670
|
|
|
|
|
|
|
|
5671
|
|
|
|
|
|
|
static forceinline u32 MAYBE_UNUSED |
5672
|
|
|
|
|
|
|
crc32_slice1(u32 crc, const u8 *p, size_t len) |
5673
|
|
|
|
|
|
|
{ |
5674
|
|
|
|
|
|
|
size_t i; |
5675
|
|
|
|
|
|
|
|
5676
|
0
|
0
|
|
|
|
|
for (i = 0; i < len; i++) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
5677
|
0
|
|
|
|
|
|
crc = (crc >> 8) ^ crc32_slice1_table[(u8)crc ^ p[i]]; |
5678
|
0
|
|
|
|
|
|
return crc; |
5679
|
|
|
|
|
|
|
} |
5680
|
|
|
|
|
|
|
|
5681
|
|
|
|
|
|
|
|
5682
|
|
|
|
|
|
|
#undef DEFAULT_IMPL |
5683
|
|
|
|
|
|
|
#undef arch_select_crc32_func |
5684
|
|
|
|
|
|
|
typedef u32 (*crc32_func_t)(u32 crc, const u8 *p, size_t len); |
5685
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
5686
|
|
|
|
|
|
|
/* # include "arm/crc32_impl.h" */ |
5687
|
|
|
|
|
|
|
|
5688
|
|
|
|
|
|
|
|
5689
|
|
|
|
|
|
|
#ifndef LIB_ARM_CRC32_IMPL_H |
5690
|
|
|
|
|
|
|
#define LIB_ARM_CRC32_IMPL_H |
5691
|
|
|
|
|
|
|
|
5692
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
5693
|
|
|
|
|
|
|
|
5694
|
|
|
|
|
|
|
|
5695
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
5696
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
5697
|
|
|
|
|
|
|
|
5698
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
5699
|
|
|
|
|
|
|
|
5700
|
|
|
|
|
|
|
|
5701
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
5702
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
5703
|
|
|
|
|
|
|
|
5704
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
5705
|
|
|
|
|
|
|
|
5706
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
5707
|
|
|
|
|
|
|
#endif |
5708
|
|
|
|
|
|
|
|
5709
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
5710
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
5711
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
5712
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
5713
|
|
|
|
|
|
|
#else |
5714
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
5715
|
|
|
|
|
|
|
#endif |
5716
|
|
|
|
|
|
|
|
5717
|
|
|
|
|
|
|
|
5718
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
5719
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
5720
|
|
|
|
|
|
|
#else |
5721
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
5722
|
|
|
|
|
|
|
#endif |
5723
|
|
|
|
|
|
|
|
5724
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
5725
|
|
|
|
|
|
|
|
5726
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
5727
|
|
|
|
|
|
|
|
5728
|
|
|
|
|
|
|
|
5729
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
5730
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
5731
|
|
|
|
|
|
|
|
5732
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
5733
|
|
|
|
|
|
|
|
5734
|
|
|
|
|
|
|
|
5735
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
5736
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
5737
|
|
|
|
|
|
|
|
5738
|
|
|
|
|
|
|
#include |
5739
|
|
|
|
|
|
|
#include |
5740
|
|
|
|
|
|
|
|
5741
|
|
|
|
|
|
|
#ifdef __cplusplus |
5742
|
|
|
|
|
|
|
extern "C" { |
5743
|
|
|
|
|
|
|
#endif |
5744
|
|
|
|
|
|
|
|
5745
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
5746
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
5747
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
5748
|
|
|
|
|
|
|
|
5749
|
|
|
|
|
|
|
|
5750
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
5751
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
5752
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
5753
|
|
|
|
|
|
|
# else |
5754
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
5755
|
|
|
|
|
|
|
# endif |
5756
|
|
|
|
|
|
|
#endif |
5757
|
|
|
|
|
|
|
|
5758
|
|
|
|
|
|
|
|
5759
|
|
|
|
|
|
|
|
5760
|
|
|
|
|
|
|
|
5761
|
|
|
|
|
|
|
|
5762
|
|
|
|
|
|
|
struct libdeflate_compressor; |
5763
|
|
|
|
|
|
|
struct libdeflate_options; |
5764
|
|
|
|
|
|
|
|
5765
|
|
|
|
|
|
|
|
5766
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
5767
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
5768
|
|
|
|
|
|
|
|
5769
|
|
|
|
|
|
|
|
5770
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
5771
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
5772
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
5773
|
|
|
|
|
|
|
|
5774
|
|
|
|
|
|
|
|
5775
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5776
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
5777
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5778
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
5779
|
|
|
|
|
|
|
|
5780
|
|
|
|
|
|
|
|
5781
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5782
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
5783
|
|
|
|
|
|
|
size_t in_nbytes); |
5784
|
|
|
|
|
|
|
|
5785
|
|
|
|
|
|
|
|
5786
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5787
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
5788
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5789
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
5790
|
|
|
|
|
|
|
|
5791
|
|
|
|
|
|
|
|
5792
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5793
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
5794
|
|
|
|
|
|
|
size_t in_nbytes); |
5795
|
|
|
|
|
|
|
|
5796
|
|
|
|
|
|
|
|
5797
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5798
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
5799
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5800
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
5801
|
|
|
|
|
|
|
|
5802
|
|
|
|
|
|
|
|
5803
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5804
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
5805
|
|
|
|
|
|
|
size_t in_nbytes); |
5806
|
|
|
|
|
|
|
|
5807
|
|
|
|
|
|
|
|
5808
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
5809
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
5810
|
|
|
|
|
|
|
|
5811
|
|
|
|
|
|
|
|
5812
|
|
|
|
|
|
|
|
5813
|
|
|
|
|
|
|
|
5814
|
|
|
|
|
|
|
|
5815
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
5816
|
|
|
|
|
|
|
struct libdeflate_options; |
5817
|
|
|
|
|
|
|
|
5818
|
|
|
|
|
|
|
|
5819
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
5820
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
5821
|
|
|
|
|
|
|
|
5822
|
|
|
|
|
|
|
|
5823
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
5824
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
5825
|
|
|
|
|
|
|
|
5826
|
|
|
|
|
|
|
|
5827
|
|
|
|
|
|
|
enum libdeflate_result { |
5828
|
|
|
|
|
|
|
|
5829
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
5830
|
|
|
|
|
|
|
|
5831
|
|
|
|
|
|
|
|
5832
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
5833
|
|
|
|
|
|
|
|
5834
|
|
|
|
|
|
|
|
5835
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
5836
|
|
|
|
|
|
|
|
5837
|
|
|
|
|
|
|
|
5838
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
5839
|
|
|
|
|
|
|
}; |
5840
|
|
|
|
|
|
|
|
5841
|
|
|
|
|
|
|
|
5842
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5843
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
5844
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5845
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5846
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5847
|
|
|
|
|
|
|
|
5848
|
|
|
|
|
|
|
|
5849
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5850
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
5851
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5852
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5853
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
5854
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5855
|
|
|
|
|
|
|
|
5856
|
|
|
|
|
|
|
|
5857
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5858
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
5859
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5860
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5861
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5862
|
|
|
|
|
|
|
|
5863
|
|
|
|
|
|
|
|
5864
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5865
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
5866
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5867
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5868
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
5869
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5870
|
|
|
|
|
|
|
|
5871
|
|
|
|
|
|
|
|
5872
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5873
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
5874
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5875
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5876
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5877
|
|
|
|
|
|
|
|
5878
|
|
|
|
|
|
|
|
5879
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5880
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
5881
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5882
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5883
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
5884
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5885
|
|
|
|
|
|
|
|
5886
|
|
|
|
|
|
|
|
5887
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
5888
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
5889
|
|
|
|
|
|
|
|
5890
|
|
|
|
|
|
|
|
5891
|
|
|
|
|
|
|
|
5892
|
|
|
|
|
|
|
|
5893
|
|
|
|
|
|
|
|
5894
|
|
|
|
|
|
|
|
5895
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
5896
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
5897
|
|
|
|
|
|
|
|
5898
|
|
|
|
|
|
|
|
5899
|
|
|
|
|
|
|
|
5900
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
5901
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
5902
|
|
|
|
|
|
|
|
5903
|
|
|
|
|
|
|
|
5904
|
|
|
|
|
|
|
|
5905
|
|
|
|
|
|
|
|
5906
|
|
|
|
|
|
|
|
5907
|
|
|
|
|
|
|
|
5908
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
5909
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
5910
|
|
|
|
|
|
|
void (*free_func)(void *)); |
5911
|
|
|
|
|
|
|
|
5912
|
|
|
|
|
|
|
|
5913
|
|
|
|
|
|
|
struct libdeflate_options { |
5914
|
|
|
|
|
|
|
|
5915
|
|
|
|
|
|
|
|
5916
|
|
|
|
|
|
|
size_t sizeof_options; |
5917
|
|
|
|
|
|
|
|
5918
|
|
|
|
|
|
|
|
5919
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
5920
|
|
|
|
|
|
|
void (*free_func)(void *); |
5921
|
|
|
|
|
|
|
}; |
5922
|
|
|
|
|
|
|
|
5923
|
|
|
|
|
|
|
#ifdef __cplusplus |
5924
|
|
|
|
|
|
|
} |
5925
|
|
|
|
|
|
|
#endif |
5926
|
|
|
|
|
|
|
|
5927
|
|
|
|
|
|
|
#endif |
5928
|
|
|
|
|
|
|
|
5929
|
|
|
|
|
|
|
|
5930
|
|
|
|
|
|
|
#include |
5931
|
|
|
|
|
|
|
#include |
5932
|
|
|
|
|
|
|
#include |
5933
|
|
|
|
|
|
|
#ifdef _MSC_VER |
5934
|
|
|
|
|
|
|
# include |
5935
|
|
|
|
|
|
|
# include |
5936
|
|
|
|
|
|
|
|
5937
|
|
|
|
|
|
|
|
5938
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
5939
|
|
|
|
|
|
|
|
5940
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
5941
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
5942
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
5943
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
5944
|
|
|
|
|
|
|
|
5945
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
5946
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
5947
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
5948
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
5949
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
5950
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
5951
|
|
|
|
|
|
|
#endif |
5952
|
|
|
|
|
|
|
#ifndef FREESTANDING |
5953
|
|
|
|
|
|
|
# include |
5954
|
|
|
|
|
|
|
#endif |
5955
|
|
|
|
|
|
|
|
5956
|
|
|
|
|
|
|
|
5957
|
|
|
|
|
|
|
|
5958
|
|
|
|
|
|
|
|
5959
|
|
|
|
|
|
|
|
5960
|
|
|
|
|
|
|
|
5961
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
5962
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
5963
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
5964
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
5965
|
|
|
|
|
|
|
#ifdef _MSC_VER |
5966
|
|
|
|
|
|
|
# if defined(_M_X64) |
5967
|
|
|
|
|
|
|
# define ARCH_X86_64 |
5968
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
5969
|
|
|
|
|
|
|
# define ARCH_X86_32 |
5970
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
5971
|
|
|
|
|
|
|
# define ARCH_ARM64 |
5972
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
5973
|
|
|
|
|
|
|
# define ARCH_ARM32 |
5974
|
|
|
|
|
|
|
# endif |
5975
|
|
|
|
|
|
|
#else |
5976
|
|
|
|
|
|
|
# if defined(__x86_64__) |
5977
|
|
|
|
|
|
|
# define ARCH_X86_64 |
5978
|
|
|
|
|
|
|
# elif defined(__i386__) |
5979
|
|
|
|
|
|
|
# define ARCH_X86_32 |
5980
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
5981
|
|
|
|
|
|
|
# define ARCH_ARM64 |
5982
|
|
|
|
|
|
|
# elif defined(__arm__) |
5983
|
|
|
|
|
|
|
# define ARCH_ARM32 |
5984
|
|
|
|
|
|
|
# endif |
5985
|
|
|
|
|
|
|
#endif |
5986
|
|
|
|
|
|
|
|
5987
|
|
|
|
|
|
|
|
5988
|
|
|
|
|
|
|
|
5989
|
|
|
|
|
|
|
|
5990
|
|
|
|
|
|
|
|
5991
|
|
|
|
|
|
|
|
5992
|
|
|
|
|
|
|
typedef uint8_t u8; |
5993
|
|
|
|
|
|
|
typedef uint16_t u16; |
5994
|
|
|
|
|
|
|
typedef uint32_t u32; |
5995
|
|
|
|
|
|
|
typedef uint64_t u64; |
5996
|
|
|
|
|
|
|
typedef int8_t s8; |
5997
|
|
|
|
|
|
|
typedef int16_t s16; |
5998
|
|
|
|
|
|
|
typedef int32_t s32; |
5999
|
|
|
|
|
|
|
typedef int64_t s64; |
6000
|
|
|
|
|
|
|
|
6001
|
|
|
|
|
|
|
|
6002
|
|
|
|
|
|
|
#ifdef _MSC_VER |
6003
|
|
|
|
|
|
|
# ifdef _WIN64 |
6004
|
|
|
|
|
|
|
typedef long long ssize_t; |
6005
|
|
|
|
|
|
|
# else |
6006
|
|
|
|
|
|
|
typedef long ssize_t; |
6007
|
|
|
|
|
|
|
# endif |
6008
|
|
|
|
|
|
|
#endif |
6009
|
|
|
|
|
|
|
|
6010
|
|
|
|
|
|
|
|
6011
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
6012
|
|
|
|
|
|
|
|
6013
|
|
|
|
|
|
|
|
6014
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
6015
|
|
|
|
|
|
|
|
6016
|
|
|
|
|
|
|
|
6017
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
6018
|
|
|
|
|
|
|
|
6019
|
|
|
|
|
|
|
|
6020
|
|
|
|
|
|
|
|
6021
|
|
|
|
|
|
|
|
6022
|
|
|
|
|
|
|
|
6023
|
|
|
|
|
|
|
|
6024
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
6025
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
6026
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
6027
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
6028
|
|
|
|
|
|
|
#else |
6029
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
6030
|
|
|
|
|
|
|
#endif |
6031
|
|
|
|
|
|
|
#ifdef __clang__ |
6032
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
6033
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
6034
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
6035
|
|
|
|
|
|
|
# else |
6036
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
6037
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
6038
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
6039
|
|
|
|
|
|
|
# endif |
6040
|
|
|
|
|
|
|
#else |
6041
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
6042
|
|
|
|
|
|
|
#endif |
6043
|
|
|
|
|
|
|
|
6044
|
|
|
|
|
|
|
|
6045
|
|
|
|
|
|
|
#ifndef __has_attribute |
6046
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
6047
|
|
|
|
|
|
|
#endif |
6048
|
|
|
|
|
|
|
#ifndef __has_builtin |
6049
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
6050
|
|
|
|
|
|
|
#endif |
6051
|
|
|
|
|
|
|
|
6052
|
|
|
|
|
|
|
|
6053
|
|
|
|
|
|
|
#ifdef _MSC_VER |
6054
|
|
|
|
|
|
|
# define inline __inline |
6055
|
|
|
|
|
|
|
#endif |
6056
|
|
|
|
|
|
|
|
6057
|
|
|
|
|
|
|
|
6058
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
6059
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
6060
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6061
|
|
|
|
|
|
|
# define forceinline __forceinline |
6062
|
|
|
|
|
|
|
#else |
6063
|
|
|
|
|
|
|
# define forceinline inline |
6064
|
|
|
|
|
|
|
#endif |
6065
|
|
|
|
|
|
|
|
6066
|
|
|
|
|
|
|
|
6067
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
6068
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
6069
|
|
|
|
|
|
|
#else |
6070
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
6071
|
|
|
|
|
|
|
#endif |
6072
|
|
|
|
|
|
|
|
6073
|
|
|
|
|
|
|
|
6074
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
6075
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
6076
|
|
|
|
|
|
|
# define restrict __restrict__ |
6077
|
|
|
|
|
|
|
# else |
6078
|
|
|
|
|
|
|
# define restrict |
6079
|
|
|
|
|
|
|
# endif |
6080
|
|
|
|
|
|
|
#endif |
6081
|
|
|
|
|
|
|
|
6082
|
|
|
|
|
|
|
|
6083
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
6084
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
6085
|
|
|
|
|
|
|
#else |
6086
|
|
|
|
|
|
|
# define likely(expr) (expr) |
6087
|
|
|
|
|
|
|
#endif |
6088
|
|
|
|
|
|
|
|
6089
|
|
|
|
|
|
|
|
6090
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
6091
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
6092
|
|
|
|
|
|
|
#else |
6093
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
6094
|
|
|
|
|
|
|
#endif |
6095
|
|
|
|
|
|
|
|
6096
|
|
|
|
|
|
|
|
6097
|
|
|
|
|
|
|
#undef prefetchr |
6098
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
6099
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
6100
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6101
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
6102
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
6103
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
6104
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
6105
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
6106
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
6107
|
|
|
|
|
|
|
# endif |
6108
|
|
|
|
|
|
|
#endif |
6109
|
|
|
|
|
|
|
#ifndef prefetchr |
6110
|
|
|
|
|
|
|
# define prefetchr(addr) |
6111
|
|
|
|
|
|
|
#endif |
6112
|
|
|
|
|
|
|
|
6113
|
|
|
|
|
|
|
|
6114
|
|
|
|
|
|
|
#undef prefetchw |
6115
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
6116
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
6117
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6118
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
6119
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
6120
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
6121
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
6122
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
6123
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
6124
|
|
|
|
|
|
|
# endif |
6125
|
|
|
|
|
|
|
#endif |
6126
|
|
|
|
|
|
|
#ifndef prefetchw |
6127
|
|
|
|
|
|
|
# define prefetchw(addr) |
6128
|
|
|
|
|
|
|
#endif |
6129
|
|
|
|
|
|
|
|
6130
|
|
|
|
|
|
|
|
6131
|
|
|
|
|
|
|
#undef _aligned_attribute |
6132
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
6133
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
6134
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6135
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
6136
|
|
|
|
|
|
|
#endif |
6137
|
|
|
|
|
|
|
|
6138
|
|
|
|
|
|
|
|
6139
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
6140
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
6141
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
6142
|
|
|
|
|
|
|
#else |
6143
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
6144
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
6145
|
|
|
|
|
|
|
#endif |
6146
|
|
|
|
|
|
|
|
6147
|
|
|
|
|
|
|
|
6148
|
|
|
|
|
|
|
|
6149
|
|
|
|
|
|
|
|
6150
|
|
|
|
|
|
|
|
6151
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
6152
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
6153
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
6154
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
6155
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
6156
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
6157
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
6158
|
|
|
|
|
|
|
|
6159
|
|
|
|
|
|
|
|
6160
|
|
|
|
|
|
|
|
6161
|
|
|
|
|
|
|
|
6162
|
|
|
|
|
|
|
|
6163
|
|
|
|
|
|
|
|
6164
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
6165
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
6166
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6167
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
6168
|
|
|
|
|
|
|
#else |
6169
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
6170
|
|
|
|
|
|
|
{ |
6171
|
|
|
|
|
|
|
union { |
6172
|
|
|
|
|
|
|
u32 w; |
6173
|
|
|
|
|
|
|
u8 b; |
6174
|
|
|
|
|
|
|
} u; |
6175
|
|
|
|
|
|
|
|
6176
|
|
|
|
|
|
|
u.w = 1; |
6177
|
|
|
|
|
|
|
return u.b; |
6178
|
|
|
|
|
|
|
} |
6179
|
|
|
|
|
|
|
#endif |
6180
|
|
|
|
|
|
|
|
6181
|
|
|
|
|
|
|
|
6182
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
6183
|
|
|
|
|
|
|
{ |
6184
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
6185
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
6186
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6187
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
6188
|
|
|
|
|
|
|
#else |
6189
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
6190
|
|
|
|
|
|
|
#endif |
6191
|
|
|
|
|
|
|
} |
6192
|
|
|
|
|
|
|
|
6193
|
|
|
|
|
|
|
|
6194
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
6195
|
|
|
|
|
|
|
{ |
6196
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
6197
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
6198
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6199
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
6200
|
|
|
|
|
|
|
#else |
6201
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
6202
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
6203
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
6204
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
6205
|
|
|
|
|
|
|
#endif |
6206
|
|
|
|
|
|
|
} |
6207
|
|
|
|
|
|
|
|
6208
|
|
|
|
|
|
|
|
6209
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
6210
|
|
|
|
|
|
|
{ |
6211
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
6212
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
6213
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6214
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
6215
|
|
|
|
|
|
|
#else |
6216
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
6217
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
6218
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
6219
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
6220
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
6221
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
6222
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
6223
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
6224
|
|
|
|
|
|
|
#endif |
6225
|
|
|
|
|
|
|
} |
6226
|
|
|
|
|
|
|
|
6227
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
6228
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
6229
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
6230
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
6231
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
6232
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
6233
|
|
|
|
|
|
|
|
6234
|
|
|
|
|
|
|
|
6235
|
|
|
|
|
|
|
|
6236
|
|
|
|
|
|
|
|
6237
|
|
|
|
|
|
|
|
6238
|
|
|
|
|
|
|
|
6239
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
6240
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
6241
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
6242
|
|
|
|
|
|
|
defined(__wasm__)) |
6243
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
6244
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6245
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
6246
|
|
|
|
|
|
|
#else |
6247
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
6248
|
|
|
|
|
|
|
#endif |
6249
|
|
|
|
|
|
|
|
6250
|
|
|
|
|
|
|
|
6251
|
|
|
|
|
|
|
|
6252
|
|
|
|
|
|
|
#ifdef FREESTANDING |
6253
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
6254
|
|
|
|
|
|
|
#else |
6255
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
6256
|
|
|
|
|
|
|
#endif |
6257
|
|
|
|
|
|
|
|
6258
|
|
|
|
|
|
|
|
6259
|
|
|
|
|
|
|
|
6260
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
6261
|
|
|
|
|
|
|
static forceinline type \ |
6262
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
6263
|
|
|
|
|
|
|
{ \ |
6264
|
|
|
|
|
|
|
type v; \ |
6265
|
|
|
|
|
|
|
\ |
6266
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
6267
|
|
|
|
|
|
|
return v; \ |
6268
|
|
|
|
|
|
|
} \ |
6269
|
|
|
|
|
|
|
\ |
6270
|
|
|
|
|
|
|
static forceinline void \ |
6271
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
6272
|
|
|
|
|
|
|
{ \ |
6273
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
6274
|
|
|
|
|
|
|
} |
6275
|
|
|
|
|
|
|
|
6276
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
6277
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
6278
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
6279
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
6280
|
|
|
|
|
|
|
|
6281
|
|
|
|
|
|
|
#undef MEMCOPY |
6282
|
|
|
|
|
|
|
|
6283
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
6284
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
6285
|
|
|
|
|
|
|
|
6286
|
|
|
|
|
|
|
|
6287
|
|
|
|
|
|
|
|
6288
|
|
|
|
|
|
|
static forceinline u16 |
6289
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
6290
|
|
|
|
|
|
|
{ |
6291
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6292
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
6293
|
|
|
|
|
|
|
else |
6294
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
6295
|
|
|
|
|
|
|
} |
6296
|
|
|
|
|
|
|
|
6297
|
|
|
|
|
|
|
static forceinline u16 |
6298
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
6299
|
|
|
|
|
|
|
{ |
6300
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6301
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
6302
|
|
|
|
|
|
|
else |
6303
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
6304
|
|
|
|
|
|
|
} |
6305
|
|
|
|
|
|
|
|
6306
|
|
|
|
|
|
|
static forceinline u32 |
6307
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
6308
|
|
|
|
|
|
|
{ |
6309
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6310
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
6311
|
|
|
|
|
|
|
else |
6312
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
6313
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
6314
|
|
|
|
|
|
|
} |
6315
|
|
|
|
|
|
|
|
6316
|
|
|
|
|
|
|
static forceinline u32 |
6317
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
6318
|
|
|
|
|
|
|
{ |
6319
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6320
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
6321
|
|
|
|
|
|
|
else |
6322
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
6323
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
6324
|
|
|
|
|
|
|
} |
6325
|
|
|
|
|
|
|
|
6326
|
|
|
|
|
|
|
static forceinline u64 |
6327
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
6328
|
|
|
|
|
|
|
{ |
6329
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6330
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
6331
|
|
|
|
|
|
|
else |
6332
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
6333
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
6334
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
6335
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
6336
|
|
|
|
|
|
|
} |
6337
|
|
|
|
|
|
|
|
6338
|
|
|
|
|
|
|
static forceinline machine_word_t |
6339
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
6340
|
|
|
|
|
|
|
{ |
6341
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
6342
|
|
|
|
|
|
|
if (WORDBITS == 32) |
6343
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
6344
|
|
|
|
|
|
|
else |
6345
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
6346
|
|
|
|
|
|
|
} |
6347
|
|
|
|
|
|
|
|
6348
|
|
|
|
|
|
|
|
6349
|
|
|
|
|
|
|
|
6350
|
|
|
|
|
|
|
static forceinline void |
6351
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
6352
|
|
|
|
|
|
|
{ |
6353
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6354
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
6355
|
|
|
|
|
|
|
} else { |
6356
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
6357
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
6358
|
|
|
|
|
|
|
} |
6359
|
|
|
|
|
|
|
} |
6360
|
|
|
|
|
|
|
|
6361
|
|
|
|
|
|
|
static forceinline void |
6362
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
6363
|
|
|
|
|
|
|
{ |
6364
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6365
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
6366
|
|
|
|
|
|
|
} else { |
6367
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
6368
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
6369
|
|
|
|
|
|
|
} |
6370
|
|
|
|
|
|
|
} |
6371
|
|
|
|
|
|
|
|
6372
|
|
|
|
|
|
|
static forceinline void |
6373
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
6374
|
|
|
|
|
|
|
{ |
6375
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6376
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
6377
|
|
|
|
|
|
|
} else { |
6378
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
6379
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
6380
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
6381
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
6382
|
|
|
|
|
|
|
} |
6383
|
|
|
|
|
|
|
} |
6384
|
|
|
|
|
|
|
|
6385
|
|
|
|
|
|
|
static forceinline void |
6386
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
6387
|
|
|
|
|
|
|
{ |
6388
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6389
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
6390
|
|
|
|
|
|
|
} else { |
6391
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
6392
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
6393
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
6394
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
6395
|
|
|
|
|
|
|
} |
6396
|
|
|
|
|
|
|
} |
6397
|
|
|
|
|
|
|
|
6398
|
|
|
|
|
|
|
static forceinline void |
6399
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
6400
|
|
|
|
|
|
|
{ |
6401
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6402
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
6403
|
|
|
|
|
|
|
} else { |
6404
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
6405
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
6406
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
6407
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
6408
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
6409
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
6410
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
6411
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
6412
|
|
|
|
|
|
|
} |
6413
|
|
|
|
|
|
|
} |
6414
|
|
|
|
|
|
|
|
6415
|
|
|
|
|
|
|
static forceinline void |
6416
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
6417
|
|
|
|
|
|
|
{ |
6418
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
6419
|
|
|
|
|
|
|
if (WORDBITS == 32) |
6420
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
6421
|
|
|
|
|
|
|
else |
6422
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
6423
|
|
|
|
|
|
|
} |
6424
|
|
|
|
|
|
|
|
6425
|
|
|
|
|
|
|
|
6426
|
|
|
|
|
|
|
|
6427
|
|
|
|
|
|
|
|
6428
|
|
|
|
|
|
|
|
6429
|
|
|
|
|
|
|
|
6430
|
|
|
|
|
|
|
|
6431
|
|
|
|
|
|
|
static forceinline unsigned |
6432
|
|
|
|
|
|
|
bsr32(u32 v) |
6433
|
|
|
|
|
|
|
{ |
6434
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
6435
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
6436
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6437
|
|
|
|
|
|
|
unsigned long i; |
6438
|
|
|
|
|
|
|
|
6439
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
6440
|
|
|
|
|
|
|
return i; |
6441
|
|
|
|
|
|
|
#else |
6442
|
|
|
|
|
|
|
unsigned i = 0; |
6443
|
|
|
|
|
|
|
|
6444
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
6445
|
|
|
|
|
|
|
i++; |
6446
|
|
|
|
|
|
|
return i; |
6447
|
|
|
|
|
|
|
#endif |
6448
|
|
|
|
|
|
|
} |
6449
|
|
|
|
|
|
|
|
6450
|
|
|
|
|
|
|
static forceinline unsigned |
6451
|
|
|
|
|
|
|
bsr64(u64 v) |
6452
|
|
|
|
|
|
|
{ |
6453
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
6454
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
6455
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
6456
|
|
|
|
|
|
|
unsigned long i; |
6457
|
|
|
|
|
|
|
|
6458
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
6459
|
|
|
|
|
|
|
return i; |
6460
|
|
|
|
|
|
|
#else |
6461
|
|
|
|
|
|
|
unsigned i = 0; |
6462
|
|
|
|
|
|
|
|
6463
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
6464
|
|
|
|
|
|
|
i++; |
6465
|
|
|
|
|
|
|
return i; |
6466
|
|
|
|
|
|
|
#endif |
6467
|
|
|
|
|
|
|
} |
6468
|
|
|
|
|
|
|
|
6469
|
|
|
|
|
|
|
static forceinline unsigned |
6470
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
6471
|
|
|
|
|
|
|
{ |
6472
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
6473
|
|
|
|
|
|
|
if (WORDBITS == 32) |
6474
|
|
|
|
|
|
|
return bsr32(v); |
6475
|
|
|
|
|
|
|
else |
6476
|
|
|
|
|
|
|
return bsr64(v); |
6477
|
|
|
|
|
|
|
} |
6478
|
|
|
|
|
|
|
|
6479
|
|
|
|
|
|
|
|
6480
|
|
|
|
|
|
|
|
6481
|
|
|
|
|
|
|
static forceinline unsigned |
6482
|
|
|
|
|
|
|
bsf32(u32 v) |
6483
|
|
|
|
|
|
|
{ |
6484
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
6485
|
|
|
|
|
|
|
return __builtin_ctz(v); |
6486
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6487
|
|
|
|
|
|
|
unsigned long i; |
6488
|
|
|
|
|
|
|
|
6489
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
6490
|
|
|
|
|
|
|
return i; |
6491
|
|
|
|
|
|
|
#else |
6492
|
|
|
|
|
|
|
unsigned i = 0; |
6493
|
|
|
|
|
|
|
|
6494
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
6495
|
|
|
|
|
|
|
i++; |
6496
|
|
|
|
|
|
|
return i; |
6497
|
|
|
|
|
|
|
#endif |
6498
|
|
|
|
|
|
|
} |
6499
|
|
|
|
|
|
|
|
6500
|
|
|
|
|
|
|
static forceinline unsigned |
6501
|
|
|
|
|
|
|
bsf64(u64 v) |
6502
|
|
|
|
|
|
|
{ |
6503
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
6504
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
6505
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
6506
|
|
|
|
|
|
|
unsigned long i; |
6507
|
|
|
|
|
|
|
|
6508
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
6509
|
|
|
|
|
|
|
return i; |
6510
|
|
|
|
|
|
|
#else |
6511
|
|
|
|
|
|
|
unsigned i = 0; |
6512
|
|
|
|
|
|
|
|
6513
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
6514
|
|
|
|
|
|
|
i++; |
6515
|
|
|
|
|
|
|
return i; |
6516
|
|
|
|
|
|
|
#endif |
6517
|
|
|
|
|
|
|
} |
6518
|
|
|
|
|
|
|
|
6519
|
|
|
|
|
|
|
static forceinline unsigned |
6520
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
6521
|
|
|
|
|
|
|
{ |
6522
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
6523
|
|
|
|
|
|
|
if (WORDBITS == 32) |
6524
|
|
|
|
|
|
|
return bsf32(v); |
6525
|
|
|
|
|
|
|
else |
6526
|
|
|
|
|
|
|
return bsf64(v); |
6527
|
|
|
|
|
|
|
} |
6528
|
|
|
|
|
|
|
|
6529
|
|
|
|
|
|
|
|
6530
|
|
|
|
|
|
|
#undef rbit32 |
6531
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
6532
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
6533
|
|
|
|
|
|
|
static forceinline u32 |
6534
|
|
|
|
|
|
|
rbit32(u32 v) |
6535
|
|
|
|
|
|
|
{ |
6536
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
6537
|
|
|
|
|
|
|
return v; |
6538
|
|
|
|
|
|
|
} |
6539
|
|
|
|
|
|
|
#define rbit32 rbit32 |
6540
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
6541
|
|
|
|
|
|
|
static forceinline u32 |
6542
|
|
|
|
|
|
|
rbit32(u32 v) |
6543
|
|
|
|
|
|
|
{ |
6544
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
6545
|
|
|
|
|
|
|
return v; |
6546
|
|
|
|
|
|
|
} |
6547
|
|
|
|
|
|
|
#define rbit32 rbit32 |
6548
|
|
|
|
|
|
|
#endif |
6549
|
|
|
|
|
|
|
|
6550
|
|
|
|
|
|
|
#endif |
6551
|
|
|
|
|
|
|
|
6552
|
|
|
|
|
|
|
|
6553
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
6554
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
6555
|
|
|
|
|
|
|
|
6556
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
6557
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
6558
|
|
|
|
|
|
|
|
6559
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
6560
|
|
|
|
|
|
|
size_t alignment, size_t size); |
6561
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
6562
|
|
|
|
|
|
|
|
6563
|
|
|
|
|
|
|
#ifdef FREESTANDING |
6564
|
|
|
|
|
|
|
|
6565
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
6566
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
6567
|
|
|
|
|
|
|
|
6568
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
6569
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
6570
|
|
|
|
|
|
|
|
6571
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
6572
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
6573
|
|
|
|
|
|
|
|
6574
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
6575
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
6576
|
|
|
|
|
|
|
|
6577
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
6578
|
|
|
|
|
|
|
#else |
6579
|
|
|
|
|
|
|
#include |
6580
|
|
|
|
|
|
|
#endif |
6581
|
|
|
|
|
|
|
|
6582
|
|
|
|
|
|
|
|
6583
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
6584
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
6585
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
6586
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
6587
|
|
|
|
|
|
|
#else |
6588
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
6589
|
|
|
|
|
|
|
#endif |
6590
|
|
|
|
|
|
|
|
6591
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
6592
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
6593
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
6594
|
|
|
|
|
|
|
|
6595
|
|
|
|
|
|
|
#endif |
6596
|
|
|
|
|
|
|
|
6597
|
|
|
|
|
|
|
|
6598
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
6599
|
|
|
|
|
|
|
|
6600
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
6601
|
|
|
|
|
|
|
|
6602
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
6603
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
6604
|
|
|
|
|
|
|
(defined(__linux__) || \ |
6605
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
6606
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
6607
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
6608
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
6609
|
|
|
|
|
|
|
#endif |
6610
|
|
|
|
|
|
|
|
6611
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
6612
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
6613
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
6614
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
6615
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
6616
|
|
|
|
|
|
|
|
6617
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
6618
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
6619
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
6620
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
6621
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
6622
|
|
|
|
|
|
|
|
6623
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
6624
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
6625
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
6626
|
|
|
|
|
|
|
|
6627
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
6628
|
|
|
|
|
|
|
|
6629
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
6630
|
|
|
|
|
|
|
{ |
6631
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
6632
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
6633
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
6634
|
|
|
|
|
|
|
} |
6635
|
|
|
|
|
|
|
#else |
6636
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
6637
|
|
|
|
|
|
|
#endif |
6638
|
|
|
|
|
|
|
|
6639
|
|
|
|
|
|
|
|
6640
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
6641
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
6642
|
|
|
|
|
|
|
#else |
6643
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
6644
|
|
|
|
|
|
|
#endif |
6645
|
|
|
|
|
|
|
|
6646
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
6647
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
6648
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
6649
|
|
|
|
|
|
|
#else |
6650
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
6651
|
|
|
|
|
|
|
#endif |
6652
|
|
|
|
|
|
|
|
6653
|
|
|
|
|
|
|
|
6654
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
6655
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
6656
|
|
|
|
|
|
|
#else |
6657
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
6658
|
|
|
|
|
|
|
#endif |
6659
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
6660
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
6661
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
6662
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
6663
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
6664
|
|
|
|
|
|
|
\ |
6665
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
6666
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
6667
|
|
|
|
|
|
|
|
6668
|
|
|
|
|
|
|
# ifdef _MSC_VER |
6669
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
6670
|
|
|
|
|
|
|
# else |
6671
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
6672
|
|
|
|
|
|
|
# endif |
6673
|
|
|
|
|
|
|
#else |
6674
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
6675
|
|
|
|
|
|
|
#endif |
6676
|
|
|
|
|
|
|
|
6677
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
6678
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
6679
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
6680
|
|
|
|
|
|
|
#else |
6681
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
6682
|
|
|
|
|
|
|
#endif |
6683
|
|
|
|
|
|
|
|
6684
|
|
|
|
|
|
|
|
6685
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
6686
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
6687
|
|
|
|
|
|
|
#else |
6688
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
6689
|
|
|
|
|
|
|
#endif |
6690
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
6691
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
6692
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
6693
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
6694
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
6695
|
|
|
|
|
|
|
|
6696
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
6697
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
6698
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
6699
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
6700
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
6701
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
6702
|
|
|
|
|
|
|
# endif |
6703
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
6704
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
6705
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
6706
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
6707
|
|
|
|
|
|
|
# endif |
6708
|
|
|
|
|
|
|
#endif |
6709
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
6710
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
6711
|
|
|
|
|
|
|
#endif |
6712
|
|
|
|
|
|
|
|
6713
|
|
|
|
|
|
|
|
6714
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
6715
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
6716
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
6717
|
|
|
|
|
|
|
# else |
6718
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
6719
|
|
|
|
|
|
|
# endif |
6720
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
6721
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
6722
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
6723
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
6724
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
6725
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
6726
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
6727
|
|
|
|
|
|
|
#else |
6728
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
6729
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
6730
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
6731
|
|
|
|
|
|
|
#endif |
6732
|
|
|
|
|
|
|
|
6733
|
|
|
|
|
|
|
|
6734
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
6735
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
6736
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
6737
|
|
|
|
|
|
|
# else |
6738
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
6739
|
|
|
|
|
|
|
# endif |
6740
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
6741
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
6742
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
6743
|
|
|
|
|
|
|
defined(_MSC_VER))) |
6744
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
6745
|
|
|
|
|
|
|
# else |
6746
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
6747
|
|
|
|
|
|
|
# endif |
6748
|
|
|
|
|
|
|
#else |
6749
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
6750
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
6751
|
|
|
|
|
|
|
#endif |
6752
|
|
|
|
|
|
|
|
6753
|
|
|
|
|
|
|
|
6754
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
6755
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
6756
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
6757
|
|
|
|
|
|
|
#endif |
6758
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
6759
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
6760
|
|
|
|
|
|
|
#endif |
6761
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
6762
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
6763
|
|
|
|
|
|
|
#endif |
6764
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
6765
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
6766
|
|
|
|
|
|
|
# include |
6767
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
6768
|
|
|
|
|
|
|
#endif |
6769
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
6770
|
|
|
|
|
|
|
# include |
6771
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
6772
|
|
|
|
|
|
|
#endif |
6773
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
6774
|
|
|
|
|
|
|
# include |
6775
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
6776
|
|
|
|
|
|
|
#endif |
6777
|
|
|
|
|
|
|
|
6778
|
|
|
|
|
|
|
#endif |
6779
|
|
|
|
|
|
|
|
6780
|
|
|
|
|
|
|
#endif |
6781
|
|
|
|
|
|
|
|
6782
|
|
|
|
|
|
|
|
6783
|
|
|
|
|
|
|
|
6784
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN |
6785
|
|
|
|
|
|
|
# if HAVE_CRC32_NATIVE |
6786
|
|
|
|
|
|
|
# define ATTRIBUTES |
6787
|
|
|
|
|
|
|
# else |
6788
|
|
|
|
|
|
|
# ifdef ARCH_ARM32 |
6789
|
|
|
|
|
|
|
# ifdef __clang__ |
6790
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("armv8-a,crc") |
6791
|
|
|
|
|
|
|
# elif defined(__ARM_PCS_VFP) |
6792
|
|
|
|
|
|
|
|
6793
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8-a+crc+simd") |
6794
|
|
|
|
|
|
|
# else |
6795
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8-a+crc") |
6796
|
|
|
|
|
|
|
# endif |
6797
|
|
|
|
|
|
|
# else |
6798
|
|
|
|
|
|
|
# ifdef __clang__ |
6799
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("crc") |
6800
|
|
|
|
|
|
|
# else |
6801
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crc") |
6802
|
|
|
|
|
|
|
# endif |
6803
|
|
|
|
|
|
|
# endif |
6804
|
|
|
|
|
|
|
# endif |
6805
|
|
|
|
|
|
|
|
6806
|
|
|
|
|
|
|
#ifndef _MSC_VER |
6807
|
|
|
|
|
|
|
# include |
6808
|
|
|
|
|
|
|
#endif |
6809
|
|
|
|
|
|
|
|
6810
|
|
|
|
|
|
|
|
6811
|
|
|
|
|
|
|
static forceinline ATTRIBUTES u32 |
6812
|
|
|
|
|
|
|
combine_crcs_slow(u32 crc0, u32 crc1, u32 crc2, u32 crc3) |
6813
|
|
|
|
|
|
|
{ |
6814
|
|
|
|
|
|
|
u64 res0 = 0, res1 = 0, res2 = 0; |
6815
|
|
|
|
|
|
|
int i; |
6816
|
|
|
|
|
|
|
|
6817
|
|
|
|
|
|
|
|
6818
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) { |
6819
|
|
|
|
|
|
|
if (CRC32_FIXED_CHUNK_MULT_3 & (1U << i)) |
6820
|
|
|
|
|
|
|
res0 ^= (u64)crc0 << i; |
6821
|
|
|
|
|
|
|
if (CRC32_FIXED_CHUNK_MULT_2 & (1U << i)) |
6822
|
|
|
|
|
|
|
res1 ^= (u64)crc1 << i; |
6823
|
|
|
|
|
|
|
if (CRC32_FIXED_CHUNK_MULT_1 & (1U << i)) |
6824
|
|
|
|
|
|
|
res2 ^= (u64)crc2 << i; |
6825
|
|
|
|
|
|
|
} |
6826
|
|
|
|
|
|
|
|
6827
|
|
|
|
|
|
|
return __crc32d(0, res0 ^ res1 ^ res2) ^ crc3; |
6828
|
|
|
|
|
|
|
} |
6829
|
|
|
|
|
|
|
|
6830
|
|
|
|
|
|
|
#define crc32_arm_crc crc32_arm_crc |
6831
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
6832
|
|
|
|
|
|
|
crc32_arm_crc(u32 crc, const u8 *p, size_t len) |
6833
|
|
|
|
|
|
|
{ |
6834
|
|
|
|
|
|
|
if (len >= 64) { |
6835
|
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 7; |
6836
|
|
|
|
|
|
|
|
6837
|
|
|
|
|
|
|
|
6838
|
|
|
|
|
|
|
if (align) { |
6839
|
|
|
|
|
|
|
if (align & 1) |
6840
|
|
|
|
|
|
|
crc = __crc32b(crc, *p++); |
6841
|
|
|
|
|
|
|
if (align & 2) { |
6842
|
|
|
|
|
|
|
crc = __crc32h(crc, le16_bswap(*(u16 *)p)); |
6843
|
|
|
|
|
|
|
p += 2; |
6844
|
|
|
|
|
|
|
} |
6845
|
|
|
|
|
|
|
if (align & 4) { |
6846
|
|
|
|
|
|
|
crc = __crc32w(crc, le32_bswap(*(u32 *)p)); |
6847
|
|
|
|
|
|
|
p += 4; |
6848
|
|
|
|
|
|
|
} |
6849
|
|
|
|
|
|
|
len -= align; |
6850
|
|
|
|
|
|
|
} |
6851
|
|
|
|
|
|
|
|
6852
|
|
|
|
|
|
|
while (len >= CRC32_NUM_CHUNKS * CRC32_FIXED_CHUNK_LEN) { |
6853
|
|
|
|
|
|
|
const u64 *wp0 = (const u64 *)p; |
6854
|
|
|
|
|
|
|
const u64 * const wp0_end = |
6855
|
|
|
|
|
|
|
(const u64 *)(p + CRC32_FIXED_CHUNK_LEN); |
6856
|
|
|
|
|
|
|
u32 crc1 = 0, crc2 = 0, crc3 = 0; |
6857
|
|
|
|
|
|
|
|
6858
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_NUM_CHUNKS == 4); |
6859
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_FIXED_CHUNK_LEN % (4 * 8) == 0); |
6860
|
|
|
|
|
|
|
do { |
6861
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 0*CRC32_FIXED_CHUNK_LEN/8]); |
6862
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 1*CRC32_FIXED_CHUNK_LEN/8]); |
6863
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 2*CRC32_FIXED_CHUNK_LEN/8]); |
6864
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 3*CRC32_FIXED_CHUNK_LEN/8]); |
6865
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_FIXED_CHUNK_LEN/8])); |
6866
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_FIXED_CHUNK_LEN/8])); |
6867
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_FIXED_CHUNK_LEN/8])); |
6868
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_FIXED_CHUNK_LEN/8])); |
6869
|
|
|
|
|
|
|
wp0++; |
6870
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_FIXED_CHUNK_LEN/8])); |
6871
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_FIXED_CHUNK_LEN/8])); |
6872
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_FIXED_CHUNK_LEN/8])); |
6873
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_FIXED_CHUNK_LEN/8])); |
6874
|
|
|
|
|
|
|
wp0++; |
6875
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_FIXED_CHUNK_LEN/8])); |
6876
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_FIXED_CHUNK_LEN/8])); |
6877
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_FIXED_CHUNK_LEN/8])); |
6878
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_FIXED_CHUNK_LEN/8])); |
6879
|
|
|
|
|
|
|
wp0++; |
6880
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_FIXED_CHUNK_LEN/8])); |
6881
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_FIXED_CHUNK_LEN/8])); |
6882
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_FIXED_CHUNK_LEN/8])); |
6883
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_FIXED_CHUNK_LEN/8])); |
6884
|
|
|
|
|
|
|
wp0++; |
6885
|
|
|
|
|
|
|
} while (wp0 != wp0_end); |
6886
|
|
|
|
|
|
|
crc = combine_crcs_slow(crc, crc1, crc2, crc3); |
6887
|
|
|
|
|
|
|
p += CRC32_NUM_CHUNKS * CRC32_FIXED_CHUNK_LEN; |
6888
|
|
|
|
|
|
|
len -= CRC32_NUM_CHUNKS * CRC32_FIXED_CHUNK_LEN; |
6889
|
|
|
|
|
|
|
} |
6890
|
|
|
|
|
|
|
|
6891
|
|
|
|
|
|
|
while (len >= 64) { |
6892
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 0))); |
6893
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 8))); |
6894
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 16))); |
6895
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 24))); |
6896
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 32))); |
6897
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 40))); |
6898
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 48))); |
6899
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 56))); |
6900
|
|
|
|
|
|
|
p += 64; |
6901
|
|
|
|
|
|
|
len -= 64; |
6902
|
|
|
|
|
|
|
} |
6903
|
|
|
|
|
|
|
} |
6904
|
|
|
|
|
|
|
if (len & 32) { |
6905
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 0)); |
6906
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 8)); |
6907
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 16)); |
6908
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 24)); |
6909
|
|
|
|
|
|
|
p += 32; |
6910
|
|
|
|
|
|
|
} |
6911
|
|
|
|
|
|
|
if (len & 16) { |
6912
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 0)); |
6913
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 8)); |
6914
|
|
|
|
|
|
|
p += 16; |
6915
|
|
|
|
|
|
|
} |
6916
|
|
|
|
|
|
|
if (len & 8) { |
6917
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p)); |
6918
|
|
|
|
|
|
|
p += 8; |
6919
|
|
|
|
|
|
|
} |
6920
|
|
|
|
|
|
|
if (len & 4) { |
6921
|
|
|
|
|
|
|
crc = __crc32w(crc, get_unaligned_le32(p)); |
6922
|
|
|
|
|
|
|
p += 4; |
6923
|
|
|
|
|
|
|
} |
6924
|
|
|
|
|
|
|
if (len & 2) { |
6925
|
|
|
|
|
|
|
crc = __crc32h(crc, get_unaligned_le16(p)); |
6926
|
|
|
|
|
|
|
p += 2; |
6927
|
|
|
|
|
|
|
} |
6928
|
|
|
|
|
|
|
if (len & 1) |
6929
|
|
|
|
|
|
|
crc = __crc32b(crc, *p); |
6930
|
|
|
|
|
|
|
return crc; |
6931
|
|
|
|
|
|
|
} |
6932
|
|
|
|
|
|
|
#undef ATTRIBUTES |
6933
|
|
|
|
|
|
|
#endif |
6934
|
|
|
|
|
|
|
|
6935
|
|
|
|
|
|
|
|
6936
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && HAVE_PMULL_INTRIN |
6937
|
|
|
|
|
|
|
# if HAVE_CRC32_NATIVE && HAVE_PMULL_NATIVE && !USE_PMULL_TARGET_EVEN_IF_NATIVE |
6938
|
|
|
|
|
|
|
# define ATTRIBUTES |
6939
|
|
|
|
|
|
|
# else |
6940
|
|
|
|
|
|
|
# ifdef ARCH_ARM32 |
6941
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8-a+crc,fpu=crypto-neon-fp-armv8") |
6942
|
|
|
|
|
|
|
# else |
6943
|
|
|
|
|
|
|
# ifdef __clang__ |
6944
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("crc,aes") |
6945
|
|
|
|
|
|
|
# else |
6946
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crc,+crypto") |
6947
|
|
|
|
|
|
|
# endif |
6948
|
|
|
|
|
|
|
# endif |
6949
|
|
|
|
|
|
|
# endif |
6950
|
|
|
|
|
|
|
|
6951
|
|
|
|
|
|
|
#ifndef _MSC_VER |
6952
|
|
|
|
|
|
|
# include |
6953
|
|
|
|
|
|
|
#endif |
6954
|
|
|
|
|
|
|
#include |
6955
|
|
|
|
|
|
|
|
6956
|
|
|
|
|
|
|
|
6957
|
|
|
|
|
|
|
static forceinline ATTRIBUTES u64 |
6958
|
|
|
|
|
|
|
clmul_u32(u32 a, u32 b) |
6959
|
|
|
|
|
|
|
{ |
6960
|
|
|
|
|
|
|
uint64x2_t res = vreinterpretq_u64_p128( |
6961
|
|
|
|
|
|
|
compat_vmull_p64((poly64_t)a, (poly64_t)b)); |
6962
|
|
|
|
|
|
|
|
6963
|
|
|
|
|
|
|
return vgetq_lane_u64(res, 0); |
6964
|
|
|
|
|
|
|
} |
6965
|
|
|
|
|
|
|
|
6966
|
|
|
|
|
|
|
|
6967
|
|
|
|
|
|
|
static forceinline ATTRIBUTES u32 |
6968
|
|
|
|
|
|
|
combine_crcs_fast(u32 crc0, u32 crc1, u32 crc2, u32 crc3, size_t i) |
6969
|
|
|
|
|
|
|
{ |
6970
|
|
|
|
|
|
|
u64 res0 = clmul_u32(crc0, crc32_mults_for_chunklen[i][0]); |
6971
|
|
|
|
|
|
|
u64 res1 = clmul_u32(crc1, crc32_mults_for_chunklen[i][1]); |
6972
|
|
|
|
|
|
|
u64 res2 = clmul_u32(crc2, crc32_mults_for_chunklen[i][2]); |
6973
|
|
|
|
|
|
|
|
6974
|
|
|
|
|
|
|
return __crc32d(0, res0 ^ res1 ^ res2) ^ crc3; |
6975
|
|
|
|
|
|
|
} |
6976
|
|
|
|
|
|
|
|
6977
|
|
|
|
|
|
|
#define crc32_arm_crc_pmullcombine crc32_arm_crc_pmullcombine |
6978
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
6979
|
|
|
|
|
|
|
crc32_arm_crc_pmullcombine(u32 crc, const u8 *p, size_t len) |
6980
|
|
|
|
|
|
|
{ |
6981
|
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 7; |
6982
|
|
|
|
|
|
|
|
6983
|
|
|
|
|
|
|
if (len >= align + CRC32_NUM_CHUNKS * CRC32_MIN_VARIABLE_CHUNK_LEN) { |
6984
|
|
|
|
|
|
|
|
6985
|
|
|
|
|
|
|
if (align) { |
6986
|
|
|
|
|
|
|
if (align & 1) |
6987
|
|
|
|
|
|
|
crc = __crc32b(crc, *p++); |
6988
|
|
|
|
|
|
|
if (align & 2) { |
6989
|
|
|
|
|
|
|
crc = __crc32h(crc, le16_bswap(*(u16 *)p)); |
6990
|
|
|
|
|
|
|
p += 2; |
6991
|
|
|
|
|
|
|
} |
6992
|
|
|
|
|
|
|
if (align & 4) { |
6993
|
|
|
|
|
|
|
crc = __crc32w(crc, le32_bswap(*(u32 *)p)); |
6994
|
|
|
|
|
|
|
p += 4; |
6995
|
|
|
|
|
|
|
} |
6996
|
|
|
|
|
|
|
len -= align; |
6997
|
|
|
|
|
|
|
} |
6998
|
|
|
|
|
|
|
|
6999
|
|
|
|
|
|
|
while (len >= CRC32_NUM_CHUNKS * CRC32_MAX_VARIABLE_CHUNK_LEN) { |
7000
|
|
|
|
|
|
|
const u64 *wp0 = (const u64 *)p; |
7001
|
|
|
|
|
|
|
const u64 * const wp0_end = |
7002
|
|
|
|
|
|
|
(const u64 *)(p + CRC32_MAX_VARIABLE_CHUNK_LEN); |
7003
|
|
|
|
|
|
|
u32 crc1 = 0, crc2 = 0, crc3 = 0; |
7004
|
|
|
|
|
|
|
|
7005
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_NUM_CHUNKS == 4); |
7006
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_MAX_VARIABLE_CHUNK_LEN % (4 * 8) == 0); |
7007
|
|
|
|
|
|
|
do { |
7008
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 0*CRC32_MAX_VARIABLE_CHUNK_LEN/8]); |
7009
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 1*CRC32_MAX_VARIABLE_CHUNK_LEN/8]); |
7010
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 2*CRC32_MAX_VARIABLE_CHUNK_LEN/8]); |
7011
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 3*CRC32_MAX_VARIABLE_CHUNK_LEN/8]); |
7012
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7013
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7014
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7015
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7016
|
|
|
|
|
|
|
wp0++; |
7017
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7018
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7019
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7020
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7021
|
|
|
|
|
|
|
wp0++; |
7022
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7023
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7024
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7025
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7026
|
|
|
|
|
|
|
wp0++; |
7027
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7028
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7029
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7030
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
7031
|
|
|
|
|
|
|
wp0++; |
7032
|
|
|
|
|
|
|
} while (wp0 != wp0_end); |
7033
|
|
|
|
|
|
|
crc = combine_crcs_fast(crc, crc1, crc2, crc3, |
7034
|
|
|
|
|
|
|
ARRAY_LEN(crc32_mults_for_chunklen) - 1); |
7035
|
|
|
|
|
|
|
p += CRC32_NUM_CHUNKS * CRC32_MAX_VARIABLE_CHUNK_LEN; |
7036
|
|
|
|
|
|
|
len -= CRC32_NUM_CHUNKS * CRC32_MAX_VARIABLE_CHUNK_LEN; |
7037
|
|
|
|
|
|
|
} |
7038
|
|
|
|
|
|
|
|
7039
|
|
|
|
|
|
|
if (len >= CRC32_NUM_CHUNKS * CRC32_MIN_VARIABLE_CHUNK_LEN) { |
7040
|
|
|
|
|
|
|
const size_t i = len / (CRC32_NUM_CHUNKS * |
7041
|
|
|
|
|
|
|
CRC32_MIN_VARIABLE_CHUNK_LEN); |
7042
|
|
|
|
|
|
|
const size_t chunk_len = |
7043
|
|
|
|
|
|
|
i * CRC32_MIN_VARIABLE_CHUNK_LEN; |
7044
|
|
|
|
|
|
|
const u64 *wp0 = (const u64 *)(p + 0*chunk_len); |
7045
|
|
|
|
|
|
|
const u64 *wp1 = (const u64 *)(p + 1*chunk_len); |
7046
|
|
|
|
|
|
|
const u64 *wp2 = (const u64 *)(p + 2*chunk_len); |
7047
|
|
|
|
|
|
|
const u64 *wp3 = (const u64 *)(p + 3*chunk_len); |
7048
|
|
|
|
|
|
|
const u64 * const wp0_end = wp1; |
7049
|
|
|
|
|
|
|
u32 crc1 = 0, crc2 = 0, crc3 = 0; |
7050
|
|
|
|
|
|
|
|
7051
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_NUM_CHUNKS == 4); |
7052
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_MIN_VARIABLE_CHUNK_LEN % (4 * 8) == 0); |
7053
|
|
|
|
|
|
|
do { |
7054
|
|
|
|
|
|
|
prefetchr(wp0 + 64); |
7055
|
|
|
|
|
|
|
prefetchr(wp1 + 64); |
7056
|
|
|
|
|
|
|
prefetchr(wp2 + 64); |
7057
|
|
|
|
|
|
|
prefetchr(wp3 + 64); |
7058
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*wp0++)); |
7059
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(*wp1++)); |
7060
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(*wp2++)); |
7061
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(*wp3++)); |
7062
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*wp0++)); |
7063
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(*wp1++)); |
7064
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(*wp2++)); |
7065
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(*wp3++)); |
7066
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*wp0++)); |
7067
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(*wp1++)); |
7068
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(*wp2++)); |
7069
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(*wp3++)); |
7070
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*wp0++)); |
7071
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(*wp1++)); |
7072
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(*wp2++)); |
7073
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(*wp3++)); |
7074
|
|
|
|
|
|
|
} while (wp0 != wp0_end); |
7075
|
|
|
|
|
|
|
crc = combine_crcs_fast(crc, crc1, crc2, crc3, i); |
7076
|
|
|
|
|
|
|
p += CRC32_NUM_CHUNKS * chunk_len; |
7077
|
|
|
|
|
|
|
len -= CRC32_NUM_CHUNKS * chunk_len; |
7078
|
|
|
|
|
|
|
} |
7079
|
|
|
|
|
|
|
|
7080
|
|
|
|
|
|
|
while (len >= 32) { |
7081
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 0))); |
7082
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 8))); |
7083
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 16))); |
7084
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 24))); |
7085
|
|
|
|
|
|
|
p += 32; |
7086
|
|
|
|
|
|
|
len -= 32; |
7087
|
|
|
|
|
|
|
} |
7088
|
|
|
|
|
|
|
} else { |
7089
|
|
|
|
|
|
|
while (len >= 32) { |
7090
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 0)); |
7091
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 8)); |
7092
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 16)); |
7093
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 24)); |
7094
|
|
|
|
|
|
|
p += 32; |
7095
|
|
|
|
|
|
|
len -= 32; |
7096
|
|
|
|
|
|
|
} |
7097
|
|
|
|
|
|
|
} |
7098
|
|
|
|
|
|
|
if (len & 16) { |
7099
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 0)); |
7100
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 8)); |
7101
|
|
|
|
|
|
|
p += 16; |
7102
|
|
|
|
|
|
|
} |
7103
|
|
|
|
|
|
|
if (len & 8) { |
7104
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p)); |
7105
|
|
|
|
|
|
|
p += 8; |
7106
|
|
|
|
|
|
|
} |
7107
|
|
|
|
|
|
|
if (len & 4) { |
7108
|
|
|
|
|
|
|
crc = __crc32w(crc, get_unaligned_le32(p)); |
7109
|
|
|
|
|
|
|
p += 4; |
7110
|
|
|
|
|
|
|
} |
7111
|
|
|
|
|
|
|
if (len & 2) { |
7112
|
|
|
|
|
|
|
crc = __crc32h(crc, get_unaligned_le16(p)); |
7113
|
|
|
|
|
|
|
p += 2; |
7114
|
|
|
|
|
|
|
} |
7115
|
|
|
|
|
|
|
if (len & 1) |
7116
|
|
|
|
|
|
|
crc = __crc32b(crc, *p); |
7117
|
|
|
|
|
|
|
return crc; |
7118
|
|
|
|
|
|
|
} |
7119
|
|
|
|
|
|
|
#undef ATTRIBUTES |
7120
|
|
|
|
|
|
|
#endif |
7121
|
|
|
|
|
|
|
|
7122
|
|
|
|
|
|
|
|
7123
|
|
|
|
|
|
|
#if HAVE_PMULL_INTRIN |
7124
|
|
|
|
|
|
|
# define crc32_arm_pmullx4 crc32_arm_pmullx4 |
7125
|
|
|
|
|
|
|
# define SUFFIX _pmullx4 |
7126
|
|
|
|
|
|
|
# if HAVE_PMULL_NATIVE && !USE_PMULL_TARGET_EVEN_IF_NATIVE |
7127
|
|
|
|
|
|
|
# define ATTRIBUTES |
7128
|
|
|
|
|
|
|
# else |
7129
|
|
|
|
|
|
|
# ifdef ARCH_ARM32 |
7130
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("fpu=crypto-neon-fp-armv8") |
7131
|
|
|
|
|
|
|
# else |
7132
|
|
|
|
|
|
|
# ifdef __clang__ |
7133
|
|
|
|
|
|
|
|
7134
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("aes") |
7135
|
|
|
|
|
|
|
# else |
7136
|
|
|
|
|
|
|
|
7137
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crypto") |
7138
|
|
|
|
|
|
|
# endif |
7139
|
|
|
|
|
|
|
# endif |
7140
|
|
|
|
|
|
|
# endif |
7141
|
|
|
|
|
|
|
# define ENABLE_EOR3 0 |
7142
|
|
|
|
|
|
|
/* #include "arm-crc32_pmull_helpers.h" */ |
7143
|
|
|
|
|
|
|
|
7144
|
|
|
|
|
|
|
|
7145
|
|
|
|
|
|
|
|
7146
|
|
|
|
|
|
|
|
7147
|
|
|
|
|
|
|
#include |
7148
|
|
|
|
|
|
|
|
7149
|
|
|
|
|
|
|
|
7150
|
|
|
|
|
|
|
#undef u32_to_bytevec |
7151
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7152
|
|
|
|
|
|
|
ADD_SUFFIX(u32_to_bytevec)(u32 a) |
7153
|
|
|
|
|
|
|
{ |
7154
|
|
|
|
|
|
|
return vreinterpretq_u8_u32(vsetq_lane_u32(a, vdupq_n_u32(0), 0)); |
7155
|
|
|
|
|
|
|
} |
7156
|
|
|
|
|
|
|
#define u32_to_bytevec ADD_SUFFIX(u32_to_bytevec) |
7157
|
|
|
|
|
|
|
|
7158
|
|
|
|
|
|
|
|
7159
|
|
|
|
|
|
|
#undef load_multipliers |
7160
|
|
|
|
|
|
|
static forceinline ATTRIBUTES poly64x2_t |
7161
|
|
|
|
|
|
|
ADD_SUFFIX(load_multipliers)(const u64 p[2]) |
7162
|
|
|
|
|
|
|
{ |
7163
|
|
|
|
|
|
|
return vreinterpretq_p64_u64(vld1q_u64(p)); |
7164
|
|
|
|
|
|
|
} |
7165
|
|
|
|
|
|
|
#define load_multipliers ADD_SUFFIX(load_multipliers) |
7166
|
|
|
|
|
|
|
|
7167
|
|
|
|
|
|
|
|
7168
|
|
|
|
|
|
|
#undef clmul_low |
7169
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7170
|
|
|
|
|
|
|
ADD_SUFFIX(clmul_low)(uint8x16_t a, poly64x2_t b) |
7171
|
|
|
|
|
|
|
{ |
7172
|
|
|
|
|
|
|
return vreinterpretq_u8_p128( |
7173
|
|
|
|
|
|
|
compat_vmull_p64(vgetq_lane_p64(vreinterpretq_p64_u8(a), 0), |
7174
|
|
|
|
|
|
|
vgetq_lane_p64(b, 0))); |
7175
|
|
|
|
|
|
|
} |
7176
|
|
|
|
|
|
|
#define clmul_low ADD_SUFFIX(clmul_low) |
7177
|
|
|
|
|
|
|
|
7178
|
|
|
|
|
|
|
|
7179
|
|
|
|
|
|
|
#undef clmul_high |
7180
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7181
|
|
|
|
|
|
|
ADD_SUFFIX(clmul_high)(uint8x16_t a, poly64x2_t b) |
7182
|
|
|
|
|
|
|
{ |
7183
|
|
|
|
|
|
|
#if defined(__clang__) && defined(ARCH_ARM64) |
7184
|
|
|
|
|
|
|
|
7185
|
|
|
|
|
|
|
uint8x16_t res; |
7186
|
|
|
|
|
|
|
|
7187
|
|
|
|
|
|
|
__asm__("pmull2 %0.1q, %1.2d, %2.2d" : "=w" (res) : "w" (a), "w" (b)); |
7188
|
|
|
|
|
|
|
return res; |
7189
|
|
|
|
|
|
|
#else |
7190
|
|
|
|
|
|
|
return vreinterpretq_u8_p128(vmull_high_p64(vreinterpretq_p64_u8(a), b)); |
7191
|
|
|
|
|
|
|
#endif |
7192
|
|
|
|
|
|
|
} |
7193
|
|
|
|
|
|
|
#define clmul_high ADD_SUFFIX(clmul_high) |
7194
|
|
|
|
|
|
|
|
7195
|
|
|
|
|
|
|
#undef eor3 |
7196
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7197
|
|
|
|
|
|
|
ADD_SUFFIX(eor3)(uint8x16_t a, uint8x16_t b, uint8x16_t c) |
7198
|
|
|
|
|
|
|
{ |
7199
|
|
|
|
|
|
|
#if ENABLE_EOR3 |
7200
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN |
7201
|
|
|
|
|
|
|
return veor3q_u8(a, b, c); |
7202
|
|
|
|
|
|
|
#else |
7203
|
|
|
|
|
|
|
uint8x16_t res; |
7204
|
|
|
|
|
|
|
|
7205
|
|
|
|
|
|
|
__asm__("eor3 %0.16b, %1.16b, %2.16b, %3.16b" |
7206
|
|
|
|
|
|
|
: "=w" (res) : "w" (a), "w" (b), "w" (c)); |
7207
|
|
|
|
|
|
|
return res; |
7208
|
|
|
|
|
|
|
#endif |
7209
|
|
|
|
|
|
|
#else |
7210
|
|
|
|
|
|
|
return veorq_u8(veorq_u8(a, b), c); |
7211
|
|
|
|
|
|
|
#endif |
7212
|
|
|
|
|
|
|
} |
7213
|
|
|
|
|
|
|
#define eor3 ADD_SUFFIX(eor3) |
7214
|
|
|
|
|
|
|
|
7215
|
|
|
|
|
|
|
#undef fold_vec |
7216
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7217
|
|
|
|
|
|
|
ADD_SUFFIX(fold_vec)(uint8x16_t src, uint8x16_t dst, poly64x2_t multipliers) |
7218
|
|
|
|
|
|
|
{ |
7219
|
|
|
|
|
|
|
uint8x16_t a = clmul_low(src, multipliers); |
7220
|
|
|
|
|
|
|
uint8x16_t b = clmul_high(src, multipliers); |
7221
|
|
|
|
|
|
|
|
7222
|
|
|
|
|
|
|
return eor3(a, b, dst); |
7223
|
|
|
|
|
|
|
} |
7224
|
|
|
|
|
|
|
#define fold_vec ADD_SUFFIX(fold_vec) |
7225
|
|
|
|
|
|
|
|
7226
|
|
|
|
|
|
|
#undef vtbl |
7227
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7228
|
|
|
|
|
|
|
ADD_SUFFIX(vtbl)(uint8x16_t table, uint8x16_t indices) |
7229
|
|
|
|
|
|
|
{ |
7230
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
7231
|
|
|
|
|
|
|
return vqtbl1q_u8(table, indices); |
7232
|
|
|
|
|
|
|
#else |
7233
|
|
|
|
|
|
|
uint8x8x2_t tab2; |
7234
|
|
|
|
|
|
|
|
7235
|
|
|
|
|
|
|
tab2.val[0] = vget_low_u8(table); |
7236
|
|
|
|
|
|
|
tab2.val[1] = vget_high_u8(table); |
7237
|
|
|
|
|
|
|
|
7238
|
|
|
|
|
|
|
return vcombine_u8(vtbl2_u8(tab2, vget_low_u8(indices)), |
7239
|
|
|
|
|
|
|
vtbl2_u8(tab2, vget_high_u8(indices))); |
7240
|
|
|
|
|
|
|
#endif |
7241
|
|
|
|
|
|
|
} |
7242
|
|
|
|
|
|
|
#define vtbl ADD_SUFFIX(vtbl) |
7243
|
|
|
|
|
|
|
|
7244
|
|
|
|
|
|
|
|
7245
|
|
|
|
|
|
|
#undef fold_partial_vec |
7246
|
|
|
|
|
|
|
static forceinline ATTRIBUTES MAYBE_UNUSED uint8x16_t |
7247
|
|
|
|
|
|
|
ADD_SUFFIX(fold_partial_vec)(uint8x16_t v, const u8 *p, size_t len, |
7248
|
|
|
|
|
|
|
poly64x2_t multipliers_1) |
7249
|
|
|
|
|
|
|
{ |
7250
|
|
|
|
|
|
|
|
7251
|
|
|
|
|
|
|
static const u8 shift_tab[48] = { |
7252
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
7253
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
7254
|
|
|
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
7255
|
|
|
|
|
|
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
7256
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
7257
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
7258
|
|
|
|
|
|
|
}; |
7259
|
|
|
|
|
|
|
const uint8x16_t lshift = vld1q_u8(&shift_tab[len]); |
7260
|
|
|
|
|
|
|
const uint8x16_t rshift = vld1q_u8(&shift_tab[len + 16]); |
7261
|
|
|
|
|
|
|
uint8x16_t x0, x1, bsl_mask; |
7262
|
|
|
|
|
|
|
|
7263
|
|
|
|
|
|
|
|
7264
|
|
|
|
|
|
|
x0 = vtbl(v, lshift); |
7265
|
|
|
|
|
|
|
|
7266
|
|
|
|
|
|
|
|
7267
|
|
|
|
|
|
|
bsl_mask = vreinterpretq_u8_s8( |
7268
|
|
|
|
|
|
|
vshrq_n_s8(vreinterpretq_s8_u8(rshift), 7)); |
7269
|
|
|
|
|
|
|
|
7270
|
|
|
|
|
|
|
|
7271
|
|
|
|
|
|
|
x1 = vbslq_u8(bsl_mask , |
7272
|
|
|
|
|
|
|
vld1q_u8(p + len - 16), vtbl(v, rshift)); |
7273
|
|
|
|
|
|
|
|
7274
|
|
|
|
|
|
|
return fold_vec(x0, x1, multipliers_1); |
7275
|
|
|
|
|
|
|
} |
7276
|
|
|
|
|
|
|
#define fold_partial_vec ADD_SUFFIX(fold_partial_vec) |
7277
|
|
|
|
|
|
|
|
7278
|
|
|
|
|
|
|
|
7279
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
7280
|
|
|
|
|
|
|
crc32_arm_pmullx4(u32 crc, const u8 *p, size_t len) |
7281
|
|
|
|
|
|
|
{ |
7282
|
|
|
|
|
|
|
static const u64 _aligned_attribute(16) mults[3][2] = { |
7283
|
|
|
|
|
|
|
CRC32_1VECS_MULTS, |
7284
|
|
|
|
|
|
|
CRC32_4VECS_MULTS, |
7285
|
|
|
|
|
|
|
CRC32_2VECS_MULTS, |
7286
|
|
|
|
|
|
|
}; |
7287
|
|
|
|
|
|
|
static const u64 _aligned_attribute(16) final_mults[3][2] = { |
7288
|
|
|
|
|
|
|
{ CRC32_FINAL_MULT, 0 }, |
7289
|
|
|
|
|
|
|
{ CRC32_BARRETT_CONSTANT_1, 0 }, |
7290
|
|
|
|
|
|
|
{ CRC32_BARRETT_CONSTANT_2, 0 }, |
7291
|
|
|
|
|
|
|
}; |
7292
|
|
|
|
|
|
|
const uint8x16_t zeroes = vdupq_n_u8(0); |
7293
|
|
|
|
|
|
|
const uint8x16_t mask32 = vreinterpretq_u8_u64(vdupq_n_u64(0xFFFFFFFF)); |
7294
|
|
|
|
|
|
|
const poly64x2_t multipliers_1 = load_multipliers(mults[0]); |
7295
|
|
|
|
|
|
|
uint8x16_t v0, v1, v2, v3; |
7296
|
|
|
|
|
|
|
|
7297
|
|
|
|
|
|
|
if (len < 64 + 15) { |
7298
|
|
|
|
|
|
|
if (len < 16) |
7299
|
|
|
|
|
|
|
return crc32_slice1(crc, p, len); |
7300
|
|
|
|
|
|
|
v0 = veorq_u8(vld1q_u8(p), u32_to_bytevec(crc)); |
7301
|
|
|
|
|
|
|
p += 16; |
7302
|
|
|
|
|
|
|
len -= 16; |
7303
|
|
|
|
|
|
|
while (len >= 16) { |
7304
|
|
|
|
|
|
|
v0 = fold_vec(v0, vld1q_u8(p), multipliers_1); |
7305
|
|
|
|
|
|
|
p += 16; |
7306
|
|
|
|
|
|
|
len -= 16; |
7307
|
|
|
|
|
|
|
} |
7308
|
|
|
|
|
|
|
} else { |
7309
|
|
|
|
|
|
|
const poly64x2_t multipliers_4 = load_multipliers(mults[1]); |
7310
|
|
|
|
|
|
|
const poly64x2_t multipliers_2 = load_multipliers(mults[2]); |
7311
|
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 15; |
7312
|
|
|
|
|
|
|
const uint8x16_t *vp; |
7313
|
|
|
|
|
|
|
|
7314
|
|
|
|
|
|
|
v0 = veorq_u8(vld1q_u8(p), u32_to_bytevec(crc)); |
7315
|
|
|
|
|
|
|
p += 16; |
7316
|
|
|
|
|
|
|
|
7317
|
|
|
|
|
|
|
if (align) { |
7318
|
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, align, multipliers_1); |
7319
|
|
|
|
|
|
|
p += align; |
7320
|
|
|
|
|
|
|
len -= align; |
7321
|
|
|
|
|
|
|
} |
7322
|
|
|
|
|
|
|
vp = (const uint8x16_t *)p; |
7323
|
|
|
|
|
|
|
v1 = *vp++; |
7324
|
|
|
|
|
|
|
v2 = *vp++; |
7325
|
|
|
|
|
|
|
v3 = *vp++; |
7326
|
|
|
|
|
|
|
while (len >= 64 + 64) { |
7327
|
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_4); |
7328
|
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_4); |
7329
|
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_4); |
7330
|
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_4); |
7331
|
|
|
|
|
|
|
len -= 64; |
7332
|
|
|
|
|
|
|
} |
7333
|
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
7334
|
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
7335
|
|
|
|
|
|
|
if (len & 32) { |
7336
|
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_2); |
7337
|
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_2); |
7338
|
|
|
|
|
|
|
} |
7339
|
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
7340
|
|
|
|
|
|
|
if (len & 16) |
7341
|
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_1); |
7342
|
|
|
|
|
|
|
p = (const u8 *)vp; |
7343
|
|
|
|
|
|
|
len &= 15; |
7344
|
|
|
|
|
|
|
} |
7345
|
|
|
|
|
|
|
|
7346
|
|
|
|
|
|
|
|
7347
|
|
|
|
|
|
|
if (len) |
7348
|
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, len, multipliers_1); |
7349
|
|
|
|
|
|
|
|
7350
|
|
|
|
|
|
|
|
7351
|
|
|
|
|
|
|
|
7352
|
|
|
|
|
|
|
v0 = veorq_u8(vextq_u8(v0, zeroes, 8), |
7353
|
|
|
|
|
|
|
clmul_high(vextq_u8(zeroes, v0, 8), multipliers_1)); |
7354
|
|
|
|
|
|
|
|
7355
|
|
|
|
|
|
|
|
7356
|
|
|
|
|
|
|
v0 = veorq_u8(vextq_u8(v0, zeroes, 4), |
7357
|
|
|
|
|
|
|
clmul_low(vandq_u8(v0, mask32), |
7358
|
|
|
|
|
|
|
load_multipliers(final_mults[0]))); |
7359
|
|
|
|
|
|
|
|
7360
|
|
|
|
|
|
|
|
7361
|
|
|
|
|
|
|
v1 = clmul_low(vandq_u8(v0, mask32), load_multipliers(final_mults[1])); |
7362
|
|
|
|
|
|
|
v1 = clmul_low(vandq_u8(v1, mask32), load_multipliers(final_mults[2])); |
7363
|
|
|
|
|
|
|
return vgetq_lane_u32(vreinterpretq_u32_u8(veorq_u8(v0, v1)), 1); |
7364
|
|
|
|
|
|
|
} |
7365
|
|
|
|
|
|
|
#undef SUFFIX |
7366
|
|
|
|
|
|
|
#undef ATTRIBUTES |
7367
|
|
|
|
|
|
|
#undef ENABLE_EOR3 |
7368
|
|
|
|
|
|
|
#endif |
7369
|
|
|
|
|
|
|
|
7370
|
|
|
|
|
|
|
|
7371
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && HAVE_PMULL_INTRIN && HAVE_CRC32_INTRIN |
7372
|
|
|
|
|
|
|
# define crc32_arm_pmullx12_crc crc32_arm_pmullx12_crc |
7373
|
|
|
|
|
|
|
# define SUFFIX _pmullx12_crc |
7374
|
|
|
|
|
|
|
# if HAVE_PMULL_NATIVE && HAVE_CRC32_NATIVE && !USE_PMULL_TARGET_EVEN_IF_NATIVE |
7375
|
|
|
|
|
|
|
# define ATTRIBUTES |
7376
|
|
|
|
|
|
|
# else |
7377
|
|
|
|
|
|
|
# ifdef __clang__ |
7378
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("aes,crc") |
7379
|
|
|
|
|
|
|
# else |
7380
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crypto,+crc") |
7381
|
|
|
|
|
|
|
# endif |
7382
|
|
|
|
|
|
|
# endif |
7383
|
|
|
|
|
|
|
# define ENABLE_EOR3 0 |
7384
|
|
|
|
|
|
|
#include "arm-crc32_pmull_wide.h" |
7385
|
|
|
|
|
|
|
#endif |
7386
|
|
|
|
|
|
|
|
7387
|
|
|
|
|
|
|
|
7388
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && HAVE_PMULL_INTRIN && HAVE_CRC32_INTRIN && \ |
7389
|
|
|
|
|
|
|
(HAVE_SHA3_TARGET || HAVE_SHA3_NATIVE) |
7390
|
|
|
|
|
|
|
# define crc32_arm_pmullx12_crc_eor3 crc32_arm_pmullx12_crc_eor3 |
7391
|
|
|
|
|
|
|
# define SUFFIX _pmullx12_crc_eor3 |
7392
|
|
|
|
|
|
|
# if HAVE_PMULL_NATIVE && HAVE_CRC32_NATIVE && HAVE_SHA3_NATIVE && \ |
7393
|
|
|
|
|
|
|
!USE_PMULL_TARGET_EVEN_IF_NATIVE |
7394
|
|
|
|
|
|
|
# define ATTRIBUTES |
7395
|
|
|
|
|
|
|
# else |
7396
|
|
|
|
|
|
|
# ifdef __clang__ |
7397
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("aes,crc,sha3") |
7398
|
|
|
|
|
|
|
|
7399
|
|
|
|
|
|
|
# elif defined(__ARM_FEATURE_JCVT) |
7400
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crypto,+crc,+sha3") |
7401
|
|
|
|
|
|
|
# else |
7402
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8.2-a+crypto+crc+sha3") |
7403
|
|
|
|
|
|
|
# endif |
7404
|
|
|
|
|
|
|
# endif |
7405
|
|
|
|
|
|
|
# define ENABLE_EOR3 1 |
7406
|
|
|
|
|
|
|
#include "arm-crc32_pmull_wide.h" |
7407
|
|
|
|
|
|
|
#endif |
7408
|
|
|
|
|
|
|
|
7409
|
|
|
|
|
|
|
|
7410
|
|
|
|
|
|
|
#define PREFER_PMULL_TO_CRC 0 |
7411
|
|
|
|
|
|
|
#ifdef __APPLE__ |
7412
|
|
|
|
|
|
|
# include |
7413
|
|
|
|
|
|
|
# if TARGET_OS_OSX |
7414
|
|
|
|
|
|
|
# undef PREFER_PMULL_TO_CRC |
7415
|
|
|
|
|
|
|
# define PREFER_PMULL_TO_CRC 1 |
7416
|
|
|
|
|
|
|
# endif |
7417
|
|
|
|
|
|
|
#endif |
7418
|
|
|
|
|
|
|
|
7419
|
|
|
|
|
|
|
|
7420
|
|
|
|
|
|
|
#if PREFER_PMULL_TO_CRC && defined(crc32_arm_pmullx12_crc_eor3) && \ |
7421
|
|
|
|
|
|
|
HAVE_PMULL_NATIVE && HAVE_CRC32_NATIVE && HAVE_SHA3_NATIVE |
7422
|
|
|
|
|
|
|
# define DEFAULT_IMPL crc32_arm_pmullx12_crc_eor3 |
7423
|
|
|
|
|
|
|
#elif !PREFER_PMULL_TO_CRC && defined(crc32_arm_crc_pmullcombine) && \ |
7424
|
|
|
|
|
|
|
HAVE_CRC32_NATIVE && HAVE_PMULL_NATIVE |
7425
|
|
|
|
|
|
|
# define DEFAULT_IMPL crc32_arm_crc_pmullcombine |
7426
|
|
|
|
|
|
|
#else |
7427
|
|
|
|
|
|
|
static inline crc32_func_t |
7428
|
|
|
|
|
|
|
arch_select_crc32_func(void) |
7429
|
|
|
|
|
|
|
{ |
7430
|
|
|
|
|
|
|
const u32 features MAYBE_UNUSED = get_arm_cpu_features(); |
7431
|
|
|
|
|
|
|
|
7432
|
|
|
|
|
|
|
#if PREFER_PMULL_TO_CRC && defined(crc32_arm_pmullx12_crc_eor3) |
7433
|
|
|
|
|
|
|
if (HAVE_PMULL(features) && HAVE_CRC32(features) && HAVE_SHA3(features)) |
7434
|
|
|
|
|
|
|
return crc32_arm_pmullx12_crc_eor3; |
7435
|
|
|
|
|
|
|
#endif |
7436
|
|
|
|
|
|
|
#if PREFER_PMULL_TO_CRC && defined(crc32_arm_pmullx12_crc) |
7437
|
|
|
|
|
|
|
if (HAVE_PMULL(features) && HAVE_CRC32(features)) |
7438
|
|
|
|
|
|
|
return crc32_arm_pmullx12_crc; |
7439
|
|
|
|
|
|
|
#endif |
7440
|
|
|
|
|
|
|
#ifdef crc32_arm_crc_pmullcombine |
7441
|
|
|
|
|
|
|
if (HAVE_CRC32(features) && HAVE_PMULL(features)) |
7442
|
|
|
|
|
|
|
return crc32_arm_crc_pmullcombine; |
7443
|
|
|
|
|
|
|
#endif |
7444
|
|
|
|
|
|
|
#ifdef crc32_arm_crc |
7445
|
|
|
|
|
|
|
if (HAVE_CRC32(features)) |
7446
|
|
|
|
|
|
|
return crc32_arm_crc; |
7447
|
|
|
|
|
|
|
#endif |
7448
|
|
|
|
|
|
|
#ifdef crc32_arm_pmullx4 |
7449
|
|
|
|
|
|
|
if (HAVE_PMULL(features)) |
7450
|
|
|
|
|
|
|
return crc32_arm_pmullx4; |
7451
|
|
|
|
|
|
|
#endif |
7452
|
|
|
|
|
|
|
return NULL; |
7453
|
|
|
|
|
|
|
} |
7454
|
|
|
|
|
|
|
#define arch_select_crc32_func arch_select_crc32_func |
7455
|
|
|
|
|
|
|
#endif |
7456
|
|
|
|
|
|
|
|
7457
|
|
|
|
|
|
|
#endif |
7458
|
|
|
|
|
|
|
|
7459
|
|
|
|
|
|
|
#elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
7460
|
|
|
|
|
|
|
/* # include "x86/crc32_impl.h" */ |
7461
|
|
|
|
|
|
|
|
7462
|
|
|
|
|
|
|
|
7463
|
|
|
|
|
|
|
#ifndef LIB_X86_CRC32_IMPL_H |
7464
|
|
|
|
|
|
|
#define LIB_X86_CRC32_IMPL_H |
7465
|
|
|
|
|
|
|
|
7466
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
7467
|
|
|
|
|
|
|
|
7468
|
|
|
|
|
|
|
|
7469
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
7470
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
7471
|
|
|
|
|
|
|
|
7472
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
7473
|
|
|
|
|
|
|
|
7474
|
|
|
|
|
|
|
|
7475
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
7476
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
7477
|
|
|
|
|
|
|
|
7478
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
7479
|
|
|
|
|
|
|
|
7480
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
7481
|
|
|
|
|
|
|
#endif |
7482
|
|
|
|
|
|
|
|
7483
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
7484
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
7485
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
7486
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
7487
|
|
|
|
|
|
|
#else |
7488
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
7489
|
|
|
|
|
|
|
#endif |
7490
|
|
|
|
|
|
|
|
7491
|
|
|
|
|
|
|
|
7492
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
7493
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
7494
|
|
|
|
|
|
|
#else |
7495
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
7496
|
|
|
|
|
|
|
#endif |
7497
|
|
|
|
|
|
|
|
7498
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
7499
|
|
|
|
|
|
|
|
7500
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
7501
|
|
|
|
|
|
|
|
7502
|
|
|
|
|
|
|
|
7503
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
7504
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
7505
|
|
|
|
|
|
|
|
7506
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
7507
|
|
|
|
|
|
|
|
7508
|
|
|
|
|
|
|
|
7509
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
7510
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
7511
|
|
|
|
|
|
|
|
7512
|
|
|
|
|
|
|
#include |
7513
|
|
|
|
|
|
|
#include |
7514
|
|
|
|
|
|
|
|
7515
|
|
|
|
|
|
|
#ifdef __cplusplus |
7516
|
|
|
|
|
|
|
extern "C" { |
7517
|
|
|
|
|
|
|
#endif |
7518
|
|
|
|
|
|
|
|
7519
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
7520
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
7521
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
7522
|
|
|
|
|
|
|
|
7523
|
|
|
|
|
|
|
|
7524
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
7525
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
7526
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
7527
|
|
|
|
|
|
|
# else |
7528
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
7529
|
|
|
|
|
|
|
# endif |
7530
|
|
|
|
|
|
|
#endif |
7531
|
|
|
|
|
|
|
|
7532
|
|
|
|
|
|
|
|
7533
|
|
|
|
|
|
|
|
7534
|
|
|
|
|
|
|
|
7535
|
|
|
|
|
|
|
|
7536
|
|
|
|
|
|
|
struct libdeflate_compressor; |
7537
|
|
|
|
|
|
|
struct libdeflate_options; |
7538
|
|
|
|
|
|
|
|
7539
|
|
|
|
|
|
|
|
7540
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
7541
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
7542
|
|
|
|
|
|
|
|
7543
|
|
|
|
|
|
|
|
7544
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
7545
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
7546
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
7547
|
|
|
|
|
|
|
|
7548
|
|
|
|
|
|
|
|
7549
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7550
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
7551
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7552
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
7553
|
|
|
|
|
|
|
|
7554
|
|
|
|
|
|
|
|
7555
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7556
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
7557
|
|
|
|
|
|
|
size_t in_nbytes); |
7558
|
|
|
|
|
|
|
|
7559
|
|
|
|
|
|
|
|
7560
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7561
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
7562
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7563
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
7564
|
|
|
|
|
|
|
|
7565
|
|
|
|
|
|
|
|
7566
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7567
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
7568
|
|
|
|
|
|
|
size_t in_nbytes); |
7569
|
|
|
|
|
|
|
|
7570
|
|
|
|
|
|
|
|
7571
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7572
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
7573
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7574
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
7575
|
|
|
|
|
|
|
|
7576
|
|
|
|
|
|
|
|
7577
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7578
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
7579
|
|
|
|
|
|
|
size_t in_nbytes); |
7580
|
|
|
|
|
|
|
|
7581
|
|
|
|
|
|
|
|
7582
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
7583
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
7584
|
|
|
|
|
|
|
|
7585
|
|
|
|
|
|
|
|
7586
|
|
|
|
|
|
|
|
7587
|
|
|
|
|
|
|
|
7588
|
|
|
|
|
|
|
|
7589
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
7590
|
|
|
|
|
|
|
struct libdeflate_options; |
7591
|
|
|
|
|
|
|
|
7592
|
|
|
|
|
|
|
|
7593
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
7594
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
7595
|
|
|
|
|
|
|
|
7596
|
|
|
|
|
|
|
|
7597
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
7598
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
7599
|
|
|
|
|
|
|
|
7600
|
|
|
|
|
|
|
|
7601
|
|
|
|
|
|
|
enum libdeflate_result { |
7602
|
|
|
|
|
|
|
|
7603
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
7604
|
|
|
|
|
|
|
|
7605
|
|
|
|
|
|
|
|
7606
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
7607
|
|
|
|
|
|
|
|
7608
|
|
|
|
|
|
|
|
7609
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
7610
|
|
|
|
|
|
|
|
7611
|
|
|
|
|
|
|
|
7612
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
7613
|
|
|
|
|
|
|
}; |
7614
|
|
|
|
|
|
|
|
7615
|
|
|
|
|
|
|
|
7616
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7617
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
7618
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7619
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7620
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7621
|
|
|
|
|
|
|
|
7622
|
|
|
|
|
|
|
|
7623
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7624
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
7625
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7626
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7627
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
7628
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7629
|
|
|
|
|
|
|
|
7630
|
|
|
|
|
|
|
|
7631
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7632
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
7633
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7634
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7635
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7636
|
|
|
|
|
|
|
|
7637
|
|
|
|
|
|
|
|
7638
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7639
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
7640
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7641
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7642
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
7643
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7644
|
|
|
|
|
|
|
|
7645
|
|
|
|
|
|
|
|
7646
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7647
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
7648
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7649
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7650
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7651
|
|
|
|
|
|
|
|
7652
|
|
|
|
|
|
|
|
7653
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7654
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
7655
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7656
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7657
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
7658
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7659
|
|
|
|
|
|
|
|
7660
|
|
|
|
|
|
|
|
7661
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
7662
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
7663
|
|
|
|
|
|
|
|
7664
|
|
|
|
|
|
|
|
7665
|
|
|
|
|
|
|
|
7666
|
|
|
|
|
|
|
|
7667
|
|
|
|
|
|
|
|
7668
|
|
|
|
|
|
|
|
7669
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
7670
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
7671
|
|
|
|
|
|
|
|
7672
|
|
|
|
|
|
|
|
7673
|
|
|
|
|
|
|
|
7674
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
7675
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
7676
|
|
|
|
|
|
|
|
7677
|
|
|
|
|
|
|
|
7678
|
|
|
|
|
|
|
|
7679
|
|
|
|
|
|
|
|
7680
|
|
|
|
|
|
|
|
7681
|
|
|
|
|
|
|
|
7682
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
7683
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
7684
|
|
|
|
|
|
|
void (*free_func)(void *)); |
7685
|
|
|
|
|
|
|
|
7686
|
|
|
|
|
|
|
|
7687
|
|
|
|
|
|
|
struct libdeflate_options { |
7688
|
|
|
|
|
|
|
|
7689
|
|
|
|
|
|
|
|
7690
|
|
|
|
|
|
|
size_t sizeof_options; |
7691
|
|
|
|
|
|
|
|
7692
|
|
|
|
|
|
|
|
7693
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
7694
|
|
|
|
|
|
|
void (*free_func)(void *); |
7695
|
|
|
|
|
|
|
}; |
7696
|
|
|
|
|
|
|
|
7697
|
|
|
|
|
|
|
#ifdef __cplusplus |
7698
|
|
|
|
|
|
|
} |
7699
|
|
|
|
|
|
|
#endif |
7700
|
|
|
|
|
|
|
|
7701
|
|
|
|
|
|
|
#endif |
7702
|
|
|
|
|
|
|
|
7703
|
|
|
|
|
|
|
|
7704
|
|
|
|
|
|
|
#include |
7705
|
|
|
|
|
|
|
#include |
7706
|
|
|
|
|
|
|
#include |
7707
|
|
|
|
|
|
|
#ifdef _MSC_VER |
7708
|
|
|
|
|
|
|
# include |
7709
|
|
|
|
|
|
|
# include |
7710
|
|
|
|
|
|
|
|
7711
|
|
|
|
|
|
|
|
7712
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
7713
|
|
|
|
|
|
|
|
7714
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
7715
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
7716
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
7717
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
7718
|
|
|
|
|
|
|
|
7719
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
7720
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
7721
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
7722
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
7723
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
7724
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
7725
|
|
|
|
|
|
|
#endif |
7726
|
|
|
|
|
|
|
#ifndef FREESTANDING |
7727
|
|
|
|
|
|
|
# include |
7728
|
|
|
|
|
|
|
#endif |
7729
|
|
|
|
|
|
|
|
7730
|
|
|
|
|
|
|
|
7731
|
|
|
|
|
|
|
|
7732
|
|
|
|
|
|
|
|
7733
|
|
|
|
|
|
|
|
7734
|
|
|
|
|
|
|
|
7735
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
7736
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
7737
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
7738
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
7739
|
|
|
|
|
|
|
#ifdef _MSC_VER |
7740
|
|
|
|
|
|
|
# if defined(_M_X64) |
7741
|
|
|
|
|
|
|
# define ARCH_X86_64 |
7742
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
7743
|
|
|
|
|
|
|
# define ARCH_X86_32 |
7744
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
7745
|
|
|
|
|
|
|
# define ARCH_ARM64 |
7746
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
7747
|
|
|
|
|
|
|
# define ARCH_ARM32 |
7748
|
|
|
|
|
|
|
# endif |
7749
|
|
|
|
|
|
|
#else |
7750
|
|
|
|
|
|
|
# if defined(__x86_64__) |
7751
|
|
|
|
|
|
|
# define ARCH_X86_64 |
7752
|
|
|
|
|
|
|
# elif defined(__i386__) |
7753
|
|
|
|
|
|
|
# define ARCH_X86_32 |
7754
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
7755
|
|
|
|
|
|
|
# define ARCH_ARM64 |
7756
|
|
|
|
|
|
|
# elif defined(__arm__) |
7757
|
|
|
|
|
|
|
# define ARCH_ARM32 |
7758
|
|
|
|
|
|
|
# endif |
7759
|
|
|
|
|
|
|
#endif |
7760
|
|
|
|
|
|
|
|
7761
|
|
|
|
|
|
|
|
7762
|
|
|
|
|
|
|
|
7763
|
|
|
|
|
|
|
|
7764
|
|
|
|
|
|
|
|
7765
|
|
|
|
|
|
|
|
7766
|
|
|
|
|
|
|
typedef uint8_t u8; |
7767
|
|
|
|
|
|
|
typedef uint16_t u16; |
7768
|
|
|
|
|
|
|
typedef uint32_t u32; |
7769
|
|
|
|
|
|
|
typedef uint64_t u64; |
7770
|
|
|
|
|
|
|
typedef int8_t s8; |
7771
|
|
|
|
|
|
|
typedef int16_t s16; |
7772
|
|
|
|
|
|
|
typedef int32_t s32; |
7773
|
|
|
|
|
|
|
typedef int64_t s64; |
7774
|
|
|
|
|
|
|
|
7775
|
|
|
|
|
|
|
|
7776
|
|
|
|
|
|
|
#ifdef _MSC_VER |
7777
|
|
|
|
|
|
|
# ifdef _WIN64 |
7778
|
|
|
|
|
|
|
typedef long long ssize_t; |
7779
|
|
|
|
|
|
|
# else |
7780
|
|
|
|
|
|
|
typedef long ssize_t; |
7781
|
|
|
|
|
|
|
# endif |
7782
|
|
|
|
|
|
|
#endif |
7783
|
|
|
|
|
|
|
|
7784
|
|
|
|
|
|
|
|
7785
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
7786
|
|
|
|
|
|
|
|
7787
|
|
|
|
|
|
|
|
7788
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
7789
|
|
|
|
|
|
|
|
7790
|
|
|
|
|
|
|
|
7791
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
7792
|
|
|
|
|
|
|
|
7793
|
|
|
|
|
|
|
|
7794
|
|
|
|
|
|
|
|
7795
|
|
|
|
|
|
|
|
7796
|
|
|
|
|
|
|
|
7797
|
|
|
|
|
|
|
|
7798
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
7799
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
7800
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
7801
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
7802
|
|
|
|
|
|
|
#else |
7803
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
7804
|
|
|
|
|
|
|
#endif |
7805
|
|
|
|
|
|
|
#ifdef __clang__ |
7806
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
7807
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
7808
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
7809
|
|
|
|
|
|
|
# else |
7810
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
7811
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
7812
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
7813
|
|
|
|
|
|
|
# endif |
7814
|
|
|
|
|
|
|
#else |
7815
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
7816
|
|
|
|
|
|
|
#endif |
7817
|
|
|
|
|
|
|
|
7818
|
|
|
|
|
|
|
|
7819
|
|
|
|
|
|
|
#ifndef __has_attribute |
7820
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
7821
|
|
|
|
|
|
|
#endif |
7822
|
|
|
|
|
|
|
#ifndef __has_builtin |
7823
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
7824
|
|
|
|
|
|
|
#endif |
7825
|
|
|
|
|
|
|
|
7826
|
|
|
|
|
|
|
|
7827
|
|
|
|
|
|
|
#ifdef _MSC_VER |
7828
|
|
|
|
|
|
|
# define inline __inline |
7829
|
|
|
|
|
|
|
#endif |
7830
|
|
|
|
|
|
|
|
7831
|
|
|
|
|
|
|
|
7832
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
7833
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
7834
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7835
|
|
|
|
|
|
|
# define forceinline __forceinline |
7836
|
|
|
|
|
|
|
#else |
7837
|
|
|
|
|
|
|
# define forceinline inline |
7838
|
|
|
|
|
|
|
#endif |
7839
|
|
|
|
|
|
|
|
7840
|
|
|
|
|
|
|
|
7841
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
7842
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
7843
|
|
|
|
|
|
|
#else |
7844
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
7845
|
|
|
|
|
|
|
#endif |
7846
|
|
|
|
|
|
|
|
7847
|
|
|
|
|
|
|
|
7848
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
7849
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
7850
|
|
|
|
|
|
|
# define restrict __restrict__ |
7851
|
|
|
|
|
|
|
# else |
7852
|
|
|
|
|
|
|
# define restrict |
7853
|
|
|
|
|
|
|
# endif |
7854
|
|
|
|
|
|
|
#endif |
7855
|
|
|
|
|
|
|
|
7856
|
|
|
|
|
|
|
|
7857
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
7858
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
7859
|
|
|
|
|
|
|
#else |
7860
|
|
|
|
|
|
|
# define likely(expr) (expr) |
7861
|
|
|
|
|
|
|
#endif |
7862
|
|
|
|
|
|
|
|
7863
|
|
|
|
|
|
|
|
7864
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
7865
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
7866
|
|
|
|
|
|
|
#else |
7867
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
7868
|
|
|
|
|
|
|
#endif |
7869
|
|
|
|
|
|
|
|
7870
|
|
|
|
|
|
|
|
7871
|
|
|
|
|
|
|
#undef prefetchr |
7872
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
7873
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
7874
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7875
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
7876
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
7877
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
7878
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
7879
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
7880
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
7881
|
|
|
|
|
|
|
# endif |
7882
|
|
|
|
|
|
|
#endif |
7883
|
|
|
|
|
|
|
#ifndef prefetchr |
7884
|
|
|
|
|
|
|
# define prefetchr(addr) |
7885
|
|
|
|
|
|
|
#endif |
7886
|
|
|
|
|
|
|
|
7887
|
|
|
|
|
|
|
|
7888
|
|
|
|
|
|
|
#undef prefetchw |
7889
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
7890
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
7891
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7892
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
7893
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
7894
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
7895
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
7896
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
7897
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
7898
|
|
|
|
|
|
|
# endif |
7899
|
|
|
|
|
|
|
#endif |
7900
|
|
|
|
|
|
|
#ifndef prefetchw |
7901
|
|
|
|
|
|
|
# define prefetchw(addr) |
7902
|
|
|
|
|
|
|
#endif |
7903
|
|
|
|
|
|
|
|
7904
|
|
|
|
|
|
|
|
7905
|
|
|
|
|
|
|
#undef _aligned_attribute |
7906
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
7907
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
7908
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7909
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
7910
|
|
|
|
|
|
|
#endif |
7911
|
|
|
|
|
|
|
|
7912
|
|
|
|
|
|
|
|
7913
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
7914
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
7915
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
7916
|
|
|
|
|
|
|
#else |
7917
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
7918
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
7919
|
|
|
|
|
|
|
#endif |
7920
|
|
|
|
|
|
|
|
7921
|
|
|
|
|
|
|
|
7922
|
|
|
|
|
|
|
|
7923
|
|
|
|
|
|
|
|
7924
|
|
|
|
|
|
|
|
7925
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
7926
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
7927
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
7928
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
7929
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
7930
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
7931
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
7932
|
|
|
|
|
|
|
|
7933
|
|
|
|
|
|
|
|
7934
|
|
|
|
|
|
|
|
7935
|
|
|
|
|
|
|
|
7936
|
|
|
|
|
|
|
|
7937
|
|
|
|
|
|
|
|
7938
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
7939
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
7940
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7941
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
7942
|
|
|
|
|
|
|
#else |
7943
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
7944
|
|
|
|
|
|
|
{ |
7945
|
|
|
|
|
|
|
union { |
7946
|
|
|
|
|
|
|
u32 w; |
7947
|
|
|
|
|
|
|
u8 b; |
7948
|
|
|
|
|
|
|
} u; |
7949
|
|
|
|
|
|
|
|
7950
|
|
|
|
|
|
|
u.w = 1; |
7951
|
|
|
|
|
|
|
return u.b; |
7952
|
|
|
|
|
|
|
} |
7953
|
|
|
|
|
|
|
#endif |
7954
|
|
|
|
|
|
|
|
7955
|
|
|
|
|
|
|
|
7956
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
7957
|
|
|
|
|
|
|
{ |
7958
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
7959
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
7960
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7961
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
7962
|
|
|
|
|
|
|
#else |
7963
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
7964
|
|
|
|
|
|
|
#endif |
7965
|
|
|
|
|
|
|
} |
7966
|
|
|
|
|
|
|
|
7967
|
|
|
|
|
|
|
|
7968
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
7969
|
|
|
|
|
|
|
{ |
7970
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
7971
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
7972
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7973
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
7974
|
|
|
|
|
|
|
#else |
7975
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
7976
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
7977
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
7978
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
7979
|
|
|
|
|
|
|
#endif |
7980
|
|
|
|
|
|
|
} |
7981
|
|
|
|
|
|
|
|
7982
|
|
|
|
|
|
|
|
7983
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
7984
|
|
|
|
|
|
|
{ |
7985
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
7986
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
7987
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7988
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
7989
|
|
|
|
|
|
|
#else |
7990
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
7991
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
7992
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
7993
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
7994
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
7995
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
7996
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
7997
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
7998
|
|
|
|
|
|
|
#endif |
7999
|
|
|
|
|
|
|
} |
8000
|
|
|
|
|
|
|
|
8001
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
8002
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
8003
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
8004
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
8005
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
8006
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
8007
|
|
|
|
|
|
|
|
8008
|
|
|
|
|
|
|
|
8009
|
|
|
|
|
|
|
|
8010
|
|
|
|
|
|
|
|
8011
|
|
|
|
|
|
|
|
8012
|
|
|
|
|
|
|
|
8013
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
8014
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
8015
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
8016
|
|
|
|
|
|
|
defined(__wasm__)) |
8017
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
8018
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
8019
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
8020
|
|
|
|
|
|
|
#else |
8021
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
8022
|
|
|
|
|
|
|
#endif |
8023
|
|
|
|
|
|
|
|
8024
|
|
|
|
|
|
|
|
8025
|
|
|
|
|
|
|
|
8026
|
|
|
|
|
|
|
#ifdef FREESTANDING |
8027
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
8028
|
|
|
|
|
|
|
#else |
8029
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
8030
|
|
|
|
|
|
|
#endif |
8031
|
|
|
|
|
|
|
|
8032
|
|
|
|
|
|
|
|
8033
|
|
|
|
|
|
|
|
8034
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
8035
|
|
|
|
|
|
|
static forceinline type \ |
8036
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
8037
|
|
|
|
|
|
|
{ \ |
8038
|
|
|
|
|
|
|
type v; \ |
8039
|
|
|
|
|
|
|
\ |
8040
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
8041
|
|
|
|
|
|
|
return v; \ |
8042
|
|
|
|
|
|
|
} \ |
8043
|
|
|
|
|
|
|
\ |
8044
|
|
|
|
|
|
|
static forceinline void \ |
8045
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
8046
|
|
|
|
|
|
|
{ \ |
8047
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
8048
|
|
|
|
|
|
|
} |
8049
|
|
|
|
|
|
|
|
8050
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
8051
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
8052
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
8053
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
8054
|
|
|
|
|
|
|
|
8055
|
|
|
|
|
|
|
#undef MEMCOPY |
8056
|
|
|
|
|
|
|
|
8057
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
8058
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
8059
|
|
|
|
|
|
|
|
8060
|
|
|
|
|
|
|
|
8061
|
|
|
|
|
|
|
|
8062
|
|
|
|
|
|
|
static forceinline u16 |
8063
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
8064
|
|
|
|
|
|
|
{ |
8065
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
8066
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
8067
|
|
|
|
|
|
|
else |
8068
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
8069
|
|
|
|
|
|
|
} |
8070
|
|
|
|
|
|
|
|
8071
|
|
|
|
|
|
|
static forceinline u16 |
8072
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
8073
|
|
|
|
|
|
|
{ |
8074
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
8075
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
8076
|
|
|
|
|
|
|
else |
8077
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
8078
|
|
|
|
|
|
|
} |
8079
|
|
|
|
|
|
|
|
8080
|
|
|
|
|
|
|
static forceinline u32 |
8081
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
8082
|
|
|
|
|
|
|
{ |
8083
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
8084
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
8085
|
|
|
|
|
|
|
else |
8086
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
8087
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
8088
|
|
|
|
|
|
|
} |
8089
|
|
|
|
|
|
|
|
8090
|
|
|
|
|
|
|
static forceinline u32 |
8091
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
8092
|
|
|
|
|
|
|
{ |
8093
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
8094
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
8095
|
|
|
|
|
|
|
else |
8096
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
8097
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
8098
|
|
|
|
|
|
|
} |
8099
|
|
|
|
|
|
|
|
8100
|
|
|
|
|
|
|
static forceinline u64 |
8101
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
8102
|
|
|
|
|
|
|
{ |
8103
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
8104
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
8105
|
|
|
|
|
|
|
else |
8106
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
8107
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
8108
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
8109
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
8110
|
|
|
|
|
|
|
} |
8111
|
|
|
|
|
|
|
|
8112
|
|
|
|
|
|
|
static forceinline machine_word_t |
8113
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
8114
|
|
|
|
|
|
|
{ |
8115
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
8116
|
|
|
|
|
|
|
if (WORDBITS == 32) |
8117
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
8118
|
|
|
|
|
|
|
else |
8119
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
8120
|
|
|
|
|
|
|
} |
8121
|
|
|
|
|
|
|
|
8122
|
|
|
|
|
|
|
|
8123
|
|
|
|
|
|
|
|
8124
|
|
|
|
|
|
|
static forceinline void |
8125
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
8126
|
|
|
|
|
|
|
{ |
8127
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
8128
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
8129
|
|
|
|
|
|
|
} else { |
8130
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
8131
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
8132
|
|
|
|
|
|
|
} |
8133
|
|
|
|
|
|
|
} |
8134
|
|
|
|
|
|
|
|
8135
|
|
|
|
|
|
|
static forceinline void |
8136
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
8137
|
|
|
|
|
|
|
{ |
8138
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
8139
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
8140
|
|
|
|
|
|
|
} else { |
8141
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
8142
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
8143
|
|
|
|
|
|
|
} |
8144
|
|
|
|
|
|
|
} |
8145
|
|
|
|
|
|
|
|
8146
|
|
|
|
|
|
|
static forceinline void |
8147
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
8148
|
|
|
|
|
|
|
{ |
8149
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
8150
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
8151
|
|
|
|
|
|
|
} else { |
8152
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
8153
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
8154
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
8155
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
8156
|
|
|
|
|
|
|
} |
8157
|
|
|
|
|
|
|
} |
8158
|
|
|
|
|
|
|
|
8159
|
|
|
|
|
|
|
static forceinline void |
8160
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
8161
|
|
|
|
|
|
|
{ |
8162
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
8163
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
8164
|
|
|
|
|
|
|
} else { |
8165
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
8166
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
8167
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
8168
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
8169
|
|
|
|
|
|
|
} |
8170
|
|
|
|
|
|
|
} |
8171
|
|
|
|
|
|
|
|
8172
|
|
|
|
|
|
|
static forceinline void |
8173
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
8174
|
|
|
|
|
|
|
{ |
8175
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
8176
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
8177
|
|
|
|
|
|
|
} else { |
8178
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
8179
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
8180
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
8181
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
8182
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
8183
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
8184
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
8185
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
8186
|
|
|
|
|
|
|
} |
8187
|
|
|
|
|
|
|
} |
8188
|
|
|
|
|
|
|
|
8189
|
|
|
|
|
|
|
static forceinline void |
8190
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
8191
|
|
|
|
|
|
|
{ |
8192
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
8193
|
|
|
|
|
|
|
if (WORDBITS == 32) |
8194
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
8195
|
|
|
|
|
|
|
else |
8196
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
8197
|
|
|
|
|
|
|
} |
8198
|
|
|
|
|
|
|
|
8199
|
|
|
|
|
|
|
|
8200
|
|
|
|
|
|
|
|
8201
|
|
|
|
|
|
|
|
8202
|
|
|
|
|
|
|
|
8203
|
|
|
|
|
|
|
|
8204
|
|
|
|
|
|
|
|
8205
|
|
|
|
|
|
|
static forceinline unsigned |
8206
|
|
|
|
|
|
|
bsr32(u32 v) |
8207
|
|
|
|
|
|
|
{ |
8208
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
8209
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
8210
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
8211
|
|
|
|
|
|
|
unsigned long i; |
8212
|
|
|
|
|
|
|
|
8213
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
8214
|
|
|
|
|
|
|
return i; |
8215
|
|
|
|
|
|
|
#else |
8216
|
|
|
|
|
|
|
unsigned i = 0; |
8217
|
|
|
|
|
|
|
|
8218
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
8219
|
|
|
|
|
|
|
i++; |
8220
|
|
|
|
|
|
|
return i; |
8221
|
|
|
|
|
|
|
#endif |
8222
|
|
|
|
|
|
|
} |
8223
|
|
|
|
|
|
|
|
8224
|
|
|
|
|
|
|
static forceinline unsigned |
8225
|
|
|
|
|
|
|
bsr64(u64 v) |
8226
|
|
|
|
|
|
|
{ |
8227
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
8228
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
8229
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
8230
|
|
|
|
|
|
|
unsigned long i; |
8231
|
|
|
|
|
|
|
|
8232
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
8233
|
|
|
|
|
|
|
return i; |
8234
|
|
|
|
|
|
|
#else |
8235
|
|
|
|
|
|
|
unsigned i = 0; |
8236
|
|
|
|
|
|
|
|
8237
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
8238
|
|
|
|
|
|
|
i++; |
8239
|
|
|
|
|
|
|
return i; |
8240
|
|
|
|
|
|
|
#endif |
8241
|
|
|
|
|
|
|
} |
8242
|
|
|
|
|
|
|
|
8243
|
|
|
|
|
|
|
static forceinline unsigned |
8244
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
8245
|
|
|
|
|
|
|
{ |
8246
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
8247
|
|
|
|
|
|
|
if (WORDBITS == 32) |
8248
|
|
|
|
|
|
|
return bsr32(v); |
8249
|
|
|
|
|
|
|
else |
8250
|
|
|
|
|
|
|
return bsr64(v); |
8251
|
|
|
|
|
|
|
} |
8252
|
|
|
|
|
|
|
|
8253
|
|
|
|
|
|
|
|
8254
|
|
|
|
|
|
|
|
8255
|
|
|
|
|
|
|
static forceinline unsigned |
8256
|
|
|
|
|
|
|
bsf32(u32 v) |
8257
|
|
|
|
|
|
|
{ |
8258
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
8259
|
|
|
|
|
|
|
return __builtin_ctz(v); |
8260
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
8261
|
|
|
|
|
|
|
unsigned long i; |
8262
|
|
|
|
|
|
|
|
8263
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
8264
|
|
|
|
|
|
|
return i; |
8265
|
|
|
|
|
|
|
#else |
8266
|
|
|
|
|
|
|
unsigned i = 0; |
8267
|
|
|
|
|
|
|
|
8268
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
8269
|
|
|
|
|
|
|
i++; |
8270
|
|
|
|
|
|
|
return i; |
8271
|
|
|
|
|
|
|
#endif |
8272
|
|
|
|
|
|
|
} |
8273
|
|
|
|
|
|
|
|
8274
|
|
|
|
|
|
|
static forceinline unsigned |
8275
|
|
|
|
|
|
|
bsf64(u64 v) |
8276
|
|
|
|
|
|
|
{ |
8277
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
8278
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
8279
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
8280
|
|
|
|
|
|
|
unsigned long i; |
8281
|
|
|
|
|
|
|
|
8282
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
8283
|
|
|
|
|
|
|
return i; |
8284
|
|
|
|
|
|
|
#else |
8285
|
|
|
|
|
|
|
unsigned i = 0; |
8286
|
|
|
|
|
|
|
|
8287
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
8288
|
|
|
|
|
|
|
i++; |
8289
|
|
|
|
|
|
|
return i; |
8290
|
|
|
|
|
|
|
#endif |
8291
|
|
|
|
|
|
|
} |
8292
|
|
|
|
|
|
|
|
8293
|
|
|
|
|
|
|
static forceinline unsigned |
8294
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
8295
|
|
|
|
|
|
|
{ |
8296
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
8297
|
|
|
|
|
|
|
if (WORDBITS == 32) |
8298
|
|
|
|
|
|
|
return bsf32(v); |
8299
|
|
|
|
|
|
|
else |
8300
|
|
|
|
|
|
|
return bsf64(v); |
8301
|
|
|
|
|
|
|
} |
8302
|
|
|
|
|
|
|
|
8303
|
|
|
|
|
|
|
|
8304
|
|
|
|
|
|
|
#undef rbit32 |
8305
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
8306
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
8307
|
|
|
|
|
|
|
static forceinline u32 |
8308
|
|
|
|
|
|
|
rbit32(u32 v) |
8309
|
|
|
|
|
|
|
{ |
8310
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
8311
|
|
|
|
|
|
|
return v; |
8312
|
|
|
|
|
|
|
} |
8313
|
|
|
|
|
|
|
#define rbit32 rbit32 |
8314
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
8315
|
|
|
|
|
|
|
static forceinline u32 |
8316
|
|
|
|
|
|
|
rbit32(u32 v) |
8317
|
|
|
|
|
|
|
{ |
8318
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
8319
|
|
|
|
|
|
|
return v; |
8320
|
|
|
|
|
|
|
} |
8321
|
|
|
|
|
|
|
#define rbit32 rbit32 |
8322
|
|
|
|
|
|
|
#endif |
8323
|
|
|
|
|
|
|
|
8324
|
|
|
|
|
|
|
#endif |
8325
|
|
|
|
|
|
|
|
8326
|
|
|
|
|
|
|
|
8327
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
8328
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
8329
|
|
|
|
|
|
|
|
8330
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
8331
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
8332
|
|
|
|
|
|
|
|
8333
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
8334
|
|
|
|
|
|
|
size_t alignment, size_t size); |
8335
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
8336
|
|
|
|
|
|
|
|
8337
|
|
|
|
|
|
|
#ifdef FREESTANDING |
8338
|
|
|
|
|
|
|
|
8339
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
8340
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
8341
|
|
|
|
|
|
|
|
8342
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
8343
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
8344
|
|
|
|
|
|
|
|
8345
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
8346
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
8347
|
|
|
|
|
|
|
|
8348
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
8349
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
8350
|
|
|
|
|
|
|
|
8351
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
8352
|
|
|
|
|
|
|
#else |
8353
|
|
|
|
|
|
|
#include |
8354
|
|
|
|
|
|
|
#endif |
8355
|
|
|
|
|
|
|
|
8356
|
|
|
|
|
|
|
|
8357
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
8358
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
8359
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
8360
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
8361
|
|
|
|
|
|
|
#else |
8362
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
8363
|
|
|
|
|
|
|
#endif |
8364
|
|
|
|
|
|
|
|
8365
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
8366
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
8367
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
8368
|
|
|
|
|
|
|
|
8369
|
|
|
|
|
|
|
#endif |
8370
|
|
|
|
|
|
|
|
8371
|
|
|
|
|
|
|
|
8372
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
8373
|
|
|
|
|
|
|
|
8374
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
8375
|
|
|
|
|
|
|
|
8376
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
8377
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
8378
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
8379
|
|
|
|
|
|
|
#endif |
8380
|
|
|
|
|
|
|
|
8381
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
8382
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
8383
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
8384
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
8385
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
8386
|
|
|
|
|
|
|
|
8387
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
8388
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
8389
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
8390
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
8391
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
8392
|
|
|
|
|
|
|
|
8393
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
8394
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
8395
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
8396
|
|
|
|
|
|
|
|
8397
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
8398
|
|
|
|
|
|
|
|
8399
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
8400
|
|
|
|
|
|
|
{ |
8401
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
8402
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
8403
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
8404
|
|
|
|
|
|
|
} |
8405
|
|
|
|
|
|
|
#else |
8406
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
8407
|
|
|
|
|
|
|
#endif |
8408
|
|
|
|
|
|
|
|
8409
|
|
|
|
|
|
|
|
8410
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
8411
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
8412
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
8413
|
|
|
|
|
|
|
#else |
8414
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
8415
|
|
|
|
|
|
|
#endif |
8416
|
|
|
|
|
|
|
|
8417
|
|
|
|
|
|
|
|
8418
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
8419
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
8420
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
8421
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
8422
|
|
|
|
|
|
|
#else |
8423
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
8424
|
|
|
|
|
|
|
#endif |
8425
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
8426
|
|
|
|
|
|
|
|
8427
|
|
|
|
|
|
|
|
8428
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
8429
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
8430
|
|
|
|
|
|
|
#else |
8431
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
8432
|
|
|
|
|
|
|
#endif |
8433
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
8434
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
8435
|
|
|
|
|
|
|
defined(_MSC_VER))) |
8436
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
8437
|
|
|
|
|
|
|
#else |
8438
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
8439
|
|
|
|
|
|
|
#endif |
8440
|
|
|
|
|
|
|
|
8441
|
|
|
|
|
|
|
|
8442
|
|
|
|
|
|
|
#ifdef __AVX__ |
8443
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
8444
|
|
|
|
|
|
|
#else |
8445
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
8446
|
|
|
|
|
|
|
#endif |
8447
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
8448
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
8449
|
|
|
|
|
|
|
defined(_MSC_VER))) |
8450
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
8451
|
|
|
|
|
|
|
#else |
8452
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
8453
|
|
|
|
|
|
|
#endif |
8454
|
|
|
|
|
|
|
|
8455
|
|
|
|
|
|
|
|
8456
|
|
|
|
|
|
|
#ifdef __AVX2__ |
8457
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
8458
|
|
|
|
|
|
|
#else |
8459
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
8460
|
|
|
|
|
|
|
#endif |
8461
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
8462
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
8463
|
|
|
|
|
|
|
defined(_MSC_VER))) |
8464
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
8465
|
|
|
|
|
|
|
#else |
8466
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
8467
|
|
|
|
|
|
|
#endif |
8468
|
|
|
|
|
|
|
|
8469
|
|
|
|
|
|
|
|
8470
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
8471
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
8472
|
|
|
|
|
|
|
#else |
8473
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
8474
|
|
|
|
|
|
|
#endif |
8475
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
8476
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
8477
|
|
|
|
|
|
|
defined(_MSC_VER))) |
8478
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
8479
|
|
|
|
|
|
|
#else |
8480
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
8481
|
|
|
|
|
|
|
#endif |
8482
|
|
|
|
|
|
|
|
8483
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1930 |
8484
|
|
|
|
|
|
|
# undef HAVE_BMI2_NATIVE |
8485
|
|
|
|
|
|
|
# undef HAVE_BMI2_INTRIN |
8486
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
8487
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
8488
|
|
|
|
|
|
|
#endif |
8489
|
|
|
|
|
|
|
|
8490
|
|
|
|
|
|
|
#endif |
8491
|
|
|
|
|
|
|
|
8492
|
|
|
|
|
|
|
#endif |
8493
|
|
|
|
|
|
|
|
8494
|
|
|
|
|
|
|
|
8495
|
|
|
|
|
|
|
|
8496
|
|
|
|
|
|
|
#if HAVE_PCLMUL_INTRIN |
8497
|
|
|
|
|
|
|
# define crc32_x86_pclmul crc32_x86_pclmul |
8498
|
|
|
|
|
|
|
# define SUFFIX _pclmul |
8499
|
|
|
|
|
|
|
# if HAVE_PCLMUL_NATIVE |
8500
|
|
|
|
|
|
|
# define ATTRIBUTES |
8501
|
|
|
|
|
|
|
# else |
8502
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("pclmul") |
8503
|
|
|
|
|
|
|
# endif |
8504
|
|
|
|
|
|
|
# define FOLD_PARTIAL_VECS 0 |
8505
|
|
|
|
|
|
|
/* #include "x86-crc32_pclmul_template.h" */ |
8506
|
|
|
|
|
|
|
|
8507
|
|
|
|
|
|
|
|
8508
|
|
|
|
|
|
|
|
8509
|
|
|
|
|
|
|
|
8510
|
|
|
|
|
|
|
#include |
8511
|
|
|
|
|
|
|
|
8512
|
|
|
|
|
|
|
#if defined(__clang__) && defined(_MSC_VER) |
8513
|
|
|
|
|
|
|
# include |
8514
|
|
|
|
|
|
|
# include |
8515
|
|
|
|
|
|
|
# include |
8516
|
|
|
|
|
|
|
#endif |
8517
|
|
|
|
|
|
|
|
8518
|
|
|
|
|
|
|
#undef fold_vec |
8519
|
|
|
|
|
|
|
static forceinline ATTRIBUTES __m128i |
8520
|
|
|
|
|
|
|
ADD_SUFFIX(fold_vec)(__m128i src, __m128i dst, __m128i multipliers) |
8521
|
|
|
|
|
|
|
{ |
8522
|
|
|
|
|
|
|
|
8523
|
0
|
|
|
|
|
|
dst = _mm_xor_si128(dst, _mm_clmulepi64_si128(src, multipliers, 0x00)); |
8524
|
0
|
|
|
|
|
|
dst = _mm_xor_si128(dst, _mm_clmulepi64_si128(src, multipliers, 0x11)); |
8525
|
0
|
|
|
|
|
|
return dst; |
8526
|
|
|
|
|
|
|
} |
8527
|
|
|
|
|
|
|
#define fold_vec ADD_SUFFIX(fold_vec) |
8528
|
|
|
|
|
|
|
|
8529
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8530
|
|
|
|
|
|
|
|
8531
|
|
|
|
|
|
|
#undef fold_partial_vec |
8532
|
|
|
|
|
|
|
static forceinline ATTRIBUTES __m128i |
8533
|
|
|
|
|
|
|
ADD_SUFFIX(fold_partial_vec)(__m128i v, const u8 *p, size_t len, |
8534
|
|
|
|
|
|
|
__m128i multipliers_1) |
8535
|
|
|
|
|
|
|
{ |
8536
|
|
|
|
|
|
|
|
8537
|
|
|
|
|
|
|
static const u8 shift_tab[48] = { |
8538
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8539
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8540
|
|
|
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
8541
|
|
|
|
|
|
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
8542
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8543
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8544
|
|
|
|
|
|
|
}; |
8545
|
|
|
|
|
|
|
__m128i lshift = _mm_loadu_si128((const void *)&shift_tab[len]); |
8546
|
|
|
|
|
|
|
__m128i rshift = _mm_loadu_si128((const void *)&shift_tab[len + 16]); |
8547
|
|
|
|
|
|
|
__m128i x0, x1; |
8548
|
|
|
|
|
|
|
|
8549
|
|
|
|
|
|
|
|
8550
|
|
|
|
|
|
|
x0 = _mm_shuffle_epi8(v, lshift); |
8551
|
|
|
|
|
|
|
|
8552
|
|
|
|
|
|
|
|
8553
|
|
|
|
|
|
|
x1 = _mm_blendv_epi8(_mm_shuffle_epi8(v, rshift), |
8554
|
|
|
|
|
|
|
_mm_loadu_si128((const void *)(p + len - 16)), |
8555
|
|
|
|
|
|
|
|
8556
|
|
|
|
|
|
|
rshift); |
8557
|
|
|
|
|
|
|
|
8558
|
|
|
|
|
|
|
return fold_vec(x0, x1, multipliers_1); |
8559
|
|
|
|
|
|
|
} |
8560
|
|
|
|
|
|
|
#define fold_partial_vec ADD_SUFFIX(fold_partial_vec) |
8561
|
|
|
|
|
|
|
#endif |
8562
|
|
|
|
|
|
|
|
8563
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
8564
|
0
|
|
|
|
|
|
ADD_SUFFIX(crc32_x86)(u32 crc, const u8 *p, size_t len) |
8565
|
|
|
|
|
|
|
{ |
8566
|
0
|
|
|
|
|
|
const __m128i multipliers_8 = |
8567
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_8VECS_MULT_2, CRC32_8VECS_MULT_1); |
8568
|
0
|
|
|
|
|
|
const __m128i multipliers_4 = |
8569
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_4VECS_MULT_2, CRC32_4VECS_MULT_1); |
8570
|
0
|
|
|
|
|
|
const __m128i multipliers_2 = |
8571
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_2VECS_MULT_2, CRC32_2VECS_MULT_1); |
8572
|
0
|
|
|
|
|
|
const __m128i multipliers_1 = |
8573
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_1VECS_MULT_2, CRC32_1VECS_MULT_1); |
8574
|
0
|
|
|
|
|
|
const __m128i final_multiplier = |
8575
|
|
|
|
|
|
|
_mm_set_epi64x(0, CRC32_FINAL_MULT); |
8576
|
0
|
|
|
|
|
|
const __m128i mask32 = _mm_set_epi32(0, 0, 0, 0xFFFFFFFF); |
8577
|
0
|
|
|
|
|
|
const __m128i barrett_reduction_constants = |
8578
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_BARRETT_CONSTANT_2, |
8579
|
|
|
|
|
|
|
CRC32_BARRETT_CONSTANT_1); |
8580
|
|
|
|
|
|
|
__m128i v0, v1, v2, v3, v4, v5, v6, v7; |
8581
|
|
|
|
|
|
|
|
8582
|
|
|
|
|
|
|
|
8583
|
0
|
0
|
|
|
|
|
if (len < 1024) { |
8584
|
0
|
0
|
|
|
|
|
if (len < 16) |
8585
|
0
|
|
|
|
|
|
return crc32_slice1(crc, p, len); |
8586
|
|
|
|
|
|
|
|
8587
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_loadu_si128((const void *)p), |
8588
|
|
|
|
|
|
|
_mm_cvtsi32_si128(crc)); |
8589
|
0
|
|
|
|
|
|
p += 16; |
8590
|
|
|
|
|
|
|
|
8591
|
0
|
0
|
|
|
|
|
if (len >= 64) { |
8592
|
0
|
|
|
|
|
|
v1 = _mm_loadu_si128((const void *)(p + 0)); |
8593
|
0
|
|
|
|
|
|
v2 = _mm_loadu_si128((const void *)(p + 16)); |
8594
|
0
|
|
|
|
|
|
v3 = _mm_loadu_si128((const void *)(p + 32)); |
8595
|
0
|
|
|
|
|
|
p += 48; |
8596
|
0
|
0
|
|
|
|
|
while (len >= 64 + 64) { |
8597
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)(p + 0)), |
8598
|
|
|
|
|
|
|
multipliers_4); |
8599
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, _mm_loadu_si128((const void *)(p + 16)), |
8600
|
|
|
|
|
|
|
multipliers_4); |
8601
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, _mm_loadu_si128((const void *)(p + 32)), |
8602
|
|
|
|
|
|
|
multipliers_4); |
8603
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, _mm_loadu_si128((const void *)(p + 48)), |
8604
|
|
|
|
|
|
|
multipliers_4); |
8605
|
0
|
|
|
|
|
|
p += 64; |
8606
|
0
|
|
|
|
|
|
len -= 64; |
8607
|
|
|
|
|
|
|
} |
8608
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
8609
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
8610
|
0
|
0
|
|
|
|
|
if (len & 32) { |
8611
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)(p + 0)), |
8612
|
|
|
|
|
|
|
multipliers_2); |
8613
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, _mm_loadu_si128((const void *)(p + 16)), |
8614
|
|
|
|
|
|
|
multipliers_2); |
8615
|
0
|
|
|
|
|
|
p += 32; |
8616
|
|
|
|
|
|
|
} |
8617
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
8618
|
0
|
0
|
|
|
|
|
if (len & 16) { |
8619
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8620
|
|
|
|
|
|
|
multipliers_1); |
8621
|
0
|
|
|
|
|
|
p += 16; |
8622
|
|
|
|
|
|
|
} |
8623
|
|
|
|
|
|
|
} else { |
8624
|
0
|
0
|
|
|
|
|
if (len >= 32) { |
8625
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8626
|
|
|
|
|
|
|
multipliers_1); |
8627
|
0
|
|
|
|
|
|
p += 16; |
8628
|
0
|
0
|
|
|
|
|
if (len >= 48) { |
8629
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8630
|
|
|
|
|
|
|
multipliers_1); |
8631
|
0
|
|
|
|
|
|
p += 16; |
8632
|
|
|
|
|
|
|
} |
8633
|
|
|
|
|
|
|
} |
8634
|
|
|
|
|
|
|
} |
8635
|
|
|
|
|
|
|
} else { |
8636
|
0
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 15; |
8637
|
|
|
|
|
|
|
const __m128i *vp; |
8638
|
|
|
|
|
|
|
|
8639
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8640
|
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_loadu_si128((const void *)p), |
8641
|
|
|
|
|
|
|
_mm_cvtsi32_si128(crc)); |
8642
|
|
|
|
|
|
|
p += 16; |
8643
|
|
|
|
|
|
|
|
8644
|
|
|
|
|
|
|
if (align) { |
8645
|
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, align, multipliers_1); |
8646
|
|
|
|
|
|
|
p += align; |
8647
|
|
|
|
|
|
|
len -= align; |
8648
|
|
|
|
|
|
|
} |
8649
|
|
|
|
|
|
|
vp = (const __m128i *)p; |
8650
|
|
|
|
|
|
|
#else |
8651
|
|
|
|
|
|
|
|
8652
|
0
|
0
|
|
|
|
|
if (align) { |
8653
|
0
|
|
|
|
|
|
crc = crc32_slice1(crc, p, align); |
8654
|
0
|
|
|
|
|
|
p += align; |
8655
|
0
|
|
|
|
|
|
len -= align; |
8656
|
|
|
|
|
|
|
} |
8657
|
0
|
|
|
|
|
|
vp = (const __m128i *)p; |
8658
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(*vp++, _mm_cvtsi32_si128(crc)); |
8659
|
|
|
|
|
|
|
#endif |
8660
|
0
|
|
|
|
|
|
v1 = *vp++; |
8661
|
0
|
|
|
|
|
|
v2 = *vp++; |
8662
|
0
|
|
|
|
|
|
v3 = *vp++; |
8663
|
0
|
|
|
|
|
|
v4 = *vp++; |
8664
|
0
|
|
|
|
|
|
v5 = *vp++; |
8665
|
0
|
|
|
|
|
|
v6 = *vp++; |
8666
|
0
|
|
|
|
|
|
v7 = *vp++; |
8667
|
|
|
|
|
|
|
do { |
8668
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_8); |
8669
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_8); |
8670
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_8); |
8671
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_8); |
8672
|
0
|
|
|
|
|
|
v4 = fold_vec(v4, *vp++, multipliers_8); |
8673
|
0
|
|
|
|
|
|
v5 = fold_vec(v5, *vp++, multipliers_8); |
8674
|
0
|
|
|
|
|
|
v6 = fold_vec(v6, *vp++, multipliers_8); |
8675
|
0
|
|
|
|
|
|
v7 = fold_vec(v7, *vp++, multipliers_8); |
8676
|
0
|
|
|
|
|
|
len -= 128; |
8677
|
0
|
0
|
|
|
|
|
} while (len >= 128 + 128); |
8678
|
|
|
|
|
|
|
|
8679
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v4, multipliers_4); |
8680
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v5, multipliers_4); |
8681
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, v6, multipliers_4); |
8682
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, v7, multipliers_4); |
8683
|
0
|
0
|
|
|
|
|
if (len & 64) { |
8684
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_4); |
8685
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_4); |
8686
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_4); |
8687
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_4); |
8688
|
|
|
|
|
|
|
} |
8689
|
|
|
|
|
|
|
|
8690
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
8691
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
8692
|
0
|
0
|
|
|
|
|
if (len & 32) { |
8693
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_2); |
8694
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_2); |
8695
|
|
|
|
|
|
|
} |
8696
|
|
|
|
|
|
|
|
8697
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
8698
|
0
|
0
|
|
|
|
|
if (len & 16) |
8699
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_1); |
8700
|
|
|
|
|
|
|
|
8701
|
0
|
|
|
|
|
|
p = (const u8 *)vp; |
8702
|
|
|
|
|
|
|
} |
8703
|
0
|
|
|
|
|
|
len &= 15; |
8704
|
|
|
|
|
|
|
|
8705
|
|
|
|
|
|
|
|
8706
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8707
|
|
|
|
|
|
|
if (len) |
8708
|
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, len, multipliers_1); |
8709
|
|
|
|
|
|
|
#endif |
8710
|
|
|
|
|
|
|
|
8711
|
|
|
|
|
|
|
|
8712
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_srli_si128(v0, 8), |
8713
|
0
|
|
|
|
|
|
_mm_clmulepi64_si128(v0, multipliers_1, 0x10)); |
8714
|
|
|
|
|
|
|
|
8715
|
|
|
|
|
|
|
|
8716
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_srli_si128(v0, 4), |
8717
|
0
|
|
|
|
|
|
_mm_clmulepi64_si128(_mm_and_si128(v0, mask32), |
8718
|
|
|
|
|
|
|
final_multiplier, 0x00)); |
8719
|
|
|
|
|
|
|
|
8720
|
|
|
|
|
|
|
|
8721
|
0
|
|
|
|
|
|
v1 = _mm_clmulepi64_si128(_mm_and_si128(v0, mask32), |
8722
|
|
|
|
|
|
|
barrett_reduction_constants, 0x00); |
8723
|
0
|
|
|
|
|
|
v1 = _mm_clmulepi64_si128(_mm_and_si128(v1, mask32), |
8724
|
|
|
|
|
|
|
barrett_reduction_constants, 0x10); |
8725
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(v0, v1); |
8726
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8727
|
|
|
|
|
|
|
crc = _mm_extract_epi32(v0, 1); |
8728
|
|
|
|
|
|
|
#else |
8729
|
0
|
|
|
|
|
|
crc = _mm_cvtsi128_si32(_mm_shuffle_epi32(v0, 0x01)); |
8730
|
|
|
|
|
|
|
|
8731
|
0
|
|
|
|
|
|
crc = crc32_slice1(crc, p, len); |
8732
|
|
|
|
|
|
|
#endif |
8733
|
0
|
|
|
|
|
|
return crc; |
8734
|
|
|
|
|
|
|
} |
8735
|
|
|
|
|
|
|
|
8736
|
|
|
|
|
|
|
#undef SUFFIX |
8737
|
|
|
|
|
|
|
#undef ATTRIBUTES |
8738
|
|
|
|
|
|
|
#undef FOLD_PARTIAL_VECS |
8739
|
|
|
|
|
|
|
|
8740
|
|
|
|
|
|
|
#endif |
8741
|
|
|
|
|
|
|
|
8742
|
|
|
|
|
|
|
|
8743
|
|
|
|
|
|
|
#if HAVE_PCLMUL_INTRIN && HAVE_AVX_INTRIN |
8744
|
|
|
|
|
|
|
# define crc32_x86_pclmul_avx crc32_x86_pclmul_avx |
8745
|
|
|
|
|
|
|
# define SUFFIX _pclmul_avx |
8746
|
|
|
|
|
|
|
# if HAVE_PCLMUL_NATIVE && HAVE_AVX_NATIVE |
8747
|
|
|
|
|
|
|
# define ATTRIBUTES |
8748
|
|
|
|
|
|
|
# else |
8749
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("pclmul,avx") |
8750
|
|
|
|
|
|
|
# endif |
8751
|
|
|
|
|
|
|
# define FOLD_PARTIAL_VECS 1 |
8752
|
|
|
|
|
|
|
/* #include "x86-crc32_pclmul_template.h" */ |
8753
|
|
|
|
|
|
|
|
8754
|
|
|
|
|
|
|
|
8755
|
|
|
|
|
|
|
|
8756
|
|
|
|
|
|
|
|
8757
|
|
|
|
|
|
|
#include |
8758
|
|
|
|
|
|
|
|
8759
|
|
|
|
|
|
|
#if defined(__clang__) && defined(_MSC_VER) |
8760
|
|
|
|
|
|
|
# include |
8761
|
|
|
|
|
|
|
# include |
8762
|
|
|
|
|
|
|
# include |
8763
|
|
|
|
|
|
|
#endif |
8764
|
|
|
|
|
|
|
|
8765
|
|
|
|
|
|
|
#undef fold_vec |
8766
|
|
|
|
|
|
|
static forceinline ATTRIBUTES __m128i |
8767
|
|
|
|
|
|
|
ADD_SUFFIX(fold_vec)(__m128i src, __m128i dst, __m128i multipliers) |
8768
|
|
|
|
|
|
|
{ |
8769
|
|
|
|
|
|
|
|
8770
|
0
|
|
|
|
|
|
dst = _mm_xor_si128(dst, _mm_clmulepi64_si128(src, multipliers, 0x00)); |
8771
|
0
|
|
|
|
|
|
dst = _mm_xor_si128(dst, _mm_clmulepi64_si128(src, multipliers, 0x11)); |
8772
|
0
|
|
|
|
|
|
return dst; |
8773
|
|
|
|
|
|
|
} |
8774
|
|
|
|
|
|
|
#define fold_vec ADD_SUFFIX(fold_vec) |
8775
|
|
|
|
|
|
|
|
8776
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8777
|
|
|
|
|
|
|
|
8778
|
|
|
|
|
|
|
#undef fold_partial_vec |
8779
|
|
|
|
|
|
|
static forceinline ATTRIBUTES __m128i |
8780
|
|
|
|
|
|
|
ADD_SUFFIX(fold_partial_vec)(__m128i v, const u8 *p, size_t len, |
8781
|
|
|
|
|
|
|
__m128i multipliers_1) |
8782
|
|
|
|
|
|
|
{ |
8783
|
|
|
|
|
|
|
|
8784
|
|
|
|
|
|
|
static const u8 shift_tab[48] = { |
8785
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8786
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8787
|
|
|
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
8788
|
|
|
|
|
|
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
8789
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8790
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8791
|
|
|
|
|
|
|
}; |
8792
|
0
|
|
|
|
|
|
__m128i lshift = _mm_loadu_si128((const void *)&shift_tab[len]); |
8793
|
0
|
|
|
|
|
|
__m128i rshift = _mm_loadu_si128((const void *)&shift_tab[len + 16]); |
8794
|
|
|
|
|
|
|
__m128i x0, x1; |
8795
|
|
|
|
|
|
|
|
8796
|
|
|
|
|
|
|
|
8797
|
0
|
|
|
|
|
|
x0 = _mm_shuffle_epi8(v, lshift); |
8798
|
|
|
|
|
|
|
|
8799
|
|
|
|
|
|
|
|
8800
|
0
|
|
|
|
|
|
x1 = _mm_blendv_epi8(_mm_shuffle_epi8(v, rshift), |
8801
|
0
|
|
|
|
|
|
_mm_loadu_si128((const void *)(p + len - 16)), |
8802
|
|
|
|
|
|
|
|
8803
|
|
|
|
|
|
|
rshift); |
8804
|
|
|
|
|
|
|
|
8805
|
0
|
|
|
|
|
|
return fold_vec(x0, x1, multipliers_1); |
8806
|
|
|
|
|
|
|
} |
8807
|
|
|
|
|
|
|
#define fold_partial_vec ADD_SUFFIX(fold_partial_vec) |
8808
|
|
|
|
|
|
|
#endif |
8809
|
|
|
|
|
|
|
|
8810
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
8811
|
0
|
|
|
|
|
|
ADD_SUFFIX(crc32_x86)(u32 crc, const u8 *p, size_t len) |
8812
|
|
|
|
|
|
|
{ |
8813
|
0
|
|
|
|
|
|
const __m128i multipliers_8 = |
8814
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_8VECS_MULT_2, CRC32_8VECS_MULT_1); |
8815
|
0
|
|
|
|
|
|
const __m128i multipliers_4 = |
8816
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_4VECS_MULT_2, CRC32_4VECS_MULT_1); |
8817
|
0
|
|
|
|
|
|
const __m128i multipliers_2 = |
8818
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_2VECS_MULT_2, CRC32_2VECS_MULT_1); |
8819
|
0
|
|
|
|
|
|
const __m128i multipliers_1 = |
8820
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_1VECS_MULT_2, CRC32_1VECS_MULT_1); |
8821
|
0
|
|
|
|
|
|
const __m128i final_multiplier = |
8822
|
|
|
|
|
|
|
_mm_set_epi64x(0, CRC32_FINAL_MULT); |
8823
|
0
|
|
|
|
|
|
const __m128i mask32 = _mm_set_epi32(0, 0, 0, 0xFFFFFFFF); |
8824
|
0
|
|
|
|
|
|
const __m128i barrett_reduction_constants = |
8825
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_BARRETT_CONSTANT_2, |
8826
|
|
|
|
|
|
|
CRC32_BARRETT_CONSTANT_1); |
8827
|
|
|
|
|
|
|
__m128i v0, v1, v2, v3, v4, v5, v6, v7; |
8828
|
|
|
|
|
|
|
|
8829
|
|
|
|
|
|
|
|
8830
|
0
|
0
|
|
|
|
|
if (len < 1024) { |
8831
|
0
|
0
|
|
|
|
|
if (len < 16) |
8832
|
0
|
|
|
|
|
|
return crc32_slice1(crc, p, len); |
8833
|
|
|
|
|
|
|
|
8834
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_loadu_si128((const void *)p), |
8835
|
|
|
|
|
|
|
_mm_cvtsi32_si128(crc)); |
8836
|
0
|
|
|
|
|
|
p += 16; |
8837
|
|
|
|
|
|
|
|
8838
|
0
|
0
|
|
|
|
|
if (len >= 64) { |
8839
|
0
|
|
|
|
|
|
v1 = _mm_loadu_si128((const void *)(p + 0)); |
8840
|
0
|
|
|
|
|
|
v2 = _mm_loadu_si128((const void *)(p + 16)); |
8841
|
0
|
|
|
|
|
|
v3 = _mm_loadu_si128((const void *)(p + 32)); |
8842
|
0
|
|
|
|
|
|
p += 48; |
8843
|
0
|
0
|
|
|
|
|
while (len >= 64 + 64) { |
8844
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)(p + 0)), |
8845
|
|
|
|
|
|
|
multipliers_4); |
8846
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, _mm_loadu_si128((const void *)(p + 16)), |
8847
|
|
|
|
|
|
|
multipliers_4); |
8848
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, _mm_loadu_si128((const void *)(p + 32)), |
8849
|
|
|
|
|
|
|
multipliers_4); |
8850
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, _mm_loadu_si128((const void *)(p + 48)), |
8851
|
|
|
|
|
|
|
multipliers_4); |
8852
|
0
|
|
|
|
|
|
p += 64; |
8853
|
0
|
|
|
|
|
|
len -= 64; |
8854
|
|
|
|
|
|
|
} |
8855
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
8856
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
8857
|
0
|
0
|
|
|
|
|
if (len & 32) { |
8858
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)(p + 0)), |
8859
|
|
|
|
|
|
|
multipliers_2); |
8860
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, _mm_loadu_si128((const void *)(p + 16)), |
8861
|
|
|
|
|
|
|
multipliers_2); |
8862
|
0
|
|
|
|
|
|
p += 32; |
8863
|
|
|
|
|
|
|
} |
8864
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
8865
|
0
|
0
|
|
|
|
|
if (len & 16) { |
8866
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8867
|
|
|
|
|
|
|
multipliers_1); |
8868
|
0
|
|
|
|
|
|
p += 16; |
8869
|
|
|
|
|
|
|
} |
8870
|
|
|
|
|
|
|
} else { |
8871
|
0
|
0
|
|
|
|
|
if (len >= 32) { |
8872
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8873
|
|
|
|
|
|
|
multipliers_1); |
8874
|
0
|
|
|
|
|
|
p += 16; |
8875
|
0
|
0
|
|
|
|
|
if (len >= 48) { |
8876
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8877
|
|
|
|
|
|
|
multipliers_1); |
8878
|
0
|
|
|
|
|
|
p += 16; |
8879
|
|
|
|
|
|
|
} |
8880
|
|
|
|
|
|
|
} |
8881
|
|
|
|
|
|
|
} |
8882
|
|
|
|
|
|
|
} else { |
8883
|
0
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 15; |
8884
|
|
|
|
|
|
|
const __m128i *vp; |
8885
|
|
|
|
|
|
|
|
8886
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8887
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_loadu_si128((const void *)p), |
8888
|
|
|
|
|
|
|
_mm_cvtsi32_si128(crc)); |
8889
|
0
|
|
|
|
|
|
p += 16; |
8890
|
|
|
|
|
|
|
|
8891
|
0
|
0
|
|
|
|
|
if (align) { |
8892
|
0
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, align, multipliers_1); |
8893
|
0
|
|
|
|
|
|
p += align; |
8894
|
0
|
|
|
|
|
|
len -= align; |
8895
|
|
|
|
|
|
|
} |
8896
|
0
|
|
|
|
|
|
vp = (const __m128i *)p; |
8897
|
|
|
|
|
|
|
#else |
8898
|
|
|
|
|
|
|
|
8899
|
|
|
|
|
|
|
if (align) { |
8900
|
|
|
|
|
|
|
crc = crc32_slice1(crc, p, align); |
8901
|
|
|
|
|
|
|
p += align; |
8902
|
|
|
|
|
|
|
len -= align; |
8903
|
|
|
|
|
|
|
} |
8904
|
|
|
|
|
|
|
vp = (const __m128i *)p; |
8905
|
|
|
|
|
|
|
v0 = _mm_xor_si128(*vp++, _mm_cvtsi32_si128(crc)); |
8906
|
|
|
|
|
|
|
#endif |
8907
|
0
|
|
|
|
|
|
v1 = *vp++; |
8908
|
0
|
|
|
|
|
|
v2 = *vp++; |
8909
|
0
|
|
|
|
|
|
v3 = *vp++; |
8910
|
0
|
|
|
|
|
|
v4 = *vp++; |
8911
|
0
|
|
|
|
|
|
v5 = *vp++; |
8912
|
0
|
|
|
|
|
|
v6 = *vp++; |
8913
|
0
|
|
|
|
|
|
v7 = *vp++; |
8914
|
|
|
|
|
|
|
do { |
8915
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_8); |
8916
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_8); |
8917
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_8); |
8918
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_8); |
8919
|
0
|
|
|
|
|
|
v4 = fold_vec(v4, *vp++, multipliers_8); |
8920
|
0
|
|
|
|
|
|
v5 = fold_vec(v5, *vp++, multipliers_8); |
8921
|
0
|
|
|
|
|
|
v6 = fold_vec(v6, *vp++, multipliers_8); |
8922
|
0
|
|
|
|
|
|
v7 = fold_vec(v7, *vp++, multipliers_8); |
8923
|
0
|
|
|
|
|
|
len -= 128; |
8924
|
0
|
0
|
|
|
|
|
} while (len >= 128 + 128); |
8925
|
|
|
|
|
|
|
|
8926
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v4, multipliers_4); |
8927
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v5, multipliers_4); |
8928
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, v6, multipliers_4); |
8929
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, v7, multipliers_4); |
8930
|
0
|
0
|
|
|
|
|
if (len & 64) { |
8931
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_4); |
8932
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_4); |
8933
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_4); |
8934
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_4); |
8935
|
|
|
|
|
|
|
} |
8936
|
|
|
|
|
|
|
|
8937
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
8938
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
8939
|
0
|
0
|
|
|
|
|
if (len & 32) { |
8940
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_2); |
8941
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_2); |
8942
|
|
|
|
|
|
|
} |
8943
|
|
|
|
|
|
|
|
8944
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
8945
|
0
|
0
|
|
|
|
|
if (len & 16) |
8946
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_1); |
8947
|
|
|
|
|
|
|
|
8948
|
0
|
|
|
|
|
|
p = (const u8 *)vp; |
8949
|
|
|
|
|
|
|
} |
8950
|
0
|
|
|
|
|
|
len &= 15; |
8951
|
|
|
|
|
|
|
|
8952
|
|
|
|
|
|
|
|
8953
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8954
|
0
|
0
|
|
|
|
|
if (len) |
8955
|
0
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, len, multipliers_1); |
8956
|
|
|
|
|
|
|
#endif |
8957
|
|
|
|
|
|
|
|
8958
|
|
|
|
|
|
|
|
8959
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_srli_si128(v0, 8), |
8960
|
0
|
|
|
|
|
|
_mm_clmulepi64_si128(v0, multipliers_1, 0x10)); |
8961
|
|
|
|
|
|
|
|
8962
|
|
|
|
|
|
|
|
8963
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_srli_si128(v0, 4), |
8964
|
0
|
|
|
|
|
|
_mm_clmulepi64_si128(_mm_and_si128(v0, mask32), |
8965
|
|
|
|
|
|
|
final_multiplier, 0x00)); |
8966
|
|
|
|
|
|
|
|
8967
|
|
|
|
|
|
|
|
8968
|
0
|
|
|
|
|
|
v1 = _mm_clmulepi64_si128(_mm_and_si128(v0, mask32), |
8969
|
|
|
|
|
|
|
barrett_reduction_constants, 0x00); |
8970
|
0
|
|
|
|
|
|
v1 = _mm_clmulepi64_si128(_mm_and_si128(v1, mask32), |
8971
|
|
|
|
|
|
|
barrett_reduction_constants, 0x10); |
8972
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(v0, v1); |
8973
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8974
|
0
|
|
|
|
|
|
crc = _mm_extract_epi32(v0, 1); |
8975
|
|
|
|
|
|
|
#else |
8976
|
|
|
|
|
|
|
crc = _mm_cvtsi128_si32(_mm_shuffle_epi32(v0, 0x01)); |
8977
|
|
|
|
|
|
|
|
8978
|
|
|
|
|
|
|
crc = crc32_slice1(crc, p, len); |
8979
|
|
|
|
|
|
|
#endif |
8980
|
0
|
|
|
|
|
|
return crc; |
8981
|
|
|
|
|
|
|
} |
8982
|
|
|
|
|
|
|
|
8983
|
|
|
|
|
|
|
#undef SUFFIX |
8984
|
|
|
|
|
|
|
#undef ATTRIBUTES |
8985
|
|
|
|
|
|
|
#undef FOLD_PARTIAL_VECS |
8986
|
|
|
|
|
|
|
|
8987
|
|
|
|
|
|
|
#endif |
8988
|
|
|
|
|
|
|
|
8989
|
|
|
|
|
|
|
|
8990
|
|
|
|
|
|
|
#if defined(crc32_x86_pclmul_avx) && HAVE_PCLMUL_NATIVE && HAVE_AVX_NATIVE |
8991
|
|
|
|
|
|
|
#define DEFAULT_IMPL crc32_x86_pclmul_avx |
8992
|
|
|
|
|
|
|
#else |
8993
|
|
|
|
|
|
|
static inline crc32_func_t |
8994
|
2
|
|
|
|
|
|
arch_select_crc32_func(void) |
8995
|
|
|
|
|
|
|
{ |
8996
|
2
|
|
|
|
|
|
const u32 features MAYBE_UNUSED = get_x86_cpu_features(); |
8997
|
|
|
|
|
|
|
|
8998
|
|
|
|
|
|
|
#ifdef crc32_x86_pclmul_avx |
8999
|
2
|
50
|
|
|
|
|
if (HAVE_PCLMUL(features) && HAVE_AVX(features)) |
|
|
0
|
|
|
|
|
|
9000
|
0
|
|
|
|
|
|
return crc32_x86_pclmul_avx; |
9001
|
|
|
|
|
|
|
#endif |
9002
|
|
|
|
|
|
|
#ifdef crc32_x86_pclmul |
9003
|
2
|
50
|
|
|
|
|
if (HAVE_PCLMUL(features)) |
9004
|
0
|
|
|
|
|
|
return crc32_x86_pclmul; |
9005
|
|
|
|
|
|
|
#endif |
9006
|
2
|
|
|
|
|
|
return NULL; |
9007
|
|
|
|
|
|
|
} |
9008
|
|
|
|
|
|
|
#define arch_select_crc32_func arch_select_crc32_func |
9009
|
|
|
|
|
|
|
#endif |
9010
|
|
|
|
|
|
|
|
9011
|
|
|
|
|
|
|
#endif |
9012
|
|
|
|
|
|
|
|
9013
|
|
|
|
|
|
|
#endif |
9014
|
|
|
|
|
|
|
|
9015
|
|
|
|
|
|
|
#ifndef DEFAULT_IMPL |
9016
|
|
|
|
|
|
|
# define DEFAULT_IMPL crc32_slice8 |
9017
|
|
|
|
|
|
|
#endif |
9018
|
|
|
|
|
|
|
|
9019
|
|
|
|
|
|
|
#ifdef arch_select_crc32_func |
9020
|
|
|
|
|
|
|
static u32 crc32_dispatch_crc32(u32 crc, const u8 *p, size_t len); |
9021
|
|
|
|
|
|
|
|
9022
|
|
|
|
|
|
|
static volatile crc32_func_t crc32_impl = crc32_dispatch_crc32; |
9023
|
|
|
|
|
|
|
|
9024
|
|
|
|
|
|
|
|
9025
|
2
|
|
|
|
|
|
static u32 crc32_dispatch_crc32(u32 crc, const u8 *p, size_t len) |
9026
|
|
|
|
|
|
|
{ |
9027
|
2
|
|
|
|
|
|
crc32_func_t f = arch_select_crc32_func(); |
9028
|
|
|
|
|
|
|
|
9029
|
2
|
50
|
|
|
|
|
if (f == NULL) |
9030
|
2
|
|
|
|
|
|
f = DEFAULT_IMPL; |
9031
|
|
|
|
|
|
|
|
9032
|
2
|
|
|
|
|
|
crc32_impl = f; |
9033
|
2
|
|
|
|
|
|
return f(crc, p, len); |
9034
|
|
|
|
|
|
|
} |
9035
|
|
|
|
|
|
|
#else |
9036
|
|
|
|
|
|
|
|
9037
|
|
|
|
|
|
|
#define crc32_impl DEFAULT_IMPL |
9038
|
|
|
|
|
|
|
#endif |
9039
|
|
|
|
|
|
|
|
9040
|
|
|
|
|
|
|
LIBDEFLATEAPI u32 |
9041
|
29
|
|
|
|
|
|
libdeflate_crc32(u32 crc, const void *p, size_t len) |
9042
|
|
|
|
|
|
|
{ |
9043
|
29
|
50
|
|
|
|
|
if (p == NULL) |
9044
|
0
|
|
|
|
|
|
return 0; |
9045
|
29
|
|
|
|
|
|
return ~crc32_impl(~crc, p, len); |
9046
|
|
|
|
|
|
|
} |
9047
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/deflate_compress.c */ |
9048
|
|
|
|
|
|
|
|
9049
|
|
|
|
|
|
|
|
9050
|
|
|
|
|
|
|
/* #include "deflate_compress.h" */ |
9051
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_COMPRESS_H |
9052
|
|
|
|
|
|
|
#define LIB_DEFLATE_COMPRESS_H |
9053
|
|
|
|
|
|
|
|
9054
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
9055
|
|
|
|
|
|
|
|
9056
|
|
|
|
|
|
|
|
9057
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
9058
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
9059
|
|
|
|
|
|
|
|
9060
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
9061
|
|
|
|
|
|
|
|
9062
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
9063
|
|
|
|
|
|
|
#endif |
9064
|
|
|
|
|
|
|
|
9065
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
9066
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
9067
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
9068
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
9069
|
|
|
|
|
|
|
#else |
9070
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
9071
|
|
|
|
|
|
|
#endif |
9072
|
|
|
|
|
|
|
|
9073
|
|
|
|
|
|
|
|
9074
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
9075
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
9076
|
|
|
|
|
|
|
#else |
9077
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
9078
|
|
|
|
|
|
|
#endif |
9079
|
|
|
|
|
|
|
|
9080
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
9081
|
|
|
|
|
|
|
|
9082
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
9083
|
|
|
|
|
|
|
|
9084
|
|
|
|
|
|
|
|
9085
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
9086
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
9087
|
|
|
|
|
|
|
|
9088
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
9089
|
|
|
|
|
|
|
|
9090
|
|
|
|
|
|
|
|
9091
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
9092
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
9093
|
|
|
|
|
|
|
|
9094
|
|
|
|
|
|
|
#include |
9095
|
|
|
|
|
|
|
#include |
9096
|
|
|
|
|
|
|
|
9097
|
|
|
|
|
|
|
#ifdef __cplusplus |
9098
|
|
|
|
|
|
|
extern "C" { |
9099
|
|
|
|
|
|
|
#endif |
9100
|
|
|
|
|
|
|
|
9101
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
9102
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
9103
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
9104
|
|
|
|
|
|
|
|
9105
|
|
|
|
|
|
|
|
9106
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
9107
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
9108
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
9109
|
|
|
|
|
|
|
# else |
9110
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
9111
|
|
|
|
|
|
|
# endif |
9112
|
|
|
|
|
|
|
#endif |
9113
|
|
|
|
|
|
|
|
9114
|
|
|
|
|
|
|
|
9115
|
|
|
|
|
|
|
|
9116
|
|
|
|
|
|
|
|
9117
|
|
|
|
|
|
|
|
9118
|
|
|
|
|
|
|
struct libdeflate_compressor; |
9119
|
|
|
|
|
|
|
struct libdeflate_options; |
9120
|
|
|
|
|
|
|
|
9121
|
|
|
|
|
|
|
|
9122
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
9123
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
9124
|
|
|
|
|
|
|
|
9125
|
|
|
|
|
|
|
|
9126
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
9127
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
9128
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
9129
|
|
|
|
|
|
|
|
9130
|
|
|
|
|
|
|
|
9131
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9132
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
9133
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9134
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
9135
|
|
|
|
|
|
|
|
9136
|
|
|
|
|
|
|
|
9137
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9138
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
9139
|
|
|
|
|
|
|
size_t in_nbytes); |
9140
|
|
|
|
|
|
|
|
9141
|
|
|
|
|
|
|
|
9142
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9143
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
9144
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9145
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
9146
|
|
|
|
|
|
|
|
9147
|
|
|
|
|
|
|
|
9148
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9149
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
9150
|
|
|
|
|
|
|
size_t in_nbytes); |
9151
|
|
|
|
|
|
|
|
9152
|
|
|
|
|
|
|
|
9153
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9154
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
9155
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9156
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
9157
|
|
|
|
|
|
|
|
9158
|
|
|
|
|
|
|
|
9159
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9160
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
9161
|
|
|
|
|
|
|
size_t in_nbytes); |
9162
|
|
|
|
|
|
|
|
9163
|
|
|
|
|
|
|
|
9164
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
9165
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
9166
|
|
|
|
|
|
|
|
9167
|
|
|
|
|
|
|
|
9168
|
|
|
|
|
|
|
|
9169
|
|
|
|
|
|
|
|
9170
|
|
|
|
|
|
|
|
9171
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
9172
|
|
|
|
|
|
|
struct libdeflate_options; |
9173
|
|
|
|
|
|
|
|
9174
|
|
|
|
|
|
|
|
9175
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
9176
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
9177
|
|
|
|
|
|
|
|
9178
|
|
|
|
|
|
|
|
9179
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
9180
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
9181
|
|
|
|
|
|
|
|
9182
|
|
|
|
|
|
|
|
9183
|
|
|
|
|
|
|
enum libdeflate_result { |
9184
|
|
|
|
|
|
|
|
9185
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
9186
|
|
|
|
|
|
|
|
9187
|
|
|
|
|
|
|
|
9188
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
9189
|
|
|
|
|
|
|
|
9190
|
|
|
|
|
|
|
|
9191
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
9192
|
|
|
|
|
|
|
|
9193
|
|
|
|
|
|
|
|
9194
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
9195
|
|
|
|
|
|
|
}; |
9196
|
|
|
|
|
|
|
|
9197
|
|
|
|
|
|
|
|
9198
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9199
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
9200
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9201
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9202
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9203
|
|
|
|
|
|
|
|
9204
|
|
|
|
|
|
|
|
9205
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9206
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
9207
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9208
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9209
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
9210
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9211
|
|
|
|
|
|
|
|
9212
|
|
|
|
|
|
|
|
9213
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9214
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
9215
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9216
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9217
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9218
|
|
|
|
|
|
|
|
9219
|
|
|
|
|
|
|
|
9220
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9221
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
9222
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9223
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9224
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
9225
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9226
|
|
|
|
|
|
|
|
9227
|
|
|
|
|
|
|
|
9228
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9229
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
9230
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9231
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9232
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9233
|
|
|
|
|
|
|
|
9234
|
|
|
|
|
|
|
|
9235
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9236
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
9237
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9238
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9239
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
9240
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9241
|
|
|
|
|
|
|
|
9242
|
|
|
|
|
|
|
|
9243
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
9244
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
9245
|
|
|
|
|
|
|
|
9246
|
|
|
|
|
|
|
|
9247
|
|
|
|
|
|
|
|
9248
|
|
|
|
|
|
|
|
9249
|
|
|
|
|
|
|
|
9250
|
|
|
|
|
|
|
|
9251
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
9252
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
9253
|
|
|
|
|
|
|
|
9254
|
|
|
|
|
|
|
|
9255
|
|
|
|
|
|
|
|
9256
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
9257
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
9258
|
|
|
|
|
|
|
|
9259
|
|
|
|
|
|
|
|
9260
|
|
|
|
|
|
|
|
9261
|
|
|
|
|
|
|
|
9262
|
|
|
|
|
|
|
|
9263
|
|
|
|
|
|
|
|
9264
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
9265
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
9266
|
|
|
|
|
|
|
void (*free_func)(void *)); |
9267
|
|
|
|
|
|
|
|
9268
|
|
|
|
|
|
|
|
9269
|
|
|
|
|
|
|
struct libdeflate_options { |
9270
|
|
|
|
|
|
|
|
9271
|
|
|
|
|
|
|
|
9272
|
|
|
|
|
|
|
size_t sizeof_options; |
9273
|
|
|
|
|
|
|
|
9274
|
|
|
|
|
|
|
|
9275
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
9276
|
|
|
|
|
|
|
void (*free_func)(void *); |
9277
|
|
|
|
|
|
|
}; |
9278
|
|
|
|
|
|
|
|
9279
|
|
|
|
|
|
|
#ifdef __cplusplus |
9280
|
|
|
|
|
|
|
} |
9281
|
|
|
|
|
|
|
#endif |
9282
|
|
|
|
|
|
|
|
9283
|
|
|
|
|
|
|
#endif |
9284
|
|
|
|
|
|
|
|
9285
|
|
|
|
|
|
|
|
9286
|
|
|
|
|
|
|
#include |
9287
|
|
|
|
|
|
|
#include |
9288
|
|
|
|
|
|
|
#include |
9289
|
|
|
|
|
|
|
#ifdef _MSC_VER |
9290
|
|
|
|
|
|
|
# include |
9291
|
|
|
|
|
|
|
# include |
9292
|
|
|
|
|
|
|
|
9293
|
|
|
|
|
|
|
|
9294
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
9295
|
|
|
|
|
|
|
|
9296
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
9297
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
9298
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
9299
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
9300
|
|
|
|
|
|
|
|
9301
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
9302
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
9303
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
9304
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
9305
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
9306
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
9307
|
|
|
|
|
|
|
#endif |
9308
|
|
|
|
|
|
|
#ifndef FREESTANDING |
9309
|
|
|
|
|
|
|
# include |
9310
|
|
|
|
|
|
|
#endif |
9311
|
|
|
|
|
|
|
|
9312
|
|
|
|
|
|
|
|
9313
|
|
|
|
|
|
|
|
9314
|
|
|
|
|
|
|
|
9315
|
|
|
|
|
|
|
|
9316
|
|
|
|
|
|
|
|
9317
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
9318
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
9319
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
9320
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
9321
|
|
|
|
|
|
|
#ifdef _MSC_VER |
9322
|
|
|
|
|
|
|
# if defined(_M_X64) |
9323
|
|
|
|
|
|
|
# define ARCH_X86_64 |
9324
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
9325
|
|
|
|
|
|
|
# define ARCH_X86_32 |
9326
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
9327
|
|
|
|
|
|
|
# define ARCH_ARM64 |
9328
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
9329
|
|
|
|
|
|
|
# define ARCH_ARM32 |
9330
|
|
|
|
|
|
|
# endif |
9331
|
|
|
|
|
|
|
#else |
9332
|
|
|
|
|
|
|
# if defined(__x86_64__) |
9333
|
|
|
|
|
|
|
# define ARCH_X86_64 |
9334
|
|
|
|
|
|
|
# elif defined(__i386__) |
9335
|
|
|
|
|
|
|
# define ARCH_X86_32 |
9336
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
9337
|
|
|
|
|
|
|
# define ARCH_ARM64 |
9338
|
|
|
|
|
|
|
# elif defined(__arm__) |
9339
|
|
|
|
|
|
|
# define ARCH_ARM32 |
9340
|
|
|
|
|
|
|
# endif |
9341
|
|
|
|
|
|
|
#endif |
9342
|
|
|
|
|
|
|
|
9343
|
|
|
|
|
|
|
|
9344
|
|
|
|
|
|
|
|
9345
|
|
|
|
|
|
|
|
9346
|
|
|
|
|
|
|
|
9347
|
|
|
|
|
|
|
|
9348
|
|
|
|
|
|
|
typedef uint8_t u8; |
9349
|
|
|
|
|
|
|
typedef uint16_t u16; |
9350
|
|
|
|
|
|
|
typedef uint32_t u32; |
9351
|
|
|
|
|
|
|
typedef uint64_t u64; |
9352
|
|
|
|
|
|
|
typedef int8_t s8; |
9353
|
|
|
|
|
|
|
typedef int16_t s16; |
9354
|
|
|
|
|
|
|
typedef int32_t s32; |
9355
|
|
|
|
|
|
|
typedef int64_t s64; |
9356
|
|
|
|
|
|
|
|
9357
|
|
|
|
|
|
|
|
9358
|
|
|
|
|
|
|
#ifdef _MSC_VER |
9359
|
|
|
|
|
|
|
# ifdef _WIN64 |
9360
|
|
|
|
|
|
|
typedef long long ssize_t; |
9361
|
|
|
|
|
|
|
# else |
9362
|
|
|
|
|
|
|
typedef long ssize_t; |
9363
|
|
|
|
|
|
|
# endif |
9364
|
|
|
|
|
|
|
#endif |
9365
|
|
|
|
|
|
|
|
9366
|
|
|
|
|
|
|
|
9367
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
9368
|
|
|
|
|
|
|
|
9369
|
|
|
|
|
|
|
|
9370
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
9371
|
|
|
|
|
|
|
|
9372
|
|
|
|
|
|
|
|
9373
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
9374
|
|
|
|
|
|
|
|
9375
|
|
|
|
|
|
|
|
9376
|
|
|
|
|
|
|
|
9377
|
|
|
|
|
|
|
|
9378
|
|
|
|
|
|
|
|
9379
|
|
|
|
|
|
|
|
9380
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
9381
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
9382
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
9383
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
9384
|
|
|
|
|
|
|
#else |
9385
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
9386
|
|
|
|
|
|
|
#endif |
9387
|
|
|
|
|
|
|
#ifdef __clang__ |
9388
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
9389
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
9390
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
9391
|
|
|
|
|
|
|
# else |
9392
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
9393
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
9394
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
9395
|
|
|
|
|
|
|
# endif |
9396
|
|
|
|
|
|
|
#else |
9397
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
9398
|
|
|
|
|
|
|
#endif |
9399
|
|
|
|
|
|
|
|
9400
|
|
|
|
|
|
|
|
9401
|
|
|
|
|
|
|
#ifndef __has_attribute |
9402
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
9403
|
|
|
|
|
|
|
#endif |
9404
|
|
|
|
|
|
|
#ifndef __has_builtin |
9405
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
9406
|
|
|
|
|
|
|
#endif |
9407
|
|
|
|
|
|
|
|
9408
|
|
|
|
|
|
|
|
9409
|
|
|
|
|
|
|
#ifdef _MSC_VER |
9410
|
|
|
|
|
|
|
# define inline __inline |
9411
|
|
|
|
|
|
|
#endif |
9412
|
|
|
|
|
|
|
|
9413
|
|
|
|
|
|
|
|
9414
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
9415
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
9416
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9417
|
|
|
|
|
|
|
# define forceinline __forceinline |
9418
|
|
|
|
|
|
|
#else |
9419
|
|
|
|
|
|
|
# define forceinline inline |
9420
|
|
|
|
|
|
|
#endif |
9421
|
|
|
|
|
|
|
|
9422
|
|
|
|
|
|
|
|
9423
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
9424
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
9425
|
|
|
|
|
|
|
#else |
9426
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
9427
|
|
|
|
|
|
|
#endif |
9428
|
|
|
|
|
|
|
|
9429
|
|
|
|
|
|
|
|
9430
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
9431
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
9432
|
|
|
|
|
|
|
# define restrict __restrict__ |
9433
|
|
|
|
|
|
|
# else |
9434
|
|
|
|
|
|
|
# define restrict |
9435
|
|
|
|
|
|
|
# endif |
9436
|
|
|
|
|
|
|
#endif |
9437
|
|
|
|
|
|
|
|
9438
|
|
|
|
|
|
|
|
9439
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
9440
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
9441
|
|
|
|
|
|
|
#else |
9442
|
|
|
|
|
|
|
# define likely(expr) (expr) |
9443
|
|
|
|
|
|
|
#endif |
9444
|
|
|
|
|
|
|
|
9445
|
|
|
|
|
|
|
|
9446
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
9447
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
9448
|
|
|
|
|
|
|
#else |
9449
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
9450
|
|
|
|
|
|
|
#endif |
9451
|
|
|
|
|
|
|
|
9452
|
|
|
|
|
|
|
|
9453
|
|
|
|
|
|
|
#undef prefetchr |
9454
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
9455
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
9456
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9457
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
9458
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
9459
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
9460
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
9461
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
9462
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
9463
|
|
|
|
|
|
|
# endif |
9464
|
|
|
|
|
|
|
#endif |
9465
|
|
|
|
|
|
|
#ifndef prefetchr |
9466
|
|
|
|
|
|
|
# define prefetchr(addr) |
9467
|
|
|
|
|
|
|
#endif |
9468
|
|
|
|
|
|
|
|
9469
|
|
|
|
|
|
|
|
9470
|
|
|
|
|
|
|
#undef prefetchw |
9471
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
9472
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
9473
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9474
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
9475
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
9476
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
9477
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
9478
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
9479
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
9480
|
|
|
|
|
|
|
# endif |
9481
|
|
|
|
|
|
|
#endif |
9482
|
|
|
|
|
|
|
#ifndef prefetchw |
9483
|
|
|
|
|
|
|
# define prefetchw(addr) |
9484
|
|
|
|
|
|
|
#endif |
9485
|
|
|
|
|
|
|
|
9486
|
|
|
|
|
|
|
|
9487
|
|
|
|
|
|
|
#undef _aligned_attribute |
9488
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
9489
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
9490
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9491
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
9492
|
|
|
|
|
|
|
#endif |
9493
|
|
|
|
|
|
|
|
9494
|
|
|
|
|
|
|
|
9495
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
9496
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
9497
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
9498
|
|
|
|
|
|
|
#else |
9499
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
9500
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
9501
|
|
|
|
|
|
|
#endif |
9502
|
|
|
|
|
|
|
|
9503
|
|
|
|
|
|
|
|
9504
|
|
|
|
|
|
|
|
9505
|
|
|
|
|
|
|
|
9506
|
|
|
|
|
|
|
|
9507
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
9508
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
9509
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
9510
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
9511
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
9512
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
9513
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
9514
|
|
|
|
|
|
|
|
9515
|
|
|
|
|
|
|
|
9516
|
|
|
|
|
|
|
|
9517
|
|
|
|
|
|
|
|
9518
|
|
|
|
|
|
|
|
9519
|
|
|
|
|
|
|
|
9520
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
9521
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
9522
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9523
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
9524
|
|
|
|
|
|
|
#else |
9525
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
9526
|
|
|
|
|
|
|
{ |
9527
|
|
|
|
|
|
|
union { |
9528
|
|
|
|
|
|
|
u32 w; |
9529
|
|
|
|
|
|
|
u8 b; |
9530
|
|
|
|
|
|
|
} u; |
9531
|
|
|
|
|
|
|
|
9532
|
|
|
|
|
|
|
u.w = 1; |
9533
|
|
|
|
|
|
|
return u.b; |
9534
|
|
|
|
|
|
|
} |
9535
|
|
|
|
|
|
|
#endif |
9536
|
|
|
|
|
|
|
|
9537
|
|
|
|
|
|
|
|
9538
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
9539
|
|
|
|
|
|
|
{ |
9540
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
9541
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
9542
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9543
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
9544
|
|
|
|
|
|
|
#else |
9545
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
9546
|
|
|
|
|
|
|
#endif |
9547
|
|
|
|
|
|
|
} |
9548
|
|
|
|
|
|
|
|
9549
|
|
|
|
|
|
|
|
9550
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
9551
|
|
|
|
|
|
|
{ |
9552
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
9553
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
9554
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9555
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
9556
|
|
|
|
|
|
|
#else |
9557
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
9558
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
9559
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
9560
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
9561
|
|
|
|
|
|
|
#endif |
9562
|
|
|
|
|
|
|
} |
9563
|
|
|
|
|
|
|
|
9564
|
|
|
|
|
|
|
|
9565
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
9566
|
|
|
|
|
|
|
{ |
9567
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
9568
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
9569
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9570
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
9571
|
|
|
|
|
|
|
#else |
9572
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
9573
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
9574
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
9575
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
9576
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
9577
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
9578
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
9579
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
9580
|
|
|
|
|
|
|
#endif |
9581
|
|
|
|
|
|
|
} |
9582
|
|
|
|
|
|
|
|
9583
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
9584
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
9585
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
9586
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
9587
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
9588
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
9589
|
|
|
|
|
|
|
|
9590
|
|
|
|
|
|
|
|
9591
|
|
|
|
|
|
|
|
9592
|
|
|
|
|
|
|
|
9593
|
|
|
|
|
|
|
|
9594
|
|
|
|
|
|
|
|
9595
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
9596
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
9597
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
9598
|
|
|
|
|
|
|
defined(__wasm__)) |
9599
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
9600
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9601
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
9602
|
|
|
|
|
|
|
#else |
9603
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
9604
|
|
|
|
|
|
|
#endif |
9605
|
|
|
|
|
|
|
|
9606
|
|
|
|
|
|
|
|
9607
|
|
|
|
|
|
|
|
9608
|
|
|
|
|
|
|
#ifdef FREESTANDING |
9609
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
9610
|
|
|
|
|
|
|
#else |
9611
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
9612
|
|
|
|
|
|
|
#endif |
9613
|
|
|
|
|
|
|
|
9614
|
|
|
|
|
|
|
|
9615
|
|
|
|
|
|
|
|
9616
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
9617
|
|
|
|
|
|
|
static forceinline type \ |
9618
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
9619
|
|
|
|
|
|
|
{ \ |
9620
|
|
|
|
|
|
|
type v; \ |
9621
|
|
|
|
|
|
|
\ |
9622
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
9623
|
|
|
|
|
|
|
return v; \ |
9624
|
|
|
|
|
|
|
} \ |
9625
|
|
|
|
|
|
|
\ |
9626
|
|
|
|
|
|
|
static forceinline void \ |
9627
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
9628
|
|
|
|
|
|
|
{ \ |
9629
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
9630
|
|
|
|
|
|
|
} |
9631
|
|
|
|
|
|
|
|
9632
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
9633
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
9634
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
9635
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
9636
|
|
|
|
|
|
|
|
9637
|
|
|
|
|
|
|
#undef MEMCOPY |
9638
|
|
|
|
|
|
|
|
9639
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
9640
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
9641
|
|
|
|
|
|
|
|
9642
|
|
|
|
|
|
|
|
9643
|
|
|
|
|
|
|
|
9644
|
|
|
|
|
|
|
static forceinline u16 |
9645
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
9646
|
|
|
|
|
|
|
{ |
9647
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9648
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
9649
|
|
|
|
|
|
|
else |
9650
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
9651
|
|
|
|
|
|
|
} |
9652
|
|
|
|
|
|
|
|
9653
|
|
|
|
|
|
|
static forceinline u16 |
9654
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
9655
|
|
|
|
|
|
|
{ |
9656
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9657
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
9658
|
|
|
|
|
|
|
else |
9659
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
9660
|
|
|
|
|
|
|
} |
9661
|
|
|
|
|
|
|
|
9662
|
|
|
|
|
|
|
static forceinline u32 |
9663
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
9664
|
|
|
|
|
|
|
{ |
9665
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9666
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
9667
|
|
|
|
|
|
|
else |
9668
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
9669
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
9670
|
|
|
|
|
|
|
} |
9671
|
|
|
|
|
|
|
|
9672
|
|
|
|
|
|
|
static forceinline u32 |
9673
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
9674
|
|
|
|
|
|
|
{ |
9675
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9676
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
9677
|
|
|
|
|
|
|
else |
9678
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
9679
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
9680
|
|
|
|
|
|
|
} |
9681
|
|
|
|
|
|
|
|
9682
|
|
|
|
|
|
|
static forceinline u64 |
9683
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
9684
|
|
|
|
|
|
|
{ |
9685
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9686
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
9687
|
|
|
|
|
|
|
else |
9688
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
9689
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
9690
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
9691
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
9692
|
|
|
|
|
|
|
} |
9693
|
|
|
|
|
|
|
|
9694
|
|
|
|
|
|
|
static forceinline machine_word_t |
9695
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
9696
|
|
|
|
|
|
|
{ |
9697
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
9698
|
|
|
|
|
|
|
if (WORDBITS == 32) |
9699
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
9700
|
|
|
|
|
|
|
else |
9701
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
9702
|
|
|
|
|
|
|
} |
9703
|
|
|
|
|
|
|
|
9704
|
|
|
|
|
|
|
|
9705
|
|
|
|
|
|
|
|
9706
|
|
|
|
|
|
|
static forceinline void |
9707
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
9708
|
|
|
|
|
|
|
{ |
9709
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9710
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
9711
|
|
|
|
|
|
|
} else { |
9712
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
9713
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
9714
|
|
|
|
|
|
|
} |
9715
|
|
|
|
|
|
|
} |
9716
|
|
|
|
|
|
|
|
9717
|
|
|
|
|
|
|
static forceinline void |
9718
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
9719
|
|
|
|
|
|
|
{ |
9720
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9721
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
9722
|
|
|
|
|
|
|
} else { |
9723
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
9724
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
9725
|
|
|
|
|
|
|
} |
9726
|
|
|
|
|
|
|
} |
9727
|
|
|
|
|
|
|
|
9728
|
|
|
|
|
|
|
static forceinline void |
9729
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
9730
|
|
|
|
|
|
|
{ |
9731
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9732
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
9733
|
|
|
|
|
|
|
} else { |
9734
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
9735
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
9736
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
9737
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
9738
|
|
|
|
|
|
|
} |
9739
|
|
|
|
|
|
|
} |
9740
|
|
|
|
|
|
|
|
9741
|
|
|
|
|
|
|
static forceinline void |
9742
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
9743
|
|
|
|
|
|
|
{ |
9744
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9745
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
9746
|
|
|
|
|
|
|
} else { |
9747
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
9748
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
9749
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
9750
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
9751
|
|
|
|
|
|
|
} |
9752
|
|
|
|
|
|
|
} |
9753
|
|
|
|
|
|
|
|
9754
|
|
|
|
|
|
|
static forceinline void |
9755
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
9756
|
|
|
|
|
|
|
{ |
9757
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9758
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
9759
|
|
|
|
|
|
|
} else { |
9760
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
9761
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
9762
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
9763
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
9764
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
9765
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
9766
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
9767
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
9768
|
|
|
|
|
|
|
} |
9769
|
|
|
|
|
|
|
} |
9770
|
|
|
|
|
|
|
|
9771
|
|
|
|
|
|
|
static forceinline void |
9772
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
9773
|
|
|
|
|
|
|
{ |
9774
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
9775
|
|
|
|
|
|
|
if (WORDBITS == 32) |
9776
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
9777
|
|
|
|
|
|
|
else |
9778
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
9779
|
|
|
|
|
|
|
} |
9780
|
|
|
|
|
|
|
|
9781
|
|
|
|
|
|
|
|
9782
|
|
|
|
|
|
|
|
9783
|
|
|
|
|
|
|
|
9784
|
|
|
|
|
|
|
|
9785
|
|
|
|
|
|
|
|
9786
|
|
|
|
|
|
|
|
9787
|
|
|
|
|
|
|
static forceinline unsigned |
9788
|
|
|
|
|
|
|
bsr32(u32 v) |
9789
|
|
|
|
|
|
|
{ |
9790
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
9791
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
9792
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9793
|
|
|
|
|
|
|
unsigned long i; |
9794
|
|
|
|
|
|
|
|
9795
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
9796
|
|
|
|
|
|
|
return i; |
9797
|
|
|
|
|
|
|
#else |
9798
|
|
|
|
|
|
|
unsigned i = 0; |
9799
|
|
|
|
|
|
|
|
9800
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
9801
|
|
|
|
|
|
|
i++; |
9802
|
|
|
|
|
|
|
return i; |
9803
|
|
|
|
|
|
|
#endif |
9804
|
|
|
|
|
|
|
} |
9805
|
|
|
|
|
|
|
|
9806
|
|
|
|
|
|
|
static forceinline unsigned |
9807
|
|
|
|
|
|
|
bsr64(u64 v) |
9808
|
|
|
|
|
|
|
{ |
9809
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
9810
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
9811
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
9812
|
|
|
|
|
|
|
unsigned long i; |
9813
|
|
|
|
|
|
|
|
9814
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
9815
|
|
|
|
|
|
|
return i; |
9816
|
|
|
|
|
|
|
#else |
9817
|
|
|
|
|
|
|
unsigned i = 0; |
9818
|
|
|
|
|
|
|
|
9819
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
9820
|
|
|
|
|
|
|
i++; |
9821
|
|
|
|
|
|
|
return i; |
9822
|
|
|
|
|
|
|
#endif |
9823
|
|
|
|
|
|
|
} |
9824
|
|
|
|
|
|
|
|
9825
|
|
|
|
|
|
|
static forceinline unsigned |
9826
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
9827
|
|
|
|
|
|
|
{ |
9828
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
9829
|
|
|
|
|
|
|
if (WORDBITS == 32) |
9830
|
|
|
|
|
|
|
return bsr32(v); |
9831
|
|
|
|
|
|
|
else |
9832
|
|
|
|
|
|
|
return bsr64(v); |
9833
|
|
|
|
|
|
|
} |
9834
|
|
|
|
|
|
|
|
9835
|
|
|
|
|
|
|
|
9836
|
|
|
|
|
|
|
|
9837
|
|
|
|
|
|
|
static forceinline unsigned |
9838
|
|
|
|
|
|
|
bsf32(u32 v) |
9839
|
|
|
|
|
|
|
{ |
9840
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
9841
|
|
|
|
|
|
|
return __builtin_ctz(v); |
9842
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9843
|
|
|
|
|
|
|
unsigned long i; |
9844
|
|
|
|
|
|
|
|
9845
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
9846
|
|
|
|
|
|
|
return i; |
9847
|
|
|
|
|
|
|
#else |
9848
|
|
|
|
|
|
|
unsigned i = 0; |
9849
|
|
|
|
|
|
|
|
9850
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
9851
|
|
|
|
|
|
|
i++; |
9852
|
|
|
|
|
|
|
return i; |
9853
|
|
|
|
|
|
|
#endif |
9854
|
|
|
|
|
|
|
} |
9855
|
|
|
|
|
|
|
|
9856
|
|
|
|
|
|
|
static forceinline unsigned |
9857
|
|
|
|
|
|
|
bsf64(u64 v) |
9858
|
|
|
|
|
|
|
{ |
9859
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
9860
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
9861
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
9862
|
|
|
|
|
|
|
unsigned long i; |
9863
|
|
|
|
|
|
|
|
9864
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
9865
|
|
|
|
|
|
|
return i; |
9866
|
|
|
|
|
|
|
#else |
9867
|
|
|
|
|
|
|
unsigned i = 0; |
9868
|
|
|
|
|
|
|
|
9869
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
9870
|
|
|
|
|
|
|
i++; |
9871
|
|
|
|
|
|
|
return i; |
9872
|
|
|
|
|
|
|
#endif |
9873
|
|
|
|
|
|
|
} |
9874
|
|
|
|
|
|
|
|
9875
|
|
|
|
|
|
|
static forceinline unsigned |
9876
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
9877
|
|
|
|
|
|
|
{ |
9878
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
9879
|
|
|
|
|
|
|
if (WORDBITS == 32) |
9880
|
|
|
|
|
|
|
return bsf32(v); |
9881
|
|
|
|
|
|
|
else |
9882
|
|
|
|
|
|
|
return bsf64(v); |
9883
|
|
|
|
|
|
|
} |
9884
|
|
|
|
|
|
|
|
9885
|
|
|
|
|
|
|
|
9886
|
|
|
|
|
|
|
#undef rbit32 |
9887
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
9888
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
9889
|
|
|
|
|
|
|
static forceinline u32 |
9890
|
|
|
|
|
|
|
rbit32(u32 v) |
9891
|
|
|
|
|
|
|
{ |
9892
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
9893
|
|
|
|
|
|
|
return v; |
9894
|
|
|
|
|
|
|
} |
9895
|
|
|
|
|
|
|
#define rbit32 rbit32 |
9896
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
9897
|
|
|
|
|
|
|
static forceinline u32 |
9898
|
|
|
|
|
|
|
rbit32(u32 v) |
9899
|
|
|
|
|
|
|
{ |
9900
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
9901
|
|
|
|
|
|
|
return v; |
9902
|
|
|
|
|
|
|
} |
9903
|
|
|
|
|
|
|
#define rbit32 rbit32 |
9904
|
|
|
|
|
|
|
#endif |
9905
|
|
|
|
|
|
|
|
9906
|
|
|
|
|
|
|
#endif |
9907
|
|
|
|
|
|
|
|
9908
|
|
|
|
|
|
|
|
9909
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
9910
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
9911
|
|
|
|
|
|
|
|
9912
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
9913
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
9914
|
|
|
|
|
|
|
|
9915
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
9916
|
|
|
|
|
|
|
size_t alignment, size_t size); |
9917
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
9918
|
|
|
|
|
|
|
|
9919
|
|
|
|
|
|
|
#ifdef FREESTANDING |
9920
|
|
|
|
|
|
|
|
9921
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
9922
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
9923
|
|
|
|
|
|
|
|
9924
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
9925
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
9926
|
|
|
|
|
|
|
|
9927
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
9928
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
9929
|
|
|
|
|
|
|
|
9930
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
9931
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
9932
|
|
|
|
|
|
|
|
9933
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
9934
|
|
|
|
|
|
|
#else |
9935
|
|
|
|
|
|
|
#include |
9936
|
|
|
|
|
|
|
#endif |
9937
|
|
|
|
|
|
|
|
9938
|
|
|
|
|
|
|
|
9939
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
9940
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
9941
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
9942
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
9943
|
|
|
|
|
|
|
#else |
9944
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
9945
|
|
|
|
|
|
|
#endif |
9946
|
|
|
|
|
|
|
|
9947
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
9948
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
9949
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
9950
|
|
|
|
|
|
|
|
9951
|
|
|
|
|
|
|
#endif |
9952
|
|
|
|
|
|
|
|
9953
|
|
|
|
|
|
|
|
9954
|
|
|
|
|
|
|
|
9955
|
|
|
|
|
|
|
|
9956
|
|
|
|
|
|
|
struct libdeflate_compressor; |
9957
|
|
|
|
|
|
|
|
9958
|
|
|
|
|
|
|
unsigned int libdeflate_get_compression_level(struct libdeflate_compressor *c); |
9959
|
|
|
|
|
|
|
|
9960
|
|
|
|
|
|
|
#endif |
9961
|
|
|
|
|
|
|
|
9962
|
|
|
|
|
|
|
/* #include "deflate_constants.h" */ |
9963
|
|
|
|
|
|
|
|
9964
|
|
|
|
|
|
|
|
9965
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_CONSTANTS_H |
9966
|
|
|
|
|
|
|
#define LIB_DEFLATE_CONSTANTS_H |
9967
|
|
|
|
|
|
|
|
9968
|
|
|
|
|
|
|
|
9969
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_UNCOMPRESSED 0 |
9970
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_STATIC_HUFFMAN 1 |
9971
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN 2 |
9972
|
|
|
|
|
|
|
|
9973
|
|
|
|
|
|
|
|
9974
|
|
|
|
|
|
|
#define DEFLATE_MIN_MATCH_LEN 3 |
9975
|
|
|
|
|
|
|
#define DEFLATE_MAX_MATCH_LEN 258 |
9976
|
|
|
|
|
|
|
|
9977
|
|
|
|
|
|
|
|
9978
|
|
|
|
|
|
|
#define DEFLATE_MAX_MATCH_OFFSET 32768 |
9979
|
|
|
|
|
|
|
|
9980
|
|
|
|
|
|
|
|
9981
|
|
|
|
|
|
|
#define DEFLATE_WINDOW_ORDER 15 |
9982
|
|
|
|
|
|
|
|
9983
|
|
|
|
|
|
|
|
9984
|
|
|
|
|
|
|
#define DEFLATE_NUM_PRECODE_SYMS 19 |
9985
|
|
|
|
|
|
|
#define DEFLATE_NUM_LITLEN_SYMS 288 |
9986
|
|
|
|
|
|
|
#define DEFLATE_NUM_OFFSET_SYMS 32 |
9987
|
|
|
|
|
|
|
|
9988
|
|
|
|
|
|
|
|
9989
|
|
|
|
|
|
|
#define DEFLATE_MAX_NUM_SYMS 288 |
9990
|
|
|
|
|
|
|
|
9991
|
|
|
|
|
|
|
|
9992
|
|
|
|
|
|
|
#define DEFLATE_NUM_LITERALS 256 |
9993
|
|
|
|
|
|
|
#define DEFLATE_END_OF_BLOCK 256 |
9994
|
|
|
|
|
|
|
#define DEFLATE_FIRST_LEN_SYM 257 |
9995
|
|
|
|
|
|
|
|
9996
|
|
|
|
|
|
|
|
9997
|
|
|
|
|
|
|
#define DEFLATE_MAX_PRE_CODEWORD_LEN 7 |
9998
|
|
|
|
|
|
|
#define DEFLATE_MAX_LITLEN_CODEWORD_LEN 15 |
9999
|
|
|
|
|
|
|
#define DEFLATE_MAX_OFFSET_CODEWORD_LEN 15 |
10000
|
|
|
|
|
|
|
|
10001
|
|
|
|
|
|
|
|
10002
|
|
|
|
|
|
|
#define DEFLATE_MAX_CODEWORD_LEN 15 |
10003
|
|
|
|
|
|
|
|
10004
|
|
|
|
|
|
|
|
10005
|
|
|
|
|
|
|
#define DEFLATE_MAX_LENS_OVERRUN 137 |
10006
|
|
|
|
|
|
|
|
10007
|
|
|
|
|
|
|
|
10008
|
|
|
|
|
|
|
#define DEFLATE_MAX_EXTRA_LENGTH_BITS 5 |
10009
|
|
|
|
|
|
|
#define DEFLATE_MAX_EXTRA_OFFSET_BITS 13 |
10010
|
|
|
|
|
|
|
|
10011
|
|
|
|
|
|
|
#endif |
10012
|
|
|
|
|
|
|
|
10013
|
|
|
|
|
|
|
|
10014
|
|
|
|
|
|
|
|
10015
|
|
|
|
|
|
|
|
10016
|
|
|
|
|
|
|
|
10017
|
|
|
|
|
|
|
|
10018
|
|
|
|
|
|
|
|
10019
|
|
|
|
|
|
|
#define SUPPORT_NEAR_OPTIMAL_PARSING 1 |
10020
|
|
|
|
|
|
|
|
10021
|
|
|
|
|
|
|
|
10022
|
|
|
|
|
|
|
#define MIN_BLOCK_LENGTH 5000 |
10023
|
|
|
|
|
|
|
|
10024
|
|
|
|
|
|
|
|
10025
|
|
|
|
|
|
|
#define SOFT_MAX_BLOCK_LENGTH 300000 |
10026
|
|
|
|
|
|
|
|
10027
|
|
|
|
|
|
|
|
10028
|
|
|
|
|
|
|
#define SEQ_STORE_LENGTH 50000 |
10029
|
|
|
|
|
|
|
|
10030
|
|
|
|
|
|
|
|
10031
|
|
|
|
|
|
|
#define FAST_SOFT_MAX_BLOCK_LENGTH 65535 |
10032
|
|
|
|
|
|
|
|
10033
|
|
|
|
|
|
|
|
10034
|
|
|
|
|
|
|
#define FAST_SEQ_STORE_LENGTH 8192 |
10035
|
|
|
|
|
|
|
|
10036
|
|
|
|
|
|
|
|
10037
|
|
|
|
|
|
|
#define MAX_LITLEN_CODEWORD_LEN 14 |
10038
|
|
|
|
|
|
|
#define MAX_OFFSET_CODEWORD_LEN DEFLATE_MAX_OFFSET_CODEWORD_LEN |
10039
|
|
|
|
|
|
|
#define MAX_PRE_CODEWORD_LEN DEFLATE_MAX_PRE_CODEWORD_LEN |
10040
|
|
|
|
|
|
|
|
10041
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
10042
|
|
|
|
|
|
|
|
10043
|
|
|
|
|
|
|
|
10044
|
|
|
|
|
|
|
|
10045
|
|
|
|
|
|
|
|
10046
|
|
|
|
|
|
|
#define BIT_COST 16 |
10047
|
|
|
|
|
|
|
|
10048
|
|
|
|
|
|
|
|
10049
|
|
|
|
|
|
|
#define LITERAL_NOSTAT_BITS 13 |
10050
|
|
|
|
|
|
|
#define LENGTH_NOSTAT_BITS 13 |
10051
|
|
|
|
|
|
|
#define OFFSET_NOSTAT_BITS 10 |
10052
|
|
|
|
|
|
|
|
10053
|
|
|
|
|
|
|
|
10054
|
|
|
|
|
|
|
#define MATCH_CACHE_LENGTH (SOFT_MAX_BLOCK_LENGTH * 5) |
10055
|
|
|
|
|
|
|
|
10056
|
|
|
|
|
|
|
#endif |
10057
|
|
|
|
|
|
|
|
10058
|
|
|
|
|
|
|
|
10059
|
|
|
|
|
|
|
|
10060
|
|
|
|
|
|
|
|
10061
|
|
|
|
|
|
|
#define MATCHFINDER_WINDOW_ORDER DEFLATE_WINDOW_ORDER |
10062
|
|
|
|
|
|
|
/* #include "hc_matchfinder.h" */ |
10063
|
|
|
|
|
|
|
|
10064
|
|
|
|
|
|
|
|
10065
|
|
|
|
|
|
|
#ifndef LIB_HC_MATCHFINDER_H |
10066
|
|
|
|
|
|
|
#define LIB_HC_MATCHFINDER_H |
10067
|
|
|
|
|
|
|
|
10068
|
|
|
|
|
|
|
/* #include "matchfinder_common.h" */ |
10069
|
|
|
|
|
|
|
|
10070
|
|
|
|
|
|
|
|
10071
|
|
|
|
|
|
|
#ifndef LIB_MATCHFINDER_COMMON_H |
10072
|
|
|
|
|
|
|
#define LIB_MATCHFINDER_COMMON_H |
10073
|
|
|
|
|
|
|
|
10074
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
10075
|
|
|
|
|
|
|
|
10076
|
|
|
|
|
|
|
|
10077
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
10078
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
10079
|
|
|
|
|
|
|
|
10080
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
10081
|
|
|
|
|
|
|
|
10082
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
10083
|
|
|
|
|
|
|
#endif |
10084
|
|
|
|
|
|
|
|
10085
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
10086
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
10087
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
10088
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
10089
|
|
|
|
|
|
|
#else |
10090
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
10091
|
|
|
|
|
|
|
#endif |
10092
|
|
|
|
|
|
|
|
10093
|
|
|
|
|
|
|
|
10094
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
10095
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
10096
|
|
|
|
|
|
|
#else |
10097
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
10098
|
|
|
|
|
|
|
#endif |
10099
|
|
|
|
|
|
|
|
10100
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
10101
|
|
|
|
|
|
|
|
10102
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
10103
|
|
|
|
|
|
|
|
10104
|
|
|
|
|
|
|
|
10105
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
10106
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
10107
|
|
|
|
|
|
|
|
10108
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
10109
|
|
|
|
|
|
|
|
10110
|
|
|
|
|
|
|
|
10111
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
10112
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
10113
|
|
|
|
|
|
|
|
10114
|
|
|
|
|
|
|
#include |
10115
|
|
|
|
|
|
|
#include |
10116
|
|
|
|
|
|
|
|
10117
|
|
|
|
|
|
|
#ifdef __cplusplus |
10118
|
|
|
|
|
|
|
extern "C" { |
10119
|
|
|
|
|
|
|
#endif |
10120
|
|
|
|
|
|
|
|
10121
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
10122
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
10123
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
10124
|
|
|
|
|
|
|
|
10125
|
|
|
|
|
|
|
|
10126
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
10127
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
10128
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
10129
|
|
|
|
|
|
|
# else |
10130
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
10131
|
|
|
|
|
|
|
# endif |
10132
|
|
|
|
|
|
|
#endif |
10133
|
|
|
|
|
|
|
|
10134
|
|
|
|
|
|
|
|
10135
|
|
|
|
|
|
|
|
10136
|
|
|
|
|
|
|
|
10137
|
|
|
|
|
|
|
|
10138
|
|
|
|
|
|
|
struct libdeflate_compressor; |
10139
|
|
|
|
|
|
|
struct libdeflate_options; |
10140
|
|
|
|
|
|
|
|
10141
|
|
|
|
|
|
|
|
10142
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
10143
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
10144
|
|
|
|
|
|
|
|
10145
|
|
|
|
|
|
|
|
10146
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
10147
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
10148
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
10149
|
|
|
|
|
|
|
|
10150
|
|
|
|
|
|
|
|
10151
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10152
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
10153
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10154
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
10155
|
|
|
|
|
|
|
|
10156
|
|
|
|
|
|
|
|
10157
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10158
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
10159
|
|
|
|
|
|
|
size_t in_nbytes); |
10160
|
|
|
|
|
|
|
|
10161
|
|
|
|
|
|
|
|
10162
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10163
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
10164
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10165
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
10166
|
|
|
|
|
|
|
|
10167
|
|
|
|
|
|
|
|
10168
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10169
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
10170
|
|
|
|
|
|
|
size_t in_nbytes); |
10171
|
|
|
|
|
|
|
|
10172
|
|
|
|
|
|
|
|
10173
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10174
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
10175
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10176
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
10177
|
|
|
|
|
|
|
|
10178
|
|
|
|
|
|
|
|
10179
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10180
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
10181
|
|
|
|
|
|
|
size_t in_nbytes); |
10182
|
|
|
|
|
|
|
|
10183
|
|
|
|
|
|
|
|
10184
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
10185
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
10186
|
|
|
|
|
|
|
|
10187
|
|
|
|
|
|
|
|
10188
|
|
|
|
|
|
|
|
10189
|
|
|
|
|
|
|
|
10190
|
|
|
|
|
|
|
|
10191
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
10192
|
|
|
|
|
|
|
struct libdeflate_options; |
10193
|
|
|
|
|
|
|
|
10194
|
|
|
|
|
|
|
|
10195
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
10196
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
10197
|
|
|
|
|
|
|
|
10198
|
|
|
|
|
|
|
|
10199
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
10200
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
10201
|
|
|
|
|
|
|
|
10202
|
|
|
|
|
|
|
|
10203
|
|
|
|
|
|
|
enum libdeflate_result { |
10204
|
|
|
|
|
|
|
|
10205
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
10206
|
|
|
|
|
|
|
|
10207
|
|
|
|
|
|
|
|
10208
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
10209
|
|
|
|
|
|
|
|
10210
|
|
|
|
|
|
|
|
10211
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
10212
|
|
|
|
|
|
|
|
10213
|
|
|
|
|
|
|
|
10214
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
10215
|
|
|
|
|
|
|
}; |
10216
|
|
|
|
|
|
|
|
10217
|
|
|
|
|
|
|
|
10218
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10219
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
10220
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10221
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10222
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10223
|
|
|
|
|
|
|
|
10224
|
|
|
|
|
|
|
|
10225
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10226
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
10227
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10228
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10229
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10230
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10231
|
|
|
|
|
|
|
|
10232
|
|
|
|
|
|
|
|
10233
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10234
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
10235
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10236
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10237
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10238
|
|
|
|
|
|
|
|
10239
|
|
|
|
|
|
|
|
10240
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10241
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
10242
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10243
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10244
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10245
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10246
|
|
|
|
|
|
|
|
10247
|
|
|
|
|
|
|
|
10248
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10249
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
10250
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10251
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10252
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10253
|
|
|
|
|
|
|
|
10254
|
|
|
|
|
|
|
|
10255
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10256
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
10257
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10258
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10259
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10260
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10261
|
|
|
|
|
|
|
|
10262
|
|
|
|
|
|
|
|
10263
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
10264
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
10265
|
|
|
|
|
|
|
|
10266
|
|
|
|
|
|
|
|
10267
|
|
|
|
|
|
|
|
10268
|
|
|
|
|
|
|
|
10269
|
|
|
|
|
|
|
|
10270
|
|
|
|
|
|
|
|
10271
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
10272
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
10273
|
|
|
|
|
|
|
|
10274
|
|
|
|
|
|
|
|
10275
|
|
|
|
|
|
|
|
10276
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
10277
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
10278
|
|
|
|
|
|
|
|
10279
|
|
|
|
|
|
|
|
10280
|
|
|
|
|
|
|
|
10281
|
|
|
|
|
|
|
|
10282
|
|
|
|
|
|
|
|
10283
|
|
|
|
|
|
|
|
10284
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
10285
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
10286
|
|
|
|
|
|
|
void (*free_func)(void *)); |
10287
|
|
|
|
|
|
|
|
10288
|
|
|
|
|
|
|
|
10289
|
|
|
|
|
|
|
struct libdeflate_options { |
10290
|
|
|
|
|
|
|
|
10291
|
|
|
|
|
|
|
|
10292
|
|
|
|
|
|
|
size_t sizeof_options; |
10293
|
|
|
|
|
|
|
|
10294
|
|
|
|
|
|
|
|
10295
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
10296
|
|
|
|
|
|
|
void (*free_func)(void *); |
10297
|
|
|
|
|
|
|
}; |
10298
|
|
|
|
|
|
|
|
10299
|
|
|
|
|
|
|
#ifdef __cplusplus |
10300
|
|
|
|
|
|
|
} |
10301
|
|
|
|
|
|
|
#endif |
10302
|
|
|
|
|
|
|
|
10303
|
|
|
|
|
|
|
#endif |
10304
|
|
|
|
|
|
|
|
10305
|
|
|
|
|
|
|
|
10306
|
|
|
|
|
|
|
#include |
10307
|
|
|
|
|
|
|
#include |
10308
|
|
|
|
|
|
|
#include |
10309
|
|
|
|
|
|
|
#ifdef _MSC_VER |
10310
|
|
|
|
|
|
|
# include |
10311
|
|
|
|
|
|
|
# include |
10312
|
|
|
|
|
|
|
|
10313
|
|
|
|
|
|
|
|
10314
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
10315
|
|
|
|
|
|
|
|
10316
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
10317
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
10318
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
10319
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
10320
|
|
|
|
|
|
|
|
10321
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
10322
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
10323
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
10324
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
10325
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
10326
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
10327
|
|
|
|
|
|
|
#endif |
10328
|
|
|
|
|
|
|
#ifndef FREESTANDING |
10329
|
|
|
|
|
|
|
# include |
10330
|
|
|
|
|
|
|
#endif |
10331
|
|
|
|
|
|
|
|
10332
|
|
|
|
|
|
|
|
10333
|
|
|
|
|
|
|
|
10334
|
|
|
|
|
|
|
|
10335
|
|
|
|
|
|
|
|
10336
|
|
|
|
|
|
|
|
10337
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
10338
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
10339
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
10340
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
10341
|
|
|
|
|
|
|
#ifdef _MSC_VER |
10342
|
|
|
|
|
|
|
# if defined(_M_X64) |
10343
|
|
|
|
|
|
|
# define ARCH_X86_64 |
10344
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
10345
|
|
|
|
|
|
|
# define ARCH_X86_32 |
10346
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
10347
|
|
|
|
|
|
|
# define ARCH_ARM64 |
10348
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
10349
|
|
|
|
|
|
|
# define ARCH_ARM32 |
10350
|
|
|
|
|
|
|
# endif |
10351
|
|
|
|
|
|
|
#else |
10352
|
|
|
|
|
|
|
# if defined(__x86_64__) |
10353
|
|
|
|
|
|
|
# define ARCH_X86_64 |
10354
|
|
|
|
|
|
|
# elif defined(__i386__) |
10355
|
|
|
|
|
|
|
# define ARCH_X86_32 |
10356
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
10357
|
|
|
|
|
|
|
# define ARCH_ARM64 |
10358
|
|
|
|
|
|
|
# elif defined(__arm__) |
10359
|
|
|
|
|
|
|
# define ARCH_ARM32 |
10360
|
|
|
|
|
|
|
# endif |
10361
|
|
|
|
|
|
|
#endif |
10362
|
|
|
|
|
|
|
|
10363
|
|
|
|
|
|
|
|
10364
|
|
|
|
|
|
|
|
10365
|
|
|
|
|
|
|
|
10366
|
|
|
|
|
|
|
|
10367
|
|
|
|
|
|
|
|
10368
|
|
|
|
|
|
|
typedef uint8_t u8; |
10369
|
|
|
|
|
|
|
typedef uint16_t u16; |
10370
|
|
|
|
|
|
|
typedef uint32_t u32; |
10371
|
|
|
|
|
|
|
typedef uint64_t u64; |
10372
|
|
|
|
|
|
|
typedef int8_t s8; |
10373
|
|
|
|
|
|
|
typedef int16_t s16; |
10374
|
|
|
|
|
|
|
typedef int32_t s32; |
10375
|
|
|
|
|
|
|
typedef int64_t s64; |
10376
|
|
|
|
|
|
|
|
10377
|
|
|
|
|
|
|
|
10378
|
|
|
|
|
|
|
#ifdef _MSC_VER |
10379
|
|
|
|
|
|
|
# ifdef _WIN64 |
10380
|
|
|
|
|
|
|
typedef long long ssize_t; |
10381
|
|
|
|
|
|
|
# else |
10382
|
|
|
|
|
|
|
typedef long ssize_t; |
10383
|
|
|
|
|
|
|
# endif |
10384
|
|
|
|
|
|
|
#endif |
10385
|
|
|
|
|
|
|
|
10386
|
|
|
|
|
|
|
|
10387
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
10388
|
|
|
|
|
|
|
|
10389
|
|
|
|
|
|
|
|
10390
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
10391
|
|
|
|
|
|
|
|
10392
|
|
|
|
|
|
|
|
10393
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
10394
|
|
|
|
|
|
|
|
10395
|
|
|
|
|
|
|
|
10396
|
|
|
|
|
|
|
|
10397
|
|
|
|
|
|
|
|
10398
|
|
|
|
|
|
|
|
10399
|
|
|
|
|
|
|
|
10400
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
10401
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
10402
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
10403
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
10404
|
|
|
|
|
|
|
#else |
10405
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
10406
|
|
|
|
|
|
|
#endif |
10407
|
|
|
|
|
|
|
#ifdef __clang__ |
10408
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
10409
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
10410
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
10411
|
|
|
|
|
|
|
# else |
10412
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
10413
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
10414
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
10415
|
|
|
|
|
|
|
# endif |
10416
|
|
|
|
|
|
|
#else |
10417
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
10418
|
|
|
|
|
|
|
#endif |
10419
|
|
|
|
|
|
|
|
10420
|
|
|
|
|
|
|
|
10421
|
|
|
|
|
|
|
#ifndef __has_attribute |
10422
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
10423
|
|
|
|
|
|
|
#endif |
10424
|
|
|
|
|
|
|
#ifndef __has_builtin |
10425
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
10426
|
|
|
|
|
|
|
#endif |
10427
|
|
|
|
|
|
|
|
10428
|
|
|
|
|
|
|
|
10429
|
|
|
|
|
|
|
#ifdef _MSC_VER |
10430
|
|
|
|
|
|
|
# define inline __inline |
10431
|
|
|
|
|
|
|
#endif |
10432
|
|
|
|
|
|
|
|
10433
|
|
|
|
|
|
|
|
10434
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
10435
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
10436
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10437
|
|
|
|
|
|
|
# define forceinline __forceinline |
10438
|
|
|
|
|
|
|
#else |
10439
|
|
|
|
|
|
|
# define forceinline inline |
10440
|
|
|
|
|
|
|
#endif |
10441
|
|
|
|
|
|
|
|
10442
|
|
|
|
|
|
|
|
10443
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
10444
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
10445
|
|
|
|
|
|
|
#else |
10446
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
10447
|
|
|
|
|
|
|
#endif |
10448
|
|
|
|
|
|
|
|
10449
|
|
|
|
|
|
|
|
10450
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
10451
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
10452
|
|
|
|
|
|
|
# define restrict __restrict__ |
10453
|
|
|
|
|
|
|
# else |
10454
|
|
|
|
|
|
|
# define restrict |
10455
|
|
|
|
|
|
|
# endif |
10456
|
|
|
|
|
|
|
#endif |
10457
|
|
|
|
|
|
|
|
10458
|
|
|
|
|
|
|
|
10459
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
10460
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
10461
|
|
|
|
|
|
|
#else |
10462
|
|
|
|
|
|
|
# define likely(expr) (expr) |
10463
|
|
|
|
|
|
|
#endif |
10464
|
|
|
|
|
|
|
|
10465
|
|
|
|
|
|
|
|
10466
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
10467
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
10468
|
|
|
|
|
|
|
#else |
10469
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
10470
|
|
|
|
|
|
|
#endif |
10471
|
|
|
|
|
|
|
|
10472
|
|
|
|
|
|
|
|
10473
|
|
|
|
|
|
|
#undef prefetchr |
10474
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
10475
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
10476
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10477
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
10478
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
10479
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
10480
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
10481
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
10482
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
10483
|
|
|
|
|
|
|
# endif |
10484
|
|
|
|
|
|
|
#endif |
10485
|
|
|
|
|
|
|
#ifndef prefetchr |
10486
|
|
|
|
|
|
|
# define prefetchr(addr) |
10487
|
|
|
|
|
|
|
#endif |
10488
|
|
|
|
|
|
|
|
10489
|
|
|
|
|
|
|
|
10490
|
|
|
|
|
|
|
#undef prefetchw |
10491
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
10492
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
10493
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10494
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
10495
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
10496
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
10497
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
10498
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
10499
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
10500
|
|
|
|
|
|
|
# endif |
10501
|
|
|
|
|
|
|
#endif |
10502
|
|
|
|
|
|
|
#ifndef prefetchw |
10503
|
|
|
|
|
|
|
# define prefetchw(addr) |
10504
|
|
|
|
|
|
|
#endif |
10505
|
|
|
|
|
|
|
|
10506
|
|
|
|
|
|
|
|
10507
|
|
|
|
|
|
|
#undef _aligned_attribute |
10508
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
10509
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
10510
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10511
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
10512
|
|
|
|
|
|
|
#endif |
10513
|
|
|
|
|
|
|
|
10514
|
|
|
|
|
|
|
|
10515
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
10516
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
10517
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
10518
|
|
|
|
|
|
|
#else |
10519
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
10520
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
10521
|
|
|
|
|
|
|
#endif |
10522
|
|
|
|
|
|
|
|
10523
|
|
|
|
|
|
|
|
10524
|
|
|
|
|
|
|
|
10525
|
|
|
|
|
|
|
|
10526
|
|
|
|
|
|
|
|
10527
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
10528
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
10529
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
10530
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
10531
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
10532
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
10533
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
10534
|
|
|
|
|
|
|
|
10535
|
|
|
|
|
|
|
|
10536
|
|
|
|
|
|
|
|
10537
|
|
|
|
|
|
|
|
10538
|
|
|
|
|
|
|
|
10539
|
|
|
|
|
|
|
|
10540
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
10541
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
10542
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10543
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
10544
|
|
|
|
|
|
|
#else |
10545
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
10546
|
|
|
|
|
|
|
{ |
10547
|
|
|
|
|
|
|
union { |
10548
|
|
|
|
|
|
|
u32 w; |
10549
|
|
|
|
|
|
|
u8 b; |
10550
|
|
|
|
|
|
|
} u; |
10551
|
|
|
|
|
|
|
|
10552
|
|
|
|
|
|
|
u.w = 1; |
10553
|
|
|
|
|
|
|
return u.b; |
10554
|
|
|
|
|
|
|
} |
10555
|
|
|
|
|
|
|
#endif |
10556
|
|
|
|
|
|
|
|
10557
|
|
|
|
|
|
|
|
10558
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
10559
|
|
|
|
|
|
|
{ |
10560
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
10561
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
10562
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10563
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
10564
|
|
|
|
|
|
|
#else |
10565
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
10566
|
|
|
|
|
|
|
#endif |
10567
|
|
|
|
|
|
|
} |
10568
|
|
|
|
|
|
|
|
10569
|
|
|
|
|
|
|
|
10570
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
10571
|
|
|
|
|
|
|
{ |
10572
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
10573
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
10574
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10575
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
10576
|
|
|
|
|
|
|
#else |
10577
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
10578
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
10579
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
10580
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
10581
|
|
|
|
|
|
|
#endif |
10582
|
|
|
|
|
|
|
} |
10583
|
|
|
|
|
|
|
|
10584
|
|
|
|
|
|
|
|
10585
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
10586
|
|
|
|
|
|
|
{ |
10587
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
10588
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
10589
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10590
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
10591
|
|
|
|
|
|
|
#else |
10592
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
10593
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
10594
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
10595
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
10596
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
10597
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
10598
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
10599
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
10600
|
|
|
|
|
|
|
#endif |
10601
|
|
|
|
|
|
|
} |
10602
|
|
|
|
|
|
|
|
10603
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
10604
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
10605
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
10606
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
10607
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
10608
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
10609
|
|
|
|
|
|
|
|
10610
|
|
|
|
|
|
|
|
10611
|
|
|
|
|
|
|
|
10612
|
|
|
|
|
|
|
|
10613
|
|
|
|
|
|
|
|
10614
|
|
|
|
|
|
|
|
10615
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
10616
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
10617
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
10618
|
|
|
|
|
|
|
defined(__wasm__)) |
10619
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
10620
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10621
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
10622
|
|
|
|
|
|
|
#else |
10623
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
10624
|
|
|
|
|
|
|
#endif |
10625
|
|
|
|
|
|
|
|
10626
|
|
|
|
|
|
|
|
10627
|
|
|
|
|
|
|
|
10628
|
|
|
|
|
|
|
#ifdef FREESTANDING |
10629
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
10630
|
|
|
|
|
|
|
#else |
10631
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
10632
|
|
|
|
|
|
|
#endif |
10633
|
|
|
|
|
|
|
|
10634
|
|
|
|
|
|
|
|
10635
|
|
|
|
|
|
|
|
10636
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
10637
|
|
|
|
|
|
|
static forceinline type \ |
10638
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
10639
|
|
|
|
|
|
|
{ \ |
10640
|
|
|
|
|
|
|
type v; \ |
10641
|
|
|
|
|
|
|
\ |
10642
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
10643
|
|
|
|
|
|
|
return v; \ |
10644
|
|
|
|
|
|
|
} \ |
10645
|
|
|
|
|
|
|
\ |
10646
|
|
|
|
|
|
|
static forceinline void \ |
10647
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
10648
|
|
|
|
|
|
|
{ \ |
10649
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
10650
|
|
|
|
|
|
|
} |
10651
|
|
|
|
|
|
|
|
10652
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
10653
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
10654
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
10655
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
10656
|
|
|
|
|
|
|
|
10657
|
|
|
|
|
|
|
#undef MEMCOPY |
10658
|
|
|
|
|
|
|
|
10659
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
10660
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
10661
|
|
|
|
|
|
|
|
10662
|
|
|
|
|
|
|
|
10663
|
|
|
|
|
|
|
|
10664
|
|
|
|
|
|
|
static forceinline u16 |
10665
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
10666
|
|
|
|
|
|
|
{ |
10667
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10668
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
10669
|
|
|
|
|
|
|
else |
10670
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
10671
|
|
|
|
|
|
|
} |
10672
|
|
|
|
|
|
|
|
10673
|
|
|
|
|
|
|
static forceinline u16 |
10674
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
10675
|
|
|
|
|
|
|
{ |
10676
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10677
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
10678
|
|
|
|
|
|
|
else |
10679
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
10680
|
|
|
|
|
|
|
} |
10681
|
|
|
|
|
|
|
|
10682
|
|
|
|
|
|
|
static forceinline u32 |
10683
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
10684
|
|
|
|
|
|
|
{ |
10685
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10686
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
10687
|
|
|
|
|
|
|
else |
10688
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
10689
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
10690
|
|
|
|
|
|
|
} |
10691
|
|
|
|
|
|
|
|
10692
|
|
|
|
|
|
|
static forceinline u32 |
10693
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
10694
|
|
|
|
|
|
|
{ |
10695
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10696
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
10697
|
|
|
|
|
|
|
else |
10698
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
10699
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
10700
|
|
|
|
|
|
|
} |
10701
|
|
|
|
|
|
|
|
10702
|
|
|
|
|
|
|
static forceinline u64 |
10703
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
10704
|
|
|
|
|
|
|
{ |
10705
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10706
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
10707
|
|
|
|
|
|
|
else |
10708
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
10709
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
10710
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
10711
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
10712
|
|
|
|
|
|
|
} |
10713
|
|
|
|
|
|
|
|
10714
|
|
|
|
|
|
|
static forceinline machine_word_t |
10715
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
10716
|
|
|
|
|
|
|
{ |
10717
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
10718
|
|
|
|
|
|
|
if (WORDBITS == 32) |
10719
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
10720
|
|
|
|
|
|
|
else |
10721
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
10722
|
|
|
|
|
|
|
} |
10723
|
|
|
|
|
|
|
|
10724
|
|
|
|
|
|
|
|
10725
|
|
|
|
|
|
|
|
10726
|
|
|
|
|
|
|
static forceinline void |
10727
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
10728
|
|
|
|
|
|
|
{ |
10729
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10730
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
10731
|
|
|
|
|
|
|
} else { |
10732
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
10733
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
10734
|
|
|
|
|
|
|
} |
10735
|
|
|
|
|
|
|
} |
10736
|
|
|
|
|
|
|
|
10737
|
|
|
|
|
|
|
static forceinline void |
10738
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
10739
|
|
|
|
|
|
|
{ |
10740
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10741
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
10742
|
|
|
|
|
|
|
} else { |
10743
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
10744
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
10745
|
|
|
|
|
|
|
} |
10746
|
|
|
|
|
|
|
} |
10747
|
|
|
|
|
|
|
|
10748
|
|
|
|
|
|
|
static forceinline void |
10749
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
10750
|
|
|
|
|
|
|
{ |
10751
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10752
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
10753
|
|
|
|
|
|
|
} else { |
10754
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
10755
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
10756
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
10757
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
10758
|
|
|
|
|
|
|
} |
10759
|
|
|
|
|
|
|
} |
10760
|
|
|
|
|
|
|
|
10761
|
|
|
|
|
|
|
static forceinline void |
10762
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
10763
|
|
|
|
|
|
|
{ |
10764
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10765
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
10766
|
|
|
|
|
|
|
} else { |
10767
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
10768
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
10769
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
10770
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
10771
|
|
|
|
|
|
|
} |
10772
|
|
|
|
|
|
|
} |
10773
|
|
|
|
|
|
|
|
10774
|
|
|
|
|
|
|
static forceinline void |
10775
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
10776
|
|
|
|
|
|
|
{ |
10777
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10778
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
10779
|
|
|
|
|
|
|
} else { |
10780
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
10781
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
10782
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
10783
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
10784
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
10785
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
10786
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
10787
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
10788
|
|
|
|
|
|
|
} |
10789
|
|
|
|
|
|
|
} |
10790
|
|
|
|
|
|
|
|
10791
|
|
|
|
|
|
|
static forceinline void |
10792
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
10793
|
|
|
|
|
|
|
{ |
10794
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
10795
|
|
|
|
|
|
|
if (WORDBITS == 32) |
10796
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
10797
|
|
|
|
|
|
|
else |
10798
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
10799
|
|
|
|
|
|
|
} |
10800
|
|
|
|
|
|
|
|
10801
|
|
|
|
|
|
|
|
10802
|
|
|
|
|
|
|
|
10803
|
|
|
|
|
|
|
|
10804
|
|
|
|
|
|
|
|
10805
|
|
|
|
|
|
|
|
10806
|
|
|
|
|
|
|
|
10807
|
|
|
|
|
|
|
static forceinline unsigned |
10808
|
|
|
|
|
|
|
bsr32(u32 v) |
10809
|
|
|
|
|
|
|
{ |
10810
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
10811
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
10812
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10813
|
|
|
|
|
|
|
unsigned long i; |
10814
|
|
|
|
|
|
|
|
10815
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
10816
|
|
|
|
|
|
|
return i; |
10817
|
|
|
|
|
|
|
#else |
10818
|
|
|
|
|
|
|
unsigned i = 0; |
10819
|
|
|
|
|
|
|
|
10820
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
10821
|
|
|
|
|
|
|
i++; |
10822
|
|
|
|
|
|
|
return i; |
10823
|
|
|
|
|
|
|
#endif |
10824
|
|
|
|
|
|
|
} |
10825
|
|
|
|
|
|
|
|
10826
|
|
|
|
|
|
|
static forceinline unsigned |
10827
|
|
|
|
|
|
|
bsr64(u64 v) |
10828
|
|
|
|
|
|
|
{ |
10829
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
10830
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
10831
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
10832
|
|
|
|
|
|
|
unsigned long i; |
10833
|
|
|
|
|
|
|
|
10834
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
10835
|
|
|
|
|
|
|
return i; |
10836
|
|
|
|
|
|
|
#else |
10837
|
|
|
|
|
|
|
unsigned i = 0; |
10838
|
|
|
|
|
|
|
|
10839
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
10840
|
|
|
|
|
|
|
i++; |
10841
|
|
|
|
|
|
|
return i; |
10842
|
|
|
|
|
|
|
#endif |
10843
|
|
|
|
|
|
|
} |
10844
|
|
|
|
|
|
|
|
10845
|
|
|
|
|
|
|
static forceinline unsigned |
10846
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
10847
|
|
|
|
|
|
|
{ |
10848
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
10849
|
|
|
|
|
|
|
if (WORDBITS == 32) |
10850
|
|
|
|
|
|
|
return bsr32(v); |
10851
|
|
|
|
|
|
|
else |
10852
|
|
|
|
|
|
|
return bsr64(v); |
10853
|
|
|
|
|
|
|
} |
10854
|
|
|
|
|
|
|
|
10855
|
|
|
|
|
|
|
|
10856
|
|
|
|
|
|
|
|
10857
|
|
|
|
|
|
|
static forceinline unsigned |
10858
|
|
|
|
|
|
|
bsf32(u32 v) |
10859
|
|
|
|
|
|
|
{ |
10860
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
10861
|
|
|
|
|
|
|
return __builtin_ctz(v); |
10862
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10863
|
|
|
|
|
|
|
unsigned long i; |
10864
|
|
|
|
|
|
|
|
10865
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
10866
|
|
|
|
|
|
|
return i; |
10867
|
|
|
|
|
|
|
#else |
10868
|
|
|
|
|
|
|
unsigned i = 0; |
10869
|
|
|
|
|
|
|
|
10870
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
10871
|
|
|
|
|
|
|
i++; |
10872
|
|
|
|
|
|
|
return i; |
10873
|
|
|
|
|
|
|
#endif |
10874
|
|
|
|
|
|
|
} |
10875
|
|
|
|
|
|
|
|
10876
|
|
|
|
|
|
|
static forceinline unsigned |
10877
|
|
|
|
|
|
|
bsf64(u64 v) |
10878
|
|
|
|
|
|
|
{ |
10879
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
10880
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
10881
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
10882
|
|
|
|
|
|
|
unsigned long i; |
10883
|
|
|
|
|
|
|
|
10884
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
10885
|
|
|
|
|
|
|
return i; |
10886
|
|
|
|
|
|
|
#else |
10887
|
|
|
|
|
|
|
unsigned i = 0; |
10888
|
|
|
|
|
|
|
|
10889
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
10890
|
|
|
|
|
|
|
i++; |
10891
|
|
|
|
|
|
|
return i; |
10892
|
|
|
|
|
|
|
#endif |
10893
|
|
|
|
|
|
|
} |
10894
|
|
|
|
|
|
|
|
10895
|
|
|
|
|
|
|
static forceinline unsigned |
10896
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
10897
|
|
|
|
|
|
|
{ |
10898
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
10899
|
|
|
|
|
|
|
if (WORDBITS == 32) |
10900
|
|
|
|
|
|
|
return bsf32(v); |
10901
|
|
|
|
|
|
|
else |
10902
|
|
|
|
|
|
|
return bsf64(v); |
10903
|
|
|
|
|
|
|
} |
10904
|
|
|
|
|
|
|
|
10905
|
|
|
|
|
|
|
|
10906
|
|
|
|
|
|
|
#undef rbit32 |
10907
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
10908
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
10909
|
|
|
|
|
|
|
static forceinline u32 |
10910
|
|
|
|
|
|
|
rbit32(u32 v) |
10911
|
|
|
|
|
|
|
{ |
10912
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
10913
|
|
|
|
|
|
|
return v; |
10914
|
|
|
|
|
|
|
} |
10915
|
|
|
|
|
|
|
#define rbit32 rbit32 |
10916
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
10917
|
|
|
|
|
|
|
static forceinline u32 |
10918
|
|
|
|
|
|
|
rbit32(u32 v) |
10919
|
|
|
|
|
|
|
{ |
10920
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
10921
|
|
|
|
|
|
|
return v; |
10922
|
|
|
|
|
|
|
} |
10923
|
|
|
|
|
|
|
#define rbit32 rbit32 |
10924
|
|
|
|
|
|
|
#endif |
10925
|
|
|
|
|
|
|
|
10926
|
|
|
|
|
|
|
#endif |
10927
|
|
|
|
|
|
|
|
10928
|
|
|
|
|
|
|
|
10929
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
10930
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
10931
|
|
|
|
|
|
|
|
10932
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
10933
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
10934
|
|
|
|
|
|
|
|
10935
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
10936
|
|
|
|
|
|
|
size_t alignment, size_t size); |
10937
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
10938
|
|
|
|
|
|
|
|
10939
|
|
|
|
|
|
|
#ifdef FREESTANDING |
10940
|
|
|
|
|
|
|
|
10941
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
10942
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
10943
|
|
|
|
|
|
|
|
10944
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
10945
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
10946
|
|
|
|
|
|
|
|
10947
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
10948
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
10949
|
|
|
|
|
|
|
|
10950
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
10951
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
10952
|
|
|
|
|
|
|
|
10953
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
10954
|
|
|
|
|
|
|
#else |
10955
|
|
|
|
|
|
|
#include |
10956
|
|
|
|
|
|
|
#endif |
10957
|
|
|
|
|
|
|
|
10958
|
|
|
|
|
|
|
|
10959
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
10960
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
10961
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
10962
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
10963
|
|
|
|
|
|
|
#else |
10964
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
10965
|
|
|
|
|
|
|
#endif |
10966
|
|
|
|
|
|
|
|
10967
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
10968
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
10969
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
10970
|
|
|
|
|
|
|
|
10971
|
|
|
|
|
|
|
#endif |
10972
|
|
|
|
|
|
|
|
10973
|
|
|
|
|
|
|
|
10974
|
|
|
|
|
|
|
#ifndef MATCHFINDER_WINDOW_ORDER |
10975
|
|
|
|
|
|
|
# error "MATCHFINDER_WINDOW_ORDER must be defined!" |
10976
|
|
|
|
|
|
|
#endif |
10977
|
|
|
|
|
|
|
|
10978
|
|
|
|
|
|
|
|
10979
|
|
|
|
|
|
|
static forceinline u32 |
10980
|
|
|
|
|
|
|
loaded_u32_to_u24(u32 v) |
10981
|
|
|
|
|
|
|
{ |
10982
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
10983
|
126
|
|
|
|
|
|
return v & 0xFFFFFF; |
10984
|
|
|
|
|
|
|
else |
10985
|
|
|
|
|
|
|
return v >> 8; |
10986
|
|
|
|
|
|
|
} |
10987
|
|
|
|
|
|
|
|
10988
|
|
|
|
|
|
|
|
10989
|
|
|
|
|
|
|
static forceinline u32 |
10990
|
|
|
|
|
|
|
load_u24_unaligned(const u8 *p) |
10991
|
|
|
|
|
|
|
{ |
10992
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
10993
|
126
|
|
|
|
|
|
return loaded_u32_to_u24(load_u32_unaligned(p)); |
10994
|
|
|
|
|
|
|
#else |
10995
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
10996
|
|
|
|
|
|
|
return ((u32)p[0] << 0) | ((u32)p[1] << 8) | ((u32)p[2] << 16); |
10997
|
|
|
|
|
|
|
else |
10998
|
|
|
|
|
|
|
return ((u32)p[2] << 0) | ((u32)p[1] << 8) | ((u32)p[0] << 16); |
10999
|
|
|
|
|
|
|
#endif |
11000
|
|
|
|
|
|
|
} |
11001
|
|
|
|
|
|
|
|
11002
|
|
|
|
|
|
|
#define MATCHFINDER_WINDOW_SIZE (1UL << MATCHFINDER_WINDOW_ORDER) |
11003
|
|
|
|
|
|
|
|
11004
|
|
|
|
|
|
|
typedef s16 mf_pos_t; |
11005
|
|
|
|
|
|
|
|
11006
|
|
|
|
|
|
|
#define MATCHFINDER_INITVAL ((mf_pos_t)-MATCHFINDER_WINDOW_SIZE) |
11007
|
|
|
|
|
|
|
|
11008
|
|
|
|
|
|
|
|
11009
|
|
|
|
|
|
|
#define MATCHFINDER_MEM_ALIGNMENT 32 |
11010
|
|
|
|
|
|
|
#define MATCHFINDER_SIZE_ALIGNMENT 128 |
11011
|
|
|
|
|
|
|
|
11012
|
|
|
|
|
|
|
#undef matchfinder_init |
11013
|
|
|
|
|
|
|
#undef matchfinder_rebase |
11014
|
|
|
|
|
|
|
#ifdef _aligned_attribute |
11015
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED _aligned_attribute(MATCHFINDER_MEM_ALIGNMENT) |
11016
|
|
|
|
|
|
|
# if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
11017
|
|
|
|
|
|
|
/* # include "arm/matchfinder_impl.h" */ |
11018
|
|
|
|
|
|
|
|
11019
|
|
|
|
|
|
|
|
11020
|
|
|
|
|
|
|
#ifndef LIB_ARM_MATCHFINDER_IMPL_H |
11021
|
|
|
|
|
|
|
#define LIB_ARM_MATCHFINDER_IMPL_H |
11022
|
|
|
|
|
|
|
|
11023
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
11024
|
|
|
|
|
|
|
|
11025
|
|
|
|
|
|
|
|
11026
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
11027
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
11028
|
|
|
|
|
|
|
|
11029
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
11030
|
|
|
|
|
|
|
|
11031
|
|
|
|
|
|
|
|
11032
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
11033
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
11034
|
|
|
|
|
|
|
|
11035
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
11036
|
|
|
|
|
|
|
|
11037
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
11038
|
|
|
|
|
|
|
#endif |
11039
|
|
|
|
|
|
|
|
11040
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
11041
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
11042
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
11043
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
11044
|
|
|
|
|
|
|
#else |
11045
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
11046
|
|
|
|
|
|
|
#endif |
11047
|
|
|
|
|
|
|
|
11048
|
|
|
|
|
|
|
|
11049
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
11050
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
11051
|
|
|
|
|
|
|
#else |
11052
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
11053
|
|
|
|
|
|
|
#endif |
11054
|
|
|
|
|
|
|
|
11055
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
11056
|
|
|
|
|
|
|
|
11057
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
11058
|
|
|
|
|
|
|
|
11059
|
|
|
|
|
|
|
|
11060
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
11061
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
11062
|
|
|
|
|
|
|
|
11063
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
11064
|
|
|
|
|
|
|
|
11065
|
|
|
|
|
|
|
|
11066
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
11067
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
11068
|
|
|
|
|
|
|
|
11069
|
|
|
|
|
|
|
#include |
11070
|
|
|
|
|
|
|
#include |
11071
|
|
|
|
|
|
|
|
11072
|
|
|
|
|
|
|
#ifdef __cplusplus |
11073
|
|
|
|
|
|
|
extern "C" { |
11074
|
|
|
|
|
|
|
#endif |
11075
|
|
|
|
|
|
|
|
11076
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
11077
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
11078
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
11079
|
|
|
|
|
|
|
|
11080
|
|
|
|
|
|
|
|
11081
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
11082
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
11083
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
11084
|
|
|
|
|
|
|
# else |
11085
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
11086
|
|
|
|
|
|
|
# endif |
11087
|
|
|
|
|
|
|
#endif |
11088
|
|
|
|
|
|
|
|
11089
|
|
|
|
|
|
|
|
11090
|
|
|
|
|
|
|
|
11091
|
|
|
|
|
|
|
|
11092
|
|
|
|
|
|
|
|
11093
|
|
|
|
|
|
|
struct libdeflate_compressor; |
11094
|
|
|
|
|
|
|
struct libdeflate_options; |
11095
|
|
|
|
|
|
|
|
11096
|
|
|
|
|
|
|
|
11097
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
11098
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
11099
|
|
|
|
|
|
|
|
11100
|
|
|
|
|
|
|
|
11101
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
11102
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
11103
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
11104
|
|
|
|
|
|
|
|
11105
|
|
|
|
|
|
|
|
11106
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
11107
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
11108
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11109
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
11110
|
|
|
|
|
|
|
|
11111
|
|
|
|
|
|
|
|
11112
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
11113
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
11114
|
|
|
|
|
|
|
size_t in_nbytes); |
11115
|
|
|
|
|
|
|
|
11116
|
|
|
|
|
|
|
|
11117
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
11118
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
11119
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11120
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
11121
|
|
|
|
|
|
|
|
11122
|
|
|
|
|
|
|
|
11123
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
11124
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
11125
|
|
|
|
|
|
|
size_t in_nbytes); |
11126
|
|
|
|
|
|
|
|
11127
|
|
|
|
|
|
|
|
11128
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
11129
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
11130
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11131
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
11132
|
|
|
|
|
|
|
|
11133
|
|
|
|
|
|
|
|
11134
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
11135
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
11136
|
|
|
|
|
|
|
size_t in_nbytes); |
11137
|
|
|
|
|
|
|
|
11138
|
|
|
|
|
|
|
|
11139
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
11140
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
11141
|
|
|
|
|
|
|
|
11142
|
|
|
|
|
|
|
|
11143
|
|
|
|
|
|
|
|
11144
|
|
|
|
|
|
|
|
11145
|
|
|
|
|
|
|
|
11146
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
11147
|
|
|
|
|
|
|
struct libdeflate_options; |
11148
|
|
|
|
|
|
|
|
11149
|
|
|
|
|
|
|
|
11150
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
11151
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
11152
|
|
|
|
|
|
|
|
11153
|
|
|
|
|
|
|
|
11154
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
11155
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
11156
|
|
|
|
|
|
|
|
11157
|
|
|
|
|
|
|
|
11158
|
|
|
|
|
|
|
enum libdeflate_result { |
11159
|
|
|
|
|
|
|
|
11160
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
11161
|
|
|
|
|
|
|
|
11162
|
|
|
|
|
|
|
|
11163
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
11164
|
|
|
|
|
|
|
|
11165
|
|
|
|
|
|
|
|
11166
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
11167
|
|
|
|
|
|
|
|
11168
|
|
|
|
|
|
|
|
11169
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
11170
|
|
|
|
|
|
|
}; |
11171
|
|
|
|
|
|
|
|
11172
|
|
|
|
|
|
|
|
11173
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
11174
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
11175
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11176
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
11177
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
11178
|
|
|
|
|
|
|
|
11179
|
|
|
|
|
|
|
|
11180
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
11181
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
11182
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11183
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
11184
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
11185
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
11186
|
|
|
|
|
|
|
|
11187
|
|
|
|
|
|
|
|
11188
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
11189
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
11190
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11191
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
11192
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
11193
|
|
|
|
|
|
|
|
11194
|
|
|
|
|
|
|
|
11195
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
11196
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
11197
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11198
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
11199
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
11200
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
11201
|
|
|
|
|
|
|
|
11202
|
|
|
|
|
|
|
|
11203
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
11204
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
11205
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11206
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
11207
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
11208
|
|
|
|
|
|
|
|
11209
|
|
|
|
|
|
|
|
11210
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
11211
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
11212
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
11213
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
11214
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
11215
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
11216
|
|
|
|
|
|
|
|
11217
|
|
|
|
|
|
|
|
11218
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
11219
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
11220
|
|
|
|
|
|
|
|
11221
|
|
|
|
|
|
|
|
11222
|
|
|
|
|
|
|
|
11223
|
|
|
|
|
|
|
|
11224
|
|
|
|
|
|
|
|
11225
|
|
|
|
|
|
|
|
11226
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
11227
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
11228
|
|
|
|
|
|
|
|
11229
|
|
|
|
|
|
|
|
11230
|
|
|
|
|
|
|
|
11231
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
11232
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
11233
|
|
|
|
|
|
|
|
11234
|
|
|
|
|
|
|
|
11235
|
|
|
|
|
|
|
|
11236
|
|
|
|
|
|
|
|
11237
|
|
|
|
|
|
|
|
11238
|
|
|
|
|
|
|
|
11239
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
11240
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
11241
|
|
|
|
|
|
|
void (*free_func)(void *)); |
11242
|
|
|
|
|
|
|
|
11243
|
|
|
|
|
|
|
|
11244
|
|
|
|
|
|
|
struct libdeflate_options { |
11245
|
|
|
|
|
|
|
|
11246
|
|
|
|
|
|
|
|
11247
|
|
|
|
|
|
|
size_t sizeof_options; |
11248
|
|
|
|
|
|
|
|
11249
|
|
|
|
|
|
|
|
11250
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
11251
|
|
|
|
|
|
|
void (*free_func)(void *); |
11252
|
|
|
|
|
|
|
}; |
11253
|
|
|
|
|
|
|
|
11254
|
|
|
|
|
|
|
#ifdef __cplusplus |
11255
|
|
|
|
|
|
|
} |
11256
|
|
|
|
|
|
|
#endif |
11257
|
|
|
|
|
|
|
|
11258
|
|
|
|
|
|
|
#endif |
11259
|
|
|
|
|
|
|
|
11260
|
|
|
|
|
|
|
|
11261
|
|
|
|
|
|
|
#include |
11262
|
|
|
|
|
|
|
#include |
11263
|
|
|
|
|
|
|
#include |
11264
|
|
|
|
|
|
|
#ifdef _MSC_VER |
11265
|
|
|
|
|
|
|
# include |
11266
|
|
|
|
|
|
|
# include |
11267
|
|
|
|
|
|
|
|
11268
|
|
|
|
|
|
|
|
11269
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
11270
|
|
|
|
|
|
|
|
11271
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
11272
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
11273
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
11274
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
11275
|
|
|
|
|
|
|
|
11276
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
11277
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
11278
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
11279
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
11280
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
11281
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
11282
|
|
|
|
|
|
|
#endif |
11283
|
|
|
|
|
|
|
#ifndef FREESTANDING |
11284
|
|
|
|
|
|
|
# include |
11285
|
|
|
|
|
|
|
#endif |
11286
|
|
|
|
|
|
|
|
11287
|
|
|
|
|
|
|
|
11288
|
|
|
|
|
|
|
|
11289
|
|
|
|
|
|
|
|
11290
|
|
|
|
|
|
|
|
11291
|
|
|
|
|
|
|
|
11292
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
11293
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
11294
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
11295
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
11296
|
|
|
|
|
|
|
#ifdef _MSC_VER |
11297
|
|
|
|
|
|
|
# if defined(_M_X64) |
11298
|
|
|
|
|
|
|
# define ARCH_X86_64 |
11299
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
11300
|
|
|
|
|
|
|
# define ARCH_X86_32 |
11301
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
11302
|
|
|
|
|
|
|
# define ARCH_ARM64 |
11303
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
11304
|
|
|
|
|
|
|
# define ARCH_ARM32 |
11305
|
|
|
|
|
|
|
# endif |
11306
|
|
|
|
|
|
|
#else |
11307
|
|
|
|
|
|
|
# if defined(__x86_64__) |
11308
|
|
|
|
|
|
|
# define ARCH_X86_64 |
11309
|
|
|
|
|
|
|
# elif defined(__i386__) |
11310
|
|
|
|
|
|
|
# define ARCH_X86_32 |
11311
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
11312
|
|
|
|
|
|
|
# define ARCH_ARM64 |
11313
|
|
|
|
|
|
|
# elif defined(__arm__) |
11314
|
|
|
|
|
|
|
# define ARCH_ARM32 |
11315
|
|
|
|
|
|
|
# endif |
11316
|
|
|
|
|
|
|
#endif |
11317
|
|
|
|
|
|
|
|
11318
|
|
|
|
|
|
|
|
11319
|
|
|
|
|
|
|
|
11320
|
|
|
|
|
|
|
|
11321
|
|
|
|
|
|
|
|
11322
|
|
|
|
|
|
|
|
11323
|
|
|
|
|
|
|
typedef uint8_t u8; |
11324
|
|
|
|
|
|
|
typedef uint16_t u16; |
11325
|
|
|
|
|
|
|
typedef uint32_t u32; |
11326
|
|
|
|
|
|
|
typedef uint64_t u64; |
11327
|
|
|
|
|
|
|
typedef int8_t s8; |
11328
|
|
|
|
|
|
|
typedef int16_t s16; |
11329
|
|
|
|
|
|
|
typedef int32_t s32; |
11330
|
|
|
|
|
|
|
typedef int64_t s64; |
11331
|
|
|
|
|
|
|
|
11332
|
|
|
|
|
|
|
|
11333
|
|
|
|
|
|
|
#ifdef _MSC_VER |
11334
|
|
|
|
|
|
|
# ifdef _WIN64 |
11335
|
|
|
|
|
|
|
typedef long long ssize_t; |
11336
|
|
|
|
|
|
|
# else |
11337
|
|
|
|
|
|
|
typedef long ssize_t; |
11338
|
|
|
|
|
|
|
# endif |
11339
|
|
|
|
|
|
|
#endif |
11340
|
|
|
|
|
|
|
|
11341
|
|
|
|
|
|
|
|
11342
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
11343
|
|
|
|
|
|
|
|
11344
|
|
|
|
|
|
|
|
11345
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
11346
|
|
|
|
|
|
|
|
11347
|
|
|
|
|
|
|
|
11348
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
11349
|
|
|
|
|
|
|
|
11350
|
|
|
|
|
|
|
|
11351
|
|
|
|
|
|
|
|
11352
|
|
|
|
|
|
|
|
11353
|
|
|
|
|
|
|
|
11354
|
|
|
|
|
|
|
|
11355
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
11356
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
11357
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
11358
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
11359
|
|
|
|
|
|
|
#else |
11360
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
11361
|
|
|
|
|
|
|
#endif |
11362
|
|
|
|
|
|
|
#ifdef __clang__ |
11363
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
11364
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
11365
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
11366
|
|
|
|
|
|
|
# else |
11367
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
11368
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
11369
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
11370
|
|
|
|
|
|
|
# endif |
11371
|
|
|
|
|
|
|
#else |
11372
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
11373
|
|
|
|
|
|
|
#endif |
11374
|
|
|
|
|
|
|
|
11375
|
|
|
|
|
|
|
|
11376
|
|
|
|
|
|
|
#ifndef __has_attribute |
11377
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
11378
|
|
|
|
|
|
|
#endif |
11379
|
|
|
|
|
|
|
#ifndef __has_builtin |
11380
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
11381
|
|
|
|
|
|
|
#endif |
11382
|
|
|
|
|
|
|
|
11383
|
|
|
|
|
|
|
|
11384
|
|
|
|
|
|
|
#ifdef _MSC_VER |
11385
|
|
|
|
|
|
|
# define inline __inline |
11386
|
|
|
|
|
|
|
#endif |
11387
|
|
|
|
|
|
|
|
11388
|
|
|
|
|
|
|
|
11389
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
11390
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
11391
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11392
|
|
|
|
|
|
|
# define forceinline __forceinline |
11393
|
|
|
|
|
|
|
#else |
11394
|
|
|
|
|
|
|
# define forceinline inline |
11395
|
|
|
|
|
|
|
#endif |
11396
|
|
|
|
|
|
|
|
11397
|
|
|
|
|
|
|
|
11398
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
11399
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
11400
|
|
|
|
|
|
|
#else |
11401
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
11402
|
|
|
|
|
|
|
#endif |
11403
|
|
|
|
|
|
|
|
11404
|
|
|
|
|
|
|
|
11405
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
11406
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
11407
|
|
|
|
|
|
|
# define restrict __restrict__ |
11408
|
|
|
|
|
|
|
# else |
11409
|
|
|
|
|
|
|
# define restrict |
11410
|
|
|
|
|
|
|
# endif |
11411
|
|
|
|
|
|
|
#endif |
11412
|
|
|
|
|
|
|
|
11413
|
|
|
|
|
|
|
|
11414
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
11415
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
11416
|
|
|
|
|
|
|
#else |
11417
|
|
|
|
|
|
|
# define likely(expr) (expr) |
11418
|
|
|
|
|
|
|
#endif |
11419
|
|
|
|
|
|
|
|
11420
|
|
|
|
|
|
|
|
11421
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
11422
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
11423
|
|
|
|
|
|
|
#else |
11424
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
11425
|
|
|
|
|
|
|
#endif |
11426
|
|
|
|
|
|
|
|
11427
|
|
|
|
|
|
|
|
11428
|
|
|
|
|
|
|
#undef prefetchr |
11429
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
11430
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
11431
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11432
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
11433
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
11434
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
11435
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
11436
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
11437
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
11438
|
|
|
|
|
|
|
# endif |
11439
|
|
|
|
|
|
|
#endif |
11440
|
|
|
|
|
|
|
#ifndef prefetchr |
11441
|
|
|
|
|
|
|
# define prefetchr(addr) |
11442
|
|
|
|
|
|
|
#endif |
11443
|
|
|
|
|
|
|
|
11444
|
|
|
|
|
|
|
|
11445
|
|
|
|
|
|
|
#undef prefetchw |
11446
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
11447
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
11448
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11449
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
11450
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
11451
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
11452
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
11453
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
11454
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
11455
|
|
|
|
|
|
|
# endif |
11456
|
|
|
|
|
|
|
#endif |
11457
|
|
|
|
|
|
|
#ifndef prefetchw |
11458
|
|
|
|
|
|
|
# define prefetchw(addr) |
11459
|
|
|
|
|
|
|
#endif |
11460
|
|
|
|
|
|
|
|
11461
|
|
|
|
|
|
|
|
11462
|
|
|
|
|
|
|
#undef _aligned_attribute |
11463
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
11464
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
11465
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11466
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
11467
|
|
|
|
|
|
|
#endif |
11468
|
|
|
|
|
|
|
|
11469
|
|
|
|
|
|
|
|
11470
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
11471
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
11472
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
11473
|
|
|
|
|
|
|
#else |
11474
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
11475
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
11476
|
|
|
|
|
|
|
#endif |
11477
|
|
|
|
|
|
|
|
11478
|
|
|
|
|
|
|
|
11479
|
|
|
|
|
|
|
|
11480
|
|
|
|
|
|
|
|
11481
|
|
|
|
|
|
|
|
11482
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
11483
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
11484
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
11485
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
11486
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
11487
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
11488
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
11489
|
|
|
|
|
|
|
|
11490
|
|
|
|
|
|
|
|
11491
|
|
|
|
|
|
|
|
11492
|
|
|
|
|
|
|
|
11493
|
|
|
|
|
|
|
|
11494
|
|
|
|
|
|
|
|
11495
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
11496
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
11497
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11498
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
11499
|
|
|
|
|
|
|
#else |
11500
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
11501
|
|
|
|
|
|
|
{ |
11502
|
|
|
|
|
|
|
union { |
11503
|
|
|
|
|
|
|
u32 w; |
11504
|
|
|
|
|
|
|
u8 b; |
11505
|
|
|
|
|
|
|
} u; |
11506
|
|
|
|
|
|
|
|
11507
|
|
|
|
|
|
|
u.w = 1; |
11508
|
|
|
|
|
|
|
return u.b; |
11509
|
|
|
|
|
|
|
} |
11510
|
|
|
|
|
|
|
#endif |
11511
|
|
|
|
|
|
|
|
11512
|
|
|
|
|
|
|
|
11513
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
11514
|
|
|
|
|
|
|
{ |
11515
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
11516
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
11517
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11518
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
11519
|
|
|
|
|
|
|
#else |
11520
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
11521
|
|
|
|
|
|
|
#endif |
11522
|
|
|
|
|
|
|
} |
11523
|
|
|
|
|
|
|
|
11524
|
|
|
|
|
|
|
|
11525
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
11526
|
|
|
|
|
|
|
{ |
11527
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
11528
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
11529
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11530
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
11531
|
|
|
|
|
|
|
#else |
11532
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
11533
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
11534
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
11535
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
11536
|
|
|
|
|
|
|
#endif |
11537
|
|
|
|
|
|
|
} |
11538
|
|
|
|
|
|
|
|
11539
|
|
|
|
|
|
|
|
11540
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
11541
|
|
|
|
|
|
|
{ |
11542
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
11543
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
11544
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11545
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
11546
|
|
|
|
|
|
|
#else |
11547
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
11548
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
11549
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
11550
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
11551
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
11552
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
11553
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
11554
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
11555
|
|
|
|
|
|
|
#endif |
11556
|
|
|
|
|
|
|
} |
11557
|
|
|
|
|
|
|
|
11558
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
11559
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
11560
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
11561
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
11562
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
11563
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
11564
|
|
|
|
|
|
|
|
11565
|
|
|
|
|
|
|
|
11566
|
|
|
|
|
|
|
|
11567
|
|
|
|
|
|
|
|
11568
|
|
|
|
|
|
|
|
11569
|
|
|
|
|
|
|
|
11570
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
11571
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
11572
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
11573
|
|
|
|
|
|
|
defined(__wasm__)) |
11574
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
11575
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11576
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
11577
|
|
|
|
|
|
|
#else |
11578
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
11579
|
|
|
|
|
|
|
#endif |
11580
|
|
|
|
|
|
|
|
11581
|
|
|
|
|
|
|
|
11582
|
|
|
|
|
|
|
|
11583
|
|
|
|
|
|
|
#ifdef FREESTANDING |
11584
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
11585
|
|
|
|
|
|
|
#else |
11586
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
11587
|
|
|
|
|
|
|
#endif |
11588
|
|
|
|
|
|
|
|
11589
|
|
|
|
|
|
|
|
11590
|
|
|
|
|
|
|
|
11591
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
11592
|
|
|
|
|
|
|
static forceinline type \ |
11593
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
11594
|
|
|
|
|
|
|
{ \ |
11595
|
|
|
|
|
|
|
type v; \ |
11596
|
|
|
|
|
|
|
\ |
11597
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
11598
|
|
|
|
|
|
|
return v; \ |
11599
|
|
|
|
|
|
|
} \ |
11600
|
|
|
|
|
|
|
\ |
11601
|
|
|
|
|
|
|
static forceinline void \ |
11602
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
11603
|
|
|
|
|
|
|
{ \ |
11604
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
11605
|
|
|
|
|
|
|
} |
11606
|
|
|
|
|
|
|
|
11607
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
11608
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
11609
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
11610
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
11611
|
|
|
|
|
|
|
|
11612
|
|
|
|
|
|
|
#undef MEMCOPY |
11613
|
|
|
|
|
|
|
|
11614
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
11615
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
11616
|
|
|
|
|
|
|
|
11617
|
|
|
|
|
|
|
|
11618
|
|
|
|
|
|
|
|
11619
|
|
|
|
|
|
|
static forceinline u16 |
11620
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
11621
|
|
|
|
|
|
|
{ |
11622
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11623
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
11624
|
|
|
|
|
|
|
else |
11625
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
11626
|
|
|
|
|
|
|
} |
11627
|
|
|
|
|
|
|
|
11628
|
|
|
|
|
|
|
static forceinline u16 |
11629
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
11630
|
|
|
|
|
|
|
{ |
11631
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11632
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
11633
|
|
|
|
|
|
|
else |
11634
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
11635
|
|
|
|
|
|
|
} |
11636
|
|
|
|
|
|
|
|
11637
|
|
|
|
|
|
|
static forceinline u32 |
11638
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
11639
|
|
|
|
|
|
|
{ |
11640
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11641
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
11642
|
|
|
|
|
|
|
else |
11643
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
11644
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
11645
|
|
|
|
|
|
|
} |
11646
|
|
|
|
|
|
|
|
11647
|
|
|
|
|
|
|
static forceinline u32 |
11648
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
11649
|
|
|
|
|
|
|
{ |
11650
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11651
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
11652
|
|
|
|
|
|
|
else |
11653
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
11654
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
11655
|
|
|
|
|
|
|
} |
11656
|
|
|
|
|
|
|
|
11657
|
|
|
|
|
|
|
static forceinline u64 |
11658
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
11659
|
|
|
|
|
|
|
{ |
11660
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11661
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
11662
|
|
|
|
|
|
|
else |
11663
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
11664
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
11665
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
11666
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
11667
|
|
|
|
|
|
|
} |
11668
|
|
|
|
|
|
|
|
11669
|
|
|
|
|
|
|
static forceinline machine_word_t |
11670
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
11671
|
|
|
|
|
|
|
{ |
11672
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
11673
|
|
|
|
|
|
|
if (WORDBITS == 32) |
11674
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
11675
|
|
|
|
|
|
|
else |
11676
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
11677
|
|
|
|
|
|
|
} |
11678
|
|
|
|
|
|
|
|
11679
|
|
|
|
|
|
|
|
11680
|
|
|
|
|
|
|
|
11681
|
|
|
|
|
|
|
static forceinline void |
11682
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
11683
|
|
|
|
|
|
|
{ |
11684
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11685
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
11686
|
|
|
|
|
|
|
} else { |
11687
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
11688
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
11689
|
|
|
|
|
|
|
} |
11690
|
|
|
|
|
|
|
} |
11691
|
|
|
|
|
|
|
|
11692
|
|
|
|
|
|
|
static forceinline void |
11693
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
11694
|
|
|
|
|
|
|
{ |
11695
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11696
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
11697
|
|
|
|
|
|
|
} else { |
11698
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
11699
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
11700
|
|
|
|
|
|
|
} |
11701
|
|
|
|
|
|
|
} |
11702
|
|
|
|
|
|
|
|
11703
|
|
|
|
|
|
|
static forceinline void |
11704
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
11705
|
|
|
|
|
|
|
{ |
11706
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11707
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
11708
|
|
|
|
|
|
|
} else { |
11709
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
11710
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
11711
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
11712
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
11713
|
|
|
|
|
|
|
} |
11714
|
|
|
|
|
|
|
} |
11715
|
|
|
|
|
|
|
|
11716
|
|
|
|
|
|
|
static forceinline void |
11717
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
11718
|
|
|
|
|
|
|
{ |
11719
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11720
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
11721
|
|
|
|
|
|
|
} else { |
11722
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
11723
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
11724
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
11725
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
11726
|
|
|
|
|
|
|
} |
11727
|
|
|
|
|
|
|
} |
11728
|
|
|
|
|
|
|
|
11729
|
|
|
|
|
|
|
static forceinline void |
11730
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
11731
|
|
|
|
|
|
|
{ |
11732
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11733
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
11734
|
|
|
|
|
|
|
} else { |
11735
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
11736
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
11737
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
11738
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
11739
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
11740
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
11741
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
11742
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
11743
|
|
|
|
|
|
|
} |
11744
|
|
|
|
|
|
|
} |
11745
|
|
|
|
|
|
|
|
11746
|
|
|
|
|
|
|
static forceinline void |
11747
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
11748
|
|
|
|
|
|
|
{ |
11749
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
11750
|
|
|
|
|
|
|
if (WORDBITS == 32) |
11751
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
11752
|
|
|
|
|
|
|
else |
11753
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
11754
|
|
|
|
|
|
|
} |
11755
|
|
|
|
|
|
|
|
11756
|
|
|
|
|
|
|
|
11757
|
|
|
|
|
|
|
|
11758
|
|
|
|
|
|
|
|
11759
|
|
|
|
|
|
|
|
11760
|
|
|
|
|
|
|
|
11761
|
|
|
|
|
|
|
|
11762
|
|
|
|
|
|
|
static forceinline unsigned |
11763
|
|
|
|
|
|
|
bsr32(u32 v) |
11764
|
|
|
|
|
|
|
{ |
11765
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
11766
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
11767
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11768
|
|
|
|
|
|
|
unsigned long i; |
11769
|
|
|
|
|
|
|
|
11770
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
11771
|
|
|
|
|
|
|
return i; |
11772
|
|
|
|
|
|
|
#else |
11773
|
|
|
|
|
|
|
unsigned i = 0; |
11774
|
|
|
|
|
|
|
|
11775
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
11776
|
|
|
|
|
|
|
i++; |
11777
|
|
|
|
|
|
|
return i; |
11778
|
|
|
|
|
|
|
#endif |
11779
|
|
|
|
|
|
|
} |
11780
|
|
|
|
|
|
|
|
11781
|
|
|
|
|
|
|
static forceinline unsigned |
11782
|
|
|
|
|
|
|
bsr64(u64 v) |
11783
|
|
|
|
|
|
|
{ |
11784
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
11785
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
11786
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
11787
|
|
|
|
|
|
|
unsigned long i; |
11788
|
|
|
|
|
|
|
|
11789
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
11790
|
|
|
|
|
|
|
return i; |
11791
|
|
|
|
|
|
|
#else |
11792
|
|
|
|
|
|
|
unsigned i = 0; |
11793
|
|
|
|
|
|
|
|
11794
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
11795
|
|
|
|
|
|
|
i++; |
11796
|
|
|
|
|
|
|
return i; |
11797
|
|
|
|
|
|
|
#endif |
11798
|
|
|
|
|
|
|
} |
11799
|
|
|
|
|
|
|
|
11800
|
|
|
|
|
|
|
static forceinline unsigned |
11801
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
11802
|
|
|
|
|
|
|
{ |
11803
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
11804
|
|
|
|
|
|
|
if (WORDBITS == 32) |
11805
|
|
|
|
|
|
|
return bsr32(v); |
11806
|
|
|
|
|
|
|
else |
11807
|
|
|
|
|
|
|
return bsr64(v); |
11808
|
|
|
|
|
|
|
} |
11809
|
|
|
|
|
|
|
|
11810
|
|
|
|
|
|
|
|
11811
|
|
|
|
|
|
|
|
11812
|
|
|
|
|
|
|
static forceinline unsigned |
11813
|
|
|
|
|
|
|
bsf32(u32 v) |
11814
|
|
|
|
|
|
|
{ |
11815
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
11816
|
|
|
|
|
|
|
return __builtin_ctz(v); |
11817
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11818
|
|
|
|
|
|
|
unsigned long i; |
11819
|
|
|
|
|
|
|
|
11820
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
11821
|
|
|
|
|
|
|
return i; |
11822
|
|
|
|
|
|
|
#else |
11823
|
|
|
|
|
|
|
unsigned i = 0; |
11824
|
|
|
|
|
|
|
|
11825
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
11826
|
|
|
|
|
|
|
i++; |
11827
|
|
|
|
|
|
|
return i; |
11828
|
|
|
|
|
|
|
#endif |
11829
|
|
|
|
|
|
|
} |
11830
|
|
|
|
|
|
|
|
11831
|
|
|
|
|
|
|
static forceinline unsigned |
11832
|
|
|
|
|
|
|
bsf64(u64 v) |
11833
|
|
|
|
|
|
|
{ |
11834
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
11835
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
11836
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
11837
|
|
|
|
|
|
|
unsigned long i; |
11838
|
|
|
|
|
|
|
|
11839
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
11840
|
|
|
|
|
|
|
return i; |
11841
|
|
|
|
|
|
|
#else |
11842
|
|
|
|
|
|
|
unsigned i = 0; |
11843
|
|
|
|
|
|
|
|
11844
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
11845
|
|
|
|
|
|
|
i++; |
11846
|
|
|
|
|
|
|
return i; |
11847
|
|
|
|
|
|
|
#endif |
11848
|
|
|
|
|
|
|
} |
11849
|
|
|
|
|
|
|
|
11850
|
|
|
|
|
|
|
static forceinline unsigned |
11851
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
11852
|
|
|
|
|
|
|
{ |
11853
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
11854
|
|
|
|
|
|
|
if (WORDBITS == 32) |
11855
|
|
|
|
|
|
|
return bsf32(v); |
11856
|
|
|
|
|
|
|
else |
11857
|
|
|
|
|
|
|
return bsf64(v); |
11858
|
|
|
|
|
|
|
} |
11859
|
|
|
|
|
|
|
|
11860
|
|
|
|
|
|
|
|
11861
|
|
|
|
|
|
|
#undef rbit32 |
11862
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
11863
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
11864
|
|
|
|
|
|
|
static forceinline u32 |
11865
|
|
|
|
|
|
|
rbit32(u32 v) |
11866
|
|
|
|
|
|
|
{ |
11867
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
11868
|
|
|
|
|
|
|
return v; |
11869
|
|
|
|
|
|
|
} |
11870
|
|
|
|
|
|
|
#define rbit32 rbit32 |
11871
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
11872
|
|
|
|
|
|
|
static forceinline u32 |
11873
|
|
|
|
|
|
|
rbit32(u32 v) |
11874
|
|
|
|
|
|
|
{ |
11875
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
11876
|
|
|
|
|
|
|
return v; |
11877
|
|
|
|
|
|
|
} |
11878
|
|
|
|
|
|
|
#define rbit32 rbit32 |
11879
|
|
|
|
|
|
|
#endif |
11880
|
|
|
|
|
|
|
|
11881
|
|
|
|
|
|
|
#endif |
11882
|
|
|
|
|
|
|
|
11883
|
|
|
|
|
|
|
|
11884
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
11885
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
11886
|
|
|
|
|
|
|
|
11887
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
11888
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
11889
|
|
|
|
|
|
|
|
11890
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
11891
|
|
|
|
|
|
|
size_t alignment, size_t size); |
11892
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
11893
|
|
|
|
|
|
|
|
11894
|
|
|
|
|
|
|
#ifdef FREESTANDING |
11895
|
|
|
|
|
|
|
|
11896
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
11897
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
11898
|
|
|
|
|
|
|
|
11899
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
11900
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
11901
|
|
|
|
|
|
|
|
11902
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
11903
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
11904
|
|
|
|
|
|
|
|
11905
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
11906
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
11907
|
|
|
|
|
|
|
|
11908
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
11909
|
|
|
|
|
|
|
#else |
11910
|
|
|
|
|
|
|
#include |
11911
|
|
|
|
|
|
|
#endif |
11912
|
|
|
|
|
|
|
|
11913
|
|
|
|
|
|
|
|
11914
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
11915
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
11916
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
11917
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
11918
|
|
|
|
|
|
|
#else |
11919
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
11920
|
|
|
|
|
|
|
#endif |
11921
|
|
|
|
|
|
|
|
11922
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
11923
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
11924
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
11925
|
|
|
|
|
|
|
|
11926
|
|
|
|
|
|
|
#endif |
11927
|
|
|
|
|
|
|
|
11928
|
|
|
|
|
|
|
|
11929
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
11930
|
|
|
|
|
|
|
|
11931
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
11932
|
|
|
|
|
|
|
|
11933
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
11934
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
11935
|
|
|
|
|
|
|
(defined(__linux__) || \ |
11936
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
11937
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
11938
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
11939
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
11940
|
|
|
|
|
|
|
#endif |
11941
|
|
|
|
|
|
|
|
11942
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
11943
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
11944
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
11945
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
11946
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
11947
|
|
|
|
|
|
|
|
11948
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
11949
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
11950
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
11951
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
11952
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
11953
|
|
|
|
|
|
|
|
11954
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
11955
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
11956
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
11957
|
|
|
|
|
|
|
|
11958
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
11959
|
|
|
|
|
|
|
|
11960
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
11961
|
|
|
|
|
|
|
{ |
11962
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
11963
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
11964
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
11965
|
|
|
|
|
|
|
} |
11966
|
|
|
|
|
|
|
#else |
11967
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
11968
|
|
|
|
|
|
|
#endif |
11969
|
|
|
|
|
|
|
|
11970
|
|
|
|
|
|
|
|
11971
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
11972
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
11973
|
|
|
|
|
|
|
#else |
11974
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
11975
|
|
|
|
|
|
|
#endif |
11976
|
|
|
|
|
|
|
|
11977
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
11978
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
11979
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
11980
|
|
|
|
|
|
|
#else |
11981
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
11982
|
|
|
|
|
|
|
#endif |
11983
|
|
|
|
|
|
|
|
11984
|
|
|
|
|
|
|
|
11985
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
11986
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
11987
|
|
|
|
|
|
|
#else |
11988
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
11989
|
|
|
|
|
|
|
#endif |
11990
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
11991
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
11992
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
11993
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
11994
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
11995
|
|
|
|
|
|
|
\ |
11996
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
11997
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
11998
|
|
|
|
|
|
|
|
11999
|
|
|
|
|
|
|
# ifdef _MSC_VER |
12000
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
12001
|
|
|
|
|
|
|
# else |
12002
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
12003
|
|
|
|
|
|
|
# endif |
12004
|
|
|
|
|
|
|
#else |
12005
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
12006
|
|
|
|
|
|
|
#endif |
12007
|
|
|
|
|
|
|
|
12008
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
12009
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
12010
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
12011
|
|
|
|
|
|
|
#else |
12012
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
12013
|
|
|
|
|
|
|
#endif |
12014
|
|
|
|
|
|
|
|
12015
|
|
|
|
|
|
|
|
12016
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
12017
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
12018
|
|
|
|
|
|
|
#else |
12019
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
12020
|
|
|
|
|
|
|
#endif |
12021
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
12022
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
12023
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
12024
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
12025
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
12026
|
|
|
|
|
|
|
|
12027
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
12028
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
12029
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
12030
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
12031
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
12032
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
12033
|
|
|
|
|
|
|
# endif |
12034
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
12035
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
12036
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
12037
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
12038
|
|
|
|
|
|
|
# endif |
12039
|
|
|
|
|
|
|
#endif |
12040
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
12041
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
12042
|
|
|
|
|
|
|
#endif |
12043
|
|
|
|
|
|
|
|
12044
|
|
|
|
|
|
|
|
12045
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
12046
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
12047
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
12048
|
|
|
|
|
|
|
# else |
12049
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
12050
|
|
|
|
|
|
|
# endif |
12051
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
12052
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
12053
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
12054
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
12055
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
12056
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
12057
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
12058
|
|
|
|
|
|
|
#else |
12059
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
12060
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
12061
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
12062
|
|
|
|
|
|
|
#endif |
12063
|
|
|
|
|
|
|
|
12064
|
|
|
|
|
|
|
|
12065
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
12066
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
12067
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
12068
|
|
|
|
|
|
|
# else |
12069
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
12070
|
|
|
|
|
|
|
# endif |
12071
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
12072
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
12073
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
12074
|
|
|
|
|
|
|
defined(_MSC_VER))) |
12075
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
12076
|
|
|
|
|
|
|
# else |
12077
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
12078
|
|
|
|
|
|
|
# endif |
12079
|
|
|
|
|
|
|
#else |
12080
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
12081
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
12082
|
|
|
|
|
|
|
#endif |
12083
|
|
|
|
|
|
|
|
12084
|
|
|
|
|
|
|
|
12085
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
12086
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
12087
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
12088
|
|
|
|
|
|
|
#endif |
12089
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
12090
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
12091
|
|
|
|
|
|
|
#endif |
12092
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
12093
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
12094
|
|
|
|
|
|
|
#endif |
12095
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
12096
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
12097
|
|
|
|
|
|
|
# include |
12098
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
12099
|
|
|
|
|
|
|
#endif |
12100
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
12101
|
|
|
|
|
|
|
# include |
12102
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
12103
|
|
|
|
|
|
|
#endif |
12104
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
12105
|
|
|
|
|
|
|
# include |
12106
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
12107
|
|
|
|
|
|
|
#endif |
12108
|
|
|
|
|
|
|
|
12109
|
|
|
|
|
|
|
#endif |
12110
|
|
|
|
|
|
|
|
12111
|
|
|
|
|
|
|
#endif |
12112
|
|
|
|
|
|
|
|
12113
|
|
|
|
|
|
|
|
12114
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE |
12115
|
|
|
|
|
|
|
# include |
12116
|
|
|
|
|
|
|
static forceinline void |
12117
|
|
|
|
|
|
|
matchfinder_init_neon(mf_pos_t *data, size_t size) |
12118
|
|
|
|
|
|
|
{ |
12119
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
12120
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16(MATCHFINDER_INITVAL); |
12121
|
|
|
|
|
|
|
|
12122
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
12123
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
12124
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
12125
|
|
|
|
|
|
|
|
12126
|
|
|
|
|
|
|
do { |
12127
|
|
|
|
|
|
|
p[0] = v; |
12128
|
|
|
|
|
|
|
p[1] = v; |
12129
|
|
|
|
|
|
|
p[2] = v; |
12130
|
|
|
|
|
|
|
p[3] = v; |
12131
|
|
|
|
|
|
|
p += 4; |
12132
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
12133
|
|
|
|
|
|
|
} while (size != 0); |
12134
|
|
|
|
|
|
|
} |
12135
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_neon |
12136
|
|
|
|
|
|
|
|
12137
|
|
|
|
|
|
|
static forceinline void |
12138
|
|
|
|
|
|
|
matchfinder_rebase_neon(mf_pos_t *data, size_t size) |
12139
|
|
|
|
|
|
|
{ |
12140
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
12141
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16((u16)-MATCHFINDER_WINDOW_SIZE); |
12142
|
|
|
|
|
|
|
|
12143
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
12144
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
12145
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
12146
|
|
|
|
|
|
|
|
12147
|
|
|
|
|
|
|
do { |
12148
|
|
|
|
|
|
|
p[0] = vqaddq_s16(p[0], v); |
12149
|
|
|
|
|
|
|
p[1] = vqaddq_s16(p[1], v); |
12150
|
|
|
|
|
|
|
p[2] = vqaddq_s16(p[2], v); |
12151
|
|
|
|
|
|
|
p[3] = vqaddq_s16(p[3], v); |
12152
|
|
|
|
|
|
|
p += 4; |
12153
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
12154
|
|
|
|
|
|
|
} while (size != 0); |
12155
|
|
|
|
|
|
|
} |
12156
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_neon |
12157
|
|
|
|
|
|
|
|
12158
|
|
|
|
|
|
|
#endif |
12159
|
|
|
|
|
|
|
|
12160
|
|
|
|
|
|
|
#endif |
12161
|
|
|
|
|
|
|
|
12162
|
|
|
|
|
|
|
# elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
12163
|
|
|
|
|
|
|
/* # include "x86/matchfinder_impl.h" */ |
12164
|
|
|
|
|
|
|
|
12165
|
|
|
|
|
|
|
|
12166
|
|
|
|
|
|
|
#ifndef LIB_X86_MATCHFINDER_IMPL_H |
12167
|
|
|
|
|
|
|
#define LIB_X86_MATCHFINDER_IMPL_H |
12168
|
|
|
|
|
|
|
|
12169
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
12170
|
|
|
|
|
|
|
|
12171
|
|
|
|
|
|
|
|
12172
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
12173
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
12174
|
|
|
|
|
|
|
|
12175
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
12176
|
|
|
|
|
|
|
|
12177
|
|
|
|
|
|
|
|
12178
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
12179
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
12180
|
|
|
|
|
|
|
|
12181
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
12182
|
|
|
|
|
|
|
|
12183
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
12184
|
|
|
|
|
|
|
#endif |
12185
|
|
|
|
|
|
|
|
12186
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
12187
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
12188
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
12189
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
12190
|
|
|
|
|
|
|
#else |
12191
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
12192
|
|
|
|
|
|
|
#endif |
12193
|
|
|
|
|
|
|
|
12194
|
|
|
|
|
|
|
|
12195
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
12196
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
12197
|
|
|
|
|
|
|
#else |
12198
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
12199
|
|
|
|
|
|
|
#endif |
12200
|
|
|
|
|
|
|
|
12201
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
12202
|
|
|
|
|
|
|
|
12203
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
12204
|
|
|
|
|
|
|
|
12205
|
|
|
|
|
|
|
|
12206
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
12207
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
12208
|
|
|
|
|
|
|
|
12209
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
12210
|
|
|
|
|
|
|
|
12211
|
|
|
|
|
|
|
|
12212
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
12213
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
12214
|
|
|
|
|
|
|
|
12215
|
|
|
|
|
|
|
#include |
12216
|
|
|
|
|
|
|
#include |
12217
|
|
|
|
|
|
|
|
12218
|
|
|
|
|
|
|
#ifdef __cplusplus |
12219
|
|
|
|
|
|
|
extern "C" { |
12220
|
|
|
|
|
|
|
#endif |
12221
|
|
|
|
|
|
|
|
12222
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
12223
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
12224
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
12225
|
|
|
|
|
|
|
|
12226
|
|
|
|
|
|
|
|
12227
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
12228
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
12229
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
12230
|
|
|
|
|
|
|
# else |
12231
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
12232
|
|
|
|
|
|
|
# endif |
12233
|
|
|
|
|
|
|
#endif |
12234
|
|
|
|
|
|
|
|
12235
|
|
|
|
|
|
|
|
12236
|
|
|
|
|
|
|
|
12237
|
|
|
|
|
|
|
|
12238
|
|
|
|
|
|
|
|
12239
|
|
|
|
|
|
|
struct libdeflate_compressor; |
12240
|
|
|
|
|
|
|
struct libdeflate_options; |
12241
|
|
|
|
|
|
|
|
12242
|
|
|
|
|
|
|
|
12243
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
12244
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
12245
|
|
|
|
|
|
|
|
12246
|
|
|
|
|
|
|
|
12247
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
12248
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
12249
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
12250
|
|
|
|
|
|
|
|
12251
|
|
|
|
|
|
|
|
12252
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12253
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
12254
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12255
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
12256
|
|
|
|
|
|
|
|
12257
|
|
|
|
|
|
|
|
12258
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12259
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
12260
|
|
|
|
|
|
|
size_t in_nbytes); |
12261
|
|
|
|
|
|
|
|
12262
|
|
|
|
|
|
|
|
12263
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12264
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
12265
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12266
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
12267
|
|
|
|
|
|
|
|
12268
|
|
|
|
|
|
|
|
12269
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12270
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
12271
|
|
|
|
|
|
|
size_t in_nbytes); |
12272
|
|
|
|
|
|
|
|
12273
|
|
|
|
|
|
|
|
12274
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12275
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
12276
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12277
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
12278
|
|
|
|
|
|
|
|
12279
|
|
|
|
|
|
|
|
12280
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12281
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
12282
|
|
|
|
|
|
|
size_t in_nbytes); |
12283
|
|
|
|
|
|
|
|
12284
|
|
|
|
|
|
|
|
12285
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
12286
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
12287
|
|
|
|
|
|
|
|
12288
|
|
|
|
|
|
|
|
12289
|
|
|
|
|
|
|
|
12290
|
|
|
|
|
|
|
|
12291
|
|
|
|
|
|
|
|
12292
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
12293
|
|
|
|
|
|
|
struct libdeflate_options; |
12294
|
|
|
|
|
|
|
|
12295
|
|
|
|
|
|
|
|
12296
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
12297
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
12298
|
|
|
|
|
|
|
|
12299
|
|
|
|
|
|
|
|
12300
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
12301
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
12302
|
|
|
|
|
|
|
|
12303
|
|
|
|
|
|
|
|
12304
|
|
|
|
|
|
|
enum libdeflate_result { |
12305
|
|
|
|
|
|
|
|
12306
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
12307
|
|
|
|
|
|
|
|
12308
|
|
|
|
|
|
|
|
12309
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
12310
|
|
|
|
|
|
|
|
12311
|
|
|
|
|
|
|
|
12312
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
12313
|
|
|
|
|
|
|
|
12314
|
|
|
|
|
|
|
|
12315
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
12316
|
|
|
|
|
|
|
}; |
12317
|
|
|
|
|
|
|
|
12318
|
|
|
|
|
|
|
|
12319
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12320
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
12321
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12322
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12323
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12324
|
|
|
|
|
|
|
|
12325
|
|
|
|
|
|
|
|
12326
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12327
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
12328
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12329
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12330
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
12331
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12332
|
|
|
|
|
|
|
|
12333
|
|
|
|
|
|
|
|
12334
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12335
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
12336
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12337
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12338
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12339
|
|
|
|
|
|
|
|
12340
|
|
|
|
|
|
|
|
12341
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12342
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
12343
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12344
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12345
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
12346
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12347
|
|
|
|
|
|
|
|
12348
|
|
|
|
|
|
|
|
12349
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12350
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
12351
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12352
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12353
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12354
|
|
|
|
|
|
|
|
12355
|
|
|
|
|
|
|
|
12356
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12357
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
12358
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12359
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12360
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
12361
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12362
|
|
|
|
|
|
|
|
12363
|
|
|
|
|
|
|
|
12364
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
12365
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
12366
|
|
|
|
|
|
|
|
12367
|
|
|
|
|
|
|
|
12368
|
|
|
|
|
|
|
|
12369
|
|
|
|
|
|
|
|
12370
|
|
|
|
|
|
|
|
12371
|
|
|
|
|
|
|
|
12372
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
12373
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
12374
|
|
|
|
|
|
|
|
12375
|
|
|
|
|
|
|
|
12376
|
|
|
|
|
|
|
|
12377
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
12378
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
12379
|
|
|
|
|
|
|
|
12380
|
|
|
|
|
|
|
|
12381
|
|
|
|
|
|
|
|
12382
|
|
|
|
|
|
|
|
12383
|
|
|
|
|
|
|
|
12384
|
|
|
|
|
|
|
|
12385
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
12386
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
12387
|
|
|
|
|
|
|
void (*free_func)(void *)); |
12388
|
|
|
|
|
|
|
|
12389
|
|
|
|
|
|
|
|
12390
|
|
|
|
|
|
|
struct libdeflate_options { |
12391
|
|
|
|
|
|
|
|
12392
|
|
|
|
|
|
|
|
12393
|
|
|
|
|
|
|
size_t sizeof_options; |
12394
|
|
|
|
|
|
|
|
12395
|
|
|
|
|
|
|
|
12396
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
12397
|
|
|
|
|
|
|
void (*free_func)(void *); |
12398
|
|
|
|
|
|
|
}; |
12399
|
|
|
|
|
|
|
|
12400
|
|
|
|
|
|
|
#ifdef __cplusplus |
12401
|
|
|
|
|
|
|
} |
12402
|
|
|
|
|
|
|
#endif |
12403
|
|
|
|
|
|
|
|
12404
|
|
|
|
|
|
|
#endif |
12405
|
|
|
|
|
|
|
|
12406
|
|
|
|
|
|
|
|
12407
|
|
|
|
|
|
|
#include |
12408
|
|
|
|
|
|
|
#include |
12409
|
|
|
|
|
|
|
#include |
12410
|
|
|
|
|
|
|
#ifdef _MSC_VER |
12411
|
|
|
|
|
|
|
# include |
12412
|
|
|
|
|
|
|
# include |
12413
|
|
|
|
|
|
|
|
12414
|
|
|
|
|
|
|
|
12415
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
12416
|
|
|
|
|
|
|
|
12417
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
12418
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
12419
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
12420
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
12421
|
|
|
|
|
|
|
|
12422
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
12423
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
12424
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
12425
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
12426
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
12427
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
12428
|
|
|
|
|
|
|
#endif |
12429
|
|
|
|
|
|
|
#ifndef FREESTANDING |
12430
|
|
|
|
|
|
|
# include |
12431
|
|
|
|
|
|
|
#endif |
12432
|
|
|
|
|
|
|
|
12433
|
|
|
|
|
|
|
|
12434
|
|
|
|
|
|
|
|
12435
|
|
|
|
|
|
|
|
12436
|
|
|
|
|
|
|
|
12437
|
|
|
|
|
|
|
|
12438
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
12439
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
12440
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
12441
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
12442
|
|
|
|
|
|
|
#ifdef _MSC_VER |
12443
|
|
|
|
|
|
|
# if defined(_M_X64) |
12444
|
|
|
|
|
|
|
# define ARCH_X86_64 |
12445
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
12446
|
|
|
|
|
|
|
# define ARCH_X86_32 |
12447
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
12448
|
|
|
|
|
|
|
# define ARCH_ARM64 |
12449
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
12450
|
|
|
|
|
|
|
# define ARCH_ARM32 |
12451
|
|
|
|
|
|
|
# endif |
12452
|
|
|
|
|
|
|
#else |
12453
|
|
|
|
|
|
|
# if defined(__x86_64__) |
12454
|
|
|
|
|
|
|
# define ARCH_X86_64 |
12455
|
|
|
|
|
|
|
# elif defined(__i386__) |
12456
|
|
|
|
|
|
|
# define ARCH_X86_32 |
12457
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
12458
|
|
|
|
|
|
|
# define ARCH_ARM64 |
12459
|
|
|
|
|
|
|
# elif defined(__arm__) |
12460
|
|
|
|
|
|
|
# define ARCH_ARM32 |
12461
|
|
|
|
|
|
|
# endif |
12462
|
|
|
|
|
|
|
#endif |
12463
|
|
|
|
|
|
|
|
12464
|
|
|
|
|
|
|
|
12465
|
|
|
|
|
|
|
|
12466
|
|
|
|
|
|
|
|
12467
|
|
|
|
|
|
|
|
12468
|
|
|
|
|
|
|
|
12469
|
|
|
|
|
|
|
typedef uint8_t u8; |
12470
|
|
|
|
|
|
|
typedef uint16_t u16; |
12471
|
|
|
|
|
|
|
typedef uint32_t u32; |
12472
|
|
|
|
|
|
|
typedef uint64_t u64; |
12473
|
|
|
|
|
|
|
typedef int8_t s8; |
12474
|
|
|
|
|
|
|
typedef int16_t s16; |
12475
|
|
|
|
|
|
|
typedef int32_t s32; |
12476
|
|
|
|
|
|
|
typedef int64_t s64; |
12477
|
|
|
|
|
|
|
|
12478
|
|
|
|
|
|
|
|
12479
|
|
|
|
|
|
|
#ifdef _MSC_VER |
12480
|
|
|
|
|
|
|
# ifdef _WIN64 |
12481
|
|
|
|
|
|
|
typedef long long ssize_t; |
12482
|
|
|
|
|
|
|
# else |
12483
|
|
|
|
|
|
|
typedef long ssize_t; |
12484
|
|
|
|
|
|
|
# endif |
12485
|
|
|
|
|
|
|
#endif |
12486
|
|
|
|
|
|
|
|
12487
|
|
|
|
|
|
|
|
12488
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
12489
|
|
|
|
|
|
|
|
12490
|
|
|
|
|
|
|
|
12491
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
12492
|
|
|
|
|
|
|
|
12493
|
|
|
|
|
|
|
|
12494
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
12495
|
|
|
|
|
|
|
|
12496
|
|
|
|
|
|
|
|
12497
|
|
|
|
|
|
|
|
12498
|
|
|
|
|
|
|
|
12499
|
|
|
|
|
|
|
|
12500
|
|
|
|
|
|
|
|
12501
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
12502
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
12503
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
12504
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
12505
|
|
|
|
|
|
|
#else |
12506
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
12507
|
|
|
|
|
|
|
#endif |
12508
|
|
|
|
|
|
|
#ifdef __clang__ |
12509
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
12510
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
12511
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
12512
|
|
|
|
|
|
|
# else |
12513
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
12514
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
12515
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
12516
|
|
|
|
|
|
|
# endif |
12517
|
|
|
|
|
|
|
#else |
12518
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
12519
|
|
|
|
|
|
|
#endif |
12520
|
|
|
|
|
|
|
|
12521
|
|
|
|
|
|
|
|
12522
|
|
|
|
|
|
|
#ifndef __has_attribute |
12523
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
12524
|
|
|
|
|
|
|
#endif |
12525
|
|
|
|
|
|
|
#ifndef __has_builtin |
12526
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
12527
|
|
|
|
|
|
|
#endif |
12528
|
|
|
|
|
|
|
|
12529
|
|
|
|
|
|
|
|
12530
|
|
|
|
|
|
|
#ifdef _MSC_VER |
12531
|
|
|
|
|
|
|
# define inline __inline |
12532
|
|
|
|
|
|
|
#endif |
12533
|
|
|
|
|
|
|
|
12534
|
|
|
|
|
|
|
|
12535
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
12536
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
12537
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12538
|
|
|
|
|
|
|
# define forceinline __forceinline |
12539
|
|
|
|
|
|
|
#else |
12540
|
|
|
|
|
|
|
# define forceinline inline |
12541
|
|
|
|
|
|
|
#endif |
12542
|
|
|
|
|
|
|
|
12543
|
|
|
|
|
|
|
|
12544
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
12545
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
12546
|
|
|
|
|
|
|
#else |
12547
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
12548
|
|
|
|
|
|
|
#endif |
12549
|
|
|
|
|
|
|
|
12550
|
|
|
|
|
|
|
|
12551
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
12552
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
12553
|
|
|
|
|
|
|
# define restrict __restrict__ |
12554
|
|
|
|
|
|
|
# else |
12555
|
|
|
|
|
|
|
# define restrict |
12556
|
|
|
|
|
|
|
# endif |
12557
|
|
|
|
|
|
|
#endif |
12558
|
|
|
|
|
|
|
|
12559
|
|
|
|
|
|
|
|
12560
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
12561
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
12562
|
|
|
|
|
|
|
#else |
12563
|
|
|
|
|
|
|
# define likely(expr) (expr) |
12564
|
|
|
|
|
|
|
#endif |
12565
|
|
|
|
|
|
|
|
12566
|
|
|
|
|
|
|
|
12567
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
12568
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
12569
|
|
|
|
|
|
|
#else |
12570
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
12571
|
|
|
|
|
|
|
#endif |
12572
|
|
|
|
|
|
|
|
12573
|
|
|
|
|
|
|
|
12574
|
|
|
|
|
|
|
#undef prefetchr |
12575
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
12576
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
12577
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12578
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
12579
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
12580
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
12581
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
12582
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
12583
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
12584
|
|
|
|
|
|
|
# endif |
12585
|
|
|
|
|
|
|
#endif |
12586
|
|
|
|
|
|
|
#ifndef prefetchr |
12587
|
|
|
|
|
|
|
# define prefetchr(addr) |
12588
|
|
|
|
|
|
|
#endif |
12589
|
|
|
|
|
|
|
|
12590
|
|
|
|
|
|
|
|
12591
|
|
|
|
|
|
|
#undef prefetchw |
12592
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
12593
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
12594
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12595
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
12596
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
12597
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
12598
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
12599
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
12600
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
12601
|
|
|
|
|
|
|
# endif |
12602
|
|
|
|
|
|
|
#endif |
12603
|
|
|
|
|
|
|
#ifndef prefetchw |
12604
|
|
|
|
|
|
|
# define prefetchw(addr) |
12605
|
|
|
|
|
|
|
#endif |
12606
|
|
|
|
|
|
|
|
12607
|
|
|
|
|
|
|
|
12608
|
|
|
|
|
|
|
#undef _aligned_attribute |
12609
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
12610
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
12611
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12612
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
12613
|
|
|
|
|
|
|
#endif |
12614
|
|
|
|
|
|
|
|
12615
|
|
|
|
|
|
|
|
12616
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
12617
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
12618
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
12619
|
|
|
|
|
|
|
#else |
12620
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
12621
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
12622
|
|
|
|
|
|
|
#endif |
12623
|
|
|
|
|
|
|
|
12624
|
|
|
|
|
|
|
|
12625
|
|
|
|
|
|
|
|
12626
|
|
|
|
|
|
|
|
12627
|
|
|
|
|
|
|
|
12628
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
12629
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
12630
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
12631
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
12632
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
12633
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
12634
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
12635
|
|
|
|
|
|
|
|
12636
|
|
|
|
|
|
|
|
12637
|
|
|
|
|
|
|
|
12638
|
|
|
|
|
|
|
|
12639
|
|
|
|
|
|
|
|
12640
|
|
|
|
|
|
|
|
12641
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
12642
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
12643
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12644
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
12645
|
|
|
|
|
|
|
#else |
12646
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
12647
|
|
|
|
|
|
|
{ |
12648
|
|
|
|
|
|
|
union { |
12649
|
|
|
|
|
|
|
u32 w; |
12650
|
|
|
|
|
|
|
u8 b; |
12651
|
|
|
|
|
|
|
} u; |
12652
|
|
|
|
|
|
|
|
12653
|
|
|
|
|
|
|
u.w = 1; |
12654
|
|
|
|
|
|
|
return u.b; |
12655
|
|
|
|
|
|
|
} |
12656
|
|
|
|
|
|
|
#endif |
12657
|
|
|
|
|
|
|
|
12658
|
|
|
|
|
|
|
|
12659
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
12660
|
|
|
|
|
|
|
{ |
12661
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
12662
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
12663
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12664
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
12665
|
|
|
|
|
|
|
#else |
12666
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
12667
|
|
|
|
|
|
|
#endif |
12668
|
|
|
|
|
|
|
} |
12669
|
|
|
|
|
|
|
|
12670
|
|
|
|
|
|
|
|
12671
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
12672
|
|
|
|
|
|
|
{ |
12673
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
12674
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
12675
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12676
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
12677
|
|
|
|
|
|
|
#else |
12678
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
12679
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
12680
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
12681
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
12682
|
|
|
|
|
|
|
#endif |
12683
|
|
|
|
|
|
|
} |
12684
|
|
|
|
|
|
|
|
12685
|
|
|
|
|
|
|
|
12686
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
12687
|
|
|
|
|
|
|
{ |
12688
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
12689
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
12690
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12691
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
12692
|
|
|
|
|
|
|
#else |
12693
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
12694
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
12695
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
12696
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
12697
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
12698
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
12699
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
12700
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
12701
|
|
|
|
|
|
|
#endif |
12702
|
|
|
|
|
|
|
} |
12703
|
|
|
|
|
|
|
|
12704
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
12705
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
12706
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
12707
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
12708
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
12709
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
12710
|
|
|
|
|
|
|
|
12711
|
|
|
|
|
|
|
|
12712
|
|
|
|
|
|
|
|
12713
|
|
|
|
|
|
|
|
12714
|
|
|
|
|
|
|
|
12715
|
|
|
|
|
|
|
|
12716
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
12717
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
12718
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
12719
|
|
|
|
|
|
|
defined(__wasm__)) |
12720
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
12721
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12722
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
12723
|
|
|
|
|
|
|
#else |
12724
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
12725
|
|
|
|
|
|
|
#endif |
12726
|
|
|
|
|
|
|
|
12727
|
|
|
|
|
|
|
|
12728
|
|
|
|
|
|
|
|
12729
|
|
|
|
|
|
|
#ifdef FREESTANDING |
12730
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
12731
|
|
|
|
|
|
|
#else |
12732
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
12733
|
|
|
|
|
|
|
#endif |
12734
|
|
|
|
|
|
|
|
12735
|
|
|
|
|
|
|
|
12736
|
|
|
|
|
|
|
|
12737
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
12738
|
|
|
|
|
|
|
static forceinline type \ |
12739
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
12740
|
|
|
|
|
|
|
{ \ |
12741
|
|
|
|
|
|
|
type v; \ |
12742
|
|
|
|
|
|
|
\ |
12743
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
12744
|
|
|
|
|
|
|
return v; \ |
12745
|
|
|
|
|
|
|
} \ |
12746
|
|
|
|
|
|
|
\ |
12747
|
|
|
|
|
|
|
static forceinline void \ |
12748
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
12749
|
|
|
|
|
|
|
{ \ |
12750
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
12751
|
|
|
|
|
|
|
} |
12752
|
|
|
|
|
|
|
|
12753
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
12754
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
12755
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
12756
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
12757
|
|
|
|
|
|
|
|
12758
|
|
|
|
|
|
|
#undef MEMCOPY |
12759
|
|
|
|
|
|
|
|
12760
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
12761
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
12762
|
|
|
|
|
|
|
|
12763
|
|
|
|
|
|
|
|
12764
|
|
|
|
|
|
|
|
12765
|
|
|
|
|
|
|
static forceinline u16 |
12766
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
12767
|
|
|
|
|
|
|
{ |
12768
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12769
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
12770
|
|
|
|
|
|
|
else |
12771
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
12772
|
|
|
|
|
|
|
} |
12773
|
|
|
|
|
|
|
|
12774
|
|
|
|
|
|
|
static forceinline u16 |
12775
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
12776
|
|
|
|
|
|
|
{ |
12777
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12778
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
12779
|
|
|
|
|
|
|
else |
12780
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
12781
|
|
|
|
|
|
|
} |
12782
|
|
|
|
|
|
|
|
12783
|
|
|
|
|
|
|
static forceinline u32 |
12784
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
12785
|
|
|
|
|
|
|
{ |
12786
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12787
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
12788
|
|
|
|
|
|
|
else |
12789
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
12790
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
12791
|
|
|
|
|
|
|
} |
12792
|
|
|
|
|
|
|
|
12793
|
|
|
|
|
|
|
static forceinline u32 |
12794
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
12795
|
|
|
|
|
|
|
{ |
12796
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12797
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
12798
|
|
|
|
|
|
|
else |
12799
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
12800
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
12801
|
|
|
|
|
|
|
} |
12802
|
|
|
|
|
|
|
|
12803
|
|
|
|
|
|
|
static forceinline u64 |
12804
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
12805
|
|
|
|
|
|
|
{ |
12806
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12807
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
12808
|
|
|
|
|
|
|
else |
12809
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
12810
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
12811
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
12812
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
12813
|
|
|
|
|
|
|
} |
12814
|
|
|
|
|
|
|
|
12815
|
|
|
|
|
|
|
static forceinline machine_word_t |
12816
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
12817
|
|
|
|
|
|
|
{ |
12818
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
12819
|
|
|
|
|
|
|
if (WORDBITS == 32) |
12820
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
12821
|
|
|
|
|
|
|
else |
12822
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
12823
|
|
|
|
|
|
|
} |
12824
|
|
|
|
|
|
|
|
12825
|
|
|
|
|
|
|
|
12826
|
|
|
|
|
|
|
|
12827
|
|
|
|
|
|
|
static forceinline void |
12828
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
12829
|
|
|
|
|
|
|
{ |
12830
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12831
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
12832
|
|
|
|
|
|
|
} else { |
12833
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
12834
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
12835
|
|
|
|
|
|
|
} |
12836
|
|
|
|
|
|
|
} |
12837
|
|
|
|
|
|
|
|
12838
|
|
|
|
|
|
|
static forceinline void |
12839
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
12840
|
|
|
|
|
|
|
{ |
12841
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12842
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
12843
|
|
|
|
|
|
|
} else { |
12844
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
12845
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
12846
|
|
|
|
|
|
|
} |
12847
|
|
|
|
|
|
|
} |
12848
|
|
|
|
|
|
|
|
12849
|
|
|
|
|
|
|
static forceinline void |
12850
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
12851
|
|
|
|
|
|
|
{ |
12852
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12853
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
12854
|
|
|
|
|
|
|
} else { |
12855
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
12856
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
12857
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
12858
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
12859
|
|
|
|
|
|
|
} |
12860
|
|
|
|
|
|
|
} |
12861
|
|
|
|
|
|
|
|
12862
|
|
|
|
|
|
|
static forceinline void |
12863
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
12864
|
|
|
|
|
|
|
{ |
12865
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12866
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
12867
|
|
|
|
|
|
|
} else { |
12868
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
12869
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
12870
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
12871
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
12872
|
|
|
|
|
|
|
} |
12873
|
|
|
|
|
|
|
} |
12874
|
|
|
|
|
|
|
|
12875
|
|
|
|
|
|
|
static forceinline void |
12876
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
12877
|
|
|
|
|
|
|
{ |
12878
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12879
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
12880
|
|
|
|
|
|
|
} else { |
12881
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
12882
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
12883
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
12884
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
12885
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
12886
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
12887
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
12888
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
12889
|
|
|
|
|
|
|
} |
12890
|
|
|
|
|
|
|
} |
12891
|
|
|
|
|
|
|
|
12892
|
|
|
|
|
|
|
static forceinline void |
12893
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
12894
|
|
|
|
|
|
|
{ |
12895
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
12896
|
|
|
|
|
|
|
if (WORDBITS == 32) |
12897
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
12898
|
|
|
|
|
|
|
else |
12899
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
12900
|
|
|
|
|
|
|
} |
12901
|
|
|
|
|
|
|
|
12902
|
|
|
|
|
|
|
|
12903
|
|
|
|
|
|
|
|
12904
|
|
|
|
|
|
|
|
12905
|
|
|
|
|
|
|
|
12906
|
|
|
|
|
|
|
|
12907
|
|
|
|
|
|
|
|
12908
|
|
|
|
|
|
|
static forceinline unsigned |
12909
|
|
|
|
|
|
|
bsr32(u32 v) |
12910
|
|
|
|
|
|
|
{ |
12911
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
12912
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
12913
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12914
|
|
|
|
|
|
|
unsigned long i; |
12915
|
|
|
|
|
|
|
|
12916
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
12917
|
|
|
|
|
|
|
return i; |
12918
|
|
|
|
|
|
|
#else |
12919
|
|
|
|
|
|
|
unsigned i = 0; |
12920
|
|
|
|
|
|
|
|
12921
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
12922
|
|
|
|
|
|
|
i++; |
12923
|
|
|
|
|
|
|
return i; |
12924
|
|
|
|
|
|
|
#endif |
12925
|
|
|
|
|
|
|
} |
12926
|
|
|
|
|
|
|
|
12927
|
|
|
|
|
|
|
static forceinline unsigned |
12928
|
|
|
|
|
|
|
bsr64(u64 v) |
12929
|
|
|
|
|
|
|
{ |
12930
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
12931
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
12932
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
12933
|
|
|
|
|
|
|
unsigned long i; |
12934
|
|
|
|
|
|
|
|
12935
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
12936
|
|
|
|
|
|
|
return i; |
12937
|
|
|
|
|
|
|
#else |
12938
|
|
|
|
|
|
|
unsigned i = 0; |
12939
|
|
|
|
|
|
|
|
12940
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
12941
|
|
|
|
|
|
|
i++; |
12942
|
|
|
|
|
|
|
return i; |
12943
|
|
|
|
|
|
|
#endif |
12944
|
|
|
|
|
|
|
} |
12945
|
|
|
|
|
|
|
|
12946
|
|
|
|
|
|
|
static forceinline unsigned |
12947
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
12948
|
|
|
|
|
|
|
{ |
12949
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
12950
|
|
|
|
|
|
|
if (WORDBITS == 32) |
12951
|
|
|
|
|
|
|
return bsr32(v); |
12952
|
|
|
|
|
|
|
else |
12953
|
|
|
|
|
|
|
return bsr64(v); |
12954
|
|
|
|
|
|
|
} |
12955
|
|
|
|
|
|
|
|
12956
|
|
|
|
|
|
|
|
12957
|
|
|
|
|
|
|
|
12958
|
|
|
|
|
|
|
static forceinline unsigned |
12959
|
|
|
|
|
|
|
bsf32(u32 v) |
12960
|
|
|
|
|
|
|
{ |
12961
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
12962
|
|
|
|
|
|
|
return __builtin_ctz(v); |
12963
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12964
|
|
|
|
|
|
|
unsigned long i; |
12965
|
|
|
|
|
|
|
|
12966
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
12967
|
|
|
|
|
|
|
return i; |
12968
|
|
|
|
|
|
|
#else |
12969
|
|
|
|
|
|
|
unsigned i = 0; |
12970
|
|
|
|
|
|
|
|
12971
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
12972
|
|
|
|
|
|
|
i++; |
12973
|
|
|
|
|
|
|
return i; |
12974
|
|
|
|
|
|
|
#endif |
12975
|
|
|
|
|
|
|
} |
12976
|
|
|
|
|
|
|
|
12977
|
|
|
|
|
|
|
static forceinline unsigned |
12978
|
|
|
|
|
|
|
bsf64(u64 v) |
12979
|
|
|
|
|
|
|
{ |
12980
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
12981
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
12982
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
12983
|
|
|
|
|
|
|
unsigned long i; |
12984
|
|
|
|
|
|
|
|
12985
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
12986
|
|
|
|
|
|
|
return i; |
12987
|
|
|
|
|
|
|
#else |
12988
|
|
|
|
|
|
|
unsigned i = 0; |
12989
|
|
|
|
|
|
|
|
12990
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
12991
|
|
|
|
|
|
|
i++; |
12992
|
|
|
|
|
|
|
return i; |
12993
|
|
|
|
|
|
|
#endif |
12994
|
|
|
|
|
|
|
} |
12995
|
|
|
|
|
|
|
|
12996
|
|
|
|
|
|
|
static forceinline unsigned |
12997
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
12998
|
|
|
|
|
|
|
{ |
12999
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
13000
|
|
|
|
|
|
|
if (WORDBITS == 32) |
13001
|
|
|
|
|
|
|
return bsf32(v); |
13002
|
|
|
|
|
|
|
else |
13003
|
|
|
|
|
|
|
return bsf64(v); |
13004
|
|
|
|
|
|
|
} |
13005
|
|
|
|
|
|
|
|
13006
|
|
|
|
|
|
|
|
13007
|
|
|
|
|
|
|
#undef rbit32 |
13008
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
13009
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
13010
|
|
|
|
|
|
|
static forceinline u32 |
13011
|
|
|
|
|
|
|
rbit32(u32 v) |
13012
|
|
|
|
|
|
|
{ |
13013
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
13014
|
|
|
|
|
|
|
return v; |
13015
|
|
|
|
|
|
|
} |
13016
|
|
|
|
|
|
|
#define rbit32 rbit32 |
13017
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
13018
|
|
|
|
|
|
|
static forceinline u32 |
13019
|
|
|
|
|
|
|
rbit32(u32 v) |
13020
|
|
|
|
|
|
|
{ |
13021
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
13022
|
|
|
|
|
|
|
return v; |
13023
|
|
|
|
|
|
|
} |
13024
|
|
|
|
|
|
|
#define rbit32 rbit32 |
13025
|
|
|
|
|
|
|
#endif |
13026
|
|
|
|
|
|
|
|
13027
|
|
|
|
|
|
|
#endif |
13028
|
|
|
|
|
|
|
|
13029
|
|
|
|
|
|
|
|
13030
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
13031
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
13032
|
|
|
|
|
|
|
|
13033
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
13034
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
13035
|
|
|
|
|
|
|
|
13036
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
13037
|
|
|
|
|
|
|
size_t alignment, size_t size); |
13038
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
13039
|
|
|
|
|
|
|
|
13040
|
|
|
|
|
|
|
#ifdef FREESTANDING |
13041
|
|
|
|
|
|
|
|
13042
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
13043
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
13044
|
|
|
|
|
|
|
|
13045
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
13046
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
13047
|
|
|
|
|
|
|
|
13048
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
13049
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
13050
|
|
|
|
|
|
|
|
13051
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
13052
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
13053
|
|
|
|
|
|
|
|
13054
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
13055
|
|
|
|
|
|
|
#else |
13056
|
|
|
|
|
|
|
#include |
13057
|
|
|
|
|
|
|
#endif |
13058
|
|
|
|
|
|
|
|
13059
|
|
|
|
|
|
|
|
13060
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
13061
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
13062
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
13063
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
13064
|
|
|
|
|
|
|
#else |
13065
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
13066
|
|
|
|
|
|
|
#endif |
13067
|
|
|
|
|
|
|
|
13068
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
13069
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
13070
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
13071
|
|
|
|
|
|
|
|
13072
|
|
|
|
|
|
|
#endif |
13073
|
|
|
|
|
|
|
|
13074
|
|
|
|
|
|
|
|
13075
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
13076
|
|
|
|
|
|
|
|
13077
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
13078
|
|
|
|
|
|
|
|
13079
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
13080
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
13081
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
13082
|
|
|
|
|
|
|
#endif |
13083
|
|
|
|
|
|
|
|
13084
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
13085
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
13086
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
13087
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
13088
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
13089
|
|
|
|
|
|
|
|
13090
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
13091
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
13092
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
13093
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
13094
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
13095
|
|
|
|
|
|
|
|
13096
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
13097
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
13098
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
13099
|
|
|
|
|
|
|
|
13100
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
13101
|
|
|
|
|
|
|
|
13102
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
13103
|
|
|
|
|
|
|
{ |
13104
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
13105
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
13106
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
13107
|
|
|
|
|
|
|
} |
13108
|
|
|
|
|
|
|
#else |
13109
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
13110
|
|
|
|
|
|
|
#endif |
13111
|
|
|
|
|
|
|
|
13112
|
|
|
|
|
|
|
|
13113
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
13114
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
13115
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
13116
|
|
|
|
|
|
|
#else |
13117
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
13118
|
|
|
|
|
|
|
#endif |
13119
|
|
|
|
|
|
|
|
13120
|
|
|
|
|
|
|
|
13121
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
13122
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
13123
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
13124
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
13125
|
|
|
|
|
|
|
#else |
13126
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
13127
|
|
|
|
|
|
|
#endif |
13128
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
13129
|
|
|
|
|
|
|
|
13130
|
|
|
|
|
|
|
|
13131
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
13132
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
13133
|
|
|
|
|
|
|
#else |
13134
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
13135
|
|
|
|
|
|
|
#endif |
13136
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
13137
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
13138
|
|
|
|
|
|
|
defined(_MSC_VER))) |
13139
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
13140
|
|
|
|
|
|
|
#else |
13141
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
13142
|
|
|
|
|
|
|
#endif |
13143
|
|
|
|
|
|
|
|
13144
|
|
|
|
|
|
|
|
13145
|
|
|
|
|
|
|
#ifdef __AVX__ |
13146
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
13147
|
|
|
|
|
|
|
#else |
13148
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
13149
|
|
|
|
|
|
|
#endif |
13150
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
13151
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
13152
|
|
|
|
|
|
|
defined(_MSC_VER))) |
13153
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
13154
|
|
|
|
|
|
|
#else |
13155
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
13156
|
|
|
|
|
|
|
#endif |
13157
|
|
|
|
|
|
|
|
13158
|
|
|
|
|
|
|
|
13159
|
|
|
|
|
|
|
#ifdef __AVX2__ |
13160
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
13161
|
|
|
|
|
|
|
#else |
13162
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
13163
|
|
|
|
|
|
|
#endif |
13164
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
13165
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
13166
|
|
|
|
|
|
|
defined(_MSC_VER))) |
13167
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
13168
|
|
|
|
|
|
|
#else |
13169
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
13170
|
|
|
|
|
|
|
#endif |
13171
|
|
|
|
|
|
|
|
13172
|
|
|
|
|
|
|
|
13173
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
13174
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
13175
|
|
|
|
|
|
|
#else |
13176
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
13177
|
|
|
|
|
|
|
#endif |
13178
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
13179
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
13180
|
|
|
|
|
|
|
defined(_MSC_VER))) |
13181
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
13182
|
|
|
|
|
|
|
#else |
13183
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
13184
|
|
|
|
|
|
|
#endif |
13185
|
|
|
|
|
|
|
|
13186
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1930 |
13187
|
|
|
|
|
|
|
# undef HAVE_BMI2_NATIVE |
13188
|
|
|
|
|
|
|
# undef HAVE_BMI2_INTRIN |
13189
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
13190
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
13191
|
|
|
|
|
|
|
#endif |
13192
|
|
|
|
|
|
|
|
13193
|
|
|
|
|
|
|
#endif |
13194
|
|
|
|
|
|
|
|
13195
|
|
|
|
|
|
|
#endif |
13196
|
|
|
|
|
|
|
|
13197
|
|
|
|
|
|
|
|
13198
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE |
13199
|
|
|
|
|
|
|
# include |
13200
|
|
|
|
|
|
|
static forceinline void |
13201
|
|
|
|
|
|
|
matchfinder_init_avx2(mf_pos_t *data, size_t size) |
13202
|
|
|
|
|
|
|
{ |
13203
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
13204
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16(MATCHFINDER_INITVAL); |
13205
|
|
|
|
|
|
|
|
13206
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
13207
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
13208
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
13209
|
|
|
|
|
|
|
|
13210
|
|
|
|
|
|
|
do { |
13211
|
|
|
|
|
|
|
p[0] = v; |
13212
|
|
|
|
|
|
|
p[1] = v; |
13213
|
|
|
|
|
|
|
p[2] = v; |
13214
|
|
|
|
|
|
|
p[3] = v; |
13215
|
|
|
|
|
|
|
p += 4; |
13216
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
13217
|
|
|
|
|
|
|
} while (size != 0); |
13218
|
|
|
|
|
|
|
} |
13219
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_avx2 |
13220
|
|
|
|
|
|
|
|
13221
|
|
|
|
|
|
|
static forceinline void |
13222
|
|
|
|
|
|
|
matchfinder_rebase_avx2(mf_pos_t *data, size_t size) |
13223
|
|
|
|
|
|
|
{ |
13224
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
13225
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
13226
|
|
|
|
|
|
|
|
13227
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
13228
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
13229
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
13230
|
|
|
|
|
|
|
|
13231
|
|
|
|
|
|
|
do { |
13232
|
|
|
|
|
|
|
|
13233
|
|
|
|
|
|
|
p[0] = _mm256_adds_epi16(p[0], v); |
13234
|
|
|
|
|
|
|
p[1] = _mm256_adds_epi16(p[1], v); |
13235
|
|
|
|
|
|
|
p[2] = _mm256_adds_epi16(p[2], v); |
13236
|
|
|
|
|
|
|
p[3] = _mm256_adds_epi16(p[3], v); |
13237
|
|
|
|
|
|
|
p += 4; |
13238
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
13239
|
|
|
|
|
|
|
} while (size != 0); |
13240
|
|
|
|
|
|
|
} |
13241
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_avx2 |
13242
|
|
|
|
|
|
|
|
13243
|
|
|
|
|
|
|
#elif HAVE_SSE2_NATIVE |
13244
|
|
|
|
|
|
|
# include |
13245
|
|
|
|
|
|
|
static forceinline void |
13246
|
|
|
|
|
|
|
matchfinder_init_sse2(mf_pos_t *data, size_t size) |
13247
|
|
|
|
|
|
|
{ |
13248
|
37
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
13249
|
37
|
|
|
|
|
|
__m128i v = _mm_set1_epi16(MATCHFINDER_INITVAL); |
13250
|
|
|
|
|
|
|
|
13251
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
13252
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
13253
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
13254
|
|
|
|
|
|
|
|
13255
|
|
|
|
|
|
|
do { |
13256
|
138240
|
|
|
|
|
|
p[0] = v; |
13257
|
138240
|
|
|
|
|
|
p[1] = v; |
13258
|
138240
|
|
|
|
|
|
p[2] = v; |
13259
|
138240
|
|
|
|
|
|
p[3] = v; |
13260
|
138240
|
|
|
|
|
|
p += 4; |
13261
|
138240
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
13262
|
138240
|
100
|
|
|
|
|
} while (size != 0); |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
13263
|
|
|
|
|
|
|
} |
13264
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_sse2 |
13265
|
|
|
|
|
|
|
|
13266
|
|
|
|
|
|
|
static forceinline void |
13267
|
|
|
|
|
|
|
matchfinder_rebase_sse2(mf_pos_t *data, size_t size) |
13268
|
|
|
|
|
|
|
{ |
13269
|
0
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
13270
|
0
|
|
|
|
|
|
__m128i v = _mm_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
13271
|
|
|
|
|
|
|
|
13272
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
13273
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
13274
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
13275
|
|
|
|
|
|
|
|
13276
|
|
|
|
|
|
|
do { |
13277
|
|
|
|
|
|
|
|
13278
|
0
|
|
|
|
|
|
p[0] = _mm_adds_epi16(p[0], v); |
13279
|
0
|
|
|
|
|
|
p[1] = _mm_adds_epi16(p[1], v); |
13280
|
0
|
|
|
|
|
|
p[2] = _mm_adds_epi16(p[2], v); |
13281
|
0
|
|
|
|
|
|
p[3] = _mm_adds_epi16(p[3], v); |
13282
|
0
|
|
|
|
|
|
p += 4; |
13283
|
0
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
13284
|
0
|
0
|
|
|
|
|
} while (size != 0); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13285
|
|
|
|
|
|
|
} |
13286
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_sse2 |
13287
|
|
|
|
|
|
|
#endif |
13288
|
|
|
|
|
|
|
|
13289
|
|
|
|
|
|
|
#endif |
13290
|
|
|
|
|
|
|
|
13291
|
|
|
|
|
|
|
# endif |
13292
|
|
|
|
|
|
|
#else |
13293
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED |
13294
|
|
|
|
|
|
|
#endif |
13295
|
|
|
|
|
|
|
|
13296
|
|
|
|
|
|
|
|
13297
|
|
|
|
|
|
|
#ifndef matchfinder_init |
13298
|
|
|
|
|
|
|
static forceinline void |
13299
|
|
|
|
|
|
|
matchfinder_init(mf_pos_t *data, size_t size) |
13300
|
|
|
|
|
|
|
{ |
13301
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
13302
|
|
|
|
|
|
|
size_t i; |
13303
|
|
|
|
|
|
|
|
13304
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
13305
|
|
|
|
|
|
|
data[i] = MATCHFINDER_INITVAL; |
13306
|
|
|
|
|
|
|
} |
13307
|
|
|
|
|
|
|
#endif |
13308
|
|
|
|
|
|
|
|
13309
|
|
|
|
|
|
|
|
13310
|
|
|
|
|
|
|
#ifndef matchfinder_rebase |
13311
|
|
|
|
|
|
|
static forceinline void |
13312
|
|
|
|
|
|
|
matchfinder_rebase(mf_pos_t *data, size_t size) |
13313
|
|
|
|
|
|
|
{ |
13314
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
13315
|
|
|
|
|
|
|
size_t i; |
13316
|
|
|
|
|
|
|
|
13317
|
|
|
|
|
|
|
if (MATCHFINDER_WINDOW_SIZE == 32768) { |
13318
|
|
|
|
|
|
|
|
13319
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
13320
|
|
|
|
|
|
|
data[i] = 0x8000 | (data[i] & ~(data[i] >> 15)); |
13321
|
|
|
|
|
|
|
} else { |
13322
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) { |
13323
|
|
|
|
|
|
|
if (data[i] >= 0) |
13324
|
|
|
|
|
|
|
data[i] -= (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
13325
|
|
|
|
|
|
|
else |
13326
|
|
|
|
|
|
|
data[i] = (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
13327
|
|
|
|
|
|
|
} |
13328
|
|
|
|
|
|
|
} |
13329
|
|
|
|
|
|
|
} |
13330
|
|
|
|
|
|
|
#endif |
13331
|
|
|
|
|
|
|
|
13332
|
|
|
|
|
|
|
|
13333
|
|
|
|
|
|
|
static forceinline u32 |
13334
|
|
|
|
|
|
|
lz_hash(u32 seq, unsigned num_bits) |
13335
|
|
|
|
|
|
|
{ |
13336
|
86187
|
|
|
|
|
|
return (u32)(seq * 0x1E35A7BD) >> (32 - num_bits); |
13337
|
|
|
|
|
|
|
} |
13338
|
|
|
|
|
|
|
|
13339
|
|
|
|
|
|
|
|
13340
|
|
|
|
|
|
|
static forceinline unsigned |
13341
|
|
|
|
|
|
|
lz_extend(const u8 * const strptr, const u8 * const matchptr, |
13342
|
|
|
|
|
|
|
const unsigned start_len, const unsigned max_len) |
13343
|
|
|
|
|
|
|
{ |
13344
|
17924
|
|
|
|
|
|
unsigned len = start_len; |
13345
|
|
|
|
|
|
|
machine_word_t v_word; |
13346
|
|
|
|
|
|
|
|
13347
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
13348
|
|
|
|
|
|
|
|
13349
|
17924
|
50
|
|
|
|
|
if (likely(max_len - len >= 4 * WORDBYTES)) { |
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13350
|
|
|
|
|
|
|
|
13351
|
|
|
|
|
|
|
#define COMPARE_WORD_STEP \ |
13352
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ \ |
13353
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); \ |
13354
|
|
|
|
|
|
|
if (v_word != 0) \ |
13355
|
|
|
|
|
|
|
goto word_differs; \ |
13356
|
|
|
|
|
|
|
len += WORDBYTES; \ |
13357
|
|
|
|
|
|
|
|
13358
|
17668
|
50
|
|
|
|
|
COMPARE_WORD_STEP |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13359
|
16077
|
50
|
|
|
|
|
COMPARE_WORD_STEP |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13360
|
15496
|
50
|
|
|
|
|
COMPARE_WORD_STEP |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13361
|
15442
|
50
|
|
|
|
|
COMPARE_WORD_STEP |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13362
|
|
|
|
|
|
|
#undef COMPARE_WORD_STEP |
13363
|
|
|
|
|
|
|
} |
13364
|
|
|
|
|
|
|
|
13365
|
241392
|
100
|
|
|
|
|
while (len + WORDBYTES <= max_len) { |
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13366
|
678300
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ |
13367
|
452200
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); |
13368
|
226100
|
50
|
|
|
|
|
if (v_word != 0) |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13369
|
|
|
|
|
|
|
goto word_differs; |
13370
|
226010
|
|
|
|
|
|
len += WORDBYTES; |
13371
|
|
|
|
|
|
|
} |
13372
|
|
|
|
|
|
|
} |
13373
|
|
|
|
|
|
|
|
13374
|
58096
|
100
|
|
|
|
|
while (len < max_len && matchptr[len] == strptr[len]) |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13375
|
42804
|
|
|
|
|
|
len++; |
13376
|
15292
|
|
|
|
|
|
return len; |
13377
|
|
|
|
|
|
|
|
13378
|
|
|
|
|
|
|
word_differs: |
13379
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
13380
|
2632
|
|
|
|
|
|
len += (bsfw(v_word) >> 3); |
13381
|
|
|
|
|
|
|
else |
13382
|
|
|
|
|
|
|
len += (WORDBITS - 1 - bsrw(v_word)) >> 3; |
13383
|
2632
|
|
|
|
|
|
return len; |
13384
|
|
|
|
|
|
|
} |
13385
|
|
|
|
|
|
|
|
13386
|
|
|
|
|
|
|
#endif |
13387
|
|
|
|
|
|
|
|
13388
|
|
|
|
|
|
|
|
13389
|
|
|
|
|
|
|
#define HC_MATCHFINDER_HASH3_ORDER 15 |
13390
|
|
|
|
|
|
|
#define HC_MATCHFINDER_HASH4_ORDER 16 |
13391
|
|
|
|
|
|
|
|
13392
|
|
|
|
|
|
|
#define HC_MATCHFINDER_TOTAL_HASH_SIZE \ |
13393
|
|
|
|
|
|
|
(((1UL << HC_MATCHFINDER_HASH3_ORDER) + \ |
13394
|
|
|
|
|
|
|
(1UL << HC_MATCHFINDER_HASH4_ORDER)) * sizeof(mf_pos_t)) |
13395
|
|
|
|
|
|
|
|
13396
|
|
|
|
|
|
|
struct MATCHFINDER_ALIGNED hc_matchfinder { |
13397
|
|
|
|
|
|
|
|
13398
|
|
|
|
|
|
|
|
13399
|
|
|
|
|
|
|
mf_pos_t hash3_tab[1UL << HC_MATCHFINDER_HASH3_ORDER]; |
13400
|
|
|
|
|
|
|
|
13401
|
|
|
|
|
|
|
|
13402
|
|
|
|
|
|
|
mf_pos_t hash4_tab[1UL << HC_MATCHFINDER_HASH4_ORDER]; |
13403
|
|
|
|
|
|
|
|
13404
|
|
|
|
|
|
|
|
13405
|
|
|
|
|
|
|
mf_pos_t next_tab[MATCHFINDER_WINDOW_SIZE]; |
13406
|
|
|
|
|
|
|
}; |
13407
|
|
|
|
|
|
|
|
13408
|
|
|
|
|
|
|
|
13409
|
|
|
|
|
|
|
static forceinline void |
13410
|
|
|
|
|
|
|
hc_matchfinder_init(struct hc_matchfinder *mf) |
13411
|
|
|
|
|
|
|
{ |
13412
|
|
|
|
|
|
|
STATIC_ASSERT(HC_MATCHFINDER_TOTAL_HASH_SIZE % |
13413
|
|
|
|
|
|
|
MATCHFINDER_SIZE_ALIGNMENT == 0); |
13414
|
|
|
|
|
|
|
|
13415
|
|
|
|
|
|
|
matchfinder_init((mf_pos_t *)mf, HC_MATCHFINDER_TOTAL_HASH_SIZE); |
13416
|
|
|
|
|
|
|
} |
13417
|
|
|
|
|
|
|
|
13418
|
|
|
|
|
|
|
static forceinline void |
13419
|
|
|
|
|
|
|
hc_matchfinder_slide_window(struct hc_matchfinder *mf) |
13420
|
|
|
|
|
|
|
{ |
13421
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(*mf) % MATCHFINDER_SIZE_ALIGNMENT == 0); |
13422
|
|
|
|
|
|
|
|
13423
|
|
|
|
|
|
|
matchfinder_rebase((mf_pos_t *)mf, sizeof(*mf)); |
13424
|
|
|
|
|
|
|
} |
13425
|
|
|
|
|
|
|
|
13426
|
|
|
|
|
|
|
|
13427
|
|
|
|
|
|
|
static forceinline u32 |
13428
|
|
|
|
|
|
|
hc_matchfinder_longest_match(struct hc_matchfinder * const mf, |
13429
|
|
|
|
|
|
|
const u8 ** const in_base_p, |
13430
|
|
|
|
|
|
|
const u8 * const in_next, |
13431
|
|
|
|
|
|
|
u32 best_len, |
13432
|
|
|
|
|
|
|
const u32 max_len, |
13433
|
|
|
|
|
|
|
const u32 nice_len, |
13434
|
|
|
|
|
|
|
const u32 max_search_depth, |
13435
|
|
|
|
|
|
|
u32 * const next_hashes, |
13436
|
|
|
|
|
|
|
u32 * const offset_ret) |
13437
|
|
|
|
|
|
|
{ |
13438
|
7046
|
|
|
|
|
|
u32 depth_remaining = max_search_depth; |
13439
|
7046
|
|
|
|
|
|
const u8 *best_matchptr = in_next; |
13440
|
|
|
|
|
|
|
mf_pos_t cur_node3, cur_node4; |
13441
|
|
|
|
|
|
|
u32 hash3, hash4; |
13442
|
|
|
|
|
|
|
u32 next_hashseq; |
13443
|
|
|
|
|
|
|
u32 seq4; |
13444
|
|
|
|
|
|
|
const u8 *matchptr; |
13445
|
|
|
|
|
|
|
u32 len; |
13446
|
7046
|
|
|
|
|
|
u32 cur_pos = in_next - *in_base_p; |
13447
|
|
|
|
|
|
|
const u8 *in_base; |
13448
|
|
|
|
|
|
|
mf_pos_t cutoff; |
13449
|
|
|
|
|
|
|
|
13450
|
7046
|
50
|
|
|
|
|
if (cur_pos == MATCHFINDER_WINDOW_SIZE) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13451
|
|
|
|
|
|
|
hc_matchfinder_slide_window(mf); |
13452
|
0
|
|
|
|
|
|
*in_base_p += MATCHFINDER_WINDOW_SIZE; |
13453
|
0
|
|
|
|
|
|
cur_pos = 0; |
13454
|
|
|
|
|
|
|
} |
13455
|
|
|
|
|
|
|
|
13456
|
7046
|
|
|
|
|
|
in_base = *in_base_p; |
13457
|
7046
|
|
|
|
|
|
cutoff = cur_pos - MATCHFINDER_WINDOW_SIZE; |
13458
|
|
|
|
|
|
|
|
13459
|
7046
|
50
|
|
|
|
|
if (unlikely(max_len < 5)) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13460
|
|
|
|
|
|
|
goto out; |
13461
|
|
|
|
|
|
|
|
13462
|
|
|
|
|
|
|
|
13463
|
7046
|
|
|
|
|
|
hash3 = next_hashes[0]; |
13464
|
7046
|
|
|
|
|
|
hash4 = next_hashes[1]; |
13465
|
|
|
|
|
|
|
|
13466
|
|
|
|
|
|
|
|
13467
|
7046
|
|
|
|
|
|
cur_node3 = mf->hash3_tab[hash3]; |
13468
|
7046
|
|
|
|
|
|
cur_node4 = mf->hash4_tab[hash4]; |
13469
|
|
|
|
|
|
|
|
13470
|
|
|
|
|
|
|
|
13471
|
7046
|
|
|
|
|
|
mf->hash3_tab[hash3] = cur_pos; |
13472
|
|
|
|
|
|
|
|
13473
|
|
|
|
|
|
|
|
13474
|
7046
|
|
|
|
|
|
mf->hash4_tab[hash4] = cur_pos; |
13475
|
7046
|
|
|
|
|
|
mf->next_tab[cur_pos] = cur_node4; |
13476
|
|
|
|
|
|
|
|
13477
|
|
|
|
|
|
|
|
13478
|
14092
|
|
|
|
|
|
next_hashseq = get_unaligned_le32(in_next + 1); |
13479
|
14092
|
|
|
|
|
|
next_hashes[0] = lz_hash(next_hashseq & 0xFFFFFF, HC_MATCHFINDER_HASH3_ORDER); |
13480
|
14092
|
|
|
|
|
|
next_hashes[1] = lz_hash(next_hashseq, HC_MATCHFINDER_HASH4_ORDER); |
13481
|
7046
|
|
|
|
|
|
prefetchw(&mf->hash3_tab[next_hashes[0]]); |
13482
|
7046
|
|
|
|
|
|
prefetchw(&mf->hash4_tab[next_hashes[1]]); |
13483
|
|
|
|
|
|
|
|
13484
|
7046
|
|
|
|
|
|
if (best_len < 4) { |
13485
|
|
|
|
|
|
|
|
13486
|
|
|
|
|
|
|
|
13487
|
|
|
|
|
|
|
|
13488
|
4747
|
0
|
|
|
|
|
if (cur_node3 <= cutoff) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13489
|
|
|
|
|
|
|
goto out; |
13490
|
|
|
|
|
|
|
|
13491
|
2859
|
|
|
|
|
|
seq4 = load_u32_unaligned(in_next); |
13492
|
|
|
|
|
|
|
|
13493
|
2859
|
0
|
|
|
|
|
if (best_len < 3) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13494
|
0
|
|
|
|
|
|
matchptr = &in_base[cur_node3]; |
13495
|
0
|
0
|
|
|
|
|
if (load_u24_unaligned(matchptr) == loaded_u32_to_u24(seq4)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13496
|
0
|
|
|
|
|
|
best_len = 3; |
13497
|
0
|
|
|
|
|
|
best_matchptr = matchptr; |
13498
|
|
|
|
|
|
|
} |
13499
|
|
|
|
|
|
|
} |
13500
|
|
|
|
|
|
|
|
13501
|
|
|
|
|
|
|
|
13502
|
|
|
|
|
|
|
|
13503
|
2859
|
0
|
|
|
|
|
if (cur_node4 <= cutoff) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13504
|
|
|
|
|
|
|
goto out; |
13505
|
|
|
|
|
|
|
|
13506
|
|
|
|
|
|
|
for (;;) { |
13507
|
|
|
|
|
|
|
|
13508
|
2180
|
|
|
|
|
|
matchptr = &in_base[cur_node4]; |
13509
|
|
|
|
|
|
|
|
13510
|
2180
|
0
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq4) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13511
|
|
|
|
|
|
|
break; |
13512
|
|
|
|
|
|
|
|
13513
|
|
|
|
|
|
|
|
13514
|
216
|
|
|
|
|
|
cur_node4 = mf->next_tab[cur_node4 & (MATCHFINDER_WINDOW_SIZE - 1)]; |
13515
|
216
|
0
|
|
|
|
|
if (cur_node4 <= cutoff || !--depth_remaining) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13516
|
|
|
|
|
|
|
goto out; |
13517
|
|
|
|
|
|
|
} |
13518
|
|
|
|
|
|
|
|
13519
|
|
|
|
|
|
|
|
13520
|
1964
|
|
|
|
|
|
best_matchptr = matchptr; |
13521
|
1964
|
|
|
|
|
|
best_len = lz_extend(in_next, best_matchptr, 4, max_len); |
13522
|
1964
|
0
|
|
|
|
|
if (best_len >= nice_len) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13523
|
|
|
|
|
|
|
goto out; |
13524
|
1963
|
|
|
|
|
|
cur_node4 = mf->next_tab[cur_node4 & (MATCHFINDER_WINDOW_SIZE - 1)]; |
13525
|
1963
|
0
|
|
|
|
|
if (cur_node4 <= cutoff || !--depth_remaining) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13526
|
|
|
|
|
|
|
goto out; |
13527
|
|
|
|
|
|
|
} else { |
13528
|
2299
|
100
|
|
|
|
|
if (cur_node4 <= cutoff || best_len >= nice_len) |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13529
|
|
|
|
|
|
|
goto out; |
13530
|
|
|
|
|
|
|
} |
13531
|
|
|
|
|
|
|
|
13532
|
|
|
|
|
|
|
|
13533
|
|
|
|
|
|
|
|
13534
|
|
|
|
|
|
|
for (;;) { |
13535
|
|
|
|
|
|
|
for (;;) { |
13536
|
36147
|
|
|
|
|
|
matchptr = &in_base[cur_node4]; |
13537
|
|
|
|
|
|
|
|
13538
|
|
|
|
|
|
|
|
13539
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
13540
|
36147
|
50
|
|
|
|
|
if ((load_u32_unaligned(matchptr + best_len - 3) == |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13541
|
837
|
50
|
|
|
|
|
load_u32_unaligned(in_next + best_len - 3)) && |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13542
|
837
|
|
|
|
|
|
(load_u32_unaligned(matchptr) == |
13543
|
837
|
|
|
|
|
|
load_u32_unaligned(in_next))) |
13544
|
|
|
|
|
|
|
#else |
13545
|
|
|
|
|
|
|
if (matchptr[best_len] == in_next[best_len]) |
13546
|
|
|
|
|
|
|
#endif |
13547
|
|
|
|
|
|
|
break; |
13548
|
|
|
|
|
|
|
|
13549
|
|
|
|
|
|
|
|
13550
|
35310
|
|
|
|
|
|
cur_node4 = mf->next_tab[cur_node4 & (MATCHFINDER_WINDOW_SIZE - 1)]; |
13551
|
35310
|
0
|
|
|
|
|
if (cur_node4 <= cutoff || !--depth_remaining) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13552
|
|
|
|
|
|
|
goto out; |
13553
|
|
|
|
|
|
|
} |
13554
|
|
|
|
|
|
|
|
13555
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
13556
|
837
|
|
|
|
|
|
len = 4; |
13557
|
|
|
|
|
|
|
#else |
13558
|
|
|
|
|
|
|
len = 0; |
13559
|
|
|
|
|
|
|
#endif |
13560
|
837
|
|
|
|
|
|
len = lz_extend(in_next, matchptr, len, max_len); |
13561
|
837
|
50
|
|
|
|
|
if (len > best_len) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13562
|
|
|
|
|
|
|
|
13563
|
831
|
|
|
|
|
|
best_len = len; |
13564
|
831
|
|
|
|
|
|
best_matchptr = matchptr; |
13565
|
831
|
50
|
|
|
|
|
if (best_len >= nice_len) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13566
|
|
|
|
|
|
|
goto out; |
13567
|
|
|
|
|
|
|
} |
13568
|
|
|
|
|
|
|
|
13569
|
|
|
|
|
|
|
|
13570
|
669
|
|
|
|
|
|
cur_node4 = mf->next_tab[cur_node4 & (MATCHFINDER_WINDOW_SIZE - 1)]; |
13571
|
669
|
0
|
|
|
|
|
if (cur_node4 <= cutoff || !--depth_remaining) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13572
|
|
|
|
|
|
|
goto out; |
13573
|
|
|
|
|
|
|
} |
13574
|
|
|
|
|
|
|
out: |
13575
|
7046
|
|
|
|
|
|
*offset_ret = in_next - best_matchptr; |
13576
|
7046
|
|
|
|
|
|
return best_len; |
13577
|
|
|
|
|
|
|
} |
13578
|
|
|
|
|
|
|
|
13579
|
|
|
|
|
|
|
|
13580
|
|
|
|
|
|
|
static forceinline void |
13581
|
|
|
|
|
|
|
hc_matchfinder_skip_bytes(struct hc_matchfinder * const mf, |
13582
|
|
|
|
|
|
|
const u8 ** const in_base_p, |
13583
|
|
|
|
|
|
|
const u8 *in_next, |
13584
|
|
|
|
|
|
|
const u8 * const in_end, |
13585
|
|
|
|
|
|
|
const u32 count, |
13586
|
|
|
|
|
|
|
u32 * const next_hashes) |
13587
|
|
|
|
|
|
|
{ |
13588
|
|
|
|
|
|
|
u32 cur_pos; |
13589
|
|
|
|
|
|
|
u32 hash3, hash4; |
13590
|
|
|
|
|
|
|
u32 next_hashseq; |
13591
|
2070
|
|
|
|
|
|
u32 remaining = count; |
13592
|
|
|
|
|
|
|
|
13593
|
2070
|
100
|
|
|
|
|
if (unlikely(count + 5 > in_end - in_next)) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
13594
|
|
|
|
|
|
|
return; |
13595
|
|
|
|
|
|
|
|
13596
|
2045
|
|
|
|
|
|
cur_pos = in_next - *in_base_p; |
13597
|
2045
|
|
|
|
|
|
hash3 = next_hashes[0]; |
13598
|
2045
|
|
|
|
|
|
hash4 = next_hashes[1]; |
13599
|
|
|
|
|
|
|
do { |
13600
|
59176
|
50
|
|
|
|
|
if (cur_pos == MATCHFINDER_WINDOW_SIZE) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13601
|
|
|
|
|
|
|
hc_matchfinder_slide_window(mf); |
13602
|
0
|
|
|
|
|
|
*in_base_p += MATCHFINDER_WINDOW_SIZE; |
13603
|
0
|
|
|
|
|
|
cur_pos = 0; |
13604
|
|
|
|
|
|
|
} |
13605
|
59176
|
|
|
|
|
|
mf->hash3_tab[hash3] = cur_pos; |
13606
|
59176
|
|
|
|
|
|
mf->next_tab[cur_pos] = mf->hash4_tab[hash4]; |
13607
|
59176
|
|
|
|
|
|
mf->hash4_tab[hash4] = cur_pos; |
13608
|
|
|
|
|
|
|
|
13609
|
118352
|
|
|
|
|
|
next_hashseq = get_unaligned_le32(++in_next); |
13610
|
118352
|
|
|
|
|
|
hash3 = lz_hash(next_hashseq & 0xFFFFFF, HC_MATCHFINDER_HASH3_ORDER); |
13611
|
59176
|
|
|
|
|
|
hash4 = lz_hash(next_hashseq, HC_MATCHFINDER_HASH4_ORDER); |
13612
|
59176
|
|
|
|
|
|
cur_pos++; |
13613
|
59176
|
100
|
|
|
|
|
} while (--remaining); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
13614
|
|
|
|
|
|
|
|
13615
|
2045
|
|
|
|
|
|
prefetchw(&mf->hash3_tab[hash3]); |
13616
|
2045
|
|
|
|
|
|
prefetchw(&mf->hash4_tab[hash4]); |
13617
|
2045
|
|
|
|
|
|
next_hashes[0] = hash3; |
13618
|
2045
|
|
|
|
|
|
next_hashes[1] = hash4; |
13619
|
|
|
|
|
|
|
} |
13620
|
|
|
|
|
|
|
|
13621
|
|
|
|
|
|
|
#endif |
13622
|
|
|
|
|
|
|
|
13623
|
|
|
|
|
|
|
/* #include "ht_matchfinder.h" */ |
13624
|
|
|
|
|
|
|
|
13625
|
|
|
|
|
|
|
|
13626
|
|
|
|
|
|
|
#ifndef LIB_HT_MATCHFINDER_H |
13627
|
|
|
|
|
|
|
#define LIB_HT_MATCHFINDER_H |
13628
|
|
|
|
|
|
|
|
13629
|
|
|
|
|
|
|
/* #include "matchfinder_common.h" */ |
13630
|
|
|
|
|
|
|
|
13631
|
|
|
|
|
|
|
|
13632
|
|
|
|
|
|
|
#ifndef LIB_MATCHFINDER_COMMON_H |
13633
|
|
|
|
|
|
|
#define LIB_MATCHFINDER_COMMON_H |
13634
|
|
|
|
|
|
|
|
13635
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
13636
|
|
|
|
|
|
|
|
13637
|
|
|
|
|
|
|
|
13638
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
13639
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
13640
|
|
|
|
|
|
|
|
13641
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
13642
|
|
|
|
|
|
|
|
13643
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
13644
|
|
|
|
|
|
|
#endif |
13645
|
|
|
|
|
|
|
|
13646
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
13647
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
13648
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
13649
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
13650
|
|
|
|
|
|
|
#else |
13651
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
13652
|
|
|
|
|
|
|
#endif |
13653
|
|
|
|
|
|
|
|
13654
|
|
|
|
|
|
|
|
13655
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
13656
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
13657
|
|
|
|
|
|
|
#else |
13658
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
13659
|
|
|
|
|
|
|
#endif |
13660
|
|
|
|
|
|
|
|
13661
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
13662
|
|
|
|
|
|
|
|
13663
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
13664
|
|
|
|
|
|
|
|
13665
|
|
|
|
|
|
|
|
13666
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
13667
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
13668
|
|
|
|
|
|
|
|
13669
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
13670
|
|
|
|
|
|
|
|
13671
|
|
|
|
|
|
|
|
13672
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
13673
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
13674
|
|
|
|
|
|
|
|
13675
|
|
|
|
|
|
|
#include |
13676
|
|
|
|
|
|
|
#include |
13677
|
|
|
|
|
|
|
|
13678
|
|
|
|
|
|
|
#ifdef __cplusplus |
13679
|
|
|
|
|
|
|
extern "C" { |
13680
|
|
|
|
|
|
|
#endif |
13681
|
|
|
|
|
|
|
|
13682
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
13683
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
13684
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
13685
|
|
|
|
|
|
|
|
13686
|
|
|
|
|
|
|
|
13687
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
13688
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
13689
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
13690
|
|
|
|
|
|
|
# else |
13691
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
13692
|
|
|
|
|
|
|
# endif |
13693
|
|
|
|
|
|
|
#endif |
13694
|
|
|
|
|
|
|
|
13695
|
|
|
|
|
|
|
|
13696
|
|
|
|
|
|
|
|
13697
|
|
|
|
|
|
|
|
13698
|
|
|
|
|
|
|
|
13699
|
|
|
|
|
|
|
struct libdeflate_compressor; |
13700
|
|
|
|
|
|
|
struct libdeflate_options; |
13701
|
|
|
|
|
|
|
|
13702
|
|
|
|
|
|
|
|
13703
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
13704
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
13705
|
|
|
|
|
|
|
|
13706
|
|
|
|
|
|
|
|
13707
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
13708
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
13709
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
13710
|
|
|
|
|
|
|
|
13711
|
|
|
|
|
|
|
|
13712
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13713
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
13714
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13715
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
13716
|
|
|
|
|
|
|
|
13717
|
|
|
|
|
|
|
|
13718
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13719
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
13720
|
|
|
|
|
|
|
size_t in_nbytes); |
13721
|
|
|
|
|
|
|
|
13722
|
|
|
|
|
|
|
|
13723
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13724
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
13725
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13726
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
13727
|
|
|
|
|
|
|
|
13728
|
|
|
|
|
|
|
|
13729
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13730
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
13731
|
|
|
|
|
|
|
size_t in_nbytes); |
13732
|
|
|
|
|
|
|
|
13733
|
|
|
|
|
|
|
|
13734
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13735
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
13736
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13737
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
13738
|
|
|
|
|
|
|
|
13739
|
|
|
|
|
|
|
|
13740
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13741
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
13742
|
|
|
|
|
|
|
size_t in_nbytes); |
13743
|
|
|
|
|
|
|
|
13744
|
|
|
|
|
|
|
|
13745
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
13746
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
13747
|
|
|
|
|
|
|
|
13748
|
|
|
|
|
|
|
|
13749
|
|
|
|
|
|
|
|
13750
|
|
|
|
|
|
|
|
13751
|
|
|
|
|
|
|
|
13752
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
13753
|
|
|
|
|
|
|
struct libdeflate_options; |
13754
|
|
|
|
|
|
|
|
13755
|
|
|
|
|
|
|
|
13756
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
13757
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
13758
|
|
|
|
|
|
|
|
13759
|
|
|
|
|
|
|
|
13760
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
13761
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
13762
|
|
|
|
|
|
|
|
13763
|
|
|
|
|
|
|
|
13764
|
|
|
|
|
|
|
enum libdeflate_result { |
13765
|
|
|
|
|
|
|
|
13766
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
13767
|
|
|
|
|
|
|
|
13768
|
|
|
|
|
|
|
|
13769
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
13770
|
|
|
|
|
|
|
|
13771
|
|
|
|
|
|
|
|
13772
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
13773
|
|
|
|
|
|
|
|
13774
|
|
|
|
|
|
|
|
13775
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
13776
|
|
|
|
|
|
|
}; |
13777
|
|
|
|
|
|
|
|
13778
|
|
|
|
|
|
|
|
13779
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13780
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
13781
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13782
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13783
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13784
|
|
|
|
|
|
|
|
13785
|
|
|
|
|
|
|
|
13786
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13787
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
13788
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13789
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13790
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
13791
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13792
|
|
|
|
|
|
|
|
13793
|
|
|
|
|
|
|
|
13794
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13795
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
13796
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13797
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13798
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13799
|
|
|
|
|
|
|
|
13800
|
|
|
|
|
|
|
|
13801
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13802
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
13803
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13804
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13805
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
13806
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13807
|
|
|
|
|
|
|
|
13808
|
|
|
|
|
|
|
|
13809
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13810
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
13811
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13812
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13813
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13814
|
|
|
|
|
|
|
|
13815
|
|
|
|
|
|
|
|
13816
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13817
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
13818
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13819
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13820
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
13821
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13822
|
|
|
|
|
|
|
|
13823
|
|
|
|
|
|
|
|
13824
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
13825
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
13826
|
|
|
|
|
|
|
|
13827
|
|
|
|
|
|
|
|
13828
|
|
|
|
|
|
|
|
13829
|
|
|
|
|
|
|
|
13830
|
|
|
|
|
|
|
|
13831
|
|
|
|
|
|
|
|
13832
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
13833
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
13834
|
|
|
|
|
|
|
|
13835
|
|
|
|
|
|
|
|
13836
|
|
|
|
|
|
|
|
13837
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
13838
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
13839
|
|
|
|
|
|
|
|
13840
|
|
|
|
|
|
|
|
13841
|
|
|
|
|
|
|
|
13842
|
|
|
|
|
|
|
|
13843
|
|
|
|
|
|
|
|
13844
|
|
|
|
|
|
|
|
13845
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
13846
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
13847
|
|
|
|
|
|
|
void (*free_func)(void *)); |
13848
|
|
|
|
|
|
|
|
13849
|
|
|
|
|
|
|
|
13850
|
|
|
|
|
|
|
struct libdeflate_options { |
13851
|
|
|
|
|
|
|
|
13852
|
|
|
|
|
|
|
|
13853
|
|
|
|
|
|
|
size_t sizeof_options; |
13854
|
|
|
|
|
|
|
|
13855
|
|
|
|
|
|
|
|
13856
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
13857
|
|
|
|
|
|
|
void (*free_func)(void *); |
13858
|
|
|
|
|
|
|
}; |
13859
|
|
|
|
|
|
|
|
13860
|
|
|
|
|
|
|
#ifdef __cplusplus |
13861
|
|
|
|
|
|
|
} |
13862
|
|
|
|
|
|
|
#endif |
13863
|
|
|
|
|
|
|
|
13864
|
|
|
|
|
|
|
#endif |
13865
|
|
|
|
|
|
|
|
13866
|
|
|
|
|
|
|
|
13867
|
|
|
|
|
|
|
#include |
13868
|
|
|
|
|
|
|
#include |
13869
|
|
|
|
|
|
|
#include |
13870
|
|
|
|
|
|
|
#ifdef _MSC_VER |
13871
|
|
|
|
|
|
|
# include |
13872
|
|
|
|
|
|
|
# include |
13873
|
|
|
|
|
|
|
|
13874
|
|
|
|
|
|
|
|
13875
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
13876
|
|
|
|
|
|
|
|
13877
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
13878
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
13879
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
13880
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
13881
|
|
|
|
|
|
|
|
13882
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
13883
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
13884
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
13885
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
13886
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
13887
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
13888
|
|
|
|
|
|
|
#endif |
13889
|
|
|
|
|
|
|
#ifndef FREESTANDING |
13890
|
|
|
|
|
|
|
# include |
13891
|
|
|
|
|
|
|
#endif |
13892
|
|
|
|
|
|
|
|
13893
|
|
|
|
|
|
|
|
13894
|
|
|
|
|
|
|
|
13895
|
|
|
|
|
|
|
|
13896
|
|
|
|
|
|
|
|
13897
|
|
|
|
|
|
|
|
13898
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
13899
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
13900
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
13901
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
13902
|
|
|
|
|
|
|
#ifdef _MSC_VER |
13903
|
|
|
|
|
|
|
# if defined(_M_X64) |
13904
|
|
|
|
|
|
|
# define ARCH_X86_64 |
13905
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
13906
|
|
|
|
|
|
|
# define ARCH_X86_32 |
13907
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
13908
|
|
|
|
|
|
|
# define ARCH_ARM64 |
13909
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
13910
|
|
|
|
|
|
|
# define ARCH_ARM32 |
13911
|
|
|
|
|
|
|
# endif |
13912
|
|
|
|
|
|
|
#else |
13913
|
|
|
|
|
|
|
# if defined(__x86_64__) |
13914
|
|
|
|
|
|
|
# define ARCH_X86_64 |
13915
|
|
|
|
|
|
|
# elif defined(__i386__) |
13916
|
|
|
|
|
|
|
# define ARCH_X86_32 |
13917
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
13918
|
|
|
|
|
|
|
# define ARCH_ARM64 |
13919
|
|
|
|
|
|
|
# elif defined(__arm__) |
13920
|
|
|
|
|
|
|
# define ARCH_ARM32 |
13921
|
|
|
|
|
|
|
# endif |
13922
|
|
|
|
|
|
|
#endif |
13923
|
|
|
|
|
|
|
|
13924
|
|
|
|
|
|
|
|
13925
|
|
|
|
|
|
|
|
13926
|
|
|
|
|
|
|
|
13927
|
|
|
|
|
|
|
|
13928
|
|
|
|
|
|
|
|
13929
|
|
|
|
|
|
|
typedef uint8_t u8; |
13930
|
|
|
|
|
|
|
typedef uint16_t u16; |
13931
|
|
|
|
|
|
|
typedef uint32_t u32; |
13932
|
|
|
|
|
|
|
typedef uint64_t u64; |
13933
|
|
|
|
|
|
|
typedef int8_t s8; |
13934
|
|
|
|
|
|
|
typedef int16_t s16; |
13935
|
|
|
|
|
|
|
typedef int32_t s32; |
13936
|
|
|
|
|
|
|
typedef int64_t s64; |
13937
|
|
|
|
|
|
|
|
13938
|
|
|
|
|
|
|
|
13939
|
|
|
|
|
|
|
#ifdef _MSC_VER |
13940
|
|
|
|
|
|
|
# ifdef _WIN64 |
13941
|
|
|
|
|
|
|
typedef long long ssize_t; |
13942
|
|
|
|
|
|
|
# else |
13943
|
|
|
|
|
|
|
typedef long ssize_t; |
13944
|
|
|
|
|
|
|
# endif |
13945
|
|
|
|
|
|
|
#endif |
13946
|
|
|
|
|
|
|
|
13947
|
|
|
|
|
|
|
|
13948
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
13949
|
|
|
|
|
|
|
|
13950
|
|
|
|
|
|
|
|
13951
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
13952
|
|
|
|
|
|
|
|
13953
|
|
|
|
|
|
|
|
13954
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
13955
|
|
|
|
|
|
|
|
13956
|
|
|
|
|
|
|
|
13957
|
|
|
|
|
|
|
|
13958
|
|
|
|
|
|
|
|
13959
|
|
|
|
|
|
|
|
13960
|
|
|
|
|
|
|
|
13961
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
13962
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
13963
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
13964
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
13965
|
|
|
|
|
|
|
#else |
13966
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
13967
|
|
|
|
|
|
|
#endif |
13968
|
|
|
|
|
|
|
#ifdef __clang__ |
13969
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
13970
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
13971
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
13972
|
|
|
|
|
|
|
# else |
13973
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
13974
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
13975
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
13976
|
|
|
|
|
|
|
# endif |
13977
|
|
|
|
|
|
|
#else |
13978
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
13979
|
|
|
|
|
|
|
#endif |
13980
|
|
|
|
|
|
|
|
13981
|
|
|
|
|
|
|
|
13982
|
|
|
|
|
|
|
#ifndef __has_attribute |
13983
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
13984
|
|
|
|
|
|
|
#endif |
13985
|
|
|
|
|
|
|
#ifndef __has_builtin |
13986
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
13987
|
|
|
|
|
|
|
#endif |
13988
|
|
|
|
|
|
|
|
13989
|
|
|
|
|
|
|
|
13990
|
|
|
|
|
|
|
#ifdef _MSC_VER |
13991
|
|
|
|
|
|
|
# define inline __inline |
13992
|
|
|
|
|
|
|
#endif |
13993
|
|
|
|
|
|
|
|
13994
|
|
|
|
|
|
|
|
13995
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
13996
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
13997
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13998
|
|
|
|
|
|
|
# define forceinline __forceinline |
13999
|
|
|
|
|
|
|
#else |
14000
|
|
|
|
|
|
|
# define forceinline inline |
14001
|
|
|
|
|
|
|
#endif |
14002
|
|
|
|
|
|
|
|
14003
|
|
|
|
|
|
|
|
14004
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
14005
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
14006
|
|
|
|
|
|
|
#else |
14007
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
14008
|
|
|
|
|
|
|
#endif |
14009
|
|
|
|
|
|
|
|
14010
|
|
|
|
|
|
|
|
14011
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
14012
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
14013
|
|
|
|
|
|
|
# define restrict __restrict__ |
14014
|
|
|
|
|
|
|
# else |
14015
|
|
|
|
|
|
|
# define restrict |
14016
|
|
|
|
|
|
|
# endif |
14017
|
|
|
|
|
|
|
#endif |
14018
|
|
|
|
|
|
|
|
14019
|
|
|
|
|
|
|
|
14020
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
14021
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
14022
|
|
|
|
|
|
|
#else |
14023
|
|
|
|
|
|
|
# define likely(expr) (expr) |
14024
|
|
|
|
|
|
|
#endif |
14025
|
|
|
|
|
|
|
|
14026
|
|
|
|
|
|
|
|
14027
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
14028
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
14029
|
|
|
|
|
|
|
#else |
14030
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
14031
|
|
|
|
|
|
|
#endif |
14032
|
|
|
|
|
|
|
|
14033
|
|
|
|
|
|
|
|
14034
|
|
|
|
|
|
|
#undef prefetchr |
14035
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
14036
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
14037
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14038
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
14039
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
14040
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
14041
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
14042
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
14043
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
14044
|
|
|
|
|
|
|
# endif |
14045
|
|
|
|
|
|
|
#endif |
14046
|
|
|
|
|
|
|
#ifndef prefetchr |
14047
|
|
|
|
|
|
|
# define prefetchr(addr) |
14048
|
|
|
|
|
|
|
#endif |
14049
|
|
|
|
|
|
|
|
14050
|
|
|
|
|
|
|
|
14051
|
|
|
|
|
|
|
#undef prefetchw |
14052
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
14053
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
14054
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14055
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
14056
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
14057
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
14058
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
14059
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
14060
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
14061
|
|
|
|
|
|
|
# endif |
14062
|
|
|
|
|
|
|
#endif |
14063
|
|
|
|
|
|
|
#ifndef prefetchw |
14064
|
|
|
|
|
|
|
# define prefetchw(addr) |
14065
|
|
|
|
|
|
|
#endif |
14066
|
|
|
|
|
|
|
|
14067
|
|
|
|
|
|
|
|
14068
|
|
|
|
|
|
|
#undef _aligned_attribute |
14069
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
14070
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
14071
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14072
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
14073
|
|
|
|
|
|
|
#endif |
14074
|
|
|
|
|
|
|
|
14075
|
|
|
|
|
|
|
|
14076
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
14077
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
14078
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
14079
|
|
|
|
|
|
|
#else |
14080
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
14081
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
14082
|
|
|
|
|
|
|
#endif |
14083
|
|
|
|
|
|
|
|
14084
|
|
|
|
|
|
|
|
14085
|
|
|
|
|
|
|
|
14086
|
|
|
|
|
|
|
|
14087
|
|
|
|
|
|
|
|
14088
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
14089
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
14090
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
14091
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
14092
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
14093
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
14094
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
14095
|
|
|
|
|
|
|
|
14096
|
|
|
|
|
|
|
|
14097
|
|
|
|
|
|
|
|
14098
|
|
|
|
|
|
|
|
14099
|
|
|
|
|
|
|
|
14100
|
|
|
|
|
|
|
|
14101
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
14102
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
14103
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14104
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
14105
|
|
|
|
|
|
|
#else |
14106
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
14107
|
|
|
|
|
|
|
{ |
14108
|
|
|
|
|
|
|
union { |
14109
|
|
|
|
|
|
|
u32 w; |
14110
|
|
|
|
|
|
|
u8 b; |
14111
|
|
|
|
|
|
|
} u; |
14112
|
|
|
|
|
|
|
|
14113
|
|
|
|
|
|
|
u.w = 1; |
14114
|
|
|
|
|
|
|
return u.b; |
14115
|
|
|
|
|
|
|
} |
14116
|
|
|
|
|
|
|
#endif |
14117
|
|
|
|
|
|
|
|
14118
|
|
|
|
|
|
|
|
14119
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
14120
|
|
|
|
|
|
|
{ |
14121
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
14122
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
14123
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14124
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
14125
|
|
|
|
|
|
|
#else |
14126
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
14127
|
|
|
|
|
|
|
#endif |
14128
|
|
|
|
|
|
|
} |
14129
|
|
|
|
|
|
|
|
14130
|
|
|
|
|
|
|
|
14131
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
14132
|
|
|
|
|
|
|
{ |
14133
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
14134
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
14135
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14136
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
14137
|
|
|
|
|
|
|
#else |
14138
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
14139
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
14140
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
14141
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
14142
|
|
|
|
|
|
|
#endif |
14143
|
|
|
|
|
|
|
} |
14144
|
|
|
|
|
|
|
|
14145
|
|
|
|
|
|
|
|
14146
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
14147
|
|
|
|
|
|
|
{ |
14148
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
14149
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
14150
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14151
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
14152
|
|
|
|
|
|
|
#else |
14153
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
14154
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
14155
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
14156
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
14157
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
14158
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
14159
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
14160
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
14161
|
|
|
|
|
|
|
#endif |
14162
|
|
|
|
|
|
|
} |
14163
|
|
|
|
|
|
|
|
14164
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
14165
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
14166
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
14167
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
14168
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
14169
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
14170
|
|
|
|
|
|
|
|
14171
|
|
|
|
|
|
|
|
14172
|
|
|
|
|
|
|
|
14173
|
|
|
|
|
|
|
|
14174
|
|
|
|
|
|
|
|
14175
|
|
|
|
|
|
|
|
14176
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
14177
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
14178
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
14179
|
|
|
|
|
|
|
defined(__wasm__)) |
14180
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
14181
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14182
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
14183
|
|
|
|
|
|
|
#else |
14184
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
14185
|
|
|
|
|
|
|
#endif |
14186
|
|
|
|
|
|
|
|
14187
|
|
|
|
|
|
|
|
14188
|
|
|
|
|
|
|
|
14189
|
|
|
|
|
|
|
#ifdef FREESTANDING |
14190
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
14191
|
|
|
|
|
|
|
#else |
14192
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
14193
|
|
|
|
|
|
|
#endif |
14194
|
|
|
|
|
|
|
|
14195
|
|
|
|
|
|
|
|
14196
|
|
|
|
|
|
|
|
14197
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
14198
|
|
|
|
|
|
|
static forceinline type \ |
14199
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
14200
|
|
|
|
|
|
|
{ \ |
14201
|
|
|
|
|
|
|
type v; \ |
14202
|
|
|
|
|
|
|
\ |
14203
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
14204
|
|
|
|
|
|
|
return v; \ |
14205
|
|
|
|
|
|
|
} \ |
14206
|
|
|
|
|
|
|
\ |
14207
|
|
|
|
|
|
|
static forceinline void \ |
14208
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
14209
|
|
|
|
|
|
|
{ \ |
14210
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
14211
|
|
|
|
|
|
|
} |
14212
|
|
|
|
|
|
|
|
14213
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
14214
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
14215
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
14216
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
14217
|
|
|
|
|
|
|
|
14218
|
|
|
|
|
|
|
#undef MEMCOPY |
14219
|
|
|
|
|
|
|
|
14220
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
14221
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
14222
|
|
|
|
|
|
|
|
14223
|
|
|
|
|
|
|
|
14224
|
|
|
|
|
|
|
|
14225
|
|
|
|
|
|
|
static forceinline u16 |
14226
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
14227
|
|
|
|
|
|
|
{ |
14228
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14229
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
14230
|
|
|
|
|
|
|
else |
14231
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
14232
|
|
|
|
|
|
|
} |
14233
|
|
|
|
|
|
|
|
14234
|
|
|
|
|
|
|
static forceinline u16 |
14235
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
14236
|
|
|
|
|
|
|
{ |
14237
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14238
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
14239
|
|
|
|
|
|
|
else |
14240
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
14241
|
|
|
|
|
|
|
} |
14242
|
|
|
|
|
|
|
|
14243
|
|
|
|
|
|
|
static forceinline u32 |
14244
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
14245
|
|
|
|
|
|
|
{ |
14246
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14247
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
14248
|
|
|
|
|
|
|
else |
14249
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
14250
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
14251
|
|
|
|
|
|
|
} |
14252
|
|
|
|
|
|
|
|
14253
|
|
|
|
|
|
|
static forceinline u32 |
14254
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
14255
|
|
|
|
|
|
|
{ |
14256
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14257
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
14258
|
|
|
|
|
|
|
else |
14259
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
14260
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
14261
|
|
|
|
|
|
|
} |
14262
|
|
|
|
|
|
|
|
14263
|
|
|
|
|
|
|
static forceinline u64 |
14264
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
14265
|
|
|
|
|
|
|
{ |
14266
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14267
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
14268
|
|
|
|
|
|
|
else |
14269
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
14270
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
14271
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
14272
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
14273
|
|
|
|
|
|
|
} |
14274
|
|
|
|
|
|
|
|
14275
|
|
|
|
|
|
|
static forceinline machine_word_t |
14276
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
14277
|
|
|
|
|
|
|
{ |
14278
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14279
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14280
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
14281
|
|
|
|
|
|
|
else |
14282
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
14283
|
|
|
|
|
|
|
} |
14284
|
|
|
|
|
|
|
|
14285
|
|
|
|
|
|
|
|
14286
|
|
|
|
|
|
|
|
14287
|
|
|
|
|
|
|
static forceinline void |
14288
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
14289
|
|
|
|
|
|
|
{ |
14290
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14291
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
14292
|
|
|
|
|
|
|
} else { |
14293
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
14294
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
14295
|
|
|
|
|
|
|
} |
14296
|
|
|
|
|
|
|
} |
14297
|
|
|
|
|
|
|
|
14298
|
|
|
|
|
|
|
static forceinline void |
14299
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
14300
|
|
|
|
|
|
|
{ |
14301
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14302
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
14303
|
|
|
|
|
|
|
} else { |
14304
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
14305
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
14306
|
|
|
|
|
|
|
} |
14307
|
|
|
|
|
|
|
} |
14308
|
|
|
|
|
|
|
|
14309
|
|
|
|
|
|
|
static forceinline void |
14310
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
14311
|
|
|
|
|
|
|
{ |
14312
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14313
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
14314
|
|
|
|
|
|
|
} else { |
14315
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
14316
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
14317
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
14318
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
14319
|
|
|
|
|
|
|
} |
14320
|
|
|
|
|
|
|
} |
14321
|
|
|
|
|
|
|
|
14322
|
|
|
|
|
|
|
static forceinline void |
14323
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
14324
|
|
|
|
|
|
|
{ |
14325
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14326
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
14327
|
|
|
|
|
|
|
} else { |
14328
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
14329
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
14330
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
14331
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
14332
|
|
|
|
|
|
|
} |
14333
|
|
|
|
|
|
|
} |
14334
|
|
|
|
|
|
|
|
14335
|
|
|
|
|
|
|
static forceinline void |
14336
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
14337
|
|
|
|
|
|
|
{ |
14338
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14339
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
14340
|
|
|
|
|
|
|
} else { |
14341
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
14342
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
14343
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
14344
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
14345
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
14346
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
14347
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
14348
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
14349
|
|
|
|
|
|
|
} |
14350
|
|
|
|
|
|
|
} |
14351
|
|
|
|
|
|
|
|
14352
|
|
|
|
|
|
|
static forceinline void |
14353
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
14354
|
|
|
|
|
|
|
{ |
14355
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14356
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14357
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
14358
|
|
|
|
|
|
|
else |
14359
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
14360
|
|
|
|
|
|
|
} |
14361
|
|
|
|
|
|
|
|
14362
|
|
|
|
|
|
|
|
14363
|
|
|
|
|
|
|
|
14364
|
|
|
|
|
|
|
|
14365
|
|
|
|
|
|
|
|
14366
|
|
|
|
|
|
|
|
14367
|
|
|
|
|
|
|
|
14368
|
|
|
|
|
|
|
static forceinline unsigned |
14369
|
|
|
|
|
|
|
bsr32(u32 v) |
14370
|
|
|
|
|
|
|
{ |
14371
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
14372
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
14373
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14374
|
|
|
|
|
|
|
unsigned long i; |
14375
|
|
|
|
|
|
|
|
14376
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
14377
|
|
|
|
|
|
|
return i; |
14378
|
|
|
|
|
|
|
#else |
14379
|
|
|
|
|
|
|
unsigned i = 0; |
14380
|
|
|
|
|
|
|
|
14381
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
14382
|
|
|
|
|
|
|
i++; |
14383
|
|
|
|
|
|
|
return i; |
14384
|
|
|
|
|
|
|
#endif |
14385
|
|
|
|
|
|
|
} |
14386
|
|
|
|
|
|
|
|
14387
|
|
|
|
|
|
|
static forceinline unsigned |
14388
|
|
|
|
|
|
|
bsr64(u64 v) |
14389
|
|
|
|
|
|
|
{ |
14390
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
14391
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
14392
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
14393
|
|
|
|
|
|
|
unsigned long i; |
14394
|
|
|
|
|
|
|
|
14395
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
14396
|
|
|
|
|
|
|
return i; |
14397
|
|
|
|
|
|
|
#else |
14398
|
|
|
|
|
|
|
unsigned i = 0; |
14399
|
|
|
|
|
|
|
|
14400
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
14401
|
|
|
|
|
|
|
i++; |
14402
|
|
|
|
|
|
|
return i; |
14403
|
|
|
|
|
|
|
#endif |
14404
|
|
|
|
|
|
|
} |
14405
|
|
|
|
|
|
|
|
14406
|
|
|
|
|
|
|
static forceinline unsigned |
14407
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
14408
|
|
|
|
|
|
|
{ |
14409
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14410
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14411
|
|
|
|
|
|
|
return bsr32(v); |
14412
|
|
|
|
|
|
|
else |
14413
|
|
|
|
|
|
|
return bsr64(v); |
14414
|
|
|
|
|
|
|
} |
14415
|
|
|
|
|
|
|
|
14416
|
|
|
|
|
|
|
|
14417
|
|
|
|
|
|
|
|
14418
|
|
|
|
|
|
|
static forceinline unsigned |
14419
|
|
|
|
|
|
|
bsf32(u32 v) |
14420
|
|
|
|
|
|
|
{ |
14421
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
14422
|
|
|
|
|
|
|
return __builtin_ctz(v); |
14423
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14424
|
|
|
|
|
|
|
unsigned long i; |
14425
|
|
|
|
|
|
|
|
14426
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
14427
|
|
|
|
|
|
|
return i; |
14428
|
|
|
|
|
|
|
#else |
14429
|
|
|
|
|
|
|
unsigned i = 0; |
14430
|
|
|
|
|
|
|
|
14431
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
14432
|
|
|
|
|
|
|
i++; |
14433
|
|
|
|
|
|
|
return i; |
14434
|
|
|
|
|
|
|
#endif |
14435
|
|
|
|
|
|
|
} |
14436
|
|
|
|
|
|
|
|
14437
|
|
|
|
|
|
|
static forceinline unsigned |
14438
|
|
|
|
|
|
|
bsf64(u64 v) |
14439
|
|
|
|
|
|
|
{ |
14440
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
14441
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
14442
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
14443
|
|
|
|
|
|
|
unsigned long i; |
14444
|
|
|
|
|
|
|
|
14445
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
14446
|
|
|
|
|
|
|
return i; |
14447
|
|
|
|
|
|
|
#else |
14448
|
|
|
|
|
|
|
unsigned i = 0; |
14449
|
|
|
|
|
|
|
|
14450
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
14451
|
|
|
|
|
|
|
i++; |
14452
|
|
|
|
|
|
|
return i; |
14453
|
|
|
|
|
|
|
#endif |
14454
|
|
|
|
|
|
|
} |
14455
|
|
|
|
|
|
|
|
14456
|
|
|
|
|
|
|
static forceinline unsigned |
14457
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
14458
|
|
|
|
|
|
|
{ |
14459
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14460
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14461
|
|
|
|
|
|
|
return bsf32(v); |
14462
|
|
|
|
|
|
|
else |
14463
|
|
|
|
|
|
|
return bsf64(v); |
14464
|
|
|
|
|
|
|
} |
14465
|
|
|
|
|
|
|
|
14466
|
|
|
|
|
|
|
|
14467
|
|
|
|
|
|
|
#undef rbit32 |
14468
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
14469
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
14470
|
|
|
|
|
|
|
static forceinline u32 |
14471
|
|
|
|
|
|
|
rbit32(u32 v) |
14472
|
|
|
|
|
|
|
{ |
14473
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
14474
|
|
|
|
|
|
|
return v; |
14475
|
|
|
|
|
|
|
} |
14476
|
|
|
|
|
|
|
#define rbit32 rbit32 |
14477
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
14478
|
|
|
|
|
|
|
static forceinline u32 |
14479
|
|
|
|
|
|
|
rbit32(u32 v) |
14480
|
|
|
|
|
|
|
{ |
14481
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
14482
|
|
|
|
|
|
|
return v; |
14483
|
|
|
|
|
|
|
} |
14484
|
|
|
|
|
|
|
#define rbit32 rbit32 |
14485
|
|
|
|
|
|
|
#endif |
14486
|
|
|
|
|
|
|
|
14487
|
|
|
|
|
|
|
#endif |
14488
|
|
|
|
|
|
|
|
14489
|
|
|
|
|
|
|
|
14490
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
14491
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
14492
|
|
|
|
|
|
|
|
14493
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
14494
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
14495
|
|
|
|
|
|
|
|
14496
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
14497
|
|
|
|
|
|
|
size_t alignment, size_t size); |
14498
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
14499
|
|
|
|
|
|
|
|
14500
|
|
|
|
|
|
|
#ifdef FREESTANDING |
14501
|
|
|
|
|
|
|
|
14502
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
14503
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
14504
|
|
|
|
|
|
|
|
14505
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
14506
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
14507
|
|
|
|
|
|
|
|
14508
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
14509
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
14510
|
|
|
|
|
|
|
|
14511
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
14512
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
14513
|
|
|
|
|
|
|
|
14514
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
14515
|
|
|
|
|
|
|
#else |
14516
|
|
|
|
|
|
|
#include |
14517
|
|
|
|
|
|
|
#endif |
14518
|
|
|
|
|
|
|
|
14519
|
|
|
|
|
|
|
|
14520
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
14521
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
14522
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
14523
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
14524
|
|
|
|
|
|
|
#else |
14525
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
14526
|
|
|
|
|
|
|
#endif |
14527
|
|
|
|
|
|
|
|
14528
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
14529
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
14530
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
14531
|
|
|
|
|
|
|
|
14532
|
|
|
|
|
|
|
#endif |
14533
|
|
|
|
|
|
|
|
14534
|
|
|
|
|
|
|
|
14535
|
|
|
|
|
|
|
#ifndef MATCHFINDER_WINDOW_ORDER |
14536
|
|
|
|
|
|
|
# error "MATCHFINDER_WINDOW_ORDER must be defined!" |
14537
|
|
|
|
|
|
|
#endif |
14538
|
|
|
|
|
|
|
|
14539
|
|
|
|
|
|
|
|
14540
|
|
|
|
|
|
|
static forceinline u32 |
14541
|
|
|
|
|
|
|
loaded_u32_to_u24(u32 v) |
14542
|
|
|
|
|
|
|
{ |
14543
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
14544
|
|
|
|
|
|
|
return v & 0xFFFFFF; |
14545
|
|
|
|
|
|
|
else |
14546
|
|
|
|
|
|
|
return v >> 8; |
14547
|
|
|
|
|
|
|
} |
14548
|
|
|
|
|
|
|
|
14549
|
|
|
|
|
|
|
|
14550
|
|
|
|
|
|
|
static forceinline u32 |
14551
|
|
|
|
|
|
|
load_u24_unaligned(const u8 *p) |
14552
|
|
|
|
|
|
|
{ |
14553
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
14554
|
|
|
|
|
|
|
return loaded_u32_to_u24(load_u32_unaligned(p)); |
14555
|
|
|
|
|
|
|
#else |
14556
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
14557
|
|
|
|
|
|
|
return ((u32)p[0] << 0) | ((u32)p[1] << 8) | ((u32)p[2] << 16); |
14558
|
|
|
|
|
|
|
else |
14559
|
|
|
|
|
|
|
return ((u32)p[2] << 0) | ((u32)p[1] << 8) | ((u32)p[0] << 16); |
14560
|
|
|
|
|
|
|
#endif |
14561
|
|
|
|
|
|
|
} |
14562
|
|
|
|
|
|
|
|
14563
|
|
|
|
|
|
|
#define MATCHFINDER_WINDOW_SIZE (1UL << MATCHFINDER_WINDOW_ORDER) |
14564
|
|
|
|
|
|
|
|
14565
|
|
|
|
|
|
|
typedef s16 mf_pos_t; |
14566
|
|
|
|
|
|
|
|
14567
|
|
|
|
|
|
|
#define MATCHFINDER_INITVAL ((mf_pos_t)-MATCHFINDER_WINDOW_SIZE) |
14568
|
|
|
|
|
|
|
|
14569
|
|
|
|
|
|
|
|
14570
|
|
|
|
|
|
|
#define MATCHFINDER_MEM_ALIGNMENT 32 |
14571
|
|
|
|
|
|
|
#define MATCHFINDER_SIZE_ALIGNMENT 128 |
14572
|
|
|
|
|
|
|
|
14573
|
|
|
|
|
|
|
#undef matchfinder_init |
14574
|
|
|
|
|
|
|
#undef matchfinder_rebase |
14575
|
|
|
|
|
|
|
#ifdef _aligned_attribute |
14576
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED _aligned_attribute(MATCHFINDER_MEM_ALIGNMENT) |
14577
|
|
|
|
|
|
|
# if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
14578
|
|
|
|
|
|
|
/* # include "arm/matchfinder_impl.h" */ |
14579
|
|
|
|
|
|
|
|
14580
|
|
|
|
|
|
|
|
14581
|
|
|
|
|
|
|
#ifndef LIB_ARM_MATCHFINDER_IMPL_H |
14582
|
|
|
|
|
|
|
#define LIB_ARM_MATCHFINDER_IMPL_H |
14583
|
|
|
|
|
|
|
|
14584
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
14585
|
|
|
|
|
|
|
|
14586
|
|
|
|
|
|
|
|
14587
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
14588
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
14589
|
|
|
|
|
|
|
|
14590
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
14591
|
|
|
|
|
|
|
|
14592
|
|
|
|
|
|
|
|
14593
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
14594
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
14595
|
|
|
|
|
|
|
|
14596
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
14597
|
|
|
|
|
|
|
|
14598
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
14599
|
|
|
|
|
|
|
#endif |
14600
|
|
|
|
|
|
|
|
14601
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
14602
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
14603
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
14604
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
14605
|
|
|
|
|
|
|
#else |
14606
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
14607
|
|
|
|
|
|
|
#endif |
14608
|
|
|
|
|
|
|
|
14609
|
|
|
|
|
|
|
|
14610
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
14611
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
14612
|
|
|
|
|
|
|
#else |
14613
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
14614
|
|
|
|
|
|
|
#endif |
14615
|
|
|
|
|
|
|
|
14616
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
14617
|
|
|
|
|
|
|
|
14618
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
14619
|
|
|
|
|
|
|
|
14620
|
|
|
|
|
|
|
|
14621
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
14622
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
14623
|
|
|
|
|
|
|
|
14624
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
14625
|
|
|
|
|
|
|
|
14626
|
|
|
|
|
|
|
|
14627
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
14628
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
14629
|
|
|
|
|
|
|
|
14630
|
|
|
|
|
|
|
#include |
14631
|
|
|
|
|
|
|
#include |
14632
|
|
|
|
|
|
|
|
14633
|
|
|
|
|
|
|
#ifdef __cplusplus |
14634
|
|
|
|
|
|
|
extern "C" { |
14635
|
|
|
|
|
|
|
#endif |
14636
|
|
|
|
|
|
|
|
14637
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
14638
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
14639
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
14640
|
|
|
|
|
|
|
|
14641
|
|
|
|
|
|
|
|
14642
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
14643
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
14644
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
14645
|
|
|
|
|
|
|
# else |
14646
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
14647
|
|
|
|
|
|
|
# endif |
14648
|
|
|
|
|
|
|
#endif |
14649
|
|
|
|
|
|
|
|
14650
|
|
|
|
|
|
|
|
14651
|
|
|
|
|
|
|
|
14652
|
|
|
|
|
|
|
|
14653
|
|
|
|
|
|
|
|
14654
|
|
|
|
|
|
|
struct libdeflate_compressor; |
14655
|
|
|
|
|
|
|
struct libdeflate_options; |
14656
|
|
|
|
|
|
|
|
14657
|
|
|
|
|
|
|
|
14658
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
14659
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
14660
|
|
|
|
|
|
|
|
14661
|
|
|
|
|
|
|
|
14662
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
14663
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
14664
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
14665
|
|
|
|
|
|
|
|
14666
|
|
|
|
|
|
|
|
14667
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14668
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
14669
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14670
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
14671
|
|
|
|
|
|
|
|
14672
|
|
|
|
|
|
|
|
14673
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14674
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
14675
|
|
|
|
|
|
|
size_t in_nbytes); |
14676
|
|
|
|
|
|
|
|
14677
|
|
|
|
|
|
|
|
14678
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14679
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
14680
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14681
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
14682
|
|
|
|
|
|
|
|
14683
|
|
|
|
|
|
|
|
14684
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14685
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
14686
|
|
|
|
|
|
|
size_t in_nbytes); |
14687
|
|
|
|
|
|
|
|
14688
|
|
|
|
|
|
|
|
14689
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14690
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
14691
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14692
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
14693
|
|
|
|
|
|
|
|
14694
|
|
|
|
|
|
|
|
14695
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14696
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
14697
|
|
|
|
|
|
|
size_t in_nbytes); |
14698
|
|
|
|
|
|
|
|
14699
|
|
|
|
|
|
|
|
14700
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
14701
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
14702
|
|
|
|
|
|
|
|
14703
|
|
|
|
|
|
|
|
14704
|
|
|
|
|
|
|
|
14705
|
|
|
|
|
|
|
|
14706
|
|
|
|
|
|
|
|
14707
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
14708
|
|
|
|
|
|
|
struct libdeflate_options; |
14709
|
|
|
|
|
|
|
|
14710
|
|
|
|
|
|
|
|
14711
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
14712
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
14713
|
|
|
|
|
|
|
|
14714
|
|
|
|
|
|
|
|
14715
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
14716
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
14717
|
|
|
|
|
|
|
|
14718
|
|
|
|
|
|
|
|
14719
|
|
|
|
|
|
|
enum libdeflate_result { |
14720
|
|
|
|
|
|
|
|
14721
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
14722
|
|
|
|
|
|
|
|
14723
|
|
|
|
|
|
|
|
14724
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
14725
|
|
|
|
|
|
|
|
14726
|
|
|
|
|
|
|
|
14727
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
14728
|
|
|
|
|
|
|
|
14729
|
|
|
|
|
|
|
|
14730
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
14731
|
|
|
|
|
|
|
}; |
14732
|
|
|
|
|
|
|
|
14733
|
|
|
|
|
|
|
|
14734
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14735
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
14736
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14737
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14738
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14739
|
|
|
|
|
|
|
|
14740
|
|
|
|
|
|
|
|
14741
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14742
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
14743
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14744
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14745
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
14746
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14747
|
|
|
|
|
|
|
|
14748
|
|
|
|
|
|
|
|
14749
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14750
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
14751
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14752
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14753
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14754
|
|
|
|
|
|
|
|
14755
|
|
|
|
|
|
|
|
14756
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14757
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
14758
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14759
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14760
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
14761
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14762
|
|
|
|
|
|
|
|
14763
|
|
|
|
|
|
|
|
14764
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14765
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
14766
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14767
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14768
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14769
|
|
|
|
|
|
|
|
14770
|
|
|
|
|
|
|
|
14771
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14772
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
14773
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14774
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14775
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
14776
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14777
|
|
|
|
|
|
|
|
14778
|
|
|
|
|
|
|
|
14779
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
14780
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
14781
|
|
|
|
|
|
|
|
14782
|
|
|
|
|
|
|
|
14783
|
|
|
|
|
|
|
|
14784
|
|
|
|
|
|
|
|
14785
|
|
|
|
|
|
|
|
14786
|
|
|
|
|
|
|
|
14787
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
14788
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
14789
|
|
|
|
|
|
|
|
14790
|
|
|
|
|
|
|
|
14791
|
|
|
|
|
|
|
|
14792
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
14793
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
14794
|
|
|
|
|
|
|
|
14795
|
|
|
|
|
|
|
|
14796
|
|
|
|
|
|
|
|
14797
|
|
|
|
|
|
|
|
14798
|
|
|
|
|
|
|
|
14799
|
|
|
|
|
|
|
|
14800
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
14801
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
14802
|
|
|
|
|
|
|
void (*free_func)(void *)); |
14803
|
|
|
|
|
|
|
|
14804
|
|
|
|
|
|
|
|
14805
|
|
|
|
|
|
|
struct libdeflate_options { |
14806
|
|
|
|
|
|
|
|
14807
|
|
|
|
|
|
|
|
14808
|
|
|
|
|
|
|
size_t sizeof_options; |
14809
|
|
|
|
|
|
|
|
14810
|
|
|
|
|
|
|
|
14811
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
14812
|
|
|
|
|
|
|
void (*free_func)(void *); |
14813
|
|
|
|
|
|
|
}; |
14814
|
|
|
|
|
|
|
|
14815
|
|
|
|
|
|
|
#ifdef __cplusplus |
14816
|
|
|
|
|
|
|
} |
14817
|
|
|
|
|
|
|
#endif |
14818
|
|
|
|
|
|
|
|
14819
|
|
|
|
|
|
|
#endif |
14820
|
|
|
|
|
|
|
|
14821
|
|
|
|
|
|
|
|
14822
|
|
|
|
|
|
|
#include |
14823
|
|
|
|
|
|
|
#include |
14824
|
|
|
|
|
|
|
#include |
14825
|
|
|
|
|
|
|
#ifdef _MSC_VER |
14826
|
|
|
|
|
|
|
# include |
14827
|
|
|
|
|
|
|
# include |
14828
|
|
|
|
|
|
|
|
14829
|
|
|
|
|
|
|
|
14830
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
14831
|
|
|
|
|
|
|
|
14832
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
14833
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
14834
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
14835
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
14836
|
|
|
|
|
|
|
|
14837
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
14838
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
14839
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
14840
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
14841
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
14842
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
14843
|
|
|
|
|
|
|
#endif |
14844
|
|
|
|
|
|
|
#ifndef FREESTANDING |
14845
|
|
|
|
|
|
|
# include |
14846
|
|
|
|
|
|
|
#endif |
14847
|
|
|
|
|
|
|
|
14848
|
|
|
|
|
|
|
|
14849
|
|
|
|
|
|
|
|
14850
|
|
|
|
|
|
|
|
14851
|
|
|
|
|
|
|
|
14852
|
|
|
|
|
|
|
|
14853
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
14854
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
14855
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
14856
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
14857
|
|
|
|
|
|
|
#ifdef _MSC_VER |
14858
|
|
|
|
|
|
|
# if defined(_M_X64) |
14859
|
|
|
|
|
|
|
# define ARCH_X86_64 |
14860
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
14861
|
|
|
|
|
|
|
# define ARCH_X86_32 |
14862
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
14863
|
|
|
|
|
|
|
# define ARCH_ARM64 |
14864
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
14865
|
|
|
|
|
|
|
# define ARCH_ARM32 |
14866
|
|
|
|
|
|
|
# endif |
14867
|
|
|
|
|
|
|
#else |
14868
|
|
|
|
|
|
|
# if defined(__x86_64__) |
14869
|
|
|
|
|
|
|
# define ARCH_X86_64 |
14870
|
|
|
|
|
|
|
# elif defined(__i386__) |
14871
|
|
|
|
|
|
|
# define ARCH_X86_32 |
14872
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
14873
|
|
|
|
|
|
|
# define ARCH_ARM64 |
14874
|
|
|
|
|
|
|
# elif defined(__arm__) |
14875
|
|
|
|
|
|
|
# define ARCH_ARM32 |
14876
|
|
|
|
|
|
|
# endif |
14877
|
|
|
|
|
|
|
#endif |
14878
|
|
|
|
|
|
|
|
14879
|
|
|
|
|
|
|
|
14880
|
|
|
|
|
|
|
|
14881
|
|
|
|
|
|
|
|
14882
|
|
|
|
|
|
|
|
14883
|
|
|
|
|
|
|
|
14884
|
|
|
|
|
|
|
typedef uint8_t u8; |
14885
|
|
|
|
|
|
|
typedef uint16_t u16; |
14886
|
|
|
|
|
|
|
typedef uint32_t u32; |
14887
|
|
|
|
|
|
|
typedef uint64_t u64; |
14888
|
|
|
|
|
|
|
typedef int8_t s8; |
14889
|
|
|
|
|
|
|
typedef int16_t s16; |
14890
|
|
|
|
|
|
|
typedef int32_t s32; |
14891
|
|
|
|
|
|
|
typedef int64_t s64; |
14892
|
|
|
|
|
|
|
|
14893
|
|
|
|
|
|
|
|
14894
|
|
|
|
|
|
|
#ifdef _MSC_VER |
14895
|
|
|
|
|
|
|
# ifdef _WIN64 |
14896
|
|
|
|
|
|
|
typedef long long ssize_t; |
14897
|
|
|
|
|
|
|
# else |
14898
|
|
|
|
|
|
|
typedef long ssize_t; |
14899
|
|
|
|
|
|
|
# endif |
14900
|
|
|
|
|
|
|
#endif |
14901
|
|
|
|
|
|
|
|
14902
|
|
|
|
|
|
|
|
14903
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
14904
|
|
|
|
|
|
|
|
14905
|
|
|
|
|
|
|
|
14906
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
14907
|
|
|
|
|
|
|
|
14908
|
|
|
|
|
|
|
|
14909
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
14910
|
|
|
|
|
|
|
|
14911
|
|
|
|
|
|
|
|
14912
|
|
|
|
|
|
|
|
14913
|
|
|
|
|
|
|
|
14914
|
|
|
|
|
|
|
|
14915
|
|
|
|
|
|
|
|
14916
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
14917
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
14918
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
14919
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
14920
|
|
|
|
|
|
|
#else |
14921
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
14922
|
|
|
|
|
|
|
#endif |
14923
|
|
|
|
|
|
|
#ifdef __clang__ |
14924
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
14925
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
14926
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
14927
|
|
|
|
|
|
|
# else |
14928
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
14929
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
14930
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
14931
|
|
|
|
|
|
|
# endif |
14932
|
|
|
|
|
|
|
#else |
14933
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
14934
|
|
|
|
|
|
|
#endif |
14935
|
|
|
|
|
|
|
|
14936
|
|
|
|
|
|
|
|
14937
|
|
|
|
|
|
|
#ifndef __has_attribute |
14938
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
14939
|
|
|
|
|
|
|
#endif |
14940
|
|
|
|
|
|
|
#ifndef __has_builtin |
14941
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
14942
|
|
|
|
|
|
|
#endif |
14943
|
|
|
|
|
|
|
|
14944
|
|
|
|
|
|
|
|
14945
|
|
|
|
|
|
|
#ifdef _MSC_VER |
14946
|
|
|
|
|
|
|
# define inline __inline |
14947
|
|
|
|
|
|
|
#endif |
14948
|
|
|
|
|
|
|
|
14949
|
|
|
|
|
|
|
|
14950
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
14951
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
14952
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14953
|
|
|
|
|
|
|
# define forceinline __forceinline |
14954
|
|
|
|
|
|
|
#else |
14955
|
|
|
|
|
|
|
# define forceinline inline |
14956
|
|
|
|
|
|
|
#endif |
14957
|
|
|
|
|
|
|
|
14958
|
|
|
|
|
|
|
|
14959
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
14960
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
14961
|
|
|
|
|
|
|
#else |
14962
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
14963
|
|
|
|
|
|
|
#endif |
14964
|
|
|
|
|
|
|
|
14965
|
|
|
|
|
|
|
|
14966
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
14967
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
14968
|
|
|
|
|
|
|
# define restrict __restrict__ |
14969
|
|
|
|
|
|
|
# else |
14970
|
|
|
|
|
|
|
# define restrict |
14971
|
|
|
|
|
|
|
# endif |
14972
|
|
|
|
|
|
|
#endif |
14973
|
|
|
|
|
|
|
|
14974
|
|
|
|
|
|
|
|
14975
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
14976
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
14977
|
|
|
|
|
|
|
#else |
14978
|
|
|
|
|
|
|
# define likely(expr) (expr) |
14979
|
|
|
|
|
|
|
#endif |
14980
|
|
|
|
|
|
|
|
14981
|
|
|
|
|
|
|
|
14982
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
14983
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
14984
|
|
|
|
|
|
|
#else |
14985
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
14986
|
|
|
|
|
|
|
#endif |
14987
|
|
|
|
|
|
|
|
14988
|
|
|
|
|
|
|
|
14989
|
|
|
|
|
|
|
#undef prefetchr |
14990
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
14991
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
14992
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14993
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
14994
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
14995
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
14996
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
14997
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
14998
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
14999
|
|
|
|
|
|
|
# endif |
15000
|
|
|
|
|
|
|
#endif |
15001
|
|
|
|
|
|
|
#ifndef prefetchr |
15002
|
|
|
|
|
|
|
# define prefetchr(addr) |
15003
|
|
|
|
|
|
|
#endif |
15004
|
|
|
|
|
|
|
|
15005
|
|
|
|
|
|
|
|
15006
|
|
|
|
|
|
|
#undef prefetchw |
15007
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
15008
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
15009
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15010
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
15011
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
15012
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
15013
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
15014
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
15015
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
15016
|
|
|
|
|
|
|
# endif |
15017
|
|
|
|
|
|
|
#endif |
15018
|
|
|
|
|
|
|
#ifndef prefetchw |
15019
|
|
|
|
|
|
|
# define prefetchw(addr) |
15020
|
|
|
|
|
|
|
#endif |
15021
|
|
|
|
|
|
|
|
15022
|
|
|
|
|
|
|
|
15023
|
|
|
|
|
|
|
#undef _aligned_attribute |
15024
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
15025
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
15026
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15027
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
15028
|
|
|
|
|
|
|
#endif |
15029
|
|
|
|
|
|
|
|
15030
|
|
|
|
|
|
|
|
15031
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
15032
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
15033
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
15034
|
|
|
|
|
|
|
#else |
15035
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
15036
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
15037
|
|
|
|
|
|
|
#endif |
15038
|
|
|
|
|
|
|
|
15039
|
|
|
|
|
|
|
|
15040
|
|
|
|
|
|
|
|
15041
|
|
|
|
|
|
|
|
15042
|
|
|
|
|
|
|
|
15043
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
15044
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
15045
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
15046
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
15047
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
15048
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
15049
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
15050
|
|
|
|
|
|
|
|
15051
|
|
|
|
|
|
|
|
15052
|
|
|
|
|
|
|
|
15053
|
|
|
|
|
|
|
|
15054
|
|
|
|
|
|
|
|
15055
|
|
|
|
|
|
|
|
15056
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
15057
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
15058
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15059
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
15060
|
|
|
|
|
|
|
#else |
15061
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
15062
|
|
|
|
|
|
|
{ |
15063
|
|
|
|
|
|
|
union { |
15064
|
|
|
|
|
|
|
u32 w; |
15065
|
|
|
|
|
|
|
u8 b; |
15066
|
|
|
|
|
|
|
} u; |
15067
|
|
|
|
|
|
|
|
15068
|
|
|
|
|
|
|
u.w = 1; |
15069
|
|
|
|
|
|
|
return u.b; |
15070
|
|
|
|
|
|
|
} |
15071
|
|
|
|
|
|
|
#endif |
15072
|
|
|
|
|
|
|
|
15073
|
|
|
|
|
|
|
|
15074
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
15075
|
|
|
|
|
|
|
{ |
15076
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
15077
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
15078
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15079
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
15080
|
|
|
|
|
|
|
#else |
15081
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
15082
|
|
|
|
|
|
|
#endif |
15083
|
|
|
|
|
|
|
} |
15084
|
|
|
|
|
|
|
|
15085
|
|
|
|
|
|
|
|
15086
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
15087
|
|
|
|
|
|
|
{ |
15088
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
15089
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
15090
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15091
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
15092
|
|
|
|
|
|
|
#else |
15093
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
15094
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
15095
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
15096
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
15097
|
|
|
|
|
|
|
#endif |
15098
|
|
|
|
|
|
|
} |
15099
|
|
|
|
|
|
|
|
15100
|
|
|
|
|
|
|
|
15101
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
15102
|
|
|
|
|
|
|
{ |
15103
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
15104
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
15105
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15106
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
15107
|
|
|
|
|
|
|
#else |
15108
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
15109
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
15110
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
15111
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
15112
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
15113
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
15114
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
15115
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
15116
|
|
|
|
|
|
|
#endif |
15117
|
|
|
|
|
|
|
} |
15118
|
|
|
|
|
|
|
|
15119
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
15120
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
15121
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
15122
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
15123
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
15124
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
15125
|
|
|
|
|
|
|
|
15126
|
|
|
|
|
|
|
|
15127
|
|
|
|
|
|
|
|
15128
|
|
|
|
|
|
|
|
15129
|
|
|
|
|
|
|
|
15130
|
|
|
|
|
|
|
|
15131
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
15132
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
15133
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
15134
|
|
|
|
|
|
|
defined(__wasm__)) |
15135
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
15136
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15137
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
15138
|
|
|
|
|
|
|
#else |
15139
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
15140
|
|
|
|
|
|
|
#endif |
15141
|
|
|
|
|
|
|
|
15142
|
|
|
|
|
|
|
|
15143
|
|
|
|
|
|
|
|
15144
|
|
|
|
|
|
|
#ifdef FREESTANDING |
15145
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
15146
|
|
|
|
|
|
|
#else |
15147
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
15148
|
|
|
|
|
|
|
#endif |
15149
|
|
|
|
|
|
|
|
15150
|
|
|
|
|
|
|
|
15151
|
|
|
|
|
|
|
|
15152
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
15153
|
|
|
|
|
|
|
static forceinline type \ |
15154
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
15155
|
|
|
|
|
|
|
{ \ |
15156
|
|
|
|
|
|
|
type v; \ |
15157
|
|
|
|
|
|
|
\ |
15158
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
15159
|
|
|
|
|
|
|
return v; \ |
15160
|
|
|
|
|
|
|
} \ |
15161
|
|
|
|
|
|
|
\ |
15162
|
|
|
|
|
|
|
static forceinline void \ |
15163
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
15164
|
|
|
|
|
|
|
{ \ |
15165
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
15166
|
|
|
|
|
|
|
} |
15167
|
|
|
|
|
|
|
|
15168
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
15169
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
15170
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
15171
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
15172
|
|
|
|
|
|
|
|
15173
|
|
|
|
|
|
|
#undef MEMCOPY |
15174
|
|
|
|
|
|
|
|
15175
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
15176
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
15177
|
|
|
|
|
|
|
|
15178
|
|
|
|
|
|
|
|
15179
|
|
|
|
|
|
|
|
15180
|
|
|
|
|
|
|
static forceinline u16 |
15181
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
15182
|
|
|
|
|
|
|
{ |
15183
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
15184
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
15185
|
|
|
|
|
|
|
else |
15186
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
15187
|
|
|
|
|
|
|
} |
15188
|
|
|
|
|
|
|
|
15189
|
|
|
|
|
|
|
static forceinline u16 |
15190
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
15191
|
|
|
|
|
|
|
{ |
15192
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
15193
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
15194
|
|
|
|
|
|
|
else |
15195
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
15196
|
|
|
|
|
|
|
} |
15197
|
|
|
|
|
|
|
|
15198
|
|
|
|
|
|
|
static forceinline u32 |
15199
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
15200
|
|
|
|
|
|
|
{ |
15201
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
15202
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
15203
|
|
|
|
|
|
|
else |
15204
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
15205
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
15206
|
|
|
|
|
|
|
} |
15207
|
|
|
|
|
|
|
|
15208
|
|
|
|
|
|
|
static forceinline u32 |
15209
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
15210
|
|
|
|
|
|
|
{ |
15211
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
15212
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
15213
|
|
|
|
|
|
|
else |
15214
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
15215
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
15216
|
|
|
|
|
|
|
} |
15217
|
|
|
|
|
|
|
|
15218
|
|
|
|
|
|
|
static forceinline u64 |
15219
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
15220
|
|
|
|
|
|
|
{ |
15221
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
15222
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
15223
|
|
|
|
|
|
|
else |
15224
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
15225
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
15226
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
15227
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
15228
|
|
|
|
|
|
|
} |
15229
|
|
|
|
|
|
|
|
15230
|
|
|
|
|
|
|
static forceinline machine_word_t |
15231
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
15232
|
|
|
|
|
|
|
{ |
15233
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
15234
|
|
|
|
|
|
|
if (WORDBITS == 32) |
15235
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
15236
|
|
|
|
|
|
|
else |
15237
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
15238
|
|
|
|
|
|
|
} |
15239
|
|
|
|
|
|
|
|
15240
|
|
|
|
|
|
|
|
15241
|
|
|
|
|
|
|
|
15242
|
|
|
|
|
|
|
static forceinline void |
15243
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
15244
|
|
|
|
|
|
|
{ |
15245
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
15246
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
15247
|
|
|
|
|
|
|
} else { |
15248
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
15249
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
15250
|
|
|
|
|
|
|
} |
15251
|
|
|
|
|
|
|
} |
15252
|
|
|
|
|
|
|
|
15253
|
|
|
|
|
|
|
static forceinline void |
15254
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
15255
|
|
|
|
|
|
|
{ |
15256
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
15257
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
15258
|
|
|
|
|
|
|
} else { |
15259
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
15260
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
15261
|
|
|
|
|
|
|
} |
15262
|
|
|
|
|
|
|
} |
15263
|
|
|
|
|
|
|
|
15264
|
|
|
|
|
|
|
static forceinline void |
15265
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
15266
|
|
|
|
|
|
|
{ |
15267
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
15268
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
15269
|
|
|
|
|
|
|
} else { |
15270
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
15271
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
15272
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
15273
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
15274
|
|
|
|
|
|
|
} |
15275
|
|
|
|
|
|
|
} |
15276
|
|
|
|
|
|
|
|
15277
|
|
|
|
|
|
|
static forceinline void |
15278
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
15279
|
|
|
|
|
|
|
{ |
15280
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
15281
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
15282
|
|
|
|
|
|
|
} else { |
15283
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
15284
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
15285
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
15286
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
15287
|
|
|
|
|
|
|
} |
15288
|
|
|
|
|
|
|
} |
15289
|
|
|
|
|
|
|
|
15290
|
|
|
|
|
|
|
static forceinline void |
15291
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
15292
|
|
|
|
|
|
|
{ |
15293
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
15294
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
15295
|
|
|
|
|
|
|
} else { |
15296
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
15297
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
15298
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
15299
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
15300
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
15301
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
15302
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
15303
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
15304
|
|
|
|
|
|
|
} |
15305
|
|
|
|
|
|
|
} |
15306
|
|
|
|
|
|
|
|
15307
|
|
|
|
|
|
|
static forceinline void |
15308
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
15309
|
|
|
|
|
|
|
{ |
15310
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
15311
|
|
|
|
|
|
|
if (WORDBITS == 32) |
15312
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
15313
|
|
|
|
|
|
|
else |
15314
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
15315
|
|
|
|
|
|
|
} |
15316
|
|
|
|
|
|
|
|
15317
|
|
|
|
|
|
|
|
15318
|
|
|
|
|
|
|
|
15319
|
|
|
|
|
|
|
|
15320
|
|
|
|
|
|
|
|
15321
|
|
|
|
|
|
|
|
15322
|
|
|
|
|
|
|
|
15323
|
|
|
|
|
|
|
static forceinline unsigned |
15324
|
|
|
|
|
|
|
bsr32(u32 v) |
15325
|
|
|
|
|
|
|
{ |
15326
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
15327
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
15328
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15329
|
|
|
|
|
|
|
unsigned long i; |
15330
|
|
|
|
|
|
|
|
15331
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
15332
|
|
|
|
|
|
|
return i; |
15333
|
|
|
|
|
|
|
#else |
15334
|
|
|
|
|
|
|
unsigned i = 0; |
15335
|
|
|
|
|
|
|
|
15336
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
15337
|
|
|
|
|
|
|
i++; |
15338
|
|
|
|
|
|
|
return i; |
15339
|
|
|
|
|
|
|
#endif |
15340
|
|
|
|
|
|
|
} |
15341
|
|
|
|
|
|
|
|
15342
|
|
|
|
|
|
|
static forceinline unsigned |
15343
|
|
|
|
|
|
|
bsr64(u64 v) |
15344
|
|
|
|
|
|
|
{ |
15345
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
15346
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
15347
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
15348
|
|
|
|
|
|
|
unsigned long i; |
15349
|
|
|
|
|
|
|
|
15350
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
15351
|
|
|
|
|
|
|
return i; |
15352
|
|
|
|
|
|
|
#else |
15353
|
|
|
|
|
|
|
unsigned i = 0; |
15354
|
|
|
|
|
|
|
|
15355
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
15356
|
|
|
|
|
|
|
i++; |
15357
|
|
|
|
|
|
|
return i; |
15358
|
|
|
|
|
|
|
#endif |
15359
|
|
|
|
|
|
|
} |
15360
|
|
|
|
|
|
|
|
15361
|
|
|
|
|
|
|
static forceinline unsigned |
15362
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
15363
|
|
|
|
|
|
|
{ |
15364
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
15365
|
|
|
|
|
|
|
if (WORDBITS == 32) |
15366
|
|
|
|
|
|
|
return bsr32(v); |
15367
|
|
|
|
|
|
|
else |
15368
|
|
|
|
|
|
|
return bsr64(v); |
15369
|
|
|
|
|
|
|
} |
15370
|
|
|
|
|
|
|
|
15371
|
|
|
|
|
|
|
|
15372
|
|
|
|
|
|
|
|
15373
|
|
|
|
|
|
|
static forceinline unsigned |
15374
|
|
|
|
|
|
|
bsf32(u32 v) |
15375
|
|
|
|
|
|
|
{ |
15376
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
15377
|
|
|
|
|
|
|
return __builtin_ctz(v); |
15378
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15379
|
|
|
|
|
|
|
unsigned long i; |
15380
|
|
|
|
|
|
|
|
15381
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
15382
|
|
|
|
|
|
|
return i; |
15383
|
|
|
|
|
|
|
#else |
15384
|
|
|
|
|
|
|
unsigned i = 0; |
15385
|
|
|
|
|
|
|
|
15386
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
15387
|
|
|
|
|
|
|
i++; |
15388
|
|
|
|
|
|
|
return i; |
15389
|
|
|
|
|
|
|
#endif |
15390
|
|
|
|
|
|
|
} |
15391
|
|
|
|
|
|
|
|
15392
|
|
|
|
|
|
|
static forceinline unsigned |
15393
|
|
|
|
|
|
|
bsf64(u64 v) |
15394
|
|
|
|
|
|
|
{ |
15395
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
15396
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
15397
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
15398
|
|
|
|
|
|
|
unsigned long i; |
15399
|
|
|
|
|
|
|
|
15400
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
15401
|
|
|
|
|
|
|
return i; |
15402
|
|
|
|
|
|
|
#else |
15403
|
|
|
|
|
|
|
unsigned i = 0; |
15404
|
|
|
|
|
|
|
|
15405
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
15406
|
|
|
|
|
|
|
i++; |
15407
|
|
|
|
|
|
|
return i; |
15408
|
|
|
|
|
|
|
#endif |
15409
|
|
|
|
|
|
|
} |
15410
|
|
|
|
|
|
|
|
15411
|
|
|
|
|
|
|
static forceinline unsigned |
15412
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
15413
|
|
|
|
|
|
|
{ |
15414
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
15415
|
|
|
|
|
|
|
if (WORDBITS == 32) |
15416
|
|
|
|
|
|
|
return bsf32(v); |
15417
|
|
|
|
|
|
|
else |
15418
|
|
|
|
|
|
|
return bsf64(v); |
15419
|
|
|
|
|
|
|
} |
15420
|
|
|
|
|
|
|
|
15421
|
|
|
|
|
|
|
|
15422
|
|
|
|
|
|
|
#undef rbit32 |
15423
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
15424
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
15425
|
|
|
|
|
|
|
static forceinline u32 |
15426
|
|
|
|
|
|
|
rbit32(u32 v) |
15427
|
|
|
|
|
|
|
{ |
15428
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
15429
|
|
|
|
|
|
|
return v; |
15430
|
|
|
|
|
|
|
} |
15431
|
|
|
|
|
|
|
#define rbit32 rbit32 |
15432
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
15433
|
|
|
|
|
|
|
static forceinline u32 |
15434
|
|
|
|
|
|
|
rbit32(u32 v) |
15435
|
|
|
|
|
|
|
{ |
15436
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
15437
|
|
|
|
|
|
|
return v; |
15438
|
|
|
|
|
|
|
} |
15439
|
|
|
|
|
|
|
#define rbit32 rbit32 |
15440
|
|
|
|
|
|
|
#endif |
15441
|
|
|
|
|
|
|
|
15442
|
|
|
|
|
|
|
#endif |
15443
|
|
|
|
|
|
|
|
15444
|
|
|
|
|
|
|
|
15445
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
15446
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
15447
|
|
|
|
|
|
|
|
15448
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
15449
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
15450
|
|
|
|
|
|
|
|
15451
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
15452
|
|
|
|
|
|
|
size_t alignment, size_t size); |
15453
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
15454
|
|
|
|
|
|
|
|
15455
|
|
|
|
|
|
|
#ifdef FREESTANDING |
15456
|
|
|
|
|
|
|
|
15457
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
15458
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
15459
|
|
|
|
|
|
|
|
15460
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
15461
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
15462
|
|
|
|
|
|
|
|
15463
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
15464
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
15465
|
|
|
|
|
|
|
|
15466
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
15467
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
15468
|
|
|
|
|
|
|
|
15469
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
15470
|
|
|
|
|
|
|
#else |
15471
|
|
|
|
|
|
|
#include |
15472
|
|
|
|
|
|
|
#endif |
15473
|
|
|
|
|
|
|
|
15474
|
|
|
|
|
|
|
|
15475
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
15476
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
15477
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
15478
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
15479
|
|
|
|
|
|
|
#else |
15480
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
15481
|
|
|
|
|
|
|
#endif |
15482
|
|
|
|
|
|
|
|
15483
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
15484
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
15485
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
15486
|
|
|
|
|
|
|
|
15487
|
|
|
|
|
|
|
#endif |
15488
|
|
|
|
|
|
|
|
15489
|
|
|
|
|
|
|
|
15490
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
15491
|
|
|
|
|
|
|
|
15492
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
15493
|
|
|
|
|
|
|
|
15494
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
15495
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
15496
|
|
|
|
|
|
|
(defined(__linux__) || \ |
15497
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
15498
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
15499
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
15500
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
15501
|
|
|
|
|
|
|
#endif |
15502
|
|
|
|
|
|
|
|
15503
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
15504
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
15505
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
15506
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
15507
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
15508
|
|
|
|
|
|
|
|
15509
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
15510
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
15511
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
15512
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
15513
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
15514
|
|
|
|
|
|
|
|
15515
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
15516
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
15517
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
15518
|
|
|
|
|
|
|
|
15519
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
15520
|
|
|
|
|
|
|
|
15521
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
15522
|
|
|
|
|
|
|
{ |
15523
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
15524
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
15525
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
15526
|
|
|
|
|
|
|
} |
15527
|
|
|
|
|
|
|
#else |
15528
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
15529
|
|
|
|
|
|
|
#endif |
15530
|
|
|
|
|
|
|
|
15531
|
|
|
|
|
|
|
|
15532
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
15533
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
15534
|
|
|
|
|
|
|
#else |
15535
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
15536
|
|
|
|
|
|
|
#endif |
15537
|
|
|
|
|
|
|
|
15538
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
15539
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
15540
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
15541
|
|
|
|
|
|
|
#else |
15542
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
15543
|
|
|
|
|
|
|
#endif |
15544
|
|
|
|
|
|
|
|
15545
|
|
|
|
|
|
|
|
15546
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
15547
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
15548
|
|
|
|
|
|
|
#else |
15549
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
15550
|
|
|
|
|
|
|
#endif |
15551
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
15552
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
15553
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
15554
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
15555
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
15556
|
|
|
|
|
|
|
\ |
15557
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
15558
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
15559
|
|
|
|
|
|
|
|
15560
|
|
|
|
|
|
|
# ifdef _MSC_VER |
15561
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
15562
|
|
|
|
|
|
|
# else |
15563
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
15564
|
|
|
|
|
|
|
# endif |
15565
|
|
|
|
|
|
|
#else |
15566
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
15567
|
|
|
|
|
|
|
#endif |
15568
|
|
|
|
|
|
|
|
15569
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
15570
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
15571
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
15572
|
|
|
|
|
|
|
#else |
15573
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
15574
|
|
|
|
|
|
|
#endif |
15575
|
|
|
|
|
|
|
|
15576
|
|
|
|
|
|
|
|
15577
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
15578
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
15579
|
|
|
|
|
|
|
#else |
15580
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
15581
|
|
|
|
|
|
|
#endif |
15582
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
15583
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
15584
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
15585
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
15586
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
15587
|
|
|
|
|
|
|
|
15588
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
15589
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
15590
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
15591
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
15592
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
15593
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
15594
|
|
|
|
|
|
|
# endif |
15595
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
15596
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
15597
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
15598
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
15599
|
|
|
|
|
|
|
# endif |
15600
|
|
|
|
|
|
|
#endif |
15601
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
15602
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
15603
|
|
|
|
|
|
|
#endif |
15604
|
|
|
|
|
|
|
|
15605
|
|
|
|
|
|
|
|
15606
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
15607
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
15608
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
15609
|
|
|
|
|
|
|
# else |
15610
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
15611
|
|
|
|
|
|
|
# endif |
15612
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
15613
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
15614
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
15615
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
15616
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
15617
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
15618
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
15619
|
|
|
|
|
|
|
#else |
15620
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
15621
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
15622
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
15623
|
|
|
|
|
|
|
#endif |
15624
|
|
|
|
|
|
|
|
15625
|
|
|
|
|
|
|
|
15626
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
15627
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
15628
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
15629
|
|
|
|
|
|
|
# else |
15630
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
15631
|
|
|
|
|
|
|
# endif |
15632
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
15633
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
15634
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
15635
|
|
|
|
|
|
|
defined(_MSC_VER))) |
15636
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
15637
|
|
|
|
|
|
|
# else |
15638
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
15639
|
|
|
|
|
|
|
# endif |
15640
|
|
|
|
|
|
|
#else |
15641
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
15642
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
15643
|
|
|
|
|
|
|
#endif |
15644
|
|
|
|
|
|
|
|
15645
|
|
|
|
|
|
|
|
15646
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
15647
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
15648
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
15649
|
|
|
|
|
|
|
#endif |
15650
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
15651
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
15652
|
|
|
|
|
|
|
#endif |
15653
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
15654
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
15655
|
|
|
|
|
|
|
#endif |
15656
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
15657
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
15658
|
|
|
|
|
|
|
# include |
15659
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
15660
|
|
|
|
|
|
|
#endif |
15661
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
15662
|
|
|
|
|
|
|
# include |
15663
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
15664
|
|
|
|
|
|
|
#endif |
15665
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
15666
|
|
|
|
|
|
|
# include |
15667
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
15668
|
|
|
|
|
|
|
#endif |
15669
|
|
|
|
|
|
|
|
15670
|
|
|
|
|
|
|
#endif |
15671
|
|
|
|
|
|
|
|
15672
|
|
|
|
|
|
|
#endif |
15673
|
|
|
|
|
|
|
|
15674
|
|
|
|
|
|
|
|
15675
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE |
15676
|
|
|
|
|
|
|
# include |
15677
|
|
|
|
|
|
|
static forceinline void |
15678
|
|
|
|
|
|
|
matchfinder_init_neon(mf_pos_t *data, size_t size) |
15679
|
|
|
|
|
|
|
{ |
15680
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
15681
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16(MATCHFINDER_INITVAL); |
15682
|
|
|
|
|
|
|
|
15683
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
15684
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
15685
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
15686
|
|
|
|
|
|
|
|
15687
|
|
|
|
|
|
|
do { |
15688
|
|
|
|
|
|
|
p[0] = v; |
15689
|
|
|
|
|
|
|
p[1] = v; |
15690
|
|
|
|
|
|
|
p[2] = v; |
15691
|
|
|
|
|
|
|
p[3] = v; |
15692
|
|
|
|
|
|
|
p += 4; |
15693
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
15694
|
|
|
|
|
|
|
} while (size != 0); |
15695
|
|
|
|
|
|
|
} |
15696
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_neon |
15697
|
|
|
|
|
|
|
|
15698
|
|
|
|
|
|
|
static forceinline void |
15699
|
|
|
|
|
|
|
matchfinder_rebase_neon(mf_pos_t *data, size_t size) |
15700
|
|
|
|
|
|
|
{ |
15701
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
15702
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16((u16)-MATCHFINDER_WINDOW_SIZE); |
15703
|
|
|
|
|
|
|
|
15704
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
15705
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
15706
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
15707
|
|
|
|
|
|
|
|
15708
|
|
|
|
|
|
|
do { |
15709
|
|
|
|
|
|
|
p[0] = vqaddq_s16(p[0], v); |
15710
|
|
|
|
|
|
|
p[1] = vqaddq_s16(p[1], v); |
15711
|
|
|
|
|
|
|
p[2] = vqaddq_s16(p[2], v); |
15712
|
|
|
|
|
|
|
p[3] = vqaddq_s16(p[3], v); |
15713
|
|
|
|
|
|
|
p += 4; |
15714
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
15715
|
|
|
|
|
|
|
} while (size != 0); |
15716
|
|
|
|
|
|
|
} |
15717
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_neon |
15718
|
|
|
|
|
|
|
|
15719
|
|
|
|
|
|
|
#endif |
15720
|
|
|
|
|
|
|
|
15721
|
|
|
|
|
|
|
#endif |
15722
|
|
|
|
|
|
|
|
15723
|
|
|
|
|
|
|
# elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
15724
|
|
|
|
|
|
|
/* # include "x86/matchfinder_impl.h" */ |
15725
|
|
|
|
|
|
|
|
15726
|
|
|
|
|
|
|
|
15727
|
|
|
|
|
|
|
#ifndef LIB_X86_MATCHFINDER_IMPL_H |
15728
|
|
|
|
|
|
|
#define LIB_X86_MATCHFINDER_IMPL_H |
15729
|
|
|
|
|
|
|
|
15730
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
15731
|
|
|
|
|
|
|
|
15732
|
|
|
|
|
|
|
|
15733
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
15734
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
15735
|
|
|
|
|
|
|
|
15736
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
15737
|
|
|
|
|
|
|
|
15738
|
|
|
|
|
|
|
|
15739
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
15740
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
15741
|
|
|
|
|
|
|
|
15742
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
15743
|
|
|
|
|
|
|
|
15744
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
15745
|
|
|
|
|
|
|
#endif |
15746
|
|
|
|
|
|
|
|
15747
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
15748
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
15749
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
15750
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
15751
|
|
|
|
|
|
|
#else |
15752
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
15753
|
|
|
|
|
|
|
#endif |
15754
|
|
|
|
|
|
|
|
15755
|
|
|
|
|
|
|
|
15756
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
15757
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
15758
|
|
|
|
|
|
|
#else |
15759
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
15760
|
|
|
|
|
|
|
#endif |
15761
|
|
|
|
|
|
|
|
15762
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
15763
|
|
|
|
|
|
|
|
15764
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
15765
|
|
|
|
|
|
|
|
15766
|
|
|
|
|
|
|
|
15767
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
15768
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
15769
|
|
|
|
|
|
|
|
15770
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
15771
|
|
|
|
|
|
|
|
15772
|
|
|
|
|
|
|
|
15773
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
15774
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
15775
|
|
|
|
|
|
|
|
15776
|
|
|
|
|
|
|
#include |
15777
|
|
|
|
|
|
|
#include |
15778
|
|
|
|
|
|
|
|
15779
|
|
|
|
|
|
|
#ifdef __cplusplus |
15780
|
|
|
|
|
|
|
extern "C" { |
15781
|
|
|
|
|
|
|
#endif |
15782
|
|
|
|
|
|
|
|
15783
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
15784
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
15785
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
15786
|
|
|
|
|
|
|
|
15787
|
|
|
|
|
|
|
|
15788
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
15789
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
15790
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
15791
|
|
|
|
|
|
|
# else |
15792
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
15793
|
|
|
|
|
|
|
# endif |
15794
|
|
|
|
|
|
|
#endif |
15795
|
|
|
|
|
|
|
|
15796
|
|
|
|
|
|
|
|
15797
|
|
|
|
|
|
|
|
15798
|
|
|
|
|
|
|
|
15799
|
|
|
|
|
|
|
|
15800
|
|
|
|
|
|
|
struct libdeflate_compressor; |
15801
|
|
|
|
|
|
|
struct libdeflate_options; |
15802
|
|
|
|
|
|
|
|
15803
|
|
|
|
|
|
|
|
15804
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
15805
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
15806
|
|
|
|
|
|
|
|
15807
|
|
|
|
|
|
|
|
15808
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
15809
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
15810
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
15811
|
|
|
|
|
|
|
|
15812
|
|
|
|
|
|
|
|
15813
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15814
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
15815
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15816
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
15817
|
|
|
|
|
|
|
|
15818
|
|
|
|
|
|
|
|
15819
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15820
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
15821
|
|
|
|
|
|
|
size_t in_nbytes); |
15822
|
|
|
|
|
|
|
|
15823
|
|
|
|
|
|
|
|
15824
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15825
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
15826
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15827
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
15828
|
|
|
|
|
|
|
|
15829
|
|
|
|
|
|
|
|
15830
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15831
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
15832
|
|
|
|
|
|
|
size_t in_nbytes); |
15833
|
|
|
|
|
|
|
|
15834
|
|
|
|
|
|
|
|
15835
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15836
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
15837
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15838
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
15839
|
|
|
|
|
|
|
|
15840
|
|
|
|
|
|
|
|
15841
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15842
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
15843
|
|
|
|
|
|
|
size_t in_nbytes); |
15844
|
|
|
|
|
|
|
|
15845
|
|
|
|
|
|
|
|
15846
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
15847
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
15848
|
|
|
|
|
|
|
|
15849
|
|
|
|
|
|
|
|
15850
|
|
|
|
|
|
|
|
15851
|
|
|
|
|
|
|
|
15852
|
|
|
|
|
|
|
|
15853
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
15854
|
|
|
|
|
|
|
struct libdeflate_options; |
15855
|
|
|
|
|
|
|
|
15856
|
|
|
|
|
|
|
|
15857
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
15858
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
15859
|
|
|
|
|
|
|
|
15860
|
|
|
|
|
|
|
|
15861
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
15862
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
15863
|
|
|
|
|
|
|
|
15864
|
|
|
|
|
|
|
|
15865
|
|
|
|
|
|
|
enum libdeflate_result { |
15866
|
|
|
|
|
|
|
|
15867
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
15868
|
|
|
|
|
|
|
|
15869
|
|
|
|
|
|
|
|
15870
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
15871
|
|
|
|
|
|
|
|
15872
|
|
|
|
|
|
|
|
15873
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
15874
|
|
|
|
|
|
|
|
15875
|
|
|
|
|
|
|
|
15876
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
15877
|
|
|
|
|
|
|
}; |
15878
|
|
|
|
|
|
|
|
15879
|
|
|
|
|
|
|
|
15880
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15881
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
15882
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15883
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15884
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15885
|
|
|
|
|
|
|
|
15886
|
|
|
|
|
|
|
|
15887
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15888
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
15889
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15890
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15891
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
15892
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15893
|
|
|
|
|
|
|
|
15894
|
|
|
|
|
|
|
|
15895
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15896
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
15897
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15898
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15899
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15900
|
|
|
|
|
|
|
|
15901
|
|
|
|
|
|
|
|
15902
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15903
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
15904
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15905
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15906
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
15907
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15908
|
|
|
|
|
|
|
|
15909
|
|
|
|
|
|
|
|
15910
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15911
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
15912
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15913
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15914
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15915
|
|
|
|
|
|
|
|
15916
|
|
|
|
|
|
|
|
15917
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15918
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
15919
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15920
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15921
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
15922
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15923
|
|
|
|
|
|
|
|
15924
|
|
|
|
|
|
|
|
15925
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
15926
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
15927
|
|
|
|
|
|
|
|
15928
|
|
|
|
|
|
|
|
15929
|
|
|
|
|
|
|
|
15930
|
|
|
|
|
|
|
|
15931
|
|
|
|
|
|
|
|
15932
|
|
|
|
|
|
|
|
15933
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
15934
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
15935
|
|
|
|
|
|
|
|
15936
|
|
|
|
|
|
|
|
15937
|
|
|
|
|
|
|
|
15938
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
15939
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
15940
|
|
|
|
|
|
|
|
15941
|
|
|
|
|
|
|
|
15942
|
|
|
|
|
|
|
|
15943
|
|
|
|
|
|
|
|
15944
|
|
|
|
|
|
|
|
15945
|
|
|
|
|
|
|
|
15946
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
15947
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
15948
|
|
|
|
|
|
|
void (*free_func)(void *)); |
15949
|
|
|
|
|
|
|
|
15950
|
|
|
|
|
|
|
|
15951
|
|
|
|
|
|
|
struct libdeflate_options { |
15952
|
|
|
|
|
|
|
|
15953
|
|
|
|
|
|
|
|
15954
|
|
|
|
|
|
|
size_t sizeof_options; |
15955
|
|
|
|
|
|
|
|
15956
|
|
|
|
|
|
|
|
15957
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
15958
|
|
|
|
|
|
|
void (*free_func)(void *); |
15959
|
|
|
|
|
|
|
}; |
15960
|
|
|
|
|
|
|
|
15961
|
|
|
|
|
|
|
#ifdef __cplusplus |
15962
|
|
|
|
|
|
|
} |
15963
|
|
|
|
|
|
|
#endif |
15964
|
|
|
|
|
|
|
|
15965
|
|
|
|
|
|
|
#endif |
15966
|
|
|
|
|
|
|
|
15967
|
|
|
|
|
|
|
|
15968
|
|
|
|
|
|
|
#include |
15969
|
|
|
|
|
|
|
#include |
15970
|
|
|
|
|
|
|
#include |
15971
|
|
|
|
|
|
|
#ifdef _MSC_VER |
15972
|
|
|
|
|
|
|
# include |
15973
|
|
|
|
|
|
|
# include |
15974
|
|
|
|
|
|
|
|
15975
|
|
|
|
|
|
|
|
15976
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
15977
|
|
|
|
|
|
|
|
15978
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
15979
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
15980
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
15981
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
15982
|
|
|
|
|
|
|
|
15983
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
15984
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
15985
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
15986
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
15987
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
15988
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
15989
|
|
|
|
|
|
|
#endif |
15990
|
|
|
|
|
|
|
#ifndef FREESTANDING |
15991
|
|
|
|
|
|
|
# include |
15992
|
|
|
|
|
|
|
#endif |
15993
|
|
|
|
|
|
|
|
15994
|
|
|
|
|
|
|
|
15995
|
|
|
|
|
|
|
|
15996
|
|
|
|
|
|
|
|
15997
|
|
|
|
|
|
|
|
15998
|
|
|
|
|
|
|
|
15999
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
16000
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
16001
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
16002
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
16003
|
|
|
|
|
|
|
#ifdef _MSC_VER |
16004
|
|
|
|
|
|
|
# if defined(_M_X64) |
16005
|
|
|
|
|
|
|
# define ARCH_X86_64 |
16006
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
16007
|
|
|
|
|
|
|
# define ARCH_X86_32 |
16008
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
16009
|
|
|
|
|
|
|
# define ARCH_ARM64 |
16010
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
16011
|
|
|
|
|
|
|
# define ARCH_ARM32 |
16012
|
|
|
|
|
|
|
# endif |
16013
|
|
|
|
|
|
|
#else |
16014
|
|
|
|
|
|
|
# if defined(__x86_64__) |
16015
|
|
|
|
|
|
|
# define ARCH_X86_64 |
16016
|
|
|
|
|
|
|
# elif defined(__i386__) |
16017
|
|
|
|
|
|
|
# define ARCH_X86_32 |
16018
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
16019
|
|
|
|
|
|
|
# define ARCH_ARM64 |
16020
|
|
|
|
|
|
|
# elif defined(__arm__) |
16021
|
|
|
|
|
|
|
# define ARCH_ARM32 |
16022
|
|
|
|
|
|
|
# endif |
16023
|
|
|
|
|
|
|
#endif |
16024
|
|
|
|
|
|
|
|
16025
|
|
|
|
|
|
|
|
16026
|
|
|
|
|
|
|
|
16027
|
|
|
|
|
|
|
|
16028
|
|
|
|
|
|
|
|
16029
|
|
|
|
|
|
|
|
16030
|
|
|
|
|
|
|
typedef uint8_t u8; |
16031
|
|
|
|
|
|
|
typedef uint16_t u16; |
16032
|
|
|
|
|
|
|
typedef uint32_t u32; |
16033
|
|
|
|
|
|
|
typedef uint64_t u64; |
16034
|
|
|
|
|
|
|
typedef int8_t s8; |
16035
|
|
|
|
|
|
|
typedef int16_t s16; |
16036
|
|
|
|
|
|
|
typedef int32_t s32; |
16037
|
|
|
|
|
|
|
typedef int64_t s64; |
16038
|
|
|
|
|
|
|
|
16039
|
|
|
|
|
|
|
|
16040
|
|
|
|
|
|
|
#ifdef _MSC_VER |
16041
|
|
|
|
|
|
|
# ifdef _WIN64 |
16042
|
|
|
|
|
|
|
typedef long long ssize_t; |
16043
|
|
|
|
|
|
|
# else |
16044
|
|
|
|
|
|
|
typedef long ssize_t; |
16045
|
|
|
|
|
|
|
# endif |
16046
|
|
|
|
|
|
|
#endif |
16047
|
|
|
|
|
|
|
|
16048
|
|
|
|
|
|
|
|
16049
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
16050
|
|
|
|
|
|
|
|
16051
|
|
|
|
|
|
|
|
16052
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
16053
|
|
|
|
|
|
|
|
16054
|
|
|
|
|
|
|
|
16055
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
16056
|
|
|
|
|
|
|
|
16057
|
|
|
|
|
|
|
|
16058
|
|
|
|
|
|
|
|
16059
|
|
|
|
|
|
|
|
16060
|
|
|
|
|
|
|
|
16061
|
|
|
|
|
|
|
|
16062
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
16063
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
16064
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
16065
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
16066
|
|
|
|
|
|
|
#else |
16067
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
16068
|
|
|
|
|
|
|
#endif |
16069
|
|
|
|
|
|
|
#ifdef __clang__ |
16070
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
16071
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
16072
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
16073
|
|
|
|
|
|
|
# else |
16074
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
16075
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
16076
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
16077
|
|
|
|
|
|
|
# endif |
16078
|
|
|
|
|
|
|
#else |
16079
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
16080
|
|
|
|
|
|
|
#endif |
16081
|
|
|
|
|
|
|
|
16082
|
|
|
|
|
|
|
|
16083
|
|
|
|
|
|
|
#ifndef __has_attribute |
16084
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
16085
|
|
|
|
|
|
|
#endif |
16086
|
|
|
|
|
|
|
#ifndef __has_builtin |
16087
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
16088
|
|
|
|
|
|
|
#endif |
16089
|
|
|
|
|
|
|
|
16090
|
|
|
|
|
|
|
|
16091
|
|
|
|
|
|
|
#ifdef _MSC_VER |
16092
|
|
|
|
|
|
|
# define inline __inline |
16093
|
|
|
|
|
|
|
#endif |
16094
|
|
|
|
|
|
|
|
16095
|
|
|
|
|
|
|
|
16096
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
16097
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
16098
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16099
|
|
|
|
|
|
|
# define forceinline __forceinline |
16100
|
|
|
|
|
|
|
#else |
16101
|
|
|
|
|
|
|
# define forceinline inline |
16102
|
|
|
|
|
|
|
#endif |
16103
|
|
|
|
|
|
|
|
16104
|
|
|
|
|
|
|
|
16105
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
16106
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
16107
|
|
|
|
|
|
|
#else |
16108
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
16109
|
|
|
|
|
|
|
#endif |
16110
|
|
|
|
|
|
|
|
16111
|
|
|
|
|
|
|
|
16112
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
16113
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
16114
|
|
|
|
|
|
|
# define restrict __restrict__ |
16115
|
|
|
|
|
|
|
# else |
16116
|
|
|
|
|
|
|
# define restrict |
16117
|
|
|
|
|
|
|
# endif |
16118
|
|
|
|
|
|
|
#endif |
16119
|
|
|
|
|
|
|
|
16120
|
|
|
|
|
|
|
|
16121
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
16122
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
16123
|
|
|
|
|
|
|
#else |
16124
|
|
|
|
|
|
|
# define likely(expr) (expr) |
16125
|
|
|
|
|
|
|
#endif |
16126
|
|
|
|
|
|
|
|
16127
|
|
|
|
|
|
|
|
16128
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
16129
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
16130
|
|
|
|
|
|
|
#else |
16131
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
16132
|
|
|
|
|
|
|
#endif |
16133
|
|
|
|
|
|
|
|
16134
|
|
|
|
|
|
|
|
16135
|
|
|
|
|
|
|
#undef prefetchr |
16136
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
16137
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
16138
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16139
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
16140
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
16141
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
16142
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
16143
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
16144
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
16145
|
|
|
|
|
|
|
# endif |
16146
|
|
|
|
|
|
|
#endif |
16147
|
|
|
|
|
|
|
#ifndef prefetchr |
16148
|
|
|
|
|
|
|
# define prefetchr(addr) |
16149
|
|
|
|
|
|
|
#endif |
16150
|
|
|
|
|
|
|
|
16151
|
|
|
|
|
|
|
|
16152
|
|
|
|
|
|
|
#undef prefetchw |
16153
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
16154
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
16155
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16156
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
16157
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
16158
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
16159
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
16160
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
16161
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
16162
|
|
|
|
|
|
|
# endif |
16163
|
|
|
|
|
|
|
#endif |
16164
|
|
|
|
|
|
|
#ifndef prefetchw |
16165
|
|
|
|
|
|
|
# define prefetchw(addr) |
16166
|
|
|
|
|
|
|
#endif |
16167
|
|
|
|
|
|
|
|
16168
|
|
|
|
|
|
|
|
16169
|
|
|
|
|
|
|
#undef _aligned_attribute |
16170
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
16171
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
16172
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16173
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
16174
|
|
|
|
|
|
|
#endif |
16175
|
|
|
|
|
|
|
|
16176
|
|
|
|
|
|
|
|
16177
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
16178
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
16179
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
16180
|
|
|
|
|
|
|
#else |
16181
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
16182
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
16183
|
|
|
|
|
|
|
#endif |
16184
|
|
|
|
|
|
|
|
16185
|
|
|
|
|
|
|
|
16186
|
|
|
|
|
|
|
|
16187
|
|
|
|
|
|
|
|
16188
|
|
|
|
|
|
|
|
16189
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
16190
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
16191
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
16192
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
16193
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
16194
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
16195
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
16196
|
|
|
|
|
|
|
|
16197
|
|
|
|
|
|
|
|
16198
|
|
|
|
|
|
|
|
16199
|
|
|
|
|
|
|
|
16200
|
|
|
|
|
|
|
|
16201
|
|
|
|
|
|
|
|
16202
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
16203
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
16204
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16205
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
16206
|
|
|
|
|
|
|
#else |
16207
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
16208
|
|
|
|
|
|
|
{ |
16209
|
|
|
|
|
|
|
union { |
16210
|
|
|
|
|
|
|
u32 w; |
16211
|
|
|
|
|
|
|
u8 b; |
16212
|
|
|
|
|
|
|
} u; |
16213
|
|
|
|
|
|
|
|
16214
|
|
|
|
|
|
|
u.w = 1; |
16215
|
|
|
|
|
|
|
return u.b; |
16216
|
|
|
|
|
|
|
} |
16217
|
|
|
|
|
|
|
#endif |
16218
|
|
|
|
|
|
|
|
16219
|
|
|
|
|
|
|
|
16220
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
16221
|
|
|
|
|
|
|
{ |
16222
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
16223
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
16224
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16225
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
16226
|
|
|
|
|
|
|
#else |
16227
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
16228
|
|
|
|
|
|
|
#endif |
16229
|
|
|
|
|
|
|
} |
16230
|
|
|
|
|
|
|
|
16231
|
|
|
|
|
|
|
|
16232
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
16233
|
|
|
|
|
|
|
{ |
16234
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
16235
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
16236
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16237
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
16238
|
|
|
|
|
|
|
#else |
16239
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
16240
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
16241
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
16242
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
16243
|
|
|
|
|
|
|
#endif |
16244
|
|
|
|
|
|
|
} |
16245
|
|
|
|
|
|
|
|
16246
|
|
|
|
|
|
|
|
16247
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
16248
|
|
|
|
|
|
|
{ |
16249
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
16250
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
16251
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16252
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
16253
|
|
|
|
|
|
|
#else |
16254
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
16255
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
16256
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
16257
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
16258
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
16259
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
16260
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
16261
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
16262
|
|
|
|
|
|
|
#endif |
16263
|
|
|
|
|
|
|
} |
16264
|
|
|
|
|
|
|
|
16265
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
16266
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
16267
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
16268
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
16269
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
16270
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
16271
|
|
|
|
|
|
|
|
16272
|
|
|
|
|
|
|
|
16273
|
|
|
|
|
|
|
|
16274
|
|
|
|
|
|
|
|
16275
|
|
|
|
|
|
|
|
16276
|
|
|
|
|
|
|
|
16277
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
16278
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
16279
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
16280
|
|
|
|
|
|
|
defined(__wasm__)) |
16281
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
16282
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16283
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
16284
|
|
|
|
|
|
|
#else |
16285
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
16286
|
|
|
|
|
|
|
#endif |
16287
|
|
|
|
|
|
|
|
16288
|
|
|
|
|
|
|
|
16289
|
|
|
|
|
|
|
|
16290
|
|
|
|
|
|
|
#ifdef FREESTANDING |
16291
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
16292
|
|
|
|
|
|
|
#else |
16293
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
16294
|
|
|
|
|
|
|
#endif |
16295
|
|
|
|
|
|
|
|
16296
|
|
|
|
|
|
|
|
16297
|
|
|
|
|
|
|
|
16298
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
16299
|
|
|
|
|
|
|
static forceinline type \ |
16300
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
16301
|
|
|
|
|
|
|
{ \ |
16302
|
|
|
|
|
|
|
type v; \ |
16303
|
|
|
|
|
|
|
\ |
16304
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
16305
|
|
|
|
|
|
|
return v; \ |
16306
|
|
|
|
|
|
|
} \ |
16307
|
|
|
|
|
|
|
\ |
16308
|
|
|
|
|
|
|
static forceinline void \ |
16309
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
16310
|
|
|
|
|
|
|
{ \ |
16311
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
16312
|
|
|
|
|
|
|
} |
16313
|
|
|
|
|
|
|
|
16314
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
16315
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
16316
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
16317
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
16318
|
|
|
|
|
|
|
|
16319
|
|
|
|
|
|
|
#undef MEMCOPY |
16320
|
|
|
|
|
|
|
|
16321
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
16322
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
16323
|
|
|
|
|
|
|
|
16324
|
|
|
|
|
|
|
|
16325
|
|
|
|
|
|
|
|
16326
|
|
|
|
|
|
|
static forceinline u16 |
16327
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
16328
|
|
|
|
|
|
|
{ |
16329
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
16330
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
16331
|
|
|
|
|
|
|
else |
16332
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
16333
|
|
|
|
|
|
|
} |
16334
|
|
|
|
|
|
|
|
16335
|
|
|
|
|
|
|
static forceinline u16 |
16336
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
16337
|
|
|
|
|
|
|
{ |
16338
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
16339
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
16340
|
|
|
|
|
|
|
else |
16341
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
16342
|
|
|
|
|
|
|
} |
16343
|
|
|
|
|
|
|
|
16344
|
|
|
|
|
|
|
static forceinline u32 |
16345
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
16346
|
|
|
|
|
|
|
{ |
16347
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
16348
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
16349
|
|
|
|
|
|
|
else |
16350
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
16351
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
16352
|
|
|
|
|
|
|
} |
16353
|
|
|
|
|
|
|
|
16354
|
|
|
|
|
|
|
static forceinline u32 |
16355
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
16356
|
|
|
|
|
|
|
{ |
16357
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
16358
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
16359
|
|
|
|
|
|
|
else |
16360
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
16361
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
16362
|
|
|
|
|
|
|
} |
16363
|
|
|
|
|
|
|
|
16364
|
|
|
|
|
|
|
static forceinline u64 |
16365
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
16366
|
|
|
|
|
|
|
{ |
16367
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
16368
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
16369
|
|
|
|
|
|
|
else |
16370
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
16371
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
16372
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
16373
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
16374
|
|
|
|
|
|
|
} |
16375
|
|
|
|
|
|
|
|
16376
|
|
|
|
|
|
|
static forceinline machine_word_t |
16377
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
16378
|
|
|
|
|
|
|
{ |
16379
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
16380
|
|
|
|
|
|
|
if (WORDBITS == 32) |
16381
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
16382
|
|
|
|
|
|
|
else |
16383
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
16384
|
|
|
|
|
|
|
} |
16385
|
|
|
|
|
|
|
|
16386
|
|
|
|
|
|
|
|
16387
|
|
|
|
|
|
|
|
16388
|
|
|
|
|
|
|
static forceinline void |
16389
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
16390
|
|
|
|
|
|
|
{ |
16391
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16392
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
16393
|
|
|
|
|
|
|
} else { |
16394
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
16395
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
16396
|
|
|
|
|
|
|
} |
16397
|
|
|
|
|
|
|
} |
16398
|
|
|
|
|
|
|
|
16399
|
|
|
|
|
|
|
static forceinline void |
16400
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
16401
|
|
|
|
|
|
|
{ |
16402
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16403
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
16404
|
|
|
|
|
|
|
} else { |
16405
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
16406
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
16407
|
|
|
|
|
|
|
} |
16408
|
|
|
|
|
|
|
} |
16409
|
|
|
|
|
|
|
|
16410
|
|
|
|
|
|
|
static forceinline void |
16411
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
16412
|
|
|
|
|
|
|
{ |
16413
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16414
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
16415
|
|
|
|
|
|
|
} else { |
16416
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
16417
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
16418
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
16419
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
16420
|
|
|
|
|
|
|
} |
16421
|
|
|
|
|
|
|
} |
16422
|
|
|
|
|
|
|
|
16423
|
|
|
|
|
|
|
static forceinline void |
16424
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
16425
|
|
|
|
|
|
|
{ |
16426
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16427
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
16428
|
|
|
|
|
|
|
} else { |
16429
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
16430
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
16431
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
16432
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
16433
|
|
|
|
|
|
|
} |
16434
|
|
|
|
|
|
|
} |
16435
|
|
|
|
|
|
|
|
16436
|
|
|
|
|
|
|
static forceinline void |
16437
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
16438
|
|
|
|
|
|
|
{ |
16439
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16440
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
16441
|
|
|
|
|
|
|
} else { |
16442
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
16443
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
16444
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
16445
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
16446
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
16447
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
16448
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
16449
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
16450
|
|
|
|
|
|
|
} |
16451
|
|
|
|
|
|
|
} |
16452
|
|
|
|
|
|
|
|
16453
|
|
|
|
|
|
|
static forceinline void |
16454
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
16455
|
|
|
|
|
|
|
{ |
16456
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
16457
|
|
|
|
|
|
|
if (WORDBITS == 32) |
16458
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
16459
|
|
|
|
|
|
|
else |
16460
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
16461
|
|
|
|
|
|
|
} |
16462
|
|
|
|
|
|
|
|
16463
|
|
|
|
|
|
|
|
16464
|
|
|
|
|
|
|
|
16465
|
|
|
|
|
|
|
|
16466
|
|
|
|
|
|
|
|
16467
|
|
|
|
|
|
|
|
16468
|
|
|
|
|
|
|
|
16469
|
|
|
|
|
|
|
static forceinline unsigned |
16470
|
|
|
|
|
|
|
bsr32(u32 v) |
16471
|
|
|
|
|
|
|
{ |
16472
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
16473
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
16474
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16475
|
|
|
|
|
|
|
unsigned long i; |
16476
|
|
|
|
|
|
|
|
16477
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
16478
|
|
|
|
|
|
|
return i; |
16479
|
|
|
|
|
|
|
#else |
16480
|
|
|
|
|
|
|
unsigned i = 0; |
16481
|
|
|
|
|
|
|
|
16482
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
16483
|
|
|
|
|
|
|
i++; |
16484
|
|
|
|
|
|
|
return i; |
16485
|
|
|
|
|
|
|
#endif |
16486
|
|
|
|
|
|
|
} |
16487
|
|
|
|
|
|
|
|
16488
|
|
|
|
|
|
|
static forceinline unsigned |
16489
|
|
|
|
|
|
|
bsr64(u64 v) |
16490
|
|
|
|
|
|
|
{ |
16491
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
16492
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
16493
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
16494
|
|
|
|
|
|
|
unsigned long i; |
16495
|
|
|
|
|
|
|
|
16496
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
16497
|
|
|
|
|
|
|
return i; |
16498
|
|
|
|
|
|
|
#else |
16499
|
|
|
|
|
|
|
unsigned i = 0; |
16500
|
|
|
|
|
|
|
|
16501
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
16502
|
|
|
|
|
|
|
i++; |
16503
|
|
|
|
|
|
|
return i; |
16504
|
|
|
|
|
|
|
#endif |
16505
|
|
|
|
|
|
|
} |
16506
|
|
|
|
|
|
|
|
16507
|
|
|
|
|
|
|
static forceinline unsigned |
16508
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
16509
|
|
|
|
|
|
|
{ |
16510
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
16511
|
|
|
|
|
|
|
if (WORDBITS == 32) |
16512
|
|
|
|
|
|
|
return bsr32(v); |
16513
|
|
|
|
|
|
|
else |
16514
|
|
|
|
|
|
|
return bsr64(v); |
16515
|
|
|
|
|
|
|
} |
16516
|
|
|
|
|
|
|
|
16517
|
|
|
|
|
|
|
|
16518
|
|
|
|
|
|
|
|
16519
|
|
|
|
|
|
|
static forceinline unsigned |
16520
|
|
|
|
|
|
|
bsf32(u32 v) |
16521
|
|
|
|
|
|
|
{ |
16522
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
16523
|
|
|
|
|
|
|
return __builtin_ctz(v); |
16524
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16525
|
|
|
|
|
|
|
unsigned long i; |
16526
|
|
|
|
|
|
|
|
16527
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
16528
|
|
|
|
|
|
|
return i; |
16529
|
|
|
|
|
|
|
#else |
16530
|
|
|
|
|
|
|
unsigned i = 0; |
16531
|
|
|
|
|
|
|
|
16532
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
16533
|
|
|
|
|
|
|
i++; |
16534
|
|
|
|
|
|
|
return i; |
16535
|
|
|
|
|
|
|
#endif |
16536
|
|
|
|
|
|
|
} |
16537
|
|
|
|
|
|
|
|
16538
|
|
|
|
|
|
|
static forceinline unsigned |
16539
|
|
|
|
|
|
|
bsf64(u64 v) |
16540
|
|
|
|
|
|
|
{ |
16541
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
16542
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
16543
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
16544
|
|
|
|
|
|
|
unsigned long i; |
16545
|
|
|
|
|
|
|
|
16546
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
16547
|
|
|
|
|
|
|
return i; |
16548
|
|
|
|
|
|
|
#else |
16549
|
|
|
|
|
|
|
unsigned i = 0; |
16550
|
|
|
|
|
|
|
|
16551
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
16552
|
|
|
|
|
|
|
i++; |
16553
|
|
|
|
|
|
|
return i; |
16554
|
|
|
|
|
|
|
#endif |
16555
|
|
|
|
|
|
|
} |
16556
|
|
|
|
|
|
|
|
16557
|
|
|
|
|
|
|
static forceinline unsigned |
16558
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
16559
|
|
|
|
|
|
|
{ |
16560
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
16561
|
|
|
|
|
|
|
if (WORDBITS == 32) |
16562
|
|
|
|
|
|
|
return bsf32(v); |
16563
|
|
|
|
|
|
|
else |
16564
|
|
|
|
|
|
|
return bsf64(v); |
16565
|
|
|
|
|
|
|
} |
16566
|
|
|
|
|
|
|
|
16567
|
|
|
|
|
|
|
|
16568
|
|
|
|
|
|
|
#undef rbit32 |
16569
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
16570
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
16571
|
|
|
|
|
|
|
static forceinline u32 |
16572
|
|
|
|
|
|
|
rbit32(u32 v) |
16573
|
|
|
|
|
|
|
{ |
16574
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
16575
|
|
|
|
|
|
|
return v; |
16576
|
|
|
|
|
|
|
} |
16577
|
|
|
|
|
|
|
#define rbit32 rbit32 |
16578
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
16579
|
|
|
|
|
|
|
static forceinline u32 |
16580
|
|
|
|
|
|
|
rbit32(u32 v) |
16581
|
|
|
|
|
|
|
{ |
16582
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
16583
|
|
|
|
|
|
|
return v; |
16584
|
|
|
|
|
|
|
} |
16585
|
|
|
|
|
|
|
#define rbit32 rbit32 |
16586
|
|
|
|
|
|
|
#endif |
16587
|
|
|
|
|
|
|
|
16588
|
|
|
|
|
|
|
#endif |
16589
|
|
|
|
|
|
|
|
16590
|
|
|
|
|
|
|
|
16591
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
16592
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
16593
|
|
|
|
|
|
|
|
16594
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
16595
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
16596
|
|
|
|
|
|
|
|
16597
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
16598
|
|
|
|
|
|
|
size_t alignment, size_t size); |
16599
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
16600
|
|
|
|
|
|
|
|
16601
|
|
|
|
|
|
|
#ifdef FREESTANDING |
16602
|
|
|
|
|
|
|
|
16603
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
16604
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
16605
|
|
|
|
|
|
|
|
16606
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
16607
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
16608
|
|
|
|
|
|
|
|
16609
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
16610
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
16611
|
|
|
|
|
|
|
|
16612
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
16613
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
16614
|
|
|
|
|
|
|
|
16615
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
16616
|
|
|
|
|
|
|
#else |
16617
|
|
|
|
|
|
|
#include |
16618
|
|
|
|
|
|
|
#endif |
16619
|
|
|
|
|
|
|
|
16620
|
|
|
|
|
|
|
|
16621
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
16622
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
16623
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
16624
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
16625
|
|
|
|
|
|
|
#else |
16626
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
16627
|
|
|
|
|
|
|
#endif |
16628
|
|
|
|
|
|
|
|
16629
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
16630
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
16631
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
16632
|
|
|
|
|
|
|
|
16633
|
|
|
|
|
|
|
#endif |
16634
|
|
|
|
|
|
|
|
16635
|
|
|
|
|
|
|
|
16636
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
16637
|
|
|
|
|
|
|
|
16638
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
16639
|
|
|
|
|
|
|
|
16640
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
16641
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
16642
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
16643
|
|
|
|
|
|
|
#endif |
16644
|
|
|
|
|
|
|
|
16645
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
16646
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
16647
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
16648
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
16649
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
16650
|
|
|
|
|
|
|
|
16651
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
16652
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
16653
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
16654
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
16655
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
16656
|
|
|
|
|
|
|
|
16657
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
16658
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
16659
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
16660
|
|
|
|
|
|
|
|
16661
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
16662
|
|
|
|
|
|
|
|
16663
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
16664
|
|
|
|
|
|
|
{ |
16665
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
16666
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
16667
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
16668
|
|
|
|
|
|
|
} |
16669
|
|
|
|
|
|
|
#else |
16670
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
16671
|
|
|
|
|
|
|
#endif |
16672
|
|
|
|
|
|
|
|
16673
|
|
|
|
|
|
|
|
16674
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
16675
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
16676
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
16677
|
|
|
|
|
|
|
#else |
16678
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
16679
|
|
|
|
|
|
|
#endif |
16680
|
|
|
|
|
|
|
|
16681
|
|
|
|
|
|
|
|
16682
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
16683
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
16684
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
16685
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
16686
|
|
|
|
|
|
|
#else |
16687
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
16688
|
|
|
|
|
|
|
#endif |
16689
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
16690
|
|
|
|
|
|
|
|
16691
|
|
|
|
|
|
|
|
16692
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
16693
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
16694
|
|
|
|
|
|
|
#else |
16695
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
16696
|
|
|
|
|
|
|
#endif |
16697
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
16698
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
16699
|
|
|
|
|
|
|
defined(_MSC_VER))) |
16700
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
16701
|
|
|
|
|
|
|
#else |
16702
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
16703
|
|
|
|
|
|
|
#endif |
16704
|
|
|
|
|
|
|
|
16705
|
|
|
|
|
|
|
|
16706
|
|
|
|
|
|
|
#ifdef __AVX__ |
16707
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
16708
|
|
|
|
|
|
|
#else |
16709
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
16710
|
|
|
|
|
|
|
#endif |
16711
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
16712
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
16713
|
|
|
|
|
|
|
defined(_MSC_VER))) |
16714
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
16715
|
|
|
|
|
|
|
#else |
16716
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
16717
|
|
|
|
|
|
|
#endif |
16718
|
|
|
|
|
|
|
|
16719
|
|
|
|
|
|
|
|
16720
|
|
|
|
|
|
|
#ifdef __AVX2__ |
16721
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
16722
|
|
|
|
|
|
|
#else |
16723
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
16724
|
|
|
|
|
|
|
#endif |
16725
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
16726
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
16727
|
|
|
|
|
|
|
defined(_MSC_VER))) |
16728
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
16729
|
|
|
|
|
|
|
#else |
16730
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
16731
|
|
|
|
|
|
|
#endif |
16732
|
|
|
|
|
|
|
|
16733
|
|
|
|
|
|
|
|
16734
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
16735
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
16736
|
|
|
|
|
|
|
#else |
16737
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
16738
|
|
|
|
|
|
|
#endif |
16739
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
16740
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
16741
|
|
|
|
|
|
|
defined(_MSC_VER))) |
16742
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
16743
|
|
|
|
|
|
|
#else |
16744
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
16745
|
|
|
|
|
|
|
#endif |
16746
|
|
|
|
|
|
|
|
16747
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1930 |
16748
|
|
|
|
|
|
|
# undef HAVE_BMI2_NATIVE |
16749
|
|
|
|
|
|
|
# undef HAVE_BMI2_INTRIN |
16750
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
16751
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
16752
|
|
|
|
|
|
|
#endif |
16753
|
|
|
|
|
|
|
|
16754
|
|
|
|
|
|
|
#endif |
16755
|
|
|
|
|
|
|
|
16756
|
|
|
|
|
|
|
#endif |
16757
|
|
|
|
|
|
|
|
16758
|
|
|
|
|
|
|
|
16759
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE |
16760
|
|
|
|
|
|
|
# include |
16761
|
|
|
|
|
|
|
static forceinline void |
16762
|
|
|
|
|
|
|
matchfinder_init_avx2(mf_pos_t *data, size_t size) |
16763
|
|
|
|
|
|
|
{ |
16764
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
16765
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16(MATCHFINDER_INITVAL); |
16766
|
|
|
|
|
|
|
|
16767
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
16768
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
16769
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
16770
|
|
|
|
|
|
|
|
16771
|
|
|
|
|
|
|
do { |
16772
|
|
|
|
|
|
|
p[0] = v; |
16773
|
|
|
|
|
|
|
p[1] = v; |
16774
|
|
|
|
|
|
|
p[2] = v; |
16775
|
|
|
|
|
|
|
p[3] = v; |
16776
|
|
|
|
|
|
|
p += 4; |
16777
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
16778
|
|
|
|
|
|
|
} while (size != 0); |
16779
|
|
|
|
|
|
|
} |
16780
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_avx2 |
16781
|
|
|
|
|
|
|
|
16782
|
|
|
|
|
|
|
static forceinline void |
16783
|
|
|
|
|
|
|
matchfinder_rebase_avx2(mf_pos_t *data, size_t size) |
16784
|
|
|
|
|
|
|
{ |
16785
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
16786
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
16787
|
|
|
|
|
|
|
|
16788
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
16789
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
16790
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
16791
|
|
|
|
|
|
|
|
16792
|
|
|
|
|
|
|
do { |
16793
|
|
|
|
|
|
|
|
16794
|
|
|
|
|
|
|
p[0] = _mm256_adds_epi16(p[0], v); |
16795
|
|
|
|
|
|
|
p[1] = _mm256_adds_epi16(p[1], v); |
16796
|
|
|
|
|
|
|
p[2] = _mm256_adds_epi16(p[2], v); |
16797
|
|
|
|
|
|
|
p[3] = _mm256_adds_epi16(p[3], v); |
16798
|
|
|
|
|
|
|
p += 4; |
16799
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
16800
|
|
|
|
|
|
|
} while (size != 0); |
16801
|
|
|
|
|
|
|
} |
16802
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_avx2 |
16803
|
|
|
|
|
|
|
|
16804
|
|
|
|
|
|
|
#elif HAVE_SSE2_NATIVE |
16805
|
|
|
|
|
|
|
# include |
16806
|
|
|
|
|
|
|
static forceinline void |
16807
|
|
|
|
|
|
|
matchfinder_init_sse2(mf_pos_t *data, size_t size) |
16808
|
|
|
|
|
|
|
{ |
16809
|
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
16810
|
|
|
|
|
|
|
__m128i v = _mm_set1_epi16(MATCHFINDER_INITVAL); |
16811
|
|
|
|
|
|
|
|
16812
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
16813
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
16814
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
16815
|
|
|
|
|
|
|
|
16816
|
|
|
|
|
|
|
do { |
16817
|
|
|
|
|
|
|
p[0] = v; |
16818
|
|
|
|
|
|
|
p[1] = v; |
16819
|
|
|
|
|
|
|
p[2] = v; |
16820
|
|
|
|
|
|
|
p[3] = v; |
16821
|
|
|
|
|
|
|
p += 4; |
16822
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
16823
|
|
|
|
|
|
|
} while (size != 0); |
16824
|
|
|
|
|
|
|
} |
16825
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_sse2 |
16826
|
|
|
|
|
|
|
|
16827
|
|
|
|
|
|
|
static forceinline void |
16828
|
|
|
|
|
|
|
matchfinder_rebase_sse2(mf_pos_t *data, size_t size) |
16829
|
|
|
|
|
|
|
{ |
16830
|
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
16831
|
|
|
|
|
|
|
__m128i v = _mm_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
16832
|
|
|
|
|
|
|
|
16833
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
16834
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
16835
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
16836
|
|
|
|
|
|
|
|
16837
|
|
|
|
|
|
|
do { |
16838
|
|
|
|
|
|
|
|
16839
|
|
|
|
|
|
|
p[0] = _mm_adds_epi16(p[0], v); |
16840
|
|
|
|
|
|
|
p[1] = _mm_adds_epi16(p[1], v); |
16841
|
|
|
|
|
|
|
p[2] = _mm_adds_epi16(p[2], v); |
16842
|
|
|
|
|
|
|
p[3] = _mm_adds_epi16(p[3], v); |
16843
|
|
|
|
|
|
|
p += 4; |
16844
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
16845
|
|
|
|
|
|
|
} while (size != 0); |
16846
|
|
|
|
|
|
|
} |
16847
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_sse2 |
16848
|
|
|
|
|
|
|
#endif |
16849
|
|
|
|
|
|
|
|
16850
|
|
|
|
|
|
|
#endif |
16851
|
|
|
|
|
|
|
|
16852
|
|
|
|
|
|
|
# endif |
16853
|
|
|
|
|
|
|
#else |
16854
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED |
16855
|
|
|
|
|
|
|
#endif |
16856
|
|
|
|
|
|
|
|
16857
|
|
|
|
|
|
|
|
16858
|
|
|
|
|
|
|
#ifndef matchfinder_init |
16859
|
|
|
|
|
|
|
static forceinline void |
16860
|
|
|
|
|
|
|
matchfinder_init(mf_pos_t *data, size_t size) |
16861
|
|
|
|
|
|
|
{ |
16862
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
16863
|
|
|
|
|
|
|
size_t i; |
16864
|
|
|
|
|
|
|
|
16865
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
16866
|
|
|
|
|
|
|
data[i] = MATCHFINDER_INITVAL; |
16867
|
|
|
|
|
|
|
} |
16868
|
|
|
|
|
|
|
#endif |
16869
|
|
|
|
|
|
|
|
16870
|
|
|
|
|
|
|
|
16871
|
|
|
|
|
|
|
#ifndef matchfinder_rebase |
16872
|
|
|
|
|
|
|
static forceinline void |
16873
|
|
|
|
|
|
|
matchfinder_rebase(mf_pos_t *data, size_t size) |
16874
|
|
|
|
|
|
|
{ |
16875
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
16876
|
|
|
|
|
|
|
size_t i; |
16877
|
|
|
|
|
|
|
|
16878
|
|
|
|
|
|
|
if (MATCHFINDER_WINDOW_SIZE == 32768) { |
16879
|
|
|
|
|
|
|
|
16880
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
16881
|
|
|
|
|
|
|
data[i] = 0x8000 | (data[i] & ~(data[i] >> 15)); |
16882
|
|
|
|
|
|
|
} else { |
16883
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) { |
16884
|
|
|
|
|
|
|
if (data[i] >= 0) |
16885
|
|
|
|
|
|
|
data[i] -= (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
16886
|
|
|
|
|
|
|
else |
16887
|
|
|
|
|
|
|
data[i] = (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
16888
|
|
|
|
|
|
|
} |
16889
|
|
|
|
|
|
|
} |
16890
|
|
|
|
|
|
|
} |
16891
|
|
|
|
|
|
|
#endif |
16892
|
|
|
|
|
|
|
|
16893
|
|
|
|
|
|
|
|
16894
|
|
|
|
|
|
|
static forceinline u32 |
16895
|
|
|
|
|
|
|
lz_hash(u32 seq, unsigned num_bits) |
16896
|
|
|
|
|
|
|
{ |
16897
|
|
|
|
|
|
|
return (u32)(seq * 0x1E35A7BD) >> (32 - num_bits); |
16898
|
|
|
|
|
|
|
} |
16899
|
|
|
|
|
|
|
|
16900
|
|
|
|
|
|
|
|
16901
|
|
|
|
|
|
|
static forceinline unsigned |
16902
|
|
|
|
|
|
|
lz_extend(const u8 * const strptr, const u8 * const matchptr, |
16903
|
|
|
|
|
|
|
const unsigned start_len, const unsigned max_len) |
16904
|
|
|
|
|
|
|
{ |
16905
|
|
|
|
|
|
|
unsigned len = start_len; |
16906
|
|
|
|
|
|
|
machine_word_t v_word; |
16907
|
|
|
|
|
|
|
|
16908
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16909
|
|
|
|
|
|
|
|
16910
|
|
|
|
|
|
|
if (likely(max_len - len >= 4 * WORDBYTES)) { |
16911
|
|
|
|
|
|
|
|
16912
|
|
|
|
|
|
|
#define COMPARE_WORD_STEP \ |
16913
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ \ |
16914
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); \ |
16915
|
|
|
|
|
|
|
if (v_word != 0) \ |
16916
|
|
|
|
|
|
|
goto word_differs; \ |
16917
|
|
|
|
|
|
|
len += WORDBYTES; \ |
16918
|
|
|
|
|
|
|
|
16919
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
16920
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
16921
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
16922
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
16923
|
|
|
|
|
|
|
#undef COMPARE_WORD_STEP |
16924
|
|
|
|
|
|
|
} |
16925
|
|
|
|
|
|
|
|
16926
|
|
|
|
|
|
|
while (len + WORDBYTES <= max_len) { |
16927
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ |
16928
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); |
16929
|
|
|
|
|
|
|
if (v_word != 0) |
16930
|
|
|
|
|
|
|
goto word_differs; |
16931
|
|
|
|
|
|
|
len += WORDBYTES; |
16932
|
|
|
|
|
|
|
} |
16933
|
|
|
|
|
|
|
} |
16934
|
|
|
|
|
|
|
|
16935
|
|
|
|
|
|
|
while (len < max_len && matchptr[len] == strptr[len]) |
16936
|
|
|
|
|
|
|
len++; |
16937
|
|
|
|
|
|
|
return len; |
16938
|
|
|
|
|
|
|
|
16939
|
|
|
|
|
|
|
word_differs: |
16940
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
16941
|
|
|
|
|
|
|
len += (bsfw(v_word) >> 3); |
16942
|
|
|
|
|
|
|
else |
16943
|
|
|
|
|
|
|
len += (WORDBITS - 1 - bsrw(v_word)) >> 3; |
16944
|
|
|
|
|
|
|
return len; |
16945
|
|
|
|
|
|
|
} |
16946
|
|
|
|
|
|
|
|
16947
|
|
|
|
|
|
|
#endif |
16948
|
|
|
|
|
|
|
|
16949
|
|
|
|
|
|
|
|
16950
|
|
|
|
|
|
|
#define HT_MATCHFINDER_HASH_ORDER 15 |
16951
|
|
|
|
|
|
|
#define HT_MATCHFINDER_BUCKET_SIZE 2 |
16952
|
|
|
|
|
|
|
|
16953
|
|
|
|
|
|
|
#define HT_MATCHFINDER_MIN_MATCH_LEN 4 |
16954
|
|
|
|
|
|
|
|
16955
|
|
|
|
|
|
|
#define HT_MATCHFINDER_REQUIRED_NBYTES 5 |
16956
|
|
|
|
|
|
|
|
16957
|
|
|
|
|
|
|
struct MATCHFINDER_ALIGNED ht_matchfinder { |
16958
|
|
|
|
|
|
|
mf_pos_t hash_tab[1UL << HT_MATCHFINDER_HASH_ORDER] |
16959
|
|
|
|
|
|
|
[HT_MATCHFINDER_BUCKET_SIZE]; |
16960
|
|
|
|
|
|
|
}; |
16961
|
|
|
|
|
|
|
|
16962
|
|
|
|
|
|
|
static forceinline void |
16963
|
|
|
|
|
|
|
ht_matchfinder_init(struct ht_matchfinder *mf) |
16964
|
|
|
|
|
|
|
{ |
16965
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(*mf) % MATCHFINDER_SIZE_ALIGNMENT == 0); |
16966
|
|
|
|
|
|
|
|
16967
|
|
|
|
|
|
|
matchfinder_init((mf_pos_t *)mf, sizeof(*mf)); |
16968
|
|
|
|
|
|
|
} |
16969
|
|
|
|
|
|
|
|
16970
|
|
|
|
|
|
|
static forceinline void |
16971
|
|
|
|
|
|
|
ht_matchfinder_slide_window(struct ht_matchfinder *mf) |
16972
|
|
|
|
|
|
|
{ |
16973
|
|
|
|
|
|
|
matchfinder_rebase((mf_pos_t *)mf, sizeof(*mf)); |
16974
|
|
|
|
|
|
|
} |
16975
|
|
|
|
|
|
|
|
16976
|
|
|
|
|
|
|
|
16977
|
|
|
|
|
|
|
static forceinline u32 |
16978
|
|
|
|
|
|
|
ht_matchfinder_longest_match(struct ht_matchfinder * const mf, |
16979
|
|
|
|
|
|
|
const u8 ** const in_base_p, |
16980
|
|
|
|
|
|
|
const u8 * const in_next, |
16981
|
|
|
|
|
|
|
const u32 max_len, |
16982
|
|
|
|
|
|
|
const u32 nice_len, |
16983
|
|
|
|
|
|
|
u32 * const next_hash, |
16984
|
|
|
|
|
|
|
u32 * const offset_ret) |
16985
|
|
|
|
|
|
|
{ |
16986
|
75
|
|
|
|
|
|
u32 best_len = 0; |
16987
|
75
|
|
|
|
|
|
const u8 *best_matchptr = in_next; |
16988
|
75
|
|
|
|
|
|
u32 cur_pos = in_next - *in_base_p; |
16989
|
|
|
|
|
|
|
const u8 *in_base; |
16990
|
|
|
|
|
|
|
mf_pos_t cutoff; |
16991
|
|
|
|
|
|
|
u32 hash; |
16992
|
|
|
|
|
|
|
u32 seq; |
16993
|
|
|
|
|
|
|
mf_pos_t cur_node; |
16994
|
|
|
|
|
|
|
const u8 *matchptr; |
16995
|
|
|
|
|
|
|
#if HT_MATCHFINDER_BUCKET_SIZE > 1 |
16996
|
|
|
|
|
|
|
mf_pos_t to_insert; |
16997
|
|
|
|
|
|
|
u32 len; |
16998
|
|
|
|
|
|
|
#endif |
16999
|
|
|
|
|
|
|
#if HT_MATCHFINDER_BUCKET_SIZE > 2 |
17000
|
|
|
|
|
|
|
int i; |
17001
|
|
|
|
|
|
|
#endif |
17002
|
|
|
|
|
|
|
|
17003
|
|
|
|
|
|
|
|
17004
|
|
|
|
|
|
|
STATIC_ASSERT(HT_MATCHFINDER_MIN_MATCH_LEN == 4); |
17005
|
|
|
|
|
|
|
|
17006
|
75
|
50
|
|
|
|
|
if (cur_pos == MATCHFINDER_WINDOW_SIZE) { |
17007
|
|
|
|
|
|
|
ht_matchfinder_slide_window(mf); |
17008
|
0
|
|
|
|
|
|
*in_base_p += MATCHFINDER_WINDOW_SIZE; |
17009
|
0
|
|
|
|
|
|
cur_pos = 0; |
17010
|
|
|
|
|
|
|
} |
17011
|
75
|
|
|
|
|
|
in_base = *in_base_p; |
17012
|
75
|
|
|
|
|
|
cutoff = cur_pos - MATCHFINDER_WINDOW_SIZE; |
17013
|
|
|
|
|
|
|
|
17014
|
75
|
|
|
|
|
|
hash = *next_hash; |
17015
|
|
|
|
|
|
|
STATIC_ASSERT(HT_MATCHFINDER_REQUIRED_NBYTES == 5); |
17016
|
225
|
|
|
|
|
|
*next_hash = lz_hash(get_unaligned_le32(in_next + 1), |
17017
|
|
|
|
|
|
|
HT_MATCHFINDER_HASH_ORDER); |
17018
|
75
|
|
|
|
|
|
seq = load_u32_unaligned(in_next); |
17019
|
75
|
|
|
|
|
|
prefetchw(&mf->hash_tab[*next_hash]); |
17020
|
|
|
|
|
|
|
#if HT_MATCHFINDER_BUCKET_SIZE == 1 |
17021
|
|
|
|
|
|
|
|
17022
|
|
|
|
|
|
|
cur_node = mf->hash_tab[hash][0]; |
17023
|
|
|
|
|
|
|
mf->hash_tab[hash][0] = cur_pos; |
17024
|
|
|
|
|
|
|
if (cur_node <= cutoff) |
17025
|
|
|
|
|
|
|
goto out; |
17026
|
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
17027
|
|
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq) { |
17028
|
|
|
|
|
|
|
best_len = lz_extend(in_next, matchptr, 4, max_len); |
17029
|
|
|
|
|
|
|
best_matchptr = matchptr; |
17030
|
|
|
|
|
|
|
} |
17031
|
|
|
|
|
|
|
#elif HT_MATCHFINDER_BUCKET_SIZE == 2 |
17032
|
|
|
|
|
|
|
|
17033
|
75
|
|
|
|
|
|
cur_node = mf->hash_tab[hash][0]; |
17034
|
75
|
|
|
|
|
|
mf->hash_tab[hash][0] = cur_pos; |
17035
|
75
|
100
|
|
|
|
|
if (cur_node <= cutoff) |
17036
|
|
|
|
|
|
|
goto out; |
17037
|
21
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
17038
|
|
|
|
|
|
|
|
17039
|
21
|
|
|
|
|
|
to_insert = cur_node; |
17040
|
21
|
|
|
|
|
|
cur_node = mf->hash_tab[hash][1]; |
17041
|
21
|
|
|
|
|
|
mf->hash_tab[hash][1] = to_insert; |
17042
|
|
|
|
|
|
|
|
17043
|
21
|
50
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq) { |
17044
|
21
|
|
|
|
|
|
best_len = lz_extend(in_next, matchptr, 4, max_len); |
17045
|
21
|
|
|
|
|
|
best_matchptr = matchptr; |
17046
|
21
|
100
|
|
|
|
|
if (cur_node <= cutoff || best_len >= nice_len) |
|
|
50
|
|
|
|
|
|
17047
|
|
|
|
|
|
|
goto out; |
17048
|
0
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
17049
|
0
|
0
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq && |
|
|
0
|
|
|
|
|
|
17050
|
0
|
|
|
|
|
|
load_u32_unaligned(matchptr + best_len - 3) == |
17051
|
0
|
|
|
|
|
|
load_u32_unaligned(in_next + best_len - 3)) { |
17052
|
0
|
|
|
|
|
|
len = lz_extend(in_next, matchptr, 4, max_len); |
17053
|
0
|
0
|
|
|
|
|
if (len > best_len) { |
17054
|
0
|
|
|
|
|
|
best_len = len; |
17055
|
0
|
|
|
|
|
|
best_matchptr = matchptr; |
17056
|
|
|
|
|
|
|
} |
17057
|
|
|
|
|
|
|
} |
17058
|
|
|
|
|
|
|
} else { |
17059
|
0
|
0
|
|
|
|
|
if (cur_node <= cutoff) |
17060
|
|
|
|
|
|
|
goto out; |
17061
|
0
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
17062
|
0
|
0
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq) { |
17063
|
0
|
|
|
|
|
|
best_len = lz_extend(in_next, matchptr, 4, max_len); |
17064
|
0
|
|
|
|
|
|
best_matchptr = matchptr; |
17065
|
|
|
|
|
|
|
} |
17066
|
|
|
|
|
|
|
} |
17067
|
|
|
|
|
|
|
#else |
17068
|
|
|
|
|
|
|
|
17069
|
|
|
|
|
|
|
to_insert = cur_pos; |
17070
|
|
|
|
|
|
|
for (i = 0; i < HT_MATCHFINDER_BUCKET_SIZE; i++) { |
17071
|
|
|
|
|
|
|
cur_node = mf->hash_tab[hash][i]; |
17072
|
|
|
|
|
|
|
mf->hash_tab[hash][i] = to_insert; |
17073
|
|
|
|
|
|
|
if (cur_node <= cutoff) |
17074
|
|
|
|
|
|
|
goto out; |
17075
|
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
17076
|
|
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq) { |
17077
|
|
|
|
|
|
|
len = lz_extend(in_next, matchptr, 4, max_len); |
17078
|
|
|
|
|
|
|
if (len > best_len) { |
17079
|
|
|
|
|
|
|
best_len = len; |
17080
|
|
|
|
|
|
|
best_matchptr = matchptr; |
17081
|
|
|
|
|
|
|
if (best_len >= nice_len) |
17082
|
|
|
|
|
|
|
goto out; |
17083
|
|
|
|
|
|
|
} |
17084
|
|
|
|
|
|
|
} |
17085
|
|
|
|
|
|
|
to_insert = cur_node; |
17086
|
|
|
|
|
|
|
} |
17087
|
|
|
|
|
|
|
#endif |
17088
|
|
|
|
|
|
|
out: |
17089
|
75
|
|
|
|
|
|
*offset_ret = in_next - best_matchptr; |
17090
|
75
|
|
|
|
|
|
return best_len; |
17091
|
|
|
|
|
|
|
} |
17092
|
|
|
|
|
|
|
|
17093
|
|
|
|
|
|
|
static forceinline void |
17094
|
|
|
|
|
|
|
ht_matchfinder_skip_bytes(struct ht_matchfinder * const mf, |
17095
|
|
|
|
|
|
|
const u8 ** const in_base_p, |
17096
|
|
|
|
|
|
|
const u8 *in_next, |
17097
|
|
|
|
|
|
|
const u8 * const in_end, |
17098
|
|
|
|
|
|
|
const u32 count, |
17099
|
|
|
|
|
|
|
u32 * const next_hash) |
17100
|
|
|
|
|
|
|
{ |
17101
|
21
|
|
|
|
|
|
s32 cur_pos = in_next - *in_base_p; |
17102
|
|
|
|
|
|
|
u32 hash; |
17103
|
21
|
|
|
|
|
|
u32 remaining = count; |
17104
|
|
|
|
|
|
|
int i; |
17105
|
|
|
|
|
|
|
|
17106
|
21
|
100
|
|
|
|
|
if (unlikely(count + HT_MATCHFINDER_REQUIRED_NBYTES > in_end - in_next)) |
17107
|
|
|
|
|
|
|
return; |
17108
|
|
|
|
|
|
|
|
17109
|
18
|
50
|
|
|
|
|
if (cur_pos + count - 1 >= MATCHFINDER_WINDOW_SIZE) { |
17110
|
|
|
|
|
|
|
ht_matchfinder_slide_window(mf); |
17111
|
0
|
|
|
|
|
|
*in_base_p += MATCHFINDER_WINDOW_SIZE; |
17112
|
0
|
|
|
|
|
|
cur_pos -= MATCHFINDER_WINDOW_SIZE; |
17113
|
|
|
|
|
|
|
} |
17114
|
|
|
|
|
|
|
|
17115
|
18
|
|
|
|
|
|
hash = *next_hash; |
17116
|
|
|
|
|
|
|
do { |
17117
|
9252
|
100
|
|
|
|
|
for (i = HT_MATCHFINDER_BUCKET_SIZE - 1; i > 0; i--) |
17118
|
4626
|
|
|
|
|
|
mf->hash_tab[hash][i] = mf->hash_tab[hash][i - 1]; |
17119
|
4626
|
|
|
|
|
|
mf->hash_tab[hash][0] = cur_pos; |
17120
|
|
|
|
|
|
|
|
17121
|
13878
|
|
|
|
|
|
hash = lz_hash(get_unaligned_le32(++in_next), |
17122
|
|
|
|
|
|
|
HT_MATCHFINDER_HASH_ORDER); |
17123
|
4626
|
|
|
|
|
|
cur_pos++; |
17124
|
4626
|
100
|
|
|
|
|
} while (--remaining); |
17125
|
|
|
|
|
|
|
|
17126
|
18
|
|
|
|
|
|
prefetchw(&mf->hash_tab[hash]); |
17127
|
18
|
|
|
|
|
|
*next_hash = hash; |
17128
|
|
|
|
|
|
|
} |
17129
|
|
|
|
|
|
|
|
17130
|
|
|
|
|
|
|
#endif |
17131
|
|
|
|
|
|
|
|
17132
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
17133
|
|
|
|
|
|
|
/* # include "bt_matchfinder.h" */ |
17134
|
|
|
|
|
|
|
|
17135
|
|
|
|
|
|
|
|
17136
|
|
|
|
|
|
|
#ifndef LIB_BT_MATCHFINDER_H |
17137
|
|
|
|
|
|
|
#define LIB_BT_MATCHFINDER_H |
17138
|
|
|
|
|
|
|
|
17139
|
|
|
|
|
|
|
/* #include "matchfinder_common.h" */ |
17140
|
|
|
|
|
|
|
|
17141
|
|
|
|
|
|
|
|
17142
|
|
|
|
|
|
|
#ifndef LIB_MATCHFINDER_COMMON_H |
17143
|
|
|
|
|
|
|
#define LIB_MATCHFINDER_COMMON_H |
17144
|
|
|
|
|
|
|
|
17145
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
17146
|
|
|
|
|
|
|
|
17147
|
|
|
|
|
|
|
|
17148
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
17149
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
17150
|
|
|
|
|
|
|
|
17151
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
17152
|
|
|
|
|
|
|
|
17153
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
17154
|
|
|
|
|
|
|
#endif |
17155
|
|
|
|
|
|
|
|
17156
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
17157
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
17158
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
17159
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
17160
|
|
|
|
|
|
|
#else |
17161
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
17162
|
|
|
|
|
|
|
#endif |
17163
|
|
|
|
|
|
|
|
17164
|
|
|
|
|
|
|
|
17165
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
17166
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
17167
|
|
|
|
|
|
|
#else |
17168
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
17169
|
|
|
|
|
|
|
#endif |
17170
|
|
|
|
|
|
|
|
17171
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
17172
|
|
|
|
|
|
|
|
17173
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
17174
|
|
|
|
|
|
|
|
17175
|
|
|
|
|
|
|
|
17176
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
17177
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
17178
|
|
|
|
|
|
|
|
17179
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
17180
|
|
|
|
|
|
|
|
17181
|
|
|
|
|
|
|
|
17182
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
17183
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
17184
|
|
|
|
|
|
|
|
17185
|
|
|
|
|
|
|
#include |
17186
|
|
|
|
|
|
|
#include |
17187
|
|
|
|
|
|
|
|
17188
|
|
|
|
|
|
|
#ifdef __cplusplus |
17189
|
|
|
|
|
|
|
extern "C" { |
17190
|
|
|
|
|
|
|
#endif |
17191
|
|
|
|
|
|
|
|
17192
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
17193
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
17194
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
17195
|
|
|
|
|
|
|
|
17196
|
|
|
|
|
|
|
|
17197
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
17198
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
17199
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
17200
|
|
|
|
|
|
|
# else |
17201
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
17202
|
|
|
|
|
|
|
# endif |
17203
|
|
|
|
|
|
|
#endif |
17204
|
|
|
|
|
|
|
|
17205
|
|
|
|
|
|
|
|
17206
|
|
|
|
|
|
|
|
17207
|
|
|
|
|
|
|
|
17208
|
|
|
|
|
|
|
|
17209
|
|
|
|
|
|
|
struct libdeflate_compressor; |
17210
|
|
|
|
|
|
|
struct libdeflate_options; |
17211
|
|
|
|
|
|
|
|
17212
|
|
|
|
|
|
|
|
17213
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
17214
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
17215
|
|
|
|
|
|
|
|
17216
|
|
|
|
|
|
|
|
17217
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
17218
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
17219
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
17220
|
|
|
|
|
|
|
|
17221
|
|
|
|
|
|
|
|
17222
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17223
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
17224
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17225
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
17226
|
|
|
|
|
|
|
|
17227
|
|
|
|
|
|
|
|
17228
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17229
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
17230
|
|
|
|
|
|
|
size_t in_nbytes); |
17231
|
|
|
|
|
|
|
|
17232
|
|
|
|
|
|
|
|
17233
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17234
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
17235
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17236
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
17237
|
|
|
|
|
|
|
|
17238
|
|
|
|
|
|
|
|
17239
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17240
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
17241
|
|
|
|
|
|
|
size_t in_nbytes); |
17242
|
|
|
|
|
|
|
|
17243
|
|
|
|
|
|
|
|
17244
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17245
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
17246
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17247
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
17248
|
|
|
|
|
|
|
|
17249
|
|
|
|
|
|
|
|
17250
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17251
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
17252
|
|
|
|
|
|
|
size_t in_nbytes); |
17253
|
|
|
|
|
|
|
|
17254
|
|
|
|
|
|
|
|
17255
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
17256
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
17257
|
|
|
|
|
|
|
|
17258
|
|
|
|
|
|
|
|
17259
|
|
|
|
|
|
|
|
17260
|
|
|
|
|
|
|
|
17261
|
|
|
|
|
|
|
|
17262
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
17263
|
|
|
|
|
|
|
struct libdeflate_options; |
17264
|
|
|
|
|
|
|
|
17265
|
|
|
|
|
|
|
|
17266
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
17267
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
17268
|
|
|
|
|
|
|
|
17269
|
|
|
|
|
|
|
|
17270
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
17271
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
17272
|
|
|
|
|
|
|
|
17273
|
|
|
|
|
|
|
|
17274
|
|
|
|
|
|
|
enum libdeflate_result { |
17275
|
|
|
|
|
|
|
|
17276
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
17277
|
|
|
|
|
|
|
|
17278
|
|
|
|
|
|
|
|
17279
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
17280
|
|
|
|
|
|
|
|
17281
|
|
|
|
|
|
|
|
17282
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
17283
|
|
|
|
|
|
|
|
17284
|
|
|
|
|
|
|
|
17285
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
17286
|
|
|
|
|
|
|
}; |
17287
|
|
|
|
|
|
|
|
17288
|
|
|
|
|
|
|
|
17289
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17290
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
17291
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17292
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17293
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17294
|
|
|
|
|
|
|
|
17295
|
|
|
|
|
|
|
|
17296
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17297
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
17298
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17299
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17300
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
17301
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17302
|
|
|
|
|
|
|
|
17303
|
|
|
|
|
|
|
|
17304
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17305
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
17306
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17307
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17308
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17309
|
|
|
|
|
|
|
|
17310
|
|
|
|
|
|
|
|
17311
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17312
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
17313
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17314
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17315
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
17316
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17317
|
|
|
|
|
|
|
|
17318
|
|
|
|
|
|
|
|
17319
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17320
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
17321
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17322
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17323
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17324
|
|
|
|
|
|
|
|
17325
|
|
|
|
|
|
|
|
17326
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17327
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
17328
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17329
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17330
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
17331
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17332
|
|
|
|
|
|
|
|
17333
|
|
|
|
|
|
|
|
17334
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
17335
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
17336
|
|
|
|
|
|
|
|
17337
|
|
|
|
|
|
|
|
17338
|
|
|
|
|
|
|
|
17339
|
|
|
|
|
|
|
|
17340
|
|
|
|
|
|
|
|
17341
|
|
|
|
|
|
|
|
17342
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
17343
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
17344
|
|
|
|
|
|
|
|
17345
|
|
|
|
|
|
|
|
17346
|
|
|
|
|
|
|
|
17347
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
17348
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
17349
|
|
|
|
|
|
|
|
17350
|
|
|
|
|
|
|
|
17351
|
|
|
|
|
|
|
|
17352
|
|
|
|
|
|
|
|
17353
|
|
|
|
|
|
|
|
17354
|
|
|
|
|
|
|
|
17355
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
17356
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
17357
|
|
|
|
|
|
|
void (*free_func)(void *)); |
17358
|
|
|
|
|
|
|
|
17359
|
|
|
|
|
|
|
|
17360
|
|
|
|
|
|
|
struct libdeflate_options { |
17361
|
|
|
|
|
|
|
|
17362
|
|
|
|
|
|
|
|
17363
|
|
|
|
|
|
|
size_t sizeof_options; |
17364
|
|
|
|
|
|
|
|
17365
|
|
|
|
|
|
|
|
17366
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
17367
|
|
|
|
|
|
|
void (*free_func)(void *); |
17368
|
|
|
|
|
|
|
}; |
17369
|
|
|
|
|
|
|
|
17370
|
|
|
|
|
|
|
#ifdef __cplusplus |
17371
|
|
|
|
|
|
|
} |
17372
|
|
|
|
|
|
|
#endif |
17373
|
|
|
|
|
|
|
|
17374
|
|
|
|
|
|
|
#endif |
17375
|
|
|
|
|
|
|
|
17376
|
|
|
|
|
|
|
|
17377
|
|
|
|
|
|
|
#include |
17378
|
|
|
|
|
|
|
#include |
17379
|
|
|
|
|
|
|
#include |
17380
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17381
|
|
|
|
|
|
|
# include |
17382
|
|
|
|
|
|
|
# include |
17383
|
|
|
|
|
|
|
|
17384
|
|
|
|
|
|
|
|
17385
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
17386
|
|
|
|
|
|
|
|
17387
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
17388
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
17389
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
17390
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
17391
|
|
|
|
|
|
|
|
17392
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
17393
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
17394
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
17395
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
17396
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
17397
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
17398
|
|
|
|
|
|
|
#endif |
17399
|
|
|
|
|
|
|
#ifndef FREESTANDING |
17400
|
|
|
|
|
|
|
# include |
17401
|
|
|
|
|
|
|
#endif |
17402
|
|
|
|
|
|
|
|
17403
|
|
|
|
|
|
|
|
17404
|
|
|
|
|
|
|
|
17405
|
|
|
|
|
|
|
|
17406
|
|
|
|
|
|
|
|
17407
|
|
|
|
|
|
|
|
17408
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
17409
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
17410
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
17411
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
17412
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17413
|
|
|
|
|
|
|
# if defined(_M_X64) |
17414
|
|
|
|
|
|
|
# define ARCH_X86_64 |
17415
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
17416
|
|
|
|
|
|
|
# define ARCH_X86_32 |
17417
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
17418
|
|
|
|
|
|
|
# define ARCH_ARM64 |
17419
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
17420
|
|
|
|
|
|
|
# define ARCH_ARM32 |
17421
|
|
|
|
|
|
|
# endif |
17422
|
|
|
|
|
|
|
#else |
17423
|
|
|
|
|
|
|
# if defined(__x86_64__) |
17424
|
|
|
|
|
|
|
# define ARCH_X86_64 |
17425
|
|
|
|
|
|
|
# elif defined(__i386__) |
17426
|
|
|
|
|
|
|
# define ARCH_X86_32 |
17427
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
17428
|
|
|
|
|
|
|
# define ARCH_ARM64 |
17429
|
|
|
|
|
|
|
# elif defined(__arm__) |
17430
|
|
|
|
|
|
|
# define ARCH_ARM32 |
17431
|
|
|
|
|
|
|
# endif |
17432
|
|
|
|
|
|
|
#endif |
17433
|
|
|
|
|
|
|
|
17434
|
|
|
|
|
|
|
|
17435
|
|
|
|
|
|
|
|
17436
|
|
|
|
|
|
|
|
17437
|
|
|
|
|
|
|
|
17438
|
|
|
|
|
|
|
|
17439
|
|
|
|
|
|
|
typedef uint8_t u8; |
17440
|
|
|
|
|
|
|
typedef uint16_t u16; |
17441
|
|
|
|
|
|
|
typedef uint32_t u32; |
17442
|
|
|
|
|
|
|
typedef uint64_t u64; |
17443
|
|
|
|
|
|
|
typedef int8_t s8; |
17444
|
|
|
|
|
|
|
typedef int16_t s16; |
17445
|
|
|
|
|
|
|
typedef int32_t s32; |
17446
|
|
|
|
|
|
|
typedef int64_t s64; |
17447
|
|
|
|
|
|
|
|
17448
|
|
|
|
|
|
|
|
17449
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17450
|
|
|
|
|
|
|
# ifdef _WIN64 |
17451
|
|
|
|
|
|
|
typedef long long ssize_t; |
17452
|
|
|
|
|
|
|
# else |
17453
|
|
|
|
|
|
|
typedef long ssize_t; |
17454
|
|
|
|
|
|
|
# endif |
17455
|
|
|
|
|
|
|
#endif |
17456
|
|
|
|
|
|
|
|
17457
|
|
|
|
|
|
|
|
17458
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
17459
|
|
|
|
|
|
|
|
17460
|
|
|
|
|
|
|
|
17461
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
17462
|
|
|
|
|
|
|
|
17463
|
|
|
|
|
|
|
|
17464
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
17465
|
|
|
|
|
|
|
|
17466
|
|
|
|
|
|
|
|
17467
|
|
|
|
|
|
|
|
17468
|
|
|
|
|
|
|
|
17469
|
|
|
|
|
|
|
|
17470
|
|
|
|
|
|
|
|
17471
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
17472
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
17473
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
17474
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
17475
|
|
|
|
|
|
|
#else |
17476
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
17477
|
|
|
|
|
|
|
#endif |
17478
|
|
|
|
|
|
|
#ifdef __clang__ |
17479
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
17480
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
17481
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
17482
|
|
|
|
|
|
|
# else |
17483
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
17484
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
17485
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
17486
|
|
|
|
|
|
|
# endif |
17487
|
|
|
|
|
|
|
#else |
17488
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
17489
|
|
|
|
|
|
|
#endif |
17490
|
|
|
|
|
|
|
|
17491
|
|
|
|
|
|
|
|
17492
|
|
|
|
|
|
|
#ifndef __has_attribute |
17493
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
17494
|
|
|
|
|
|
|
#endif |
17495
|
|
|
|
|
|
|
#ifndef __has_builtin |
17496
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
17497
|
|
|
|
|
|
|
#endif |
17498
|
|
|
|
|
|
|
|
17499
|
|
|
|
|
|
|
|
17500
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17501
|
|
|
|
|
|
|
# define inline __inline |
17502
|
|
|
|
|
|
|
#endif |
17503
|
|
|
|
|
|
|
|
17504
|
|
|
|
|
|
|
|
17505
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
17506
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
17507
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17508
|
|
|
|
|
|
|
# define forceinline __forceinline |
17509
|
|
|
|
|
|
|
#else |
17510
|
|
|
|
|
|
|
# define forceinline inline |
17511
|
|
|
|
|
|
|
#endif |
17512
|
|
|
|
|
|
|
|
17513
|
|
|
|
|
|
|
|
17514
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
17515
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
17516
|
|
|
|
|
|
|
#else |
17517
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
17518
|
|
|
|
|
|
|
#endif |
17519
|
|
|
|
|
|
|
|
17520
|
|
|
|
|
|
|
|
17521
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
17522
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
17523
|
|
|
|
|
|
|
# define restrict __restrict__ |
17524
|
|
|
|
|
|
|
# else |
17525
|
|
|
|
|
|
|
# define restrict |
17526
|
|
|
|
|
|
|
# endif |
17527
|
|
|
|
|
|
|
#endif |
17528
|
|
|
|
|
|
|
|
17529
|
|
|
|
|
|
|
|
17530
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
17531
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
17532
|
|
|
|
|
|
|
#else |
17533
|
|
|
|
|
|
|
# define likely(expr) (expr) |
17534
|
|
|
|
|
|
|
#endif |
17535
|
|
|
|
|
|
|
|
17536
|
|
|
|
|
|
|
|
17537
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
17538
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
17539
|
|
|
|
|
|
|
#else |
17540
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
17541
|
|
|
|
|
|
|
#endif |
17542
|
|
|
|
|
|
|
|
17543
|
|
|
|
|
|
|
|
17544
|
|
|
|
|
|
|
#undef prefetchr |
17545
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
17546
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
17547
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17548
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
17549
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
17550
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
17551
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
17552
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
17553
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
17554
|
|
|
|
|
|
|
# endif |
17555
|
|
|
|
|
|
|
#endif |
17556
|
|
|
|
|
|
|
#ifndef prefetchr |
17557
|
|
|
|
|
|
|
# define prefetchr(addr) |
17558
|
|
|
|
|
|
|
#endif |
17559
|
|
|
|
|
|
|
|
17560
|
|
|
|
|
|
|
|
17561
|
|
|
|
|
|
|
#undef prefetchw |
17562
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
17563
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
17564
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17565
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
17566
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
17567
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
17568
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
17569
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
17570
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
17571
|
|
|
|
|
|
|
# endif |
17572
|
|
|
|
|
|
|
#endif |
17573
|
|
|
|
|
|
|
#ifndef prefetchw |
17574
|
|
|
|
|
|
|
# define prefetchw(addr) |
17575
|
|
|
|
|
|
|
#endif |
17576
|
|
|
|
|
|
|
|
17577
|
|
|
|
|
|
|
|
17578
|
|
|
|
|
|
|
#undef _aligned_attribute |
17579
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
17580
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
17581
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17582
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
17583
|
|
|
|
|
|
|
#endif |
17584
|
|
|
|
|
|
|
|
17585
|
|
|
|
|
|
|
|
17586
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
17587
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
17588
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
17589
|
|
|
|
|
|
|
#else |
17590
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
17591
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
17592
|
|
|
|
|
|
|
#endif |
17593
|
|
|
|
|
|
|
|
17594
|
|
|
|
|
|
|
|
17595
|
|
|
|
|
|
|
|
17596
|
|
|
|
|
|
|
|
17597
|
|
|
|
|
|
|
|
17598
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
17599
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
17600
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
17601
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
17602
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
17603
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
17604
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
17605
|
|
|
|
|
|
|
|
17606
|
|
|
|
|
|
|
|
17607
|
|
|
|
|
|
|
|
17608
|
|
|
|
|
|
|
|
17609
|
|
|
|
|
|
|
|
17610
|
|
|
|
|
|
|
|
17611
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
17612
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
17613
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17614
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
17615
|
|
|
|
|
|
|
#else |
17616
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
17617
|
|
|
|
|
|
|
{ |
17618
|
|
|
|
|
|
|
union { |
17619
|
|
|
|
|
|
|
u32 w; |
17620
|
|
|
|
|
|
|
u8 b; |
17621
|
|
|
|
|
|
|
} u; |
17622
|
|
|
|
|
|
|
|
17623
|
|
|
|
|
|
|
u.w = 1; |
17624
|
|
|
|
|
|
|
return u.b; |
17625
|
|
|
|
|
|
|
} |
17626
|
|
|
|
|
|
|
#endif |
17627
|
|
|
|
|
|
|
|
17628
|
|
|
|
|
|
|
|
17629
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
17630
|
|
|
|
|
|
|
{ |
17631
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
17632
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
17633
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17634
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
17635
|
|
|
|
|
|
|
#else |
17636
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
17637
|
|
|
|
|
|
|
#endif |
17638
|
|
|
|
|
|
|
} |
17639
|
|
|
|
|
|
|
|
17640
|
|
|
|
|
|
|
|
17641
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
17642
|
|
|
|
|
|
|
{ |
17643
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
17644
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
17645
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17646
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
17647
|
|
|
|
|
|
|
#else |
17648
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
17649
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
17650
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
17651
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
17652
|
|
|
|
|
|
|
#endif |
17653
|
|
|
|
|
|
|
} |
17654
|
|
|
|
|
|
|
|
17655
|
|
|
|
|
|
|
|
17656
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
17657
|
|
|
|
|
|
|
{ |
17658
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
17659
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
17660
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17661
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
17662
|
|
|
|
|
|
|
#else |
17663
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
17664
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
17665
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
17666
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
17667
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
17668
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
17669
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
17670
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
17671
|
|
|
|
|
|
|
#endif |
17672
|
|
|
|
|
|
|
} |
17673
|
|
|
|
|
|
|
|
17674
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
17675
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
17676
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
17677
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
17678
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
17679
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
17680
|
|
|
|
|
|
|
|
17681
|
|
|
|
|
|
|
|
17682
|
|
|
|
|
|
|
|
17683
|
|
|
|
|
|
|
|
17684
|
|
|
|
|
|
|
|
17685
|
|
|
|
|
|
|
|
17686
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
17687
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
17688
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
17689
|
|
|
|
|
|
|
defined(__wasm__)) |
17690
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
17691
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17692
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
17693
|
|
|
|
|
|
|
#else |
17694
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
17695
|
|
|
|
|
|
|
#endif |
17696
|
|
|
|
|
|
|
|
17697
|
|
|
|
|
|
|
|
17698
|
|
|
|
|
|
|
|
17699
|
|
|
|
|
|
|
#ifdef FREESTANDING |
17700
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
17701
|
|
|
|
|
|
|
#else |
17702
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
17703
|
|
|
|
|
|
|
#endif |
17704
|
|
|
|
|
|
|
|
17705
|
|
|
|
|
|
|
|
17706
|
|
|
|
|
|
|
|
17707
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
17708
|
|
|
|
|
|
|
static forceinline type \ |
17709
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
17710
|
|
|
|
|
|
|
{ \ |
17711
|
|
|
|
|
|
|
type v; \ |
17712
|
|
|
|
|
|
|
\ |
17713
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
17714
|
|
|
|
|
|
|
return v; \ |
17715
|
|
|
|
|
|
|
} \ |
17716
|
|
|
|
|
|
|
\ |
17717
|
|
|
|
|
|
|
static forceinline void \ |
17718
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
17719
|
|
|
|
|
|
|
{ \ |
17720
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
17721
|
|
|
|
|
|
|
} |
17722
|
|
|
|
|
|
|
|
17723
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
17724
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
17725
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
17726
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
17727
|
|
|
|
|
|
|
|
17728
|
|
|
|
|
|
|
#undef MEMCOPY |
17729
|
|
|
|
|
|
|
|
17730
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
17731
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
17732
|
|
|
|
|
|
|
|
17733
|
|
|
|
|
|
|
|
17734
|
|
|
|
|
|
|
|
17735
|
|
|
|
|
|
|
static forceinline u16 |
17736
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
17737
|
|
|
|
|
|
|
{ |
17738
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17739
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
17740
|
|
|
|
|
|
|
else |
17741
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
17742
|
|
|
|
|
|
|
} |
17743
|
|
|
|
|
|
|
|
17744
|
|
|
|
|
|
|
static forceinline u16 |
17745
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
17746
|
|
|
|
|
|
|
{ |
17747
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17748
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
17749
|
|
|
|
|
|
|
else |
17750
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
17751
|
|
|
|
|
|
|
} |
17752
|
|
|
|
|
|
|
|
17753
|
|
|
|
|
|
|
static forceinline u32 |
17754
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
17755
|
|
|
|
|
|
|
{ |
17756
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17757
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
17758
|
|
|
|
|
|
|
else |
17759
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
17760
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
17761
|
|
|
|
|
|
|
} |
17762
|
|
|
|
|
|
|
|
17763
|
|
|
|
|
|
|
static forceinline u32 |
17764
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
17765
|
|
|
|
|
|
|
{ |
17766
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17767
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
17768
|
|
|
|
|
|
|
else |
17769
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
17770
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
17771
|
|
|
|
|
|
|
} |
17772
|
|
|
|
|
|
|
|
17773
|
|
|
|
|
|
|
static forceinline u64 |
17774
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
17775
|
|
|
|
|
|
|
{ |
17776
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17777
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
17778
|
|
|
|
|
|
|
else |
17779
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
17780
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
17781
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
17782
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
17783
|
|
|
|
|
|
|
} |
17784
|
|
|
|
|
|
|
|
17785
|
|
|
|
|
|
|
static forceinline machine_word_t |
17786
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
17787
|
|
|
|
|
|
|
{ |
17788
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
17789
|
|
|
|
|
|
|
if (WORDBITS == 32) |
17790
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
17791
|
|
|
|
|
|
|
else |
17792
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
17793
|
|
|
|
|
|
|
} |
17794
|
|
|
|
|
|
|
|
17795
|
|
|
|
|
|
|
|
17796
|
|
|
|
|
|
|
|
17797
|
|
|
|
|
|
|
static forceinline void |
17798
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
17799
|
|
|
|
|
|
|
{ |
17800
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17801
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
17802
|
|
|
|
|
|
|
} else { |
17803
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
17804
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
17805
|
|
|
|
|
|
|
} |
17806
|
|
|
|
|
|
|
} |
17807
|
|
|
|
|
|
|
|
17808
|
|
|
|
|
|
|
static forceinline void |
17809
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
17810
|
|
|
|
|
|
|
{ |
17811
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17812
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
17813
|
|
|
|
|
|
|
} else { |
17814
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
17815
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
17816
|
|
|
|
|
|
|
} |
17817
|
|
|
|
|
|
|
} |
17818
|
|
|
|
|
|
|
|
17819
|
|
|
|
|
|
|
static forceinline void |
17820
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
17821
|
|
|
|
|
|
|
{ |
17822
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17823
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
17824
|
|
|
|
|
|
|
} else { |
17825
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
17826
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
17827
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
17828
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
17829
|
|
|
|
|
|
|
} |
17830
|
|
|
|
|
|
|
} |
17831
|
|
|
|
|
|
|
|
17832
|
|
|
|
|
|
|
static forceinline void |
17833
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
17834
|
|
|
|
|
|
|
{ |
17835
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17836
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
17837
|
|
|
|
|
|
|
} else { |
17838
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
17839
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
17840
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
17841
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
17842
|
|
|
|
|
|
|
} |
17843
|
|
|
|
|
|
|
} |
17844
|
|
|
|
|
|
|
|
17845
|
|
|
|
|
|
|
static forceinline void |
17846
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
17847
|
|
|
|
|
|
|
{ |
17848
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17849
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
17850
|
|
|
|
|
|
|
} else { |
17851
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
17852
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
17853
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
17854
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
17855
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
17856
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
17857
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
17858
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
17859
|
|
|
|
|
|
|
} |
17860
|
|
|
|
|
|
|
} |
17861
|
|
|
|
|
|
|
|
17862
|
|
|
|
|
|
|
static forceinline void |
17863
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
17864
|
|
|
|
|
|
|
{ |
17865
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
17866
|
|
|
|
|
|
|
if (WORDBITS == 32) |
17867
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
17868
|
|
|
|
|
|
|
else |
17869
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
17870
|
|
|
|
|
|
|
} |
17871
|
|
|
|
|
|
|
|
17872
|
|
|
|
|
|
|
|
17873
|
|
|
|
|
|
|
|
17874
|
|
|
|
|
|
|
|
17875
|
|
|
|
|
|
|
|
17876
|
|
|
|
|
|
|
|
17877
|
|
|
|
|
|
|
|
17878
|
|
|
|
|
|
|
static forceinline unsigned |
17879
|
|
|
|
|
|
|
bsr32(u32 v) |
17880
|
|
|
|
|
|
|
{ |
17881
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
17882
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
17883
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17884
|
|
|
|
|
|
|
unsigned long i; |
17885
|
|
|
|
|
|
|
|
17886
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
17887
|
|
|
|
|
|
|
return i; |
17888
|
|
|
|
|
|
|
#else |
17889
|
|
|
|
|
|
|
unsigned i = 0; |
17890
|
|
|
|
|
|
|
|
17891
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
17892
|
|
|
|
|
|
|
i++; |
17893
|
|
|
|
|
|
|
return i; |
17894
|
|
|
|
|
|
|
#endif |
17895
|
|
|
|
|
|
|
} |
17896
|
|
|
|
|
|
|
|
17897
|
|
|
|
|
|
|
static forceinline unsigned |
17898
|
|
|
|
|
|
|
bsr64(u64 v) |
17899
|
|
|
|
|
|
|
{ |
17900
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
17901
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
17902
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
17903
|
|
|
|
|
|
|
unsigned long i; |
17904
|
|
|
|
|
|
|
|
17905
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
17906
|
|
|
|
|
|
|
return i; |
17907
|
|
|
|
|
|
|
#else |
17908
|
|
|
|
|
|
|
unsigned i = 0; |
17909
|
|
|
|
|
|
|
|
17910
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
17911
|
|
|
|
|
|
|
i++; |
17912
|
|
|
|
|
|
|
return i; |
17913
|
|
|
|
|
|
|
#endif |
17914
|
|
|
|
|
|
|
} |
17915
|
|
|
|
|
|
|
|
17916
|
|
|
|
|
|
|
static forceinline unsigned |
17917
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
17918
|
|
|
|
|
|
|
{ |
17919
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
17920
|
|
|
|
|
|
|
if (WORDBITS == 32) |
17921
|
|
|
|
|
|
|
return bsr32(v); |
17922
|
|
|
|
|
|
|
else |
17923
|
|
|
|
|
|
|
return bsr64(v); |
17924
|
|
|
|
|
|
|
} |
17925
|
|
|
|
|
|
|
|
17926
|
|
|
|
|
|
|
|
17927
|
|
|
|
|
|
|
|
17928
|
|
|
|
|
|
|
static forceinline unsigned |
17929
|
|
|
|
|
|
|
bsf32(u32 v) |
17930
|
|
|
|
|
|
|
{ |
17931
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
17932
|
|
|
|
|
|
|
return __builtin_ctz(v); |
17933
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17934
|
|
|
|
|
|
|
unsigned long i; |
17935
|
|
|
|
|
|
|
|
17936
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
17937
|
|
|
|
|
|
|
return i; |
17938
|
|
|
|
|
|
|
#else |
17939
|
|
|
|
|
|
|
unsigned i = 0; |
17940
|
|
|
|
|
|
|
|
17941
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
17942
|
|
|
|
|
|
|
i++; |
17943
|
|
|
|
|
|
|
return i; |
17944
|
|
|
|
|
|
|
#endif |
17945
|
|
|
|
|
|
|
} |
17946
|
|
|
|
|
|
|
|
17947
|
|
|
|
|
|
|
static forceinline unsigned |
17948
|
|
|
|
|
|
|
bsf64(u64 v) |
17949
|
|
|
|
|
|
|
{ |
17950
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
17951
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
17952
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
17953
|
|
|
|
|
|
|
unsigned long i; |
17954
|
|
|
|
|
|
|
|
17955
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
17956
|
|
|
|
|
|
|
return i; |
17957
|
|
|
|
|
|
|
#else |
17958
|
|
|
|
|
|
|
unsigned i = 0; |
17959
|
|
|
|
|
|
|
|
17960
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
17961
|
|
|
|
|
|
|
i++; |
17962
|
|
|
|
|
|
|
return i; |
17963
|
|
|
|
|
|
|
#endif |
17964
|
|
|
|
|
|
|
} |
17965
|
|
|
|
|
|
|
|
17966
|
|
|
|
|
|
|
static forceinline unsigned |
17967
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
17968
|
|
|
|
|
|
|
{ |
17969
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
17970
|
|
|
|
|
|
|
if (WORDBITS == 32) |
17971
|
|
|
|
|
|
|
return bsf32(v); |
17972
|
|
|
|
|
|
|
else |
17973
|
|
|
|
|
|
|
return bsf64(v); |
17974
|
|
|
|
|
|
|
} |
17975
|
|
|
|
|
|
|
|
17976
|
|
|
|
|
|
|
|
17977
|
|
|
|
|
|
|
#undef rbit32 |
17978
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
17979
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
17980
|
|
|
|
|
|
|
static forceinline u32 |
17981
|
|
|
|
|
|
|
rbit32(u32 v) |
17982
|
|
|
|
|
|
|
{ |
17983
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
17984
|
|
|
|
|
|
|
return v; |
17985
|
|
|
|
|
|
|
} |
17986
|
|
|
|
|
|
|
#define rbit32 rbit32 |
17987
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
17988
|
|
|
|
|
|
|
static forceinline u32 |
17989
|
|
|
|
|
|
|
rbit32(u32 v) |
17990
|
|
|
|
|
|
|
{ |
17991
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
17992
|
|
|
|
|
|
|
return v; |
17993
|
|
|
|
|
|
|
} |
17994
|
|
|
|
|
|
|
#define rbit32 rbit32 |
17995
|
|
|
|
|
|
|
#endif |
17996
|
|
|
|
|
|
|
|
17997
|
|
|
|
|
|
|
#endif |
17998
|
|
|
|
|
|
|
|
17999
|
|
|
|
|
|
|
|
18000
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
18001
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
18002
|
|
|
|
|
|
|
|
18003
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
18004
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
18005
|
|
|
|
|
|
|
|
18006
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
18007
|
|
|
|
|
|
|
size_t alignment, size_t size); |
18008
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
18009
|
|
|
|
|
|
|
|
18010
|
|
|
|
|
|
|
#ifdef FREESTANDING |
18011
|
|
|
|
|
|
|
|
18012
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
18013
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
18014
|
|
|
|
|
|
|
|
18015
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
18016
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
18017
|
|
|
|
|
|
|
|
18018
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
18019
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
18020
|
|
|
|
|
|
|
|
18021
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
18022
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
18023
|
|
|
|
|
|
|
|
18024
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
18025
|
|
|
|
|
|
|
#else |
18026
|
|
|
|
|
|
|
#include |
18027
|
|
|
|
|
|
|
#endif |
18028
|
|
|
|
|
|
|
|
18029
|
|
|
|
|
|
|
|
18030
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
18031
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
18032
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
18033
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
18034
|
|
|
|
|
|
|
#else |
18035
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
18036
|
|
|
|
|
|
|
#endif |
18037
|
|
|
|
|
|
|
|
18038
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
18039
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
18040
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
18041
|
|
|
|
|
|
|
|
18042
|
|
|
|
|
|
|
#endif |
18043
|
|
|
|
|
|
|
|
18044
|
|
|
|
|
|
|
|
18045
|
|
|
|
|
|
|
#ifndef MATCHFINDER_WINDOW_ORDER |
18046
|
|
|
|
|
|
|
# error "MATCHFINDER_WINDOW_ORDER must be defined!" |
18047
|
|
|
|
|
|
|
#endif |
18048
|
|
|
|
|
|
|
|
18049
|
|
|
|
|
|
|
|
18050
|
|
|
|
|
|
|
static forceinline u32 |
18051
|
|
|
|
|
|
|
loaded_u32_to_u24(u32 v) |
18052
|
|
|
|
|
|
|
{ |
18053
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
18054
|
|
|
|
|
|
|
return v & 0xFFFFFF; |
18055
|
|
|
|
|
|
|
else |
18056
|
|
|
|
|
|
|
return v >> 8; |
18057
|
|
|
|
|
|
|
} |
18058
|
|
|
|
|
|
|
|
18059
|
|
|
|
|
|
|
|
18060
|
|
|
|
|
|
|
static forceinline u32 |
18061
|
|
|
|
|
|
|
load_u24_unaligned(const u8 *p) |
18062
|
|
|
|
|
|
|
{ |
18063
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
18064
|
|
|
|
|
|
|
return loaded_u32_to_u24(load_u32_unaligned(p)); |
18065
|
|
|
|
|
|
|
#else |
18066
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
18067
|
|
|
|
|
|
|
return ((u32)p[0] << 0) | ((u32)p[1] << 8) | ((u32)p[2] << 16); |
18068
|
|
|
|
|
|
|
else |
18069
|
|
|
|
|
|
|
return ((u32)p[2] << 0) | ((u32)p[1] << 8) | ((u32)p[0] << 16); |
18070
|
|
|
|
|
|
|
#endif |
18071
|
|
|
|
|
|
|
} |
18072
|
|
|
|
|
|
|
|
18073
|
|
|
|
|
|
|
#define MATCHFINDER_WINDOW_SIZE (1UL << MATCHFINDER_WINDOW_ORDER) |
18074
|
|
|
|
|
|
|
|
18075
|
|
|
|
|
|
|
typedef s16 mf_pos_t; |
18076
|
|
|
|
|
|
|
|
18077
|
|
|
|
|
|
|
#define MATCHFINDER_INITVAL ((mf_pos_t)-MATCHFINDER_WINDOW_SIZE) |
18078
|
|
|
|
|
|
|
|
18079
|
|
|
|
|
|
|
|
18080
|
|
|
|
|
|
|
#define MATCHFINDER_MEM_ALIGNMENT 32 |
18081
|
|
|
|
|
|
|
#define MATCHFINDER_SIZE_ALIGNMENT 128 |
18082
|
|
|
|
|
|
|
|
18083
|
|
|
|
|
|
|
#undef matchfinder_init |
18084
|
|
|
|
|
|
|
#undef matchfinder_rebase |
18085
|
|
|
|
|
|
|
#ifdef _aligned_attribute |
18086
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED _aligned_attribute(MATCHFINDER_MEM_ALIGNMENT) |
18087
|
|
|
|
|
|
|
# if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
18088
|
|
|
|
|
|
|
/* # include "arm/matchfinder_impl.h" */ |
18089
|
|
|
|
|
|
|
|
18090
|
|
|
|
|
|
|
|
18091
|
|
|
|
|
|
|
#ifndef LIB_ARM_MATCHFINDER_IMPL_H |
18092
|
|
|
|
|
|
|
#define LIB_ARM_MATCHFINDER_IMPL_H |
18093
|
|
|
|
|
|
|
|
18094
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
18095
|
|
|
|
|
|
|
|
18096
|
|
|
|
|
|
|
|
18097
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
18098
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
18099
|
|
|
|
|
|
|
|
18100
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
18101
|
|
|
|
|
|
|
|
18102
|
|
|
|
|
|
|
|
18103
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
18104
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
18105
|
|
|
|
|
|
|
|
18106
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
18107
|
|
|
|
|
|
|
|
18108
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
18109
|
|
|
|
|
|
|
#endif |
18110
|
|
|
|
|
|
|
|
18111
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
18112
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
18113
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
18114
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
18115
|
|
|
|
|
|
|
#else |
18116
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
18117
|
|
|
|
|
|
|
#endif |
18118
|
|
|
|
|
|
|
|
18119
|
|
|
|
|
|
|
|
18120
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
18121
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
18122
|
|
|
|
|
|
|
#else |
18123
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
18124
|
|
|
|
|
|
|
#endif |
18125
|
|
|
|
|
|
|
|
18126
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
18127
|
|
|
|
|
|
|
|
18128
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
18129
|
|
|
|
|
|
|
|
18130
|
|
|
|
|
|
|
|
18131
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
18132
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
18133
|
|
|
|
|
|
|
|
18134
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
18135
|
|
|
|
|
|
|
|
18136
|
|
|
|
|
|
|
|
18137
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
18138
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
18139
|
|
|
|
|
|
|
|
18140
|
|
|
|
|
|
|
#include |
18141
|
|
|
|
|
|
|
#include |
18142
|
|
|
|
|
|
|
|
18143
|
|
|
|
|
|
|
#ifdef __cplusplus |
18144
|
|
|
|
|
|
|
extern "C" { |
18145
|
|
|
|
|
|
|
#endif |
18146
|
|
|
|
|
|
|
|
18147
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
18148
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
18149
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
18150
|
|
|
|
|
|
|
|
18151
|
|
|
|
|
|
|
|
18152
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
18153
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
18154
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
18155
|
|
|
|
|
|
|
# else |
18156
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
18157
|
|
|
|
|
|
|
# endif |
18158
|
|
|
|
|
|
|
#endif |
18159
|
|
|
|
|
|
|
|
18160
|
|
|
|
|
|
|
|
18161
|
|
|
|
|
|
|
|
18162
|
|
|
|
|
|
|
|
18163
|
|
|
|
|
|
|
|
18164
|
|
|
|
|
|
|
struct libdeflate_compressor; |
18165
|
|
|
|
|
|
|
struct libdeflate_options; |
18166
|
|
|
|
|
|
|
|
18167
|
|
|
|
|
|
|
|
18168
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
18169
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
18170
|
|
|
|
|
|
|
|
18171
|
|
|
|
|
|
|
|
18172
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
18173
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
18174
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
18175
|
|
|
|
|
|
|
|
18176
|
|
|
|
|
|
|
|
18177
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18178
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
18179
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18180
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
18181
|
|
|
|
|
|
|
|
18182
|
|
|
|
|
|
|
|
18183
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18184
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
18185
|
|
|
|
|
|
|
size_t in_nbytes); |
18186
|
|
|
|
|
|
|
|
18187
|
|
|
|
|
|
|
|
18188
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18189
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
18190
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18191
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
18192
|
|
|
|
|
|
|
|
18193
|
|
|
|
|
|
|
|
18194
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18195
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
18196
|
|
|
|
|
|
|
size_t in_nbytes); |
18197
|
|
|
|
|
|
|
|
18198
|
|
|
|
|
|
|
|
18199
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18200
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
18201
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18202
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
18203
|
|
|
|
|
|
|
|
18204
|
|
|
|
|
|
|
|
18205
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18206
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
18207
|
|
|
|
|
|
|
size_t in_nbytes); |
18208
|
|
|
|
|
|
|
|
18209
|
|
|
|
|
|
|
|
18210
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
18211
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
18212
|
|
|
|
|
|
|
|
18213
|
|
|
|
|
|
|
|
18214
|
|
|
|
|
|
|
|
18215
|
|
|
|
|
|
|
|
18216
|
|
|
|
|
|
|
|
18217
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
18218
|
|
|
|
|
|
|
struct libdeflate_options; |
18219
|
|
|
|
|
|
|
|
18220
|
|
|
|
|
|
|
|
18221
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
18222
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
18223
|
|
|
|
|
|
|
|
18224
|
|
|
|
|
|
|
|
18225
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
18226
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
18227
|
|
|
|
|
|
|
|
18228
|
|
|
|
|
|
|
|
18229
|
|
|
|
|
|
|
enum libdeflate_result { |
18230
|
|
|
|
|
|
|
|
18231
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
18232
|
|
|
|
|
|
|
|
18233
|
|
|
|
|
|
|
|
18234
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
18235
|
|
|
|
|
|
|
|
18236
|
|
|
|
|
|
|
|
18237
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
18238
|
|
|
|
|
|
|
|
18239
|
|
|
|
|
|
|
|
18240
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
18241
|
|
|
|
|
|
|
}; |
18242
|
|
|
|
|
|
|
|
18243
|
|
|
|
|
|
|
|
18244
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18245
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
18246
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18247
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18248
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18249
|
|
|
|
|
|
|
|
18250
|
|
|
|
|
|
|
|
18251
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18252
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
18253
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18254
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18255
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
18256
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18257
|
|
|
|
|
|
|
|
18258
|
|
|
|
|
|
|
|
18259
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18260
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
18261
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18262
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18263
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18264
|
|
|
|
|
|
|
|
18265
|
|
|
|
|
|
|
|
18266
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18267
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
18268
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18269
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18270
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
18271
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18272
|
|
|
|
|
|
|
|
18273
|
|
|
|
|
|
|
|
18274
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18275
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
18276
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18277
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18278
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18279
|
|
|
|
|
|
|
|
18280
|
|
|
|
|
|
|
|
18281
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18282
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
18283
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18284
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18285
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
18286
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18287
|
|
|
|
|
|
|
|
18288
|
|
|
|
|
|
|
|
18289
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
18290
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
18291
|
|
|
|
|
|
|
|
18292
|
|
|
|
|
|
|
|
18293
|
|
|
|
|
|
|
|
18294
|
|
|
|
|
|
|
|
18295
|
|
|
|
|
|
|
|
18296
|
|
|
|
|
|
|
|
18297
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
18298
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
18299
|
|
|
|
|
|
|
|
18300
|
|
|
|
|
|
|
|
18301
|
|
|
|
|
|
|
|
18302
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
18303
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
18304
|
|
|
|
|
|
|
|
18305
|
|
|
|
|
|
|
|
18306
|
|
|
|
|
|
|
|
18307
|
|
|
|
|
|
|
|
18308
|
|
|
|
|
|
|
|
18309
|
|
|
|
|
|
|
|
18310
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
18311
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
18312
|
|
|
|
|
|
|
void (*free_func)(void *)); |
18313
|
|
|
|
|
|
|
|
18314
|
|
|
|
|
|
|
|
18315
|
|
|
|
|
|
|
struct libdeflate_options { |
18316
|
|
|
|
|
|
|
|
18317
|
|
|
|
|
|
|
|
18318
|
|
|
|
|
|
|
size_t sizeof_options; |
18319
|
|
|
|
|
|
|
|
18320
|
|
|
|
|
|
|
|
18321
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
18322
|
|
|
|
|
|
|
void (*free_func)(void *); |
18323
|
|
|
|
|
|
|
}; |
18324
|
|
|
|
|
|
|
|
18325
|
|
|
|
|
|
|
#ifdef __cplusplus |
18326
|
|
|
|
|
|
|
} |
18327
|
|
|
|
|
|
|
#endif |
18328
|
|
|
|
|
|
|
|
18329
|
|
|
|
|
|
|
#endif |
18330
|
|
|
|
|
|
|
|
18331
|
|
|
|
|
|
|
|
18332
|
|
|
|
|
|
|
#include |
18333
|
|
|
|
|
|
|
#include |
18334
|
|
|
|
|
|
|
#include |
18335
|
|
|
|
|
|
|
#ifdef _MSC_VER |
18336
|
|
|
|
|
|
|
# include |
18337
|
|
|
|
|
|
|
# include |
18338
|
|
|
|
|
|
|
|
18339
|
|
|
|
|
|
|
|
18340
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
18341
|
|
|
|
|
|
|
|
18342
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
18343
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
18344
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
18345
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
18346
|
|
|
|
|
|
|
|
18347
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
18348
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
18349
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
18350
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
18351
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
18352
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
18353
|
|
|
|
|
|
|
#endif |
18354
|
|
|
|
|
|
|
#ifndef FREESTANDING |
18355
|
|
|
|
|
|
|
# include |
18356
|
|
|
|
|
|
|
#endif |
18357
|
|
|
|
|
|
|
|
18358
|
|
|
|
|
|
|
|
18359
|
|
|
|
|
|
|
|
18360
|
|
|
|
|
|
|
|
18361
|
|
|
|
|
|
|
|
18362
|
|
|
|
|
|
|
|
18363
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
18364
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
18365
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
18366
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
18367
|
|
|
|
|
|
|
#ifdef _MSC_VER |
18368
|
|
|
|
|
|
|
# if defined(_M_X64) |
18369
|
|
|
|
|
|
|
# define ARCH_X86_64 |
18370
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
18371
|
|
|
|
|
|
|
# define ARCH_X86_32 |
18372
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
18373
|
|
|
|
|
|
|
# define ARCH_ARM64 |
18374
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
18375
|
|
|
|
|
|
|
# define ARCH_ARM32 |
18376
|
|
|
|
|
|
|
# endif |
18377
|
|
|
|
|
|
|
#else |
18378
|
|
|
|
|
|
|
# if defined(__x86_64__) |
18379
|
|
|
|
|
|
|
# define ARCH_X86_64 |
18380
|
|
|
|
|
|
|
# elif defined(__i386__) |
18381
|
|
|
|
|
|
|
# define ARCH_X86_32 |
18382
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
18383
|
|
|
|
|
|
|
# define ARCH_ARM64 |
18384
|
|
|
|
|
|
|
# elif defined(__arm__) |
18385
|
|
|
|
|
|
|
# define ARCH_ARM32 |
18386
|
|
|
|
|
|
|
# endif |
18387
|
|
|
|
|
|
|
#endif |
18388
|
|
|
|
|
|
|
|
18389
|
|
|
|
|
|
|
|
18390
|
|
|
|
|
|
|
|
18391
|
|
|
|
|
|
|
|
18392
|
|
|
|
|
|
|
|
18393
|
|
|
|
|
|
|
|
18394
|
|
|
|
|
|
|
typedef uint8_t u8; |
18395
|
|
|
|
|
|
|
typedef uint16_t u16; |
18396
|
|
|
|
|
|
|
typedef uint32_t u32; |
18397
|
|
|
|
|
|
|
typedef uint64_t u64; |
18398
|
|
|
|
|
|
|
typedef int8_t s8; |
18399
|
|
|
|
|
|
|
typedef int16_t s16; |
18400
|
|
|
|
|
|
|
typedef int32_t s32; |
18401
|
|
|
|
|
|
|
typedef int64_t s64; |
18402
|
|
|
|
|
|
|
|
18403
|
|
|
|
|
|
|
|
18404
|
|
|
|
|
|
|
#ifdef _MSC_VER |
18405
|
|
|
|
|
|
|
# ifdef _WIN64 |
18406
|
|
|
|
|
|
|
typedef long long ssize_t; |
18407
|
|
|
|
|
|
|
# else |
18408
|
|
|
|
|
|
|
typedef long ssize_t; |
18409
|
|
|
|
|
|
|
# endif |
18410
|
|
|
|
|
|
|
#endif |
18411
|
|
|
|
|
|
|
|
18412
|
|
|
|
|
|
|
|
18413
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
18414
|
|
|
|
|
|
|
|
18415
|
|
|
|
|
|
|
|
18416
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
18417
|
|
|
|
|
|
|
|
18418
|
|
|
|
|
|
|
|
18419
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
18420
|
|
|
|
|
|
|
|
18421
|
|
|
|
|
|
|
|
18422
|
|
|
|
|
|
|
|
18423
|
|
|
|
|
|
|
|
18424
|
|
|
|
|
|
|
|
18425
|
|
|
|
|
|
|
|
18426
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
18427
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
18428
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
18429
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
18430
|
|
|
|
|
|
|
#else |
18431
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
18432
|
|
|
|
|
|
|
#endif |
18433
|
|
|
|
|
|
|
#ifdef __clang__ |
18434
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
18435
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
18436
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
18437
|
|
|
|
|
|
|
# else |
18438
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
18439
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
18440
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
18441
|
|
|
|
|
|
|
# endif |
18442
|
|
|
|
|
|
|
#else |
18443
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
18444
|
|
|
|
|
|
|
#endif |
18445
|
|
|
|
|
|
|
|
18446
|
|
|
|
|
|
|
|
18447
|
|
|
|
|
|
|
#ifndef __has_attribute |
18448
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
18449
|
|
|
|
|
|
|
#endif |
18450
|
|
|
|
|
|
|
#ifndef __has_builtin |
18451
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
18452
|
|
|
|
|
|
|
#endif |
18453
|
|
|
|
|
|
|
|
18454
|
|
|
|
|
|
|
|
18455
|
|
|
|
|
|
|
#ifdef _MSC_VER |
18456
|
|
|
|
|
|
|
# define inline __inline |
18457
|
|
|
|
|
|
|
#endif |
18458
|
|
|
|
|
|
|
|
18459
|
|
|
|
|
|
|
|
18460
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
18461
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
18462
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18463
|
|
|
|
|
|
|
# define forceinline __forceinline |
18464
|
|
|
|
|
|
|
#else |
18465
|
|
|
|
|
|
|
# define forceinline inline |
18466
|
|
|
|
|
|
|
#endif |
18467
|
|
|
|
|
|
|
|
18468
|
|
|
|
|
|
|
|
18469
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
18470
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
18471
|
|
|
|
|
|
|
#else |
18472
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
18473
|
|
|
|
|
|
|
#endif |
18474
|
|
|
|
|
|
|
|
18475
|
|
|
|
|
|
|
|
18476
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
18477
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
18478
|
|
|
|
|
|
|
# define restrict __restrict__ |
18479
|
|
|
|
|
|
|
# else |
18480
|
|
|
|
|
|
|
# define restrict |
18481
|
|
|
|
|
|
|
# endif |
18482
|
|
|
|
|
|
|
#endif |
18483
|
|
|
|
|
|
|
|
18484
|
|
|
|
|
|
|
|
18485
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
18486
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
18487
|
|
|
|
|
|
|
#else |
18488
|
|
|
|
|
|
|
# define likely(expr) (expr) |
18489
|
|
|
|
|
|
|
#endif |
18490
|
|
|
|
|
|
|
|
18491
|
|
|
|
|
|
|
|
18492
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
18493
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
18494
|
|
|
|
|
|
|
#else |
18495
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
18496
|
|
|
|
|
|
|
#endif |
18497
|
|
|
|
|
|
|
|
18498
|
|
|
|
|
|
|
|
18499
|
|
|
|
|
|
|
#undef prefetchr |
18500
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
18501
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
18502
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18503
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
18504
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
18505
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
18506
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
18507
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
18508
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
18509
|
|
|
|
|
|
|
# endif |
18510
|
|
|
|
|
|
|
#endif |
18511
|
|
|
|
|
|
|
#ifndef prefetchr |
18512
|
|
|
|
|
|
|
# define prefetchr(addr) |
18513
|
|
|
|
|
|
|
#endif |
18514
|
|
|
|
|
|
|
|
18515
|
|
|
|
|
|
|
|
18516
|
|
|
|
|
|
|
#undef prefetchw |
18517
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
18518
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
18519
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18520
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
18521
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
18522
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
18523
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
18524
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
18525
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
18526
|
|
|
|
|
|
|
# endif |
18527
|
|
|
|
|
|
|
#endif |
18528
|
|
|
|
|
|
|
#ifndef prefetchw |
18529
|
|
|
|
|
|
|
# define prefetchw(addr) |
18530
|
|
|
|
|
|
|
#endif |
18531
|
|
|
|
|
|
|
|
18532
|
|
|
|
|
|
|
|
18533
|
|
|
|
|
|
|
#undef _aligned_attribute |
18534
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
18535
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
18536
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18537
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
18538
|
|
|
|
|
|
|
#endif |
18539
|
|
|
|
|
|
|
|
18540
|
|
|
|
|
|
|
|
18541
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
18542
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
18543
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
18544
|
|
|
|
|
|
|
#else |
18545
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
18546
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
18547
|
|
|
|
|
|
|
#endif |
18548
|
|
|
|
|
|
|
|
18549
|
|
|
|
|
|
|
|
18550
|
|
|
|
|
|
|
|
18551
|
|
|
|
|
|
|
|
18552
|
|
|
|
|
|
|
|
18553
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
18554
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
18555
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
18556
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
18557
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
18558
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
18559
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
18560
|
|
|
|
|
|
|
|
18561
|
|
|
|
|
|
|
|
18562
|
|
|
|
|
|
|
|
18563
|
|
|
|
|
|
|
|
18564
|
|
|
|
|
|
|
|
18565
|
|
|
|
|
|
|
|
18566
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
18567
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
18568
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18569
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
18570
|
|
|
|
|
|
|
#else |
18571
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
18572
|
|
|
|
|
|
|
{ |
18573
|
|
|
|
|
|
|
union { |
18574
|
|
|
|
|
|
|
u32 w; |
18575
|
|
|
|
|
|
|
u8 b; |
18576
|
|
|
|
|
|
|
} u; |
18577
|
|
|
|
|
|
|
|
18578
|
|
|
|
|
|
|
u.w = 1; |
18579
|
|
|
|
|
|
|
return u.b; |
18580
|
|
|
|
|
|
|
} |
18581
|
|
|
|
|
|
|
#endif |
18582
|
|
|
|
|
|
|
|
18583
|
|
|
|
|
|
|
|
18584
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
18585
|
|
|
|
|
|
|
{ |
18586
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
18587
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
18588
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18589
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
18590
|
|
|
|
|
|
|
#else |
18591
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
18592
|
|
|
|
|
|
|
#endif |
18593
|
|
|
|
|
|
|
} |
18594
|
|
|
|
|
|
|
|
18595
|
|
|
|
|
|
|
|
18596
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
18597
|
|
|
|
|
|
|
{ |
18598
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
18599
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
18600
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18601
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
18602
|
|
|
|
|
|
|
#else |
18603
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
18604
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
18605
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
18606
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
18607
|
|
|
|
|
|
|
#endif |
18608
|
|
|
|
|
|
|
} |
18609
|
|
|
|
|
|
|
|
18610
|
|
|
|
|
|
|
|
18611
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
18612
|
|
|
|
|
|
|
{ |
18613
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
18614
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
18615
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18616
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
18617
|
|
|
|
|
|
|
#else |
18618
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
18619
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
18620
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
18621
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
18622
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
18623
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
18624
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
18625
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
18626
|
|
|
|
|
|
|
#endif |
18627
|
|
|
|
|
|
|
} |
18628
|
|
|
|
|
|
|
|
18629
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
18630
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
18631
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
18632
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
18633
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
18634
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
18635
|
|
|
|
|
|
|
|
18636
|
|
|
|
|
|
|
|
18637
|
|
|
|
|
|
|
|
18638
|
|
|
|
|
|
|
|
18639
|
|
|
|
|
|
|
|
18640
|
|
|
|
|
|
|
|
18641
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
18642
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
18643
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
18644
|
|
|
|
|
|
|
defined(__wasm__)) |
18645
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
18646
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18647
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
18648
|
|
|
|
|
|
|
#else |
18649
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
18650
|
|
|
|
|
|
|
#endif |
18651
|
|
|
|
|
|
|
|
18652
|
|
|
|
|
|
|
|
18653
|
|
|
|
|
|
|
|
18654
|
|
|
|
|
|
|
#ifdef FREESTANDING |
18655
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
18656
|
|
|
|
|
|
|
#else |
18657
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
18658
|
|
|
|
|
|
|
#endif |
18659
|
|
|
|
|
|
|
|
18660
|
|
|
|
|
|
|
|
18661
|
|
|
|
|
|
|
|
18662
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
18663
|
|
|
|
|
|
|
static forceinline type \ |
18664
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
18665
|
|
|
|
|
|
|
{ \ |
18666
|
|
|
|
|
|
|
type v; \ |
18667
|
|
|
|
|
|
|
\ |
18668
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
18669
|
|
|
|
|
|
|
return v; \ |
18670
|
|
|
|
|
|
|
} \ |
18671
|
|
|
|
|
|
|
\ |
18672
|
|
|
|
|
|
|
static forceinline void \ |
18673
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
18674
|
|
|
|
|
|
|
{ \ |
18675
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
18676
|
|
|
|
|
|
|
} |
18677
|
|
|
|
|
|
|
|
18678
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
18679
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
18680
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
18681
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
18682
|
|
|
|
|
|
|
|
18683
|
|
|
|
|
|
|
#undef MEMCOPY |
18684
|
|
|
|
|
|
|
|
18685
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
18686
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
18687
|
|
|
|
|
|
|
|
18688
|
|
|
|
|
|
|
|
18689
|
|
|
|
|
|
|
|
18690
|
|
|
|
|
|
|
static forceinline u16 |
18691
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
18692
|
|
|
|
|
|
|
{ |
18693
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18694
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
18695
|
|
|
|
|
|
|
else |
18696
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
18697
|
|
|
|
|
|
|
} |
18698
|
|
|
|
|
|
|
|
18699
|
|
|
|
|
|
|
static forceinline u16 |
18700
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
18701
|
|
|
|
|
|
|
{ |
18702
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18703
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
18704
|
|
|
|
|
|
|
else |
18705
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
18706
|
|
|
|
|
|
|
} |
18707
|
|
|
|
|
|
|
|
18708
|
|
|
|
|
|
|
static forceinline u32 |
18709
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
18710
|
|
|
|
|
|
|
{ |
18711
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18712
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
18713
|
|
|
|
|
|
|
else |
18714
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
18715
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
18716
|
|
|
|
|
|
|
} |
18717
|
|
|
|
|
|
|
|
18718
|
|
|
|
|
|
|
static forceinline u32 |
18719
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
18720
|
|
|
|
|
|
|
{ |
18721
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18722
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
18723
|
|
|
|
|
|
|
else |
18724
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
18725
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
18726
|
|
|
|
|
|
|
} |
18727
|
|
|
|
|
|
|
|
18728
|
|
|
|
|
|
|
static forceinline u64 |
18729
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
18730
|
|
|
|
|
|
|
{ |
18731
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18732
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
18733
|
|
|
|
|
|
|
else |
18734
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
18735
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
18736
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
18737
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
18738
|
|
|
|
|
|
|
} |
18739
|
|
|
|
|
|
|
|
18740
|
|
|
|
|
|
|
static forceinline machine_word_t |
18741
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
18742
|
|
|
|
|
|
|
{ |
18743
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
18744
|
|
|
|
|
|
|
if (WORDBITS == 32) |
18745
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
18746
|
|
|
|
|
|
|
else |
18747
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
18748
|
|
|
|
|
|
|
} |
18749
|
|
|
|
|
|
|
|
18750
|
|
|
|
|
|
|
|
18751
|
|
|
|
|
|
|
|
18752
|
|
|
|
|
|
|
static forceinline void |
18753
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
18754
|
|
|
|
|
|
|
{ |
18755
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18756
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
18757
|
|
|
|
|
|
|
} else { |
18758
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
18759
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
18760
|
|
|
|
|
|
|
} |
18761
|
|
|
|
|
|
|
} |
18762
|
|
|
|
|
|
|
|
18763
|
|
|
|
|
|
|
static forceinline void |
18764
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
18765
|
|
|
|
|
|
|
{ |
18766
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18767
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
18768
|
|
|
|
|
|
|
} else { |
18769
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
18770
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
18771
|
|
|
|
|
|
|
} |
18772
|
|
|
|
|
|
|
} |
18773
|
|
|
|
|
|
|
|
18774
|
|
|
|
|
|
|
static forceinline void |
18775
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
18776
|
|
|
|
|
|
|
{ |
18777
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18778
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
18779
|
|
|
|
|
|
|
} else { |
18780
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
18781
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
18782
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
18783
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
18784
|
|
|
|
|
|
|
} |
18785
|
|
|
|
|
|
|
} |
18786
|
|
|
|
|
|
|
|
18787
|
|
|
|
|
|
|
static forceinline void |
18788
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
18789
|
|
|
|
|
|
|
{ |
18790
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18791
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
18792
|
|
|
|
|
|
|
} else { |
18793
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
18794
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
18795
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
18796
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
18797
|
|
|
|
|
|
|
} |
18798
|
|
|
|
|
|
|
} |
18799
|
|
|
|
|
|
|
|
18800
|
|
|
|
|
|
|
static forceinline void |
18801
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
18802
|
|
|
|
|
|
|
{ |
18803
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18804
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
18805
|
|
|
|
|
|
|
} else { |
18806
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
18807
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
18808
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
18809
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
18810
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
18811
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
18812
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
18813
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
18814
|
|
|
|
|
|
|
} |
18815
|
|
|
|
|
|
|
} |
18816
|
|
|
|
|
|
|
|
18817
|
|
|
|
|
|
|
static forceinline void |
18818
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
18819
|
|
|
|
|
|
|
{ |
18820
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
18821
|
|
|
|
|
|
|
if (WORDBITS == 32) |
18822
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
18823
|
|
|
|
|
|
|
else |
18824
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
18825
|
|
|
|
|
|
|
} |
18826
|
|
|
|
|
|
|
|
18827
|
|
|
|
|
|
|
|
18828
|
|
|
|
|
|
|
|
18829
|
|
|
|
|
|
|
|
18830
|
|
|
|
|
|
|
|
18831
|
|
|
|
|
|
|
|
18832
|
|
|
|
|
|
|
|
18833
|
|
|
|
|
|
|
static forceinline unsigned |
18834
|
|
|
|
|
|
|
bsr32(u32 v) |
18835
|
|
|
|
|
|
|
{ |
18836
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
18837
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
18838
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18839
|
|
|
|
|
|
|
unsigned long i; |
18840
|
|
|
|
|
|
|
|
18841
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
18842
|
|
|
|
|
|
|
return i; |
18843
|
|
|
|
|
|
|
#else |
18844
|
|
|
|
|
|
|
unsigned i = 0; |
18845
|
|
|
|
|
|
|
|
18846
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
18847
|
|
|
|
|
|
|
i++; |
18848
|
|
|
|
|
|
|
return i; |
18849
|
|
|
|
|
|
|
#endif |
18850
|
|
|
|
|
|
|
} |
18851
|
|
|
|
|
|
|
|
18852
|
|
|
|
|
|
|
static forceinline unsigned |
18853
|
|
|
|
|
|
|
bsr64(u64 v) |
18854
|
|
|
|
|
|
|
{ |
18855
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
18856
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
18857
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
18858
|
|
|
|
|
|
|
unsigned long i; |
18859
|
|
|
|
|
|
|
|
18860
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
18861
|
|
|
|
|
|
|
return i; |
18862
|
|
|
|
|
|
|
#else |
18863
|
|
|
|
|
|
|
unsigned i = 0; |
18864
|
|
|
|
|
|
|
|
18865
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
18866
|
|
|
|
|
|
|
i++; |
18867
|
|
|
|
|
|
|
return i; |
18868
|
|
|
|
|
|
|
#endif |
18869
|
|
|
|
|
|
|
} |
18870
|
|
|
|
|
|
|
|
18871
|
|
|
|
|
|
|
static forceinline unsigned |
18872
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
18873
|
|
|
|
|
|
|
{ |
18874
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
18875
|
|
|
|
|
|
|
if (WORDBITS == 32) |
18876
|
|
|
|
|
|
|
return bsr32(v); |
18877
|
|
|
|
|
|
|
else |
18878
|
|
|
|
|
|
|
return bsr64(v); |
18879
|
|
|
|
|
|
|
} |
18880
|
|
|
|
|
|
|
|
18881
|
|
|
|
|
|
|
|
18882
|
|
|
|
|
|
|
|
18883
|
|
|
|
|
|
|
static forceinline unsigned |
18884
|
|
|
|
|
|
|
bsf32(u32 v) |
18885
|
|
|
|
|
|
|
{ |
18886
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
18887
|
|
|
|
|
|
|
return __builtin_ctz(v); |
18888
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18889
|
|
|
|
|
|
|
unsigned long i; |
18890
|
|
|
|
|
|
|
|
18891
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
18892
|
|
|
|
|
|
|
return i; |
18893
|
|
|
|
|
|
|
#else |
18894
|
|
|
|
|
|
|
unsigned i = 0; |
18895
|
|
|
|
|
|
|
|
18896
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
18897
|
|
|
|
|
|
|
i++; |
18898
|
|
|
|
|
|
|
return i; |
18899
|
|
|
|
|
|
|
#endif |
18900
|
|
|
|
|
|
|
} |
18901
|
|
|
|
|
|
|
|
18902
|
|
|
|
|
|
|
static forceinline unsigned |
18903
|
|
|
|
|
|
|
bsf64(u64 v) |
18904
|
|
|
|
|
|
|
{ |
18905
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
18906
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
18907
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
18908
|
|
|
|
|
|
|
unsigned long i; |
18909
|
|
|
|
|
|
|
|
18910
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
18911
|
|
|
|
|
|
|
return i; |
18912
|
|
|
|
|
|
|
#else |
18913
|
|
|
|
|
|
|
unsigned i = 0; |
18914
|
|
|
|
|
|
|
|
18915
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
18916
|
|
|
|
|
|
|
i++; |
18917
|
|
|
|
|
|
|
return i; |
18918
|
|
|
|
|
|
|
#endif |
18919
|
|
|
|
|
|
|
} |
18920
|
|
|
|
|
|
|
|
18921
|
|
|
|
|
|
|
static forceinline unsigned |
18922
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
18923
|
|
|
|
|
|
|
{ |
18924
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
18925
|
|
|
|
|
|
|
if (WORDBITS == 32) |
18926
|
|
|
|
|
|
|
return bsf32(v); |
18927
|
|
|
|
|
|
|
else |
18928
|
|
|
|
|
|
|
return bsf64(v); |
18929
|
|
|
|
|
|
|
} |
18930
|
|
|
|
|
|
|
|
18931
|
|
|
|
|
|
|
|
18932
|
|
|
|
|
|
|
#undef rbit32 |
18933
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
18934
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
18935
|
|
|
|
|
|
|
static forceinline u32 |
18936
|
|
|
|
|
|
|
rbit32(u32 v) |
18937
|
|
|
|
|
|
|
{ |
18938
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
18939
|
|
|
|
|
|
|
return v; |
18940
|
|
|
|
|
|
|
} |
18941
|
|
|
|
|
|
|
#define rbit32 rbit32 |
18942
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
18943
|
|
|
|
|
|
|
static forceinline u32 |
18944
|
|
|
|
|
|
|
rbit32(u32 v) |
18945
|
|
|
|
|
|
|
{ |
18946
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
18947
|
|
|
|
|
|
|
return v; |
18948
|
|
|
|
|
|
|
} |
18949
|
|
|
|
|
|
|
#define rbit32 rbit32 |
18950
|
|
|
|
|
|
|
#endif |
18951
|
|
|
|
|
|
|
|
18952
|
|
|
|
|
|
|
#endif |
18953
|
|
|
|
|
|
|
|
18954
|
|
|
|
|
|
|
|
18955
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
18956
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
18957
|
|
|
|
|
|
|
|
18958
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
18959
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
18960
|
|
|
|
|
|
|
|
18961
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
18962
|
|
|
|
|
|
|
size_t alignment, size_t size); |
18963
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
18964
|
|
|
|
|
|
|
|
18965
|
|
|
|
|
|
|
#ifdef FREESTANDING |
18966
|
|
|
|
|
|
|
|
18967
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
18968
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
18969
|
|
|
|
|
|
|
|
18970
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
18971
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
18972
|
|
|
|
|
|
|
|
18973
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
18974
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
18975
|
|
|
|
|
|
|
|
18976
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
18977
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
18978
|
|
|
|
|
|
|
|
18979
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
18980
|
|
|
|
|
|
|
#else |
18981
|
|
|
|
|
|
|
#include |
18982
|
|
|
|
|
|
|
#endif |
18983
|
|
|
|
|
|
|
|
18984
|
|
|
|
|
|
|
|
18985
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
18986
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
18987
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
18988
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
18989
|
|
|
|
|
|
|
#else |
18990
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
18991
|
|
|
|
|
|
|
#endif |
18992
|
|
|
|
|
|
|
|
18993
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
18994
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
18995
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
18996
|
|
|
|
|
|
|
|
18997
|
|
|
|
|
|
|
#endif |
18998
|
|
|
|
|
|
|
|
18999
|
|
|
|
|
|
|
|
19000
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
19001
|
|
|
|
|
|
|
|
19002
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
19003
|
|
|
|
|
|
|
|
19004
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
19005
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
19006
|
|
|
|
|
|
|
(defined(__linux__) || \ |
19007
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
19008
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
19009
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
19010
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
19011
|
|
|
|
|
|
|
#endif |
19012
|
|
|
|
|
|
|
|
19013
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
19014
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
19015
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
19016
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
19017
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
19018
|
|
|
|
|
|
|
|
19019
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
19020
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
19021
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
19022
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
19023
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
19024
|
|
|
|
|
|
|
|
19025
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
19026
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
19027
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
19028
|
|
|
|
|
|
|
|
19029
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
19030
|
|
|
|
|
|
|
|
19031
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
19032
|
|
|
|
|
|
|
{ |
19033
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
19034
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
19035
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
19036
|
|
|
|
|
|
|
} |
19037
|
|
|
|
|
|
|
#else |
19038
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
19039
|
|
|
|
|
|
|
#endif |
19040
|
|
|
|
|
|
|
|
19041
|
|
|
|
|
|
|
|
19042
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
19043
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
19044
|
|
|
|
|
|
|
#else |
19045
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
19046
|
|
|
|
|
|
|
#endif |
19047
|
|
|
|
|
|
|
|
19048
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
19049
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
19050
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
19051
|
|
|
|
|
|
|
#else |
19052
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
19053
|
|
|
|
|
|
|
#endif |
19054
|
|
|
|
|
|
|
|
19055
|
|
|
|
|
|
|
|
19056
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
19057
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
19058
|
|
|
|
|
|
|
#else |
19059
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
19060
|
|
|
|
|
|
|
#endif |
19061
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
19062
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
19063
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
19064
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
19065
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
19066
|
|
|
|
|
|
|
\ |
19067
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
19068
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
19069
|
|
|
|
|
|
|
|
19070
|
|
|
|
|
|
|
# ifdef _MSC_VER |
19071
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
19072
|
|
|
|
|
|
|
# else |
19073
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
19074
|
|
|
|
|
|
|
# endif |
19075
|
|
|
|
|
|
|
#else |
19076
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
19077
|
|
|
|
|
|
|
#endif |
19078
|
|
|
|
|
|
|
|
19079
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
19080
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
19081
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
19082
|
|
|
|
|
|
|
#else |
19083
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
19084
|
|
|
|
|
|
|
#endif |
19085
|
|
|
|
|
|
|
|
19086
|
|
|
|
|
|
|
|
19087
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
19088
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
19089
|
|
|
|
|
|
|
#else |
19090
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
19091
|
|
|
|
|
|
|
#endif |
19092
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
19093
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
19094
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
19095
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
19096
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
19097
|
|
|
|
|
|
|
|
19098
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
19099
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
19100
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
19101
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
19102
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
19103
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
19104
|
|
|
|
|
|
|
# endif |
19105
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
19106
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
19107
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
19108
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
19109
|
|
|
|
|
|
|
# endif |
19110
|
|
|
|
|
|
|
#endif |
19111
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
19112
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
19113
|
|
|
|
|
|
|
#endif |
19114
|
|
|
|
|
|
|
|
19115
|
|
|
|
|
|
|
|
19116
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
19117
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
19118
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
19119
|
|
|
|
|
|
|
# else |
19120
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
19121
|
|
|
|
|
|
|
# endif |
19122
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
19123
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
19124
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
19125
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
19126
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
19127
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
19128
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
19129
|
|
|
|
|
|
|
#else |
19130
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
19131
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
19132
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
19133
|
|
|
|
|
|
|
#endif |
19134
|
|
|
|
|
|
|
|
19135
|
|
|
|
|
|
|
|
19136
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
19137
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
19138
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
19139
|
|
|
|
|
|
|
# else |
19140
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
19141
|
|
|
|
|
|
|
# endif |
19142
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
19143
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
19144
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
19145
|
|
|
|
|
|
|
defined(_MSC_VER))) |
19146
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
19147
|
|
|
|
|
|
|
# else |
19148
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
19149
|
|
|
|
|
|
|
# endif |
19150
|
|
|
|
|
|
|
#else |
19151
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
19152
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
19153
|
|
|
|
|
|
|
#endif |
19154
|
|
|
|
|
|
|
|
19155
|
|
|
|
|
|
|
|
19156
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
19157
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
19158
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
19159
|
|
|
|
|
|
|
#endif |
19160
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
19161
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
19162
|
|
|
|
|
|
|
#endif |
19163
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
19164
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
19165
|
|
|
|
|
|
|
#endif |
19166
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
19167
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
19168
|
|
|
|
|
|
|
# include |
19169
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
19170
|
|
|
|
|
|
|
#endif |
19171
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
19172
|
|
|
|
|
|
|
# include |
19173
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
19174
|
|
|
|
|
|
|
#endif |
19175
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
19176
|
|
|
|
|
|
|
# include |
19177
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
19178
|
|
|
|
|
|
|
#endif |
19179
|
|
|
|
|
|
|
|
19180
|
|
|
|
|
|
|
#endif |
19181
|
|
|
|
|
|
|
|
19182
|
|
|
|
|
|
|
#endif |
19183
|
|
|
|
|
|
|
|
19184
|
|
|
|
|
|
|
|
19185
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE |
19186
|
|
|
|
|
|
|
# include |
19187
|
|
|
|
|
|
|
static forceinline void |
19188
|
|
|
|
|
|
|
matchfinder_init_neon(mf_pos_t *data, size_t size) |
19189
|
|
|
|
|
|
|
{ |
19190
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
19191
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16(MATCHFINDER_INITVAL); |
19192
|
|
|
|
|
|
|
|
19193
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
19194
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
19195
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
19196
|
|
|
|
|
|
|
|
19197
|
|
|
|
|
|
|
do { |
19198
|
|
|
|
|
|
|
p[0] = v; |
19199
|
|
|
|
|
|
|
p[1] = v; |
19200
|
|
|
|
|
|
|
p[2] = v; |
19201
|
|
|
|
|
|
|
p[3] = v; |
19202
|
|
|
|
|
|
|
p += 4; |
19203
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
19204
|
|
|
|
|
|
|
} while (size != 0); |
19205
|
|
|
|
|
|
|
} |
19206
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_neon |
19207
|
|
|
|
|
|
|
|
19208
|
|
|
|
|
|
|
static forceinline void |
19209
|
|
|
|
|
|
|
matchfinder_rebase_neon(mf_pos_t *data, size_t size) |
19210
|
|
|
|
|
|
|
{ |
19211
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
19212
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16((u16)-MATCHFINDER_WINDOW_SIZE); |
19213
|
|
|
|
|
|
|
|
19214
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
19215
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
19216
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
19217
|
|
|
|
|
|
|
|
19218
|
|
|
|
|
|
|
do { |
19219
|
|
|
|
|
|
|
p[0] = vqaddq_s16(p[0], v); |
19220
|
|
|
|
|
|
|
p[1] = vqaddq_s16(p[1], v); |
19221
|
|
|
|
|
|
|
p[2] = vqaddq_s16(p[2], v); |
19222
|
|
|
|
|
|
|
p[3] = vqaddq_s16(p[3], v); |
19223
|
|
|
|
|
|
|
p += 4; |
19224
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
19225
|
|
|
|
|
|
|
} while (size != 0); |
19226
|
|
|
|
|
|
|
} |
19227
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_neon |
19228
|
|
|
|
|
|
|
|
19229
|
|
|
|
|
|
|
#endif |
19230
|
|
|
|
|
|
|
|
19231
|
|
|
|
|
|
|
#endif |
19232
|
|
|
|
|
|
|
|
19233
|
|
|
|
|
|
|
# elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
19234
|
|
|
|
|
|
|
/* # include "x86/matchfinder_impl.h" */ |
19235
|
|
|
|
|
|
|
|
19236
|
|
|
|
|
|
|
|
19237
|
|
|
|
|
|
|
#ifndef LIB_X86_MATCHFINDER_IMPL_H |
19238
|
|
|
|
|
|
|
#define LIB_X86_MATCHFINDER_IMPL_H |
19239
|
|
|
|
|
|
|
|
19240
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
19241
|
|
|
|
|
|
|
|
19242
|
|
|
|
|
|
|
|
19243
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
19244
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
19245
|
|
|
|
|
|
|
|
19246
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
19247
|
|
|
|
|
|
|
|
19248
|
|
|
|
|
|
|
|
19249
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
19250
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
19251
|
|
|
|
|
|
|
|
19252
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
19253
|
|
|
|
|
|
|
|
19254
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
19255
|
|
|
|
|
|
|
#endif |
19256
|
|
|
|
|
|
|
|
19257
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
19258
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
19259
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
19260
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
19261
|
|
|
|
|
|
|
#else |
19262
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
19263
|
|
|
|
|
|
|
#endif |
19264
|
|
|
|
|
|
|
|
19265
|
|
|
|
|
|
|
|
19266
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
19267
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
19268
|
|
|
|
|
|
|
#else |
19269
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
19270
|
|
|
|
|
|
|
#endif |
19271
|
|
|
|
|
|
|
|
19272
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
19273
|
|
|
|
|
|
|
|
19274
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
19275
|
|
|
|
|
|
|
|
19276
|
|
|
|
|
|
|
|
19277
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
19278
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
19279
|
|
|
|
|
|
|
|
19280
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
19281
|
|
|
|
|
|
|
|
19282
|
|
|
|
|
|
|
|
19283
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
19284
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
19285
|
|
|
|
|
|
|
|
19286
|
|
|
|
|
|
|
#include |
19287
|
|
|
|
|
|
|
#include |
19288
|
|
|
|
|
|
|
|
19289
|
|
|
|
|
|
|
#ifdef __cplusplus |
19290
|
|
|
|
|
|
|
extern "C" { |
19291
|
|
|
|
|
|
|
#endif |
19292
|
|
|
|
|
|
|
|
19293
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
19294
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
19295
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
19296
|
|
|
|
|
|
|
|
19297
|
|
|
|
|
|
|
|
19298
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
19299
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
19300
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
19301
|
|
|
|
|
|
|
# else |
19302
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
19303
|
|
|
|
|
|
|
# endif |
19304
|
|
|
|
|
|
|
#endif |
19305
|
|
|
|
|
|
|
|
19306
|
|
|
|
|
|
|
|
19307
|
|
|
|
|
|
|
|
19308
|
|
|
|
|
|
|
|
19309
|
|
|
|
|
|
|
|
19310
|
|
|
|
|
|
|
struct libdeflate_compressor; |
19311
|
|
|
|
|
|
|
struct libdeflate_options; |
19312
|
|
|
|
|
|
|
|
19313
|
|
|
|
|
|
|
|
19314
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
19315
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
19316
|
|
|
|
|
|
|
|
19317
|
|
|
|
|
|
|
|
19318
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
19319
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
19320
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
19321
|
|
|
|
|
|
|
|
19322
|
|
|
|
|
|
|
|
19323
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
19324
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
19325
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19326
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
19327
|
|
|
|
|
|
|
|
19328
|
|
|
|
|
|
|
|
19329
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
19330
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
19331
|
|
|
|
|
|
|
size_t in_nbytes); |
19332
|
|
|
|
|
|
|
|
19333
|
|
|
|
|
|
|
|
19334
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
19335
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
19336
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19337
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
19338
|
|
|
|
|
|
|
|
19339
|
|
|
|
|
|
|
|
19340
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
19341
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
19342
|
|
|
|
|
|
|
size_t in_nbytes); |
19343
|
|
|
|
|
|
|
|
19344
|
|
|
|
|
|
|
|
19345
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
19346
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
19347
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19348
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
19349
|
|
|
|
|
|
|
|
19350
|
|
|
|
|
|
|
|
19351
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
19352
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
19353
|
|
|
|
|
|
|
size_t in_nbytes); |
19354
|
|
|
|
|
|
|
|
19355
|
|
|
|
|
|
|
|
19356
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
19357
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
19358
|
|
|
|
|
|
|
|
19359
|
|
|
|
|
|
|
|
19360
|
|
|
|
|
|
|
|
19361
|
|
|
|
|
|
|
|
19362
|
|
|
|
|
|
|
|
19363
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
19364
|
|
|
|
|
|
|
struct libdeflate_options; |
19365
|
|
|
|
|
|
|
|
19366
|
|
|
|
|
|
|
|
19367
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
19368
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
19369
|
|
|
|
|
|
|
|
19370
|
|
|
|
|
|
|
|
19371
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
19372
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
19373
|
|
|
|
|
|
|
|
19374
|
|
|
|
|
|
|
|
19375
|
|
|
|
|
|
|
enum libdeflate_result { |
19376
|
|
|
|
|
|
|
|
19377
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
19378
|
|
|
|
|
|
|
|
19379
|
|
|
|
|
|
|
|
19380
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
19381
|
|
|
|
|
|
|
|
19382
|
|
|
|
|
|
|
|
19383
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
19384
|
|
|
|
|
|
|
|
19385
|
|
|
|
|
|
|
|
19386
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
19387
|
|
|
|
|
|
|
}; |
19388
|
|
|
|
|
|
|
|
19389
|
|
|
|
|
|
|
|
19390
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
19391
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
19392
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19393
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
19394
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
19395
|
|
|
|
|
|
|
|
19396
|
|
|
|
|
|
|
|
19397
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
19398
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
19399
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19400
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
19401
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
19402
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
19403
|
|
|
|
|
|
|
|
19404
|
|
|
|
|
|
|
|
19405
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
19406
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
19407
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19408
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
19409
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
19410
|
|
|
|
|
|
|
|
19411
|
|
|
|
|
|
|
|
19412
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
19413
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
19414
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19415
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
19416
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
19417
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
19418
|
|
|
|
|
|
|
|
19419
|
|
|
|
|
|
|
|
19420
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
19421
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
19422
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19423
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
19424
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
19425
|
|
|
|
|
|
|
|
19426
|
|
|
|
|
|
|
|
19427
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
19428
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
19429
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19430
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
19431
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
19432
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
19433
|
|
|
|
|
|
|
|
19434
|
|
|
|
|
|
|
|
19435
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
19436
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
19437
|
|
|
|
|
|
|
|
19438
|
|
|
|
|
|
|
|
19439
|
|
|
|
|
|
|
|
19440
|
|
|
|
|
|
|
|
19441
|
|
|
|
|
|
|
|
19442
|
|
|
|
|
|
|
|
19443
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
19444
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
19445
|
|
|
|
|
|
|
|
19446
|
|
|
|
|
|
|
|
19447
|
|
|
|
|
|
|
|
19448
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
19449
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
19450
|
|
|
|
|
|
|
|
19451
|
|
|
|
|
|
|
|
19452
|
|
|
|
|
|
|
|
19453
|
|
|
|
|
|
|
|
19454
|
|
|
|
|
|
|
|
19455
|
|
|
|
|
|
|
|
19456
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
19457
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
19458
|
|
|
|
|
|
|
void (*free_func)(void *)); |
19459
|
|
|
|
|
|
|
|
19460
|
|
|
|
|
|
|
|
19461
|
|
|
|
|
|
|
struct libdeflate_options { |
19462
|
|
|
|
|
|
|
|
19463
|
|
|
|
|
|
|
|
19464
|
|
|
|
|
|
|
size_t sizeof_options; |
19465
|
|
|
|
|
|
|
|
19466
|
|
|
|
|
|
|
|
19467
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
19468
|
|
|
|
|
|
|
void (*free_func)(void *); |
19469
|
|
|
|
|
|
|
}; |
19470
|
|
|
|
|
|
|
|
19471
|
|
|
|
|
|
|
#ifdef __cplusplus |
19472
|
|
|
|
|
|
|
} |
19473
|
|
|
|
|
|
|
#endif |
19474
|
|
|
|
|
|
|
|
19475
|
|
|
|
|
|
|
#endif |
19476
|
|
|
|
|
|
|
|
19477
|
|
|
|
|
|
|
|
19478
|
|
|
|
|
|
|
#include |
19479
|
|
|
|
|
|
|
#include |
19480
|
|
|
|
|
|
|
#include |
19481
|
|
|
|
|
|
|
#ifdef _MSC_VER |
19482
|
|
|
|
|
|
|
# include |
19483
|
|
|
|
|
|
|
# include |
19484
|
|
|
|
|
|
|
|
19485
|
|
|
|
|
|
|
|
19486
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
19487
|
|
|
|
|
|
|
|
19488
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
19489
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
19490
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
19491
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
19492
|
|
|
|
|
|
|
|
19493
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
19494
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
19495
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
19496
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
19497
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
19498
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
19499
|
|
|
|
|
|
|
#endif |
19500
|
|
|
|
|
|
|
#ifndef FREESTANDING |
19501
|
|
|
|
|
|
|
# include |
19502
|
|
|
|
|
|
|
#endif |
19503
|
|
|
|
|
|
|
|
19504
|
|
|
|
|
|
|
|
19505
|
|
|
|
|
|
|
|
19506
|
|
|
|
|
|
|
|
19507
|
|
|
|
|
|
|
|
19508
|
|
|
|
|
|
|
|
19509
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
19510
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
19511
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
19512
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
19513
|
|
|
|
|
|
|
#ifdef _MSC_VER |
19514
|
|
|
|
|
|
|
# if defined(_M_X64) |
19515
|
|
|
|
|
|
|
# define ARCH_X86_64 |
19516
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
19517
|
|
|
|
|
|
|
# define ARCH_X86_32 |
19518
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
19519
|
|
|
|
|
|
|
# define ARCH_ARM64 |
19520
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
19521
|
|
|
|
|
|
|
# define ARCH_ARM32 |
19522
|
|
|
|
|
|
|
# endif |
19523
|
|
|
|
|
|
|
#else |
19524
|
|
|
|
|
|
|
# if defined(__x86_64__) |
19525
|
|
|
|
|
|
|
# define ARCH_X86_64 |
19526
|
|
|
|
|
|
|
# elif defined(__i386__) |
19527
|
|
|
|
|
|
|
# define ARCH_X86_32 |
19528
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
19529
|
|
|
|
|
|
|
# define ARCH_ARM64 |
19530
|
|
|
|
|
|
|
# elif defined(__arm__) |
19531
|
|
|
|
|
|
|
# define ARCH_ARM32 |
19532
|
|
|
|
|
|
|
# endif |
19533
|
|
|
|
|
|
|
#endif |
19534
|
|
|
|
|
|
|
|
19535
|
|
|
|
|
|
|
|
19536
|
|
|
|
|
|
|
|
19537
|
|
|
|
|
|
|
|
19538
|
|
|
|
|
|
|
|
19539
|
|
|
|
|
|
|
|
19540
|
|
|
|
|
|
|
typedef uint8_t u8; |
19541
|
|
|
|
|
|
|
typedef uint16_t u16; |
19542
|
|
|
|
|
|
|
typedef uint32_t u32; |
19543
|
|
|
|
|
|
|
typedef uint64_t u64; |
19544
|
|
|
|
|
|
|
typedef int8_t s8; |
19545
|
|
|
|
|
|
|
typedef int16_t s16; |
19546
|
|
|
|
|
|
|
typedef int32_t s32; |
19547
|
|
|
|
|
|
|
typedef int64_t s64; |
19548
|
|
|
|
|
|
|
|
19549
|
|
|
|
|
|
|
|
19550
|
|
|
|
|
|
|
#ifdef _MSC_VER |
19551
|
|
|
|
|
|
|
# ifdef _WIN64 |
19552
|
|
|
|
|
|
|
typedef long long ssize_t; |
19553
|
|
|
|
|
|
|
# else |
19554
|
|
|
|
|
|
|
typedef long ssize_t; |
19555
|
|
|
|
|
|
|
# endif |
19556
|
|
|
|
|
|
|
#endif |
19557
|
|
|
|
|
|
|
|
19558
|
|
|
|
|
|
|
|
19559
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
19560
|
|
|
|
|
|
|
|
19561
|
|
|
|
|
|
|
|
19562
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
19563
|
|
|
|
|
|
|
|
19564
|
|
|
|
|
|
|
|
19565
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
19566
|
|
|
|
|
|
|
|
19567
|
|
|
|
|
|
|
|
19568
|
|
|
|
|
|
|
|
19569
|
|
|
|
|
|
|
|
19570
|
|
|
|
|
|
|
|
19571
|
|
|
|
|
|
|
|
19572
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
19573
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
19574
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
19575
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
19576
|
|
|
|
|
|
|
#else |
19577
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
19578
|
|
|
|
|
|
|
#endif |
19579
|
|
|
|
|
|
|
#ifdef __clang__ |
19580
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
19581
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
19582
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
19583
|
|
|
|
|
|
|
# else |
19584
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
19585
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
19586
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
19587
|
|
|
|
|
|
|
# endif |
19588
|
|
|
|
|
|
|
#else |
19589
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
19590
|
|
|
|
|
|
|
#endif |
19591
|
|
|
|
|
|
|
|
19592
|
|
|
|
|
|
|
|
19593
|
|
|
|
|
|
|
#ifndef __has_attribute |
19594
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
19595
|
|
|
|
|
|
|
#endif |
19596
|
|
|
|
|
|
|
#ifndef __has_builtin |
19597
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
19598
|
|
|
|
|
|
|
#endif |
19599
|
|
|
|
|
|
|
|
19600
|
|
|
|
|
|
|
|
19601
|
|
|
|
|
|
|
#ifdef _MSC_VER |
19602
|
|
|
|
|
|
|
# define inline __inline |
19603
|
|
|
|
|
|
|
#endif |
19604
|
|
|
|
|
|
|
|
19605
|
|
|
|
|
|
|
|
19606
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
19607
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
19608
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19609
|
|
|
|
|
|
|
# define forceinline __forceinline |
19610
|
|
|
|
|
|
|
#else |
19611
|
|
|
|
|
|
|
# define forceinline inline |
19612
|
|
|
|
|
|
|
#endif |
19613
|
|
|
|
|
|
|
|
19614
|
|
|
|
|
|
|
|
19615
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
19616
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
19617
|
|
|
|
|
|
|
#else |
19618
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
19619
|
|
|
|
|
|
|
#endif |
19620
|
|
|
|
|
|
|
|
19621
|
|
|
|
|
|
|
|
19622
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
19623
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
19624
|
|
|
|
|
|
|
# define restrict __restrict__ |
19625
|
|
|
|
|
|
|
# else |
19626
|
|
|
|
|
|
|
# define restrict |
19627
|
|
|
|
|
|
|
# endif |
19628
|
|
|
|
|
|
|
#endif |
19629
|
|
|
|
|
|
|
|
19630
|
|
|
|
|
|
|
|
19631
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
19632
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
19633
|
|
|
|
|
|
|
#else |
19634
|
|
|
|
|
|
|
# define likely(expr) (expr) |
19635
|
|
|
|
|
|
|
#endif |
19636
|
|
|
|
|
|
|
|
19637
|
|
|
|
|
|
|
|
19638
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
19639
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
19640
|
|
|
|
|
|
|
#else |
19641
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
19642
|
|
|
|
|
|
|
#endif |
19643
|
|
|
|
|
|
|
|
19644
|
|
|
|
|
|
|
|
19645
|
|
|
|
|
|
|
#undef prefetchr |
19646
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
19647
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
19648
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19649
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
19650
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
19651
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
19652
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
19653
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
19654
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
19655
|
|
|
|
|
|
|
# endif |
19656
|
|
|
|
|
|
|
#endif |
19657
|
|
|
|
|
|
|
#ifndef prefetchr |
19658
|
|
|
|
|
|
|
# define prefetchr(addr) |
19659
|
|
|
|
|
|
|
#endif |
19660
|
|
|
|
|
|
|
|
19661
|
|
|
|
|
|
|
|
19662
|
|
|
|
|
|
|
#undef prefetchw |
19663
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
19664
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
19665
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19666
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
19667
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
19668
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
19669
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
19670
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
19671
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
19672
|
|
|
|
|
|
|
# endif |
19673
|
|
|
|
|
|
|
#endif |
19674
|
|
|
|
|
|
|
#ifndef prefetchw |
19675
|
|
|
|
|
|
|
# define prefetchw(addr) |
19676
|
|
|
|
|
|
|
#endif |
19677
|
|
|
|
|
|
|
|
19678
|
|
|
|
|
|
|
|
19679
|
|
|
|
|
|
|
#undef _aligned_attribute |
19680
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
19681
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
19682
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19683
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
19684
|
|
|
|
|
|
|
#endif |
19685
|
|
|
|
|
|
|
|
19686
|
|
|
|
|
|
|
|
19687
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
19688
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
19689
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
19690
|
|
|
|
|
|
|
#else |
19691
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
19692
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
19693
|
|
|
|
|
|
|
#endif |
19694
|
|
|
|
|
|
|
|
19695
|
|
|
|
|
|
|
|
19696
|
|
|
|
|
|
|
|
19697
|
|
|
|
|
|
|
|
19698
|
|
|
|
|
|
|
|
19699
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
19700
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
19701
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
19702
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
19703
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
19704
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
19705
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
19706
|
|
|
|
|
|
|
|
19707
|
|
|
|
|
|
|
|
19708
|
|
|
|
|
|
|
|
19709
|
|
|
|
|
|
|
|
19710
|
|
|
|
|
|
|
|
19711
|
|
|
|
|
|
|
|
19712
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
19713
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
19714
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19715
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
19716
|
|
|
|
|
|
|
#else |
19717
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
19718
|
|
|
|
|
|
|
{ |
19719
|
|
|
|
|
|
|
union { |
19720
|
|
|
|
|
|
|
u32 w; |
19721
|
|
|
|
|
|
|
u8 b; |
19722
|
|
|
|
|
|
|
} u; |
19723
|
|
|
|
|
|
|
|
19724
|
|
|
|
|
|
|
u.w = 1; |
19725
|
|
|
|
|
|
|
return u.b; |
19726
|
|
|
|
|
|
|
} |
19727
|
|
|
|
|
|
|
#endif |
19728
|
|
|
|
|
|
|
|
19729
|
|
|
|
|
|
|
|
19730
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
19731
|
|
|
|
|
|
|
{ |
19732
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
19733
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
19734
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19735
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
19736
|
|
|
|
|
|
|
#else |
19737
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
19738
|
|
|
|
|
|
|
#endif |
19739
|
|
|
|
|
|
|
} |
19740
|
|
|
|
|
|
|
|
19741
|
|
|
|
|
|
|
|
19742
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
19743
|
|
|
|
|
|
|
{ |
19744
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
19745
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
19746
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19747
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
19748
|
|
|
|
|
|
|
#else |
19749
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
19750
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
19751
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
19752
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
19753
|
|
|
|
|
|
|
#endif |
19754
|
|
|
|
|
|
|
} |
19755
|
|
|
|
|
|
|
|
19756
|
|
|
|
|
|
|
|
19757
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
19758
|
|
|
|
|
|
|
{ |
19759
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
19760
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
19761
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19762
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
19763
|
|
|
|
|
|
|
#else |
19764
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
19765
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
19766
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
19767
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
19768
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
19769
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
19770
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
19771
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
19772
|
|
|
|
|
|
|
#endif |
19773
|
|
|
|
|
|
|
} |
19774
|
|
|
|
|
|
|
|
19775
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
19776
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
19777
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
19778
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
19779
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
19780
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
19781
|
|
|
|
|
|
|
|
19782
|
|
|
|
|
|
|
|
19783
|
|
|
|
|
|
|
|
19784
|
|
|
|
|
|
|
|
19785
|
|
|
|
|
|
|
|
19786
|
|
|
|
|
|
|
|
19787
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
19788
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
19789
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
19790
|
|
|
|
|
|
|
defined(__wasm__)) |
19791
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
19792
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19793
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
19794
|
|
|
|
|
|
|
#else |
19795
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
19796
|
|
|
|
|
|
|
#endif |
19797
|
|
|
|
|
|
|
|
19798
|
|
|
|
|
|
|
|
19799
|
|
|
|
|
|
|
|
19800
|
|
|
|
|
|
|
#ifdef FREESTANDING |
19801
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
19802
|
|
|
|
|
|
|
#else |
19803
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
19804
|
|
|
|
|
|
|
#endif |
19805
|
|
|
|
|
|
|
|
19806
|
|
|
|
|
|
|
|
19807
|
|
|
|
|
|
|
|
19808
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
19809
|
|
|
|
|
|
|
static forceinline type \ |
19810
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
19811
|
|
|
|
|
|
|
{ \ |
19812
|
|
|
|
|
|
|
type v; \ |
19813
|
|
|
|
|
|
|
\ |
19814
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
19815
|
|
|
|
|
|
|
return v; \ |
19816
|
|
|
|
|
|
|
} \ |
19817
|
|
|
|
|
|
|
\ |
19818
|
|
|
|
|
|
|
static forceinline void \ |
19819
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
19820
|
|
|
|
|
|
|
{ \ |
19821
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
19822
|
|
|
|
|
|
|
} |
19823
|
|
|
|
|
|
|
|
19824
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
19825
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
19826
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
19827
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
19828
|
|
|
|
|
|
|
|
19829
|
|
|
|
|
|
|
#undef MEMCOPY |
19830
|
|
|
|
|
|
|
|
19831
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
19832
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
19833
|
|
|
|
|
|
|
|
19834
|
|
|
|
|
|
|
|
19835
|
|
|
|
|
|
|
|
19836
|
|
|
|
|
|
|
static forceinline u16 |
19837
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
19838
|
|
|
|
|
|
|
{ |
19839
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19840
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
19841
|
|
|
|
|
|
|
else |
19842
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
19843
|
|
|
|
|
|
|
} |
19844
|
|
|
|
|
|
|
|
19845
|
|
|
|
|
|
|
static forceinline u16 |
19846
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
19847
|
|
|
|
|
|
|
{ |
19848
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19849
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
19850
|
|
|
|
|
|
|
else |
19851
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
19852
|
|
|
|
|
|
|
} |
19853
|
|
|
|
|
|
|
|
19854
|
|
|
|
|
|
|
static forceinline u32 |
19855
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
19856
|
|
|
|
|
|
|
{ |
19857
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19858
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
19859
|
|
|
|
|
|
|
else |
19860
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
19861
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
19862
|
|
|
|
|
|
|
} |
19863
|
|
|
|
|
|
|
|
19864
|
|
|
|
|
|
|
static forceinline u32 |
19865
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
19866
|
|
|
|
|
|
|
{ |
19867
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19868
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
19869
|
|
|
|
|
|
|
else |
19870
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
19871
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
19872
|
|
|
|
|
|
|
} |
19873
|
|
|
|
|
|
|
|
19874
|
|
|
|
|
|
|
static forceinline u64 |
19875
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
19876
|
|
|
|
|
|
|
{ |
19877
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19878
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
19879
|
|
|
|
|
|
|
else |
19880
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
19881
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
19882
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
19883
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
19884
|
|
|
|
|
|
|
} |
19885
|
|
|
|
|
|
|
|
19886
|
|
|
|
|
|
|
static forceinline machine_word_t |
19887
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
19888
|
|
|
|
|
|
|
{ |
19889
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
19890
|
|
|
|
|
|
|
if (WORDBITS == 32) |
19891
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
19892
|
|
|
|
|
|
|
else |
19893
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
19894
|
|
|
|
|
|
|
} |
19895
|
|
|
|
|
|
|
|
19896
|
|
|
|
|
|
|
|
19897
|
|
|
|
|
|
|
|
19898
|
|
|
|
|
|
|
static forceinline void |
19899
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
19900
|
|
|
|
|
|
|
{ |
19901
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19902
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
19903
|
|
|
|
|
|
|
} else { |
19904
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
19905
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
19906
|
|
|
|
|
|
|
} |
19907
|
|
|
|
|
|
|
} |
19908
|
|
|
|
|
|
|
|
19909
|
|
|
|
|
|
|
static forceinline void |
19910
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
19911
|
|
|
|
|
|
|
{ |
19912
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19913
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
19914
|
|
|
|
|
|
|
} else { |
19915
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
19916
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
19917
|
|
|
|
|
|
|
} |
19918
|
|
|
|
|
|
|
} |
19919
|
|
|
|
|
|
|
|
19920
|
|
|
|
|
|
|
static forceinline void |
19921
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
19922
|
|
|
|
|
|
|
{ |
19923
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19924
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
19925
|
|
|
|
|
|
|
} else { |
19926
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
19927
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
19928
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
19929
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
19930
|
|
|
|
|
|
|
} |
19931
|
|
|
|
|
|
|
} |
19932
|
|
|
|
|
|
|
|
19933
|
|
|
|
|
|
|
static forceinline void |
19934
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
19935
|
|
|
|
|
|
|
{ |
19936
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19937
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
19938
|
|
|
|
|
|
|
} else { |
19939
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
19940
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
19941
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
19942
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
19943
|
|
|
|
|
|
|
} |
19944
|
|
|
|
|
|
|
} |
19945
|
|
|
|
|
|
|
|
19946
|
|
|
|
|
|
|
static forceinline void |
19947
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
19948
|
|
|
|
|
|
|
{ |
19949
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19950
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
19951
|
|
|
|
|
|
|
} else { |
19952
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
19953
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
19954
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
19955
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
19956
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
19957
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
19958
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
19959
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
19960
|
|
|
|
|
|
|
} |
19961
|
|
|
|
|
|
|
} |
19962
|
|
|
|
|
|
|
|
19963
|
|
|
|
|
|
|
static forceinline void |
19964
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
19965
|
|
|
|
|
|
|
{ |
19966
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
19967
|
|
|
|
|
|
|
if (WORDBITS == 32) |
19968
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
19969
|
|
|
|
|
|
|
else |
19970
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
19971
|
|
|
|
|
|
|
} |
19972
|
|
|
|
|
|
|
|
19973
|
|
|
|
|
|
|
|
19974
|
|
|
|
|
|
|
|
19975
|
|
|
|
|
|
|
|
19976
|
|
|
|
|
|
|
|
19977
|
|
|
|
|
|
|
|
19978
|
|
|
|
|
|
|
|
19979
|
|
|
|
|
|
|
static forceinline unsigned |
19980
|
|
|
|
|
|
|
bsr32(u32 v) |
19981
|
|
|
|
|
|
|
{ |
19982
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
19983
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
19984
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19985
|
|
|
|
|
|
|
unsigned long i; |
19986
|
|
|
|
|
|
|
|
19987
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
19988
|
|
|
|
|
|
|
return i; |
19989
|
|
|
|
|
|
|
#else |
19990
|
|
|
|
|
|
|
unsigned i = 0; |
19991
|
|
|
|
|
|
|
|
19992
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
19993
|
|
|
|
|
|
|
i++; |
19994
|
|
|
|
|
|
|
return i; |
19995
|
|
|
|
|
|
|
#endif |
19996
|
|
|
|
|
|
|
} |
19997
|
|
|
|
|
|
|
|
19998
|
|
|
|
|
|
|
static forceinline unsigned |
19999
|
|
|
|
|
|
|
bsr64(u64 v) |
20000
|
|
|
|
|
|
|
{ |
20001
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
20002
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
20003
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
20004
|
|
|
|
|
|
|
unsigned long i; |
20005
|
|
|
|
|
|
|
|
20006
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
20007
|
|
|
|
|
|
|
return i; |
20008
|
|
|
|
|
|
|
#else |
20009
|
|
|
|
|
|
|
unsigned i = 0; |
20010
|
|
|
|
|
|
|
|
20011
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
20012
|
|
|
|
|
|
|
i++; |
20013
|
|
|
|
|
|
|
return i; |
20014
|
|
|
|
|
|
|
#endif |
20015
|
|
|
|
|
|
|
} |
20016
|
|
|
|
|
|
|
|
20017
|
|
|
|
|
|
|
static forceinline unsigned |
20018
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
20019
|
|
|
|
|
|
|
{ |
20020
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
20021
|
|
|
|
|
|
|
if (WORDBITS == 32) |
20022
|
|
|
|
|
|
|
return bsr32(v); |
20023
|
|
|
|
|
|
|
else |
20024
|
|
|
|
|
|
|
return bsr64(v); |
20025
|
|
|
|
|
|
|
} |
20026
|
|
|
|
|
|
|
|
20027
|
|
|
|
|
|
|
|
20028
|
|
|
|
|
|
|
|
20029
|
|
|
|
|
|
|
static forceinline unsigned |
20030
|
|
|
|
|
|
|
bsf32(u32 v) |
20031
|
|
|
|
|
|
|
{ |
20032
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
20033
|
|
|
|
|
|
|
return __builtin_ctz(v); |
20034
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
20035
|
|
|
|
|
|
|
unsigned long i; |
20036
|
|
|
|
|
|
|
|
20037
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
20038
|
|
|
|
|
|
|
return i; |
20039
|
|
|
|
|
|
|
#else |
20040
|
|
|
|
|
|
|
unsigned i = 0; |
20041
|
|
|
|
|
|
|
|
20042
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
20043
|
|
|
|
|
|
|
i++; |
20044
|
|
|
|
|
|
|
return i; |
20045
|
|
|
|
|
|
|
#endif |
20046
|
|
|
|
|
|
|
} |
20047
|
|
|
|
|
|
|
|
20048
|
|
|
|
|
|
|
static forceinline unsigned |
20049
|
|
|
|
|
|
|
bsf64(u64 v) |
20050
|
|
|
|
|
|
|
{ |
20051
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
20052
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
20053
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
20054
|
|
|
|
|
|
|
unsigned long i; |
20055
|
|
|
|
|
|
|
|
20056
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
20057
|
|
|
|
|
|
|
return i; |
20058
|
|
|
|
|
|
|
#else |
20059
|
|
|
|
|
|
|
unsigned i = 0; |
20060
|
|
|
|
|
|
|
|
20061
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
20062
|
|
|
|
|
|
|
i++; |
20063
|
|
|
|
|
|
|
return i; |
20064
|
|
|
|
|
|
|
#endif |
20065
|
|
|
|
|
|
|
} |
20066
|
|
|
|
|
|
|
|
20067
|
|
|
|
|
|
|
static forceinline unsigned |
20068
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
20069
|
|
|
|
|
|
|
{ |
20070
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
20071
|
|
|
|
|
|
|
if (WORDBITS == 32) |
20072
|
|
|
|
|
|
|
return bsf32(v); |
20073
|
|
|
|
|
|
|
else |
20074
|
|
|
|
|
|
|
return bsf64(v); |
20075
|
|
|
|
|
|
|
} |
20076
|
|
|
|
|
|
|
|
20077
|
|
|
|
|
|
|
|
20078
|
|
|
|
|
|
|
#undef rbit32 |
20079
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
20080
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
20081
|
|
|
|
|
|
|
static forceinline u32 |
20082
|
|
|
|
|
|
|
rbit32(u32 v) |
20083
|
|
|
|
|
|
|
{ |
20084
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
20085
|
|
|
|
|
|
|
return v; |
20086
|
|
|
|
|
|
|
} |
20087
|
|
|
|
|
|
|
#define rbit32 rbit32 |
20088
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
20089
|
|
|
|
|
|
|
static forceinline u32 |
20090
|
|
|
|
|
|
|
rbit32(u32 v) |
20091
|
|
|
|
|
|
|
{ |
20092
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
20093
|
|
|
|
|
|
|
return v; |
20094
|
|
|
|
|
|
|
} |
20095
|
|
|
|
|
|
|
#define rbit32 rbit32 |
20096
|
|
|
|
|
|
|
#endif |
20097
|
|
|
|
|
|
|
|
20098
|
|
|
|
|
|
|
#endif |
20099
|
|
|
|
|
|
|
|
20100
|
|
|
|
|
|
|
|
20101
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
20102
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
20103
|
|
|
|
|
|
|
|
20104
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
20105
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
20106
|
|
|
|
|
|
|
|
20107
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
20108
|
|
|
|
|
|
|
size_t alignment, size_t size); |
20109
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
20110
|
|
|
|
|
|
|
|
20111
|
|
|
|
|
|
|
#ifdef FREESTANDING |
20112
|
|
|
|
|
|
|
|
20113
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
20114
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
20115
|
|
|
|
|
|
|
|
20116
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
20117
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
20118
|
|
|
|
|
|
|
|
20119
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
20120
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
20121
|
|
|
|
|
|
|
|
20122
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
20123
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
20124
|
|
|
|
|
|
|
|
20125
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
20126
|
|
|
|
|
|
|
#else |
20127
|
|
|
|
|
|
|
#include |
20128
|
|
|
|
|
|
|
#endif |
20129
|
|
|
|
|
|
|
|
20130
|
|
|
|
|
|
|
|
20131
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
20132
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
20133
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
20134
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
20135
|
|
|
|
|
|
|
#else |
20136
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
20137
|
|
|
|
|
|
|
#endif |
20138
|
|
|
|
|
|
|
|
20139
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
20140
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
20141
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
20142
|
|
|
|
|
|
|
|
20143
|
|
|
|
|
|
|
#endif |
20144
|
|
|
|
|
|
|
|
20145
|
|
|
|
|
|
|
|
20146
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
20147
|
|
|
|
|
|
|
|
20148
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
20149
|
|
|
|
|
|
|
|
20150
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
20151
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
20152
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
20153
|
|
|
|
|
|
|
#endif |
20154
|
|
|
|
|
|
|
|
20155
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
20156
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
20157
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
20158
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
20159
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
20160
|
|
|
|
|
|
|
|
20161
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
20162
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
20163
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
20164
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
20165
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
20166
|
|
|
|
|
|
|
|
20167
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
20168
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
20169
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
20170
|
|
|
|
|
|
|
|
20171
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
20172
|
|
|
|
|
|
|
|
20173
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
20174
|
|
|
|
|
|
|
{ |
20175
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
20176
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
20177
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
20178
|
|
|
|
|
|
|
} |
20179
|
|
|
|
|
|
|
#else |
20180
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
20181
|
|
|
|
|
|
|
#endif |
20182
|
|
|
|
|
|
|
|
20183
|
|
|
|
|
|
|
|
20184
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
20185
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
20186
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
20187
|
|
|
|
|
|
|
#else |
20188
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
20189
|
|
|
|
|
|
|
#endif |
20190
|
|
|
|
|
|
|
|
20191
|
|
|
|
|
|
|
|
20192
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
20193
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
20194
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
20195
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
20196
|
|
|
|
|
|
|
#else |
20197
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
20198
|
|
|
|
|
|
|
#endif |
20199
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
20200
|
|
|
|
|
|
|
|
20201
|
|
|
|
|
|
|
|
20202
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
20203
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
20204
|
|
|
|
|
|
|
#else |
20205
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
20206
|
|
|
|
|
|
|
#endif |
20207
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
20208
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
20209
|
|
|
|
|
|
|
defined(_MSC_VER))) |
20210
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
20211
|
|
|
|
|
|
|
#else |
20212
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
20213
|
|
|
|
|
|
|
#endif |
20214
|
|
|
|
|
|
|
|
20215
|
|
|
|
|
|
|
|
20216
|
|
|
|
|
|
|
#ifdef __AVX__ |
20217
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
20218
|
|
|
|
|
|
|
#else |
20219
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
20220
|
|
|
|
|
|
|
#endif |
20221
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
20222
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
20223
|
|
|
|
|
|
|
defined(_MSC_VER))) |
20224
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
20225
|
|
|
|
|
|
|
#else |
20226
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
20227
|
|
|
|
|
|
|
#endif |
20228
|
|
|
|
|
|
|
|
20229
|
|
|
|
|
|
|
|
20230
|
|
|
|
|
|
|
#ifdef __AVX2__ |
20231
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
20232
|
|
|
|
|
|
|
#else |
20233
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
20234
|
|
|
|
|
|
|
#endif |
20235
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
20236
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
20237
|
|
|
|
|
|
|
defined(_MSC_VER))) |
20238
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
20239
|
|
|
|
|
|
|
#else |
20240
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
20241
|
|
|
|
|
|
|
#endif |
20242
|
|
|
|
|
|
|
|
20243
|
|
|
|
|
|
|
|
20244
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
20245
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
20246
|
|
|
|
|
|
|
#else |
20247
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
20248
|
|
|
|
|
|
|
#endif |
20249
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
20250
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
20251
|
|
|
|
|
|
|
defined(_MSC_VER))) |
20252
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
20253
|
|
|
|
|
|
|
#else |
20254
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
20255
|
|
|
|
|
|
|
#endif |
20256
|
|
|
|
|
|
|
|
20257
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1930 |
20258
|
|
|
|
|
|
|
# undef HAVE_BMI2_NATIVE |
20259
|
|
|
|
|
|
|
# undef HAVE_BMI2_INTRIN |
20260
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
20261
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
20262
|
|
|
|
|
|
|
#endif |
20263
|
|
|
|
|
|
|
|
20264
|
|
|
|
|
|
|
#endif |
20265
|
|
|
|
|
|
|
|
20266
|
|
|
|
|
|
|
#endif |
20267
|
|
|
|
|
|
|
|
20268
|
|
|
|
|
|
|
|
20269
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE |
20270
|
|
|
|
|
|
|
# include |
20271
|
|
|
|
|
|
|
static forceinline void |
20272
|
|
|
|
|
|
|
matchfinder_init_avx2(mf_pos_t *data, size_t size) |
20273
|
|
|
|
|
|
|
{ |
20274
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
20275
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16(MATCHFINDER_INITVAL); |
20276
|
|
|
|
|
|
|
|
20277
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
20278
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
20279
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
20280
|
|
|
|
|
|
|
|
20281
|
|
|
|
|
|
|
do { |
20282
|
|
|
|
|
|
|
p[0] = v; |
20283
|
|
|
|
|
|
|
p[1] = v; |
20284
|
|
|
|
|
|
|
p[2] = v; |
20285
|
|
|
|
|
|
|
p[3] = v; |
20286
|
|
|
|
|
|
|
p += 4; |
20287
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
20288
|
|
|
|
|
|
|
} while (size != 0); |
20289
|
|
|
|
|
|
|
} |
20290
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_avx2 |
20291
|
|
|
|
|
|
|
|
20292
|
|
|
|
|
|
|
static forceinline void |
20293
|
|
|
|
|
|
|
matchfinder_rebase_avx2(mf_pos_t *data, size_t size) |
20294
|
|
|
|
|
|
|
{ |
20295
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
20296
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
20297
|
|
|
|
|
|
|
|
20298
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
20299
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
20300
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
20301
|
|
|
|
|
|
|
|
20302
|
|
|
|
|
|
|
do { |
20303
|
|
|
|
|
|
|
|
20304
|
|
|
|
|
|
|
p[0] = _mm256_adds_epi16(p[0], v); |
20305
|
|
|
|
|
|
|
p[1] = _mm256_adds_epi16(p[1], v); |
20306
|
|
|
|
|
|
|
p[2] = _mm256_adds_epi16(p[2], v); |
20307
|
|
|
|
|
|
|
p[3] = _mm256_adds_epi16(p[3], v); |
20308
|
|
|
|
|
|
|
p += 4; |
20309
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
20310
|
|
|
|
|
|
|
} while (size != 0); |
20311
|
|
|
|
|
|
|
} |
20312
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_avx2 |
20313
|
|
|
|
|
|
|
|
20314
|
|
|
|
|
|
|
#elif HAVE_SSE2_NATIVE |
20315
|
|
|
|
|
|
|
# include |
20316
|
|
|
|
|
|
|
static forceinline void |
20317
|
|
|
|
|
|
|
matchfinder_init_sse2(mf_pos_t *data, size_t size) |
20318
|
|
|
|
|
|
|
{ |
20319
|
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
20320
|
|
|
|
|
|
|
__m128i v = _mm_set1_epi16(MATCHFINDER_INITVAL); |
20321
|
|
|
|
|
|
|
|
20322
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
20323
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
20324
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
20325
|
|
|
|
|
|
|
|
20326
|
|
|
|
|
|
|
do { |
20327
|
|
|
|
|
|
|
p[0] = v; |
20328
|
|
|
|
|
|
|
p[1] = v; |
20329
|
|
|
|
|
|
|
p[2] = v; |
20330
|
|
|
|
|
|
|
p[3] = v; |
20331
|
|
|
|
|
|
|
p += 4; |
20332
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
20333
|
|
|
|
|
|
|
} while (size != 0); |
20334
|
|
|
|
|
|
|
} |
20335
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_sse2 |
20336
|
|
|
|
|
|
|
|
20337
|
|
|
|
|
|
|
static forceinline void |
20338
|
|
|
|
|
|
|
matchfinder_rebase_sse2(mf_pos_t *data, size_t size) |
20339
|
|
|
|
|
|
|
{ |
20340
|
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
20341
|
|
|
|
|
|
|
__m128i v = _mm_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
20342
|
|
|
|
|
|
|
|
20343
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
20344
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
20345
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
20346
|
|
|
|
|
|
|
|
20347
|
|
|
|
|
|
|
do { |
20348
|
|
|
|
|
|
|
|
20349
|
|
|
|
|
|
|
p[0] = _mm_adds_epi16(p[0], v); |
20350
|
|
|
|
|
|
|
p[1] = _mm_adds_epi16(p[1], v); |
20351
|
|
|
|
|
|
|
p[2] = _mm_adds_epi16(p[2], v); |
20352
|
|
|
|
|
|
|
p[3] = _mm_adds_epi16(p[3], v); |
20353
|
|
|
|
|
|
|
p += 4; |
20354
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
20355
|
|
|
|
|
|
|
} while (size != 0); |
20356
|
|
|
|
|
|
|
} |
20357
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_sse2 |
20358
|
|
|
|
|
|
|
#endif |
20359
|
|
|
|
|
|
|
|
20360
|
|
|
|
|
|
|
#endif |
20361
|
|
|
|
|
|
|
|
20362
|
|
|
|
|
|
|
# endif |
20363
|
|
|
|
|
|
|
#else |
20364
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED |
20365
|
|
|
|
|
|
|
#endif |
20366
|
|
|
|
|
|
|
|
20367
|
|
|
|
|
|
|
|
20368
|
|
|
|
|
|
|
#ifndef matchfinder_init |
20369
|
|
|
|
|
|
|
static forceinline void |
20370
|
|
|
|
|
|
|
matchfinder_init(mf_pos_t *data, size_t size) |
20371
|
|
|
|
|
|
|
{ |
20372
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
20373
|
|
|
|
|
|
|
size_t i; |
20374
|
|
|
|
|
|
|
|
20375
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
20376
|
|
|
|
|
|
|
data[i] = MATCHFINDER_INITVAL; |
20377
|
|
|
|
|
|
|
} |
20378
|
|
|
|
|
|
|
#endif |
20379
|
|
|
|
|
|
|
|
20380
|
|
|
|
|
|
|
|
20381
|
|
|
|
|
|
|
#ifndef matchfinder_rebase |
20382
|
|
|
|
|
|
|
static forceinline void |
20383
|
|
|
|
|
|
|
matchfinder_rebase(mf_pos_t *data, size_t size) |
20384
|
|
|
|
|
|
|
{ |
20385
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
20386
|
|
|
|
|
|
|
size_t i; |
20387
|
|
|
|
|
|
|
|
20388
|
|
|
|
|
|
|
if (MATCHFINDER_WINDOW_SIZE == 32768) { |
20389
|
|
|
|
|
|
|
|
20390
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
20391
|
|
|
|
|
|
|
data[i] = 0x8000 | (data[i] & ~(data[i] >> 15)); |
20392
|
|
|
|
|
|
|
} else { |
20393
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) { |
20394
|
|
|
|
|
|
|
if (data[i] >= 0) |
20395
|
|
|
|
|
|
|
data[i] -= (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
20396
|
|
|
|
|
|
|
else |
20397
|
|
|
|
|
|
|
data[i] = (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
20398
|
|
|
|
|
|
|
} |
20399
|
|
|
|
|
|
|
} |
20400
|
|
|
|
|
|
|
} |
20401
|
|
|
|
|
|
|
#endif |
20402
|
|
|
|
|
|
|
|
20403
|
|
|
|
|
|
|
|
20404
|
|
|
|
|
|
|
static forceinline u32 |
20405
|
|
|
|
|
|
|
lz_hash(u32 seq, unsigned num_bits) |
20406
|
|
|
|
|
|
|
{ |
20407
|
|
|
|
|
|
|
return (u32)(seq * 0x1E35A7BD) >> (32 - num_bits); |
20408
|
|
|
|
|
|
|
} |
20409
|
|
|
|
|
|
|
|
20410
|
|
|
|
|
|
|
|
20411
|
|
|
|
|
|
|
static forceinline unsigned |
20412
|
|
|
|
|
|
|
lz_extend(const u8 * const strptr, const u8 * const matchptr, |
20413
|
|
|
|
|
|
|
const unsigned start_len, const unsigned max_len) |
20414
|
|
|
|
|
|
|
{ |
20415
|
|
|
|
|
|
|
unsigned len = start_len; |
20416
|
|
|
|
|
|
|
machine_word_t v_word; |
20417
|
|
|
|
|
|
|
|
20418
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
20419
|
|
|
|
|
|
|
|
20420
|
|
|
|
|
|
|
if (likely(max_len - len >= 4 * WORDBYTES)) { |
20421
|
|
|
|
|
|
|
|
20422
|
|
|
|
|
|
|
#define COMPARE_WORD_STEP \ |
20423
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ \ |
20424
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); \ |
20425
|
|
|
|
|
|
|
if (v_word != 0) \ |
20426
|
|
|
|
|
|
|
goto word_differs; \ |
20427
|
|
|
|
|
|
|
len += WORDBYTES; \ |
20428
|
|
|
|
|
|
|
|
20429
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
20430
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
20431
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
20432
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
20433
|
|
|
|
|
|
|
#undef COMPARE_WORD_STEP |
20434
|
|
|
|
|
|
|
} |
20435
|
|
|
|
|
|
|
|
20436
|
|
|
|
|
|
|
while (len + WORDBYTES <= max_len) { |
20437
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ |
20438
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); |
20439
|
|
|
|
|
|
|
if (v_word != 0) |
20440
|
|
|
|
|
|
|
goto word_differs; |
20441
|
|
|
|
|
|
|
len += WORDBYTES; |
20442
|
|
|
|
|
|
|
} |
20443
|
|
|
|
|
|
|
} |
20444
|
|
|
|
|
|
|
|
20445
|
|
|
|
|
|
|
while (len < max_len && matchptr[len] == strptr[len]) |
20446
|
|
|
|
|
|
|
len++; |
20447
|
|
|
|
|
|
|
return len; |
20448
|
|
|
|
|
|
|
|
20449
|
|
|
|
|
|
|
word_differs: |
20450
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
20451
|
|
|
|
|
|
|
len += (bsfw(v_word) >> 3); |
20452
|
|
|
|
|
|
|
else |
20453
|
|
|
|
|
|
|
len += (WORDBITS - 1 - bsrw(v_word)) >> 3; |
20454
|
|
|
|
|
|
|
return len; |
20455
|
|
|
|
|
|
|
} |
20456
|
|
|
|
|
|
|
|
20457
|
|
|
|
|
|
|
#endif |
20458
|
|
|
|
|
|
|
|
20459
|
|
|
|
|
|
|
|
20460
|
|
|
|
|
|
|
#define BT_MATCHFINDER_HASH3_ORDER 16 |
20461
|
|
|
|
|
|
|
#define BT_MATCHFINDER_HASH3_WAYS 2 |
20462
|
|
|
|
|
|
|
#define BT_MATCHFINDER_HASH4_ORDER 16 |
20463
|
|
|
|
|
|
|
|
20464
|
|
|
|
|
|
|
#define BT_MATCHFINDER_TOTAL_HASH_SIZE \ |
20465
|
|
|
|
|
|
|
(((1UL << BT_MATCHFINDER_HASH3_ORDER) * BT_MATCHFINDER_HASH3_WAYS + \ |
20466
|
|
|
|
|
|
|
(1UL << BT_MATCHFINDER_HASH4_ORDER)) * sizeof(mf_pos_t)) |
20467
|
|
|
|
|
|
|
|
20468
|
|
|
|
|
|
|
|
20469
|
|
|
|
|
|
|
struct lz_match { |
20470
|
|
|
|
|
|
|
|
20471
|
|
|
|
|
|
|
|
20472
|
|
|
|
|
|
|
u16 length; |
20473
|
|
|
|
|
|
|
|
20474
|
|
|
|
|
|
|
|
20475
|
|
|
|
|
|
|
u16 offset; |
20476
|
|
|
|
|
|
|
}; |
20477
|
|
|
|
|
|
|
|
20478
|
|
|
|
|
|
|
struct MATCHFINDER_ALIGNED bt_matchfinder { |
20479
|
|
|
|
|
|
|
|
20480
|
|
|
|
|
|
|
|
20481
|
|
|
|
|
|
|
mf_pos_t hash3_tab[1UL << BT_MATCHFINDER_HASH3_ORDER][BT_MATCHFINDER_HASH3_WAYS]; |
20482
|
|
|
|
|
|
|
|
20483
|
|
|
|
|
|
|
|
20484
|
|
|
|
|
|
|
mf_pos_t hash4_tab[1UL << BT_MATCHFINDER_HASH4_ORDER]; |
20485
|
|
|
|
|
|
|
|
20486
|
|
|
|
|
|
|
|
20487
|
|
|
|
|
|
|
mf_pos_t child_tab[2UL * MATCHFINDER_WINDOW_SIZE]; |
20488
|
|
|
|
|
|
|
}; |
20489
|
|
|
|
|
|
|
|
20490
|
|
|
|
|
|
|
|
20491
|
|
|
|
|
|
|
static forceinline void |
20492
|
|
|
|
|
|
|
bt_matchfinder_init(struct bt_matchfinder *mf) |
20493
|
|
|
|
|
|
|
{ |
20494
|
|
|
|
|
|
|
STATIC_ASSERT(BT_MATCHFINDER_TOTAL_HASH_SIZE % |
20495
|
|
|
|
|
|
|
MATCHFINDER_SIZE_ALIGNMENT == 0); |
20496
|
|
|
|
|
|
|
|
20497
|
|
|
|
|
|
|
matchfinder_init((mf_pos_t *)mf, BT_MATCHFINDER_TOTAL_HASH_SIZE); |
20498
|
|
|
|
|
|
|
} |
20499
|
|
|
|
|
|
|
|
20500
|
|
|
|
|
|
|
static forceinline void |
20501
|
|
|
|
|
|
|
bt_matchfinder_slide_window(struct bt_matchfinder *mf) |
20502
|
|
|
|
|
|
|
{ |
20503
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(*mf) % MATCHFINDER_SIZE_ALIGNMENT == 0); |
20504
|
|
|
|
|
|
|
|
20505
|
|
|
|
|
|
|
matchfinder_rebase((mf_pos_t *)mf, sizeof(*mf)); |
20506
|
|
|
|
|
|
|
} |
20507
|
|
|
|
|
|
|
|
20508
|
|
|
|
|
|
|
static forceinline mf_pos_t * |
20509
|
|
|
|
|
|
|
bt_left_child(struct bt_matchfinder *mf, s32 node) |
20510
|
|
|
|
|
|
|
{ |
20511
|
30366
|
|
|
|
|
|
return &mf->child_tab[2 * (node & (MATCHFINDER_WINDOW_SIZE - 1)) + 0]; |
20512
|
|
|
|
|
|
|
} |
20513
|
|
|
|
|
|
|
|
20514
|
|
|
|
|
|
|
static forceinline mf_pos_t * |
20515
|
|
|
|
|
|
|
bt_right_child(struct bt_matchfinder *mf, s32 node) |
20516
|
|
|
|
|
|
|
{ |
20517
|
30366
|
|
|
|
|
|
return &mf->child_tab[2 * (node & (MATCHFINDER_WINDOW_SIZE - 1)) + 1]; |
20518
|
|
|
|
|
|
|
} |
20519
|
|
|
|
|
|
|
|
20520
|
|
|
|
|
|
|
|
20521
|
|
|
|
|
|
|
#define BT_MATCHFINDER_REQUIRED_NBYTES 5 |
20522
|
|
|
|
|
|
|
|
20523
|
|
|
|
|
|
|
|
20524
|
|
|
|
|
|
|
static forceinline struct lz_match * |
20525
|
|
|
|
|
|
|
bt_matchfinder_advance_one_byte(struct bt_matchfinder * const mf, |
20526
|
|
|
|
|
|
|
const u8 * const in_base, |
20527
|
|
|
|
|
|
|
const ptrdiff_t cur_pos, |
20528
|
|
|
|
|
|
|
const u32 max_len, |
20529
|
|
|
|
|
|
|
const u32 nice_len, |
20530
|
|
|
|
|
|
|
const u32 max_search_depth, |
20531
|
|
|
|
|
|
|
u32 * const next_hashes, |
20532
|
|
|
|
|
|
|
struct lz_match *lz_matchptr, |
20533
|
|
|
|
|
|
|
const bool record_matches) |
20534
|
|
|
|
|
|
|
{ |
20535
|
15264
|
|
|
|
|
|
const u8 *in_next = in_base + cur_pos; |
20536
|
15264
|
|
|
|
|
|
u32 depth_remaining = max_search_depth; |
20537
|
15264
|
|
|
|
|
|
const s32 cutoff = cur_pos - MATCHFINDER_WINDOW_SIZE; |
20538
|
|
|
|
|
|
|
u32 next_hashseq; |
20539
|
|
|
|
|
|
|
u32 hash3; |
20540
|
|
|
|
|
|
|
u32 hash4; |
20541
|
|
|
|
|
|
|
s32 cur_node; |
20542
|
|
|
|
|
|
|
#if BT_MATCHFINDER_HASH3_WAYS >= 2 |
20543
|
|
|
|
|
|
|
s32 cur_node_2; |
20544
|
|
|
|
|
|
|
#endif |
20545
|
|
|
|
|
|
|
const u8 *matchptr; |
20546
|
|
|
|
|
|
|
mf_pos_t *pending_lt_ptr, *pending_gt_ptr; |
20547
|
|
|
|
|
|
|
u32 best_lt_len, best_gt_len; |
20548
|
|
|
|
|
|
|
u32 len; |
20549
|
15264
|
|
|
|
|
|
u32 best_len = 3; |
20550
|
|
|
|
|
|
|
|
20551
|
|
|
|
|
|
|
STATIC_ASSERT(BT_MATCHFINDER_HASH3_WAYS >= 1 && |
20552
|
|
|
|
|
|
|
BT_MATCHFINDER_HASH3_WAYS <= 2); |
20553
|
|
|
|
|
|
|
|
20554
|
30528
|
|
|
|
|
|
next_hashseq = get_unaligned_le32(in_next + 1); |
20555
|
|
|
|
|
|
|
|
20556
|
15264
|
|
|
|
|
|
hash3 = next_hashes[0]; |
20557
|
15264
|
|
|
|
|
|
hash4 = next_hashes[1]; |
20558
|
|
|
|
|
|
|
|
20559
|
30528
|
|
|
|
|
|
next_hashes[0] = lz_hash(next_hashseq & 0xFFFFFF, BT_MATCHFINDER_HASH3_ORDER); |
20560
|
30528
|
|
|
|
|
|
next_hashes[1] = lz_hash(next_hashseq, BT_MATCHFINDER_HASH4_ORDER); |
20561
|
15264
|
|
|
|
|
|
prefetchw(&mf->hash3_tab[next_hashes[0]]); |
20562
|
15264
|
|
|
|
|
|
prefetchw(&mf->hash4_tab[next_hashes[1]]); |
20563
|
|
|
|
|
|
|
|
20564
|
15264
|
|
|
|
|
|
cur_node = mf->hash3_tab[hash3][0]; |
20565
|
15264
|
|
|
|
|
|
mf->hash3_tab[hash3][0] = cur_pos; |
20566
|
|
|
|
|
|
|
#if BT_MATCHFINDER_HASH3_WAYS >= 2 |
20567
|
15264
|
|
|
|
|
|
cur_node_2 = mf->hash3_tab[hash3][1]; |
20568
|
15264
|
|
|
|
|
|
mf->hash3_tab[hash3][1] = cur_node; |
20569
|
|
|
|
|
|
|
#endif |
20570
|
225
|
100
|
|
|
|
|
if (record_matches && cur_node > cutoff) { |
20571
|
63
|
|
|
|
|
|
u32 seq3 = load_u24_unaligned(in_next); |
20572
|
63
|
50
|
|
|
|
|
if (seq3 == load_u24_unaligned(&in_base[cur_node])) { |
20573
|
63
|
|
|
|
|
|
lz_matchptr->length = 3; |
20574
|
63
|
|
|
|
|
|
lz_matchptr->offset = in_next - &in_base[cur_node]; |
20575
|
63
|
|
|
|
|
|
lz_matchptr++; |
20576
|
|
|
|
|
|
|
} |
20577
|
|
|
|
|
|
|
#if BT_MATCHFINDER_HASH3_WAYS >= 2 |
20578
|
0
|
0
|
|
|
|
|
else if (cur_node_2 > cutoff && |
|
|
0
|
|
|
|
|
|
20579
|
0
|
|
|
|
|
|
seq3 == load_u24_unaligned(&in_base[cur_node_2])) |
20580
|
|
|
|
|
|
|
{ |
20581
|
0
|
|
|
|
|
|
lz_matchptr->length = 3; |
20582
|
0
|
|
|
|
|
|
lz_matchptr->offset = in_next - &in_base[cur_node_2]; |
20583
|
0
|
|
|
|
|
|
lz_matchptr++; |
20584
|
|
|
|
|
|
|
} |
20585
|
|
|
|
|
|
|
#endif |
20586
|
|
|
|
|
|
|
} |
20587
|
|
|
|
|
|
|
|
20588
|
15264
|
|
|
|
|
|
cur_node = mf->hash4_tab[hash4]; |
20589
|
15264
|
|
|
|
|
|
mf->hash4_tab[hash4] = cur_pos; |
20590
|
|
|
|
|
|
|
|
20591
|
30528
|
|
|
|
|
|
pending_lt_ptr = bt_left_child(mf, cur_pos); |
20592
|
30528
|
|
|
|
|
|
pending_gt_ptr = bt_right_child(mf, cur_pos); |
20593
|
|
|
|
|
|
|
|
20594
|
15264
|
100
|
|
|
|
|
if (cur_node <= cutoff) { |
|
|
50
|
|
|
|
|
|
20595
|
162
|
|
|
|
|
|
*pending_lt_ptr = MATCHFINDER_INITVAL; |
20596
|
162
|
|
|
|
|
|
*pending_gt_ptr = MATCHFINDER_INITVAL; |
20597
|
162
|
|
|
|
|
|
return lz_matchptr; |
20598
|
|
|
|
|
|
|
} |
20599
|
|
|
|
|
|
|
|
20600
|
15102
|
|
|
|
|
|
best_lt_len = 0; |
20601
|
15102
|
|
|
|
|
|
best_gt_len = 0; |
20602
|
15102
|
|
|
|
|
|
len = 0; |
20603
|
|
|
|
|
|
|
|
20604
|
|
|
|
|
|
|
for (;;) { |
20605
|
15102
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
20606
|
|
|
|
|
|
|
|
20607
|
15102
|
50
|
|
|
|
|
if (matchptr[len] == in_next[len]) { |
|
|
50
|
|
|
|
|
|
20608
|
30204
|
|
|
|
|
|
len = lz_extend(in_next, matchptr, len + 1, max_len); |
20609
|
15102
|
50
|
|
|
|
|
if (!record_matches || len > best_len) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
20610
|
|
|
|
|
|
|
if (record_matches) { |
20611
|
63
|
|
|
|
|
|
best_len = len; |
20612
|
63
|
|
|
|
|
|
lz_matchptr->length = len; |
20613
|
63
|
|
|
|
|
|
lz_matchptr->offset = in_next - matchptr; |
20614
|
63
|
|
|
|
|
|
lz_matchptr++; |
20615
|
|
|
|
|
|
|
} |
20616
|
15102
|
50
|
|
|
|
|
if (len >= nice_len) { |
|
|
50
|
|
|
|
|
|
20617
|
15102
|
|
|
|
|
|
*pending_lt_ptr = *bt_left_child(mf, cur_node); |
20618
|
15102
|
|
|
|
|
|
*pending_gt_ptr = *bt_right_child(mf, cur_node); |
20619
|
15102
|
|
|
|
|
|
return lz_matchptr; |
20620
|
|
|
|
|
|
|
} |
20621
|
|
|
|
|
|
|
} |
20622
|
|
|
|
|
|
|
} |
20623
|
|
|
|
|
|
|
|
20624
|
0
|
0
|
|
|
|
|
if (matchptr[len] < in_next[len]) { |
|
|
0
|
|
|
|
|
|
20625
|
0
|
|
|
|
|
|
*pending_lt_ptr = cur_node; |
20626
|
0
|
|
|
|
|
|
pending_lt_ptr = bt_right_child(mf, cur_node); |
20627
|
0
|
|
|
|
|
|
cur_node = *pending_lt_ptr; |
20628
|
0
|
|
|
|
|
|
best_lt_len = len; |
20629
|
0
|
0
|
|
|
|
|
if (best_gt_len < len) |
|
|
0
|
|
|
|
|
|
20630
|
0
|
|
|
|
|
|
len = best_gt_len; |
20631
|
|
|
|
|
|
|
} else { |
20632
|
0
|
|
|
|
|
|
*pending_gt_ptr = cur_node; |
20633
|
0
|
|
|
|
|
|
pending_gt_ptr = bt_left_child(mf, cur_node); |
20634
|
0
|
|
|
|
|
|
cur_node = *pending_gt_ptr; |
20635
|
0
|
|
|
|
|
|
best_gt_len = len; |
20636
|
0
|
0
|
|
|
|
|
if (best_lt_len < len) |
|
|
0
|
|
|
|
|
|
20637
|
0
|
|
|
|
|
|
len = best_lt_len; |
20638
|
|
|
|
|
|
|
} |
20639
|
|
|
|
|
|
|
|
20640
|
0
|
0
|
|
|
|
|
if (cur_node <= cutoff || !--depth_remaining) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
20641
|
0
|
|
|
|
|
|
*pending_lt_ptr = MATCHFINDER_INITVAL; |
20642
|
0
|
|
|
|
|
|
*pending_gt_ptr = MATCHFINDER_INITVAL; |
20643
|
15039
|
|
|
|
|
|
return lz_matchptr; |
20644
|
|
|
|
|
|
|
} |
20645
|
|
|
|
|
|
|
} |
20646
|
|
|
|
|
|
|
} |
20647
|
|
|
|
|
|
|
|
20648
|
|
|
|
|
|
|
|
20649
|
|
|
|
|
|
|
static forceinline struct lz_match * |
20650
|
|
|
|
|
|
|
bt_matchfinder_get_matches(struct bt_matchfinder *mf, |
20651
|
|
|
|
|
|
|
const u8 *in_base, |
20652
|
|
|
|
|
|
|
ptrdiff_t cur_pos, |
20653
|
|
|
|
|
|
|
u32 max_len, |
20654
|
|
|
|
|
|
|
u32 nice_len, |
20655
|
|
|
|
|
|
|
u32 max_search_depth, |
20656
|
|
|
|
|
|
|
u32 next_hashes[2], |
20657
|
|
|
|
|
|
|
struct lz_match *lz_matchptr) |
20658
|
|
|
|
|
|
|
{ |
20659
|
225
|
|
|
|
|
|
return bt_matchfinder_advance_one_byte(mf, |
20660
|
|
|
|
|
|
|
in_base, |
20661
|
|
|
|
|
|
|
cur_pos, |
20662
|
|
|
|
|
|
|
max_len, |
20663
|
|
|
|
|
|
|
nice_len, |
20664
|
|
|
|
|
|
|
max_search_depth, |
20665
|
|
|
|
|
|
|
next_hashes, |
20666
|
|
|
|
|
|
|
lz_matchptr, |
20667
|
|
|
|
|
|
|
true); |
20668
|
|
|
|
|
|
|
} |
20669
|
|
|
|
|
|
|
|
20670
|
|
|
|
|
|
|
|
20671
|
|
|
|
|
|
|
static forceinline void |
20672
|
|
|
|
|
|
|
bt_matchfinder_skip_byte(struct bt_matchfinder *mf, |
20673
|
|
|
|
|
|
|
const u8 *in_base, |
20674
|
|
|
|
|
|
|
ptrdiff_t cur_pos, |
20675
|
|
|
|
|
|
|
u32 nice_len, |
20676
|
|
|
|
|
|
|
u32 max_search_depth, |
20677
|
|
|
|
|
|
|
u32 next_hashes[2]) |
20678
|
|
|
|
|
|
|
{ |
20679
|
|
|
|
|
|
|
bt_matchfinder_advance_one_byte(mf, |
20680
|
|
|
|
|
|
|
in_base, |
20681
|
|
|
|
|
|
|
cur_pos, |
20682
|
|
|
|
|
|
|
nice_len, |
20683
|
|
|
|
|
|
|
nice_len, |
20684
|
|
|
|
|
|
|
max_search_depth, |
20685
|
|
|
|
|
|
|
next_hashes, |
20686
|
|
|
|
|
|
|
NULL, |
20687
|
|
|
|
|
|
|
false); |
20688
|
|
|
|
|
|
|
} |
20689
|
|
|
|
|
|
|
|
20690
|
|
|
|
|
|
|
#endif |
20691
|
|
|
|
|
|
|
|
20692
|
|
|
|
|
|
|
|
20693
|
|
|
|
|
|
|
#define MAX_MATCHES_PER_POS \ |
20694
|
|
|
|
|
|
|
(DEFLATE_MAX_MATCH_LEN - DEFLATE_MIN_MATCH_LEN + 1) |
20695
|
|
|
|
|
|
|
#endif |
20696
|
|
|
|
|
|
|
|
20697
|
|
|
|
|
|
|
|
20698
|
|
|
|
|
|
|
#define MAX_BLOCK_LENGTH \ |
20699
|
|
|
|
|
|
|
MAX(SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH - 1, \ |
20700
|
|
|
|
|
|
|
SOFT_MAX_BLOCK_LENGTH + 1 + DEFLATE_MAX_MATCH_LEN) |
20701
|
|
|
|
|
|
|
|
20702
|
|
|
|
|
|
|
static forceinline void |
20703
|
|
|
|
|
|
|
check_buildtime_parameters(void) |
20704
|
|
|
|
|
|
|
{ |
20705
|
|
|
|
|
|
|
|
20706
|
|
|
|
|
|
|
STATIC_ASSERT(SOFT_MAX_BLOCK_LENGTH >= MIN_BLOCK_LENGTH); |
20707
|
|
|
|
|
|
|
STATIC_ASSERT(FAST_SOFT_MAX_BLOCK_LENGTH >= MIN_BLOCK_LENGTH); |
20708
|
|
|
|
|
|
|
STATIC_ASSERT(SEQ_STORE_LENGTH * DEFLATE_MIN_MATCH_LEN >= |
20709
|
|
|
|
|
|
|
MIN_BLOCK_LENGTH); |
20710
|
|
|
|
|
|
|
STATIC_ASSERT(FAST_SEQ_STORE_LENGTH * HT_MATCHFINDER_MIN_MATCH_LEN >= |
20711
|
|
|
|
|
|
|
MIN_BLOCK_LENGTH); |
20712
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
20713
|
|
|
|
|
|
|
STATIC_ASSERT(MIN_BLOCK_LENGTH * MAX_MATCHES_PER_POS <= |
20714
|
|
|
|
|
|
|
MATCH_CACHE_LENGTH); |
20715
|
|
|
|
|
|
|
#endif |
20716
|
|
|
|
|
|
|
|
20717
|
|
|
|
|
|
|
|
20718
|
|
|
|
|
|
|
STATIC_ASSERT(FAST_SOFT_MAX_BLOCK_LENGTH <= SOFT_MAX_BLOCK_LENGTH); |
20719
|
|
|
|
|
|
|
|
20720
|
|
|
|
|
|
|
|
20721
|
|
|
|
|
|
|
STATIC_ASSERT(SEQ_STORE_LENGTH * DEFLATE_MIN_MATCH_LEN <= |
20722
|
|
|
|
|
|
|
SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH); |
20723
|
|
|
|
|
|
|
STATIC_ASSERT(FAST_SEQ_STORE_LENGTH * HT_MATCHFINDER_MIN_MATCH_LEN <= |
20724
|
|
|
|
|
|
|
FAST_SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH); |
20725
|
|
|
|
|
|
|
|
20726
|
|
|
|
|
|
|
|
20727
|
|
|
|
|
|
|
STATIC_ASSERT( |
20728
|
|
|
|
|
|
|
MAX_LITLEN_CODEWORD_LEN <= DEFLATE_MAX_LITLEN_CODEWORD_LEN); |
20729
|
|
|
|
|
|
|
STATIC_ASSERT( |
20730
|
|
|
|
|
|
|
MAX_OFFSET_CODEWORD_LEN <= DEFLATE_MAX_OFFSET_CODEWORD_LEN); |
20731
|
|
|
|
|
|
|
STATIC_ASSERT( |
20732
|
|
|
|
|
|
|
MAX_PRE_CODEWORD_LEN <= DEFLATE_MAX_PRE_CODEWORD_LEN); |
20733
|
|
|
|
|
|
|
STATIC_ASSERT( |
20734
|
|
|
|
|
|
|
(1U << MAX_LITLEN_CODEWORD_LEN) >= DEFLATE_NUM_LITLEN_SYMS); |
20735
|
|
|
|
|
|
|
STATIC_ASSERT( |
20736
|
|
|
|
|
|
|
(1U << MAX_OFFSET_CODEWORD_LEN) >= DEFLATE_NUM_OFFSET_SYMS); |
20737
|
|
|
|
|
|
|
STATIC_ASSERT( |
20738
|
|
|
|
|
|
|
(1U << MAX_PRE_CODEWORD_LEN) >= DEFLATE_NUM_PRECODE_SYMS); |
20739
|
|
|
|
|
|
|
} |
20740
|
|
|
|
|
|
|
|
20741
|
|
|
|
|
|
|
|
20742
|
|
|
|
|
|
|
|
20743
|
|
|
|
|
|
|
|
20744
|
|
|
|
|
|
|
static const unsigned deflate_length_slot_base[] = { |
20745
|
|
|
|
|
|
|
3, 4, 5, 6, 7, 8, 9, 10, |
20746
|
|
|
|
|
|
|
11, 13, 15, 17, 19, 23, 27, 31, |
20747
|
|
|
|
|
|
|
35, 43, 51, 59, 67, 83, 99, 115, |
20748
|
|
|
|
|
|
|
131, 163, 195, 227, 258, |
20749
|
|
|
|
|
|
|
}; |
20750
|
|
|
|
|
|
|
|
20751
|
|
|
|
|
|
|
|
20752
|
|
|
|
|
|
|
static const u8 deflate_extra_length_bits[] = { |
20753
|
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, |
20754
|
|
|
|
|
|
|
1, 1, 1, 1, 2, 2, 2, 2, |
20755
|
|
|
|
|
|
|
3, 3, 3, 3, 4, 4, 4, 4, |
20756
|
|
|
|
|
|
|
5, 5, 5, 5, 0, |
20757
|
|
|
|
|
|
|
}; |
20758
|
|
|
|
|
|
|
|
20759
|
|
|
|
|
|
|
|
20760
|
|
|
|
|
|
|
static const unsigned deflate_offset_slot_base[] = { |
20761
|
|
|
|
|
|
|
1, 2, 3, 4, 5, 7, 9, 13, |
20762
|
|
|
|
|
|
|
17, 25, 33, 49, 65, 97, 129, 193, |
20763
|
|
|
|
|
|
|
257, 385, 513, 769, 1025, 1537, 2049, 3073, |
20764
|
|
|
|
|
|
|
4097, 6145, 8193, 12289, 16385, 24577, |
20765
|
|
|
|
|
|
|
}; |
20766
|
|
|
|
|
|
|
|
20767
|
|
|
|
|
|
|
|
20768
|
|
|
|
|
|
|
static const u8 deflate_extra_offset_bits[] = { |
20769
|
|
|
|
|
|
|
0, 0, 0, 0, 1, 1, 2, 2, |
20770
|
|
|
|
|
|
|
3, 3, 4, 4, 5, 5, 6, 6, |
20771
|
|
|
|
|
|
|
7, 7, 8, 8, 9, 9, 10, 10, |
20772
|
|
|
|
|
|
|
11, 11, 12, 12, 13, 13, |
20773
|
|
|
|
|
|
|
}; |
20774
|
|
|
|
|
|
|
|
20775
|
|
|
|
|
|
|
|
20776
|
|
|
|
|
|
|
static const u8 deflate_length_slot[DEFLATE_MAX_MATCH_LEN + 1] = { |
20777
|
|
|
|
|
|
|
0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, |
20778
|
|
|
|
|
|
|
12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, |
20779
|
|
|
|
|
|
|
16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, |
20780
|
|
|
|
|
|
|
18, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, |
20781
|
|
|
|
|
|
|
20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, |
20782
|
|
|
|
|
|
|
21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, |
20783
|
|
|
|
|
|
|
22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, |
20784
|
|
|
|
|
|
|
23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, |
20785
|
|
|
|
|
|
|
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, |
20786
|
|
|
|
|
|
|
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, |
20787
|
|
|
|
|
|
|
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, |
20788
|
|
|
|
|
|
|
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, |
20789
|
|
|
|
|
|
|
26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
20790
|
|
|
|
|
|
|
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
20791
|
|
|
|
|
|
|
27, 27, 28, |
20792
|
|
|
|
|
|
|
}; |
20793
|
|
|
|
|
|
|
|
20794
|
|
|
|
|
|
|
|
20795
|
|
|
|
|
|
|
static const u8 deflate_offset_slot[256] = { |
20796
|
|
|
|
|
|
|
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, |
20797
|
|
|
|
|
|
|
8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, |
20798
|
|
|
|
|
|
|
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
20799
|
|
|
|
|
|
|
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
20800
|
|
|
|
|
|
|
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, |
20801
|
|
|
|
|
|
|
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, |
20802
|
|
|
|
|
|
|
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, |
20803
|
|
|
|
|
|
|
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, |
20804
|
|
|
|
|
|
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
20805
|
|
|
|
|
|
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
20806
|
|
|
|
|
|
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
20807
|
|
|
|
|
|
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
20808
|
|
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
20809
|
|
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
20810
|
|
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
20811
|
|
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
20812
|
|
|
|
|
|
|
}; |
20813
|
|
|
|
|
|
|
|
20814
|
|
|
|
|
|
|
|
20815
|
|
|
|
|
|
|
static const u8 deflate_precode_lens_permutation[DEFLATE_NUM_PRECODE_SYMS] = { |
20816
|
|
|
|
|
|
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
20817
|
|
|
|
|
|
|
}; |
20818
|
|
|
|
|
|
|
|
20819
|
|
|
|
|
|
|
|
20820
|
|
|
|
|
|
|
static const u8 deflate_extra_precode_bits[DEFLATE_NUM_PRECODE_SYMS] = { |
20821
|
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 |
20822
|
|
|
|
|
|
|
}; |
20823
|
|
|
|
|
|
|
|
20824
|
|
|
|
|
|
|
|
20825
|
|
|
|
|
|
|
struct deflate_codewords { |
20826
|
|
|
|
|
|
|
u32 litlen[DEFLATE_NUM_LITLEN_SYMS]; |
20827
|
|
|
|
|
|
|
u32 offset[DEFLATE_NUM_OFFSET_SYMS]; |
20828
|
|
|
|
|
|
|
}; |
20829
|
|
|
|
|
|
|
|
20830
|
|
|
|
|
|
|
|
20831
|
|
|
|
|
|
|
struct deflate_lens { |
20832
|
|
|
|
|
|
|
u8 litlen[DEFLATE_NUM_LITLEN_SYMS]; |
20833
|
|
|
|
|
|
|
u8 offset[DEFLATE_NUM_OFFSET_SYMS]; |
20834
|
|
|
|
|
|
|
}; |
20835
|
|
|
|
|
|
|
|
20836
|
|
|
|
|
|
|
|
20837
|
|
|
|
|
|
|
struct deflate_codes { |
20838
|
|
|
|
|
|
|
struct deflate_codewords codewords; |
20839
|
|
|
|
|
|
|
struct deflate_lens lens; |
20840
|
|
|
|
|
|
|
}; |
20841
|
|
|
|
|
|
|
|
20842
|
|
|
|
|
|
|
|
20843
|
|
|
|
|
|
|
struct deflate_freqs { |
20844
|
|
|
|
|
|
|
u32 litlen[DEFLATE_NUM_LITLEN_SYMS]; |
20845
|
|
|
|
|
|
|
u32 offset[DEFLATE_NUM_OFFSET_SYMS]; |
20846
|
|
|
|
|
|
|
}; |
20847
|
|
|
|
|
|
|
|
20848
|
|
|
|
|
|
|
|
20849
|
|
|
|
|
|
|
struct deflate_sequence { |
20850
|
|
|
|
|
|
|
|
20851
|
|
|
|
|
|
|
|
20852
|
|
|
|
|
|
|
#define SEQ_LENGTH_SHIFT 23 |
20853
|
|
|
|
|
|
|
#define SEQ_LITRUNLEN_MASK (((u32)1 << SEQ_LENGTH_SHIFT) - 1) |
20854
|
|
|
|
|
|
|
u32 litrunlen_and_length; |
20855
|
|
|
|
|
|
|
|
20856
|
|
|
|
|
|
|
|
20857
|
|
|
|
|
|
|
u16 offset; |
20858
|
|
|
|
|
|
|
|
20859
|
|
|
|
|
|
|
|
20860
|
|
|
|
|
|
|
u16 offset_slot; |
20861
|
|
|
|
|
|
|
}; |
20862
|
|
|
|
|
|
|
|
20863
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
20864
|
|
|
|
|
|
|
|
20865
|
|
|
|
|
|
|
|
20866
|
|
|
|
|
|
|
struct deflate_costs { |
20867
|
|
|
|
|
|
|
|
20868
|
|
|
|
|
|
|
|
20869
|
|
|
|
|
|
|
u32 literal[DEFLATE_NUM_LITERALS]; |
20870
|
|
|
|
|
|
|
|
20871
|
|
|
|
|
|
|
|
20872
|
|
|
|
|
|
|
u32 length[DEFLATE_MAX_MATCH_LEN + 1]; |
20873
|
|
|
|
|
|
|
|
20874
|
|
|
|
|
|
|
|
20875
|
|
|
|
|
|
|
u32 offset_slot[DEFLATE_NUM_OFFSET_SYMS]; |
20876
|
|
|
|
|
|
|
}; |
20877
|
|
|
|
|
|
|
|
20878
|
|
|
|
|
|
|
|
20879
|
|
|
|
|
|
|
struct deflate_optimum_node { |
20880
|
|
|
|
|
|
|
|
20881
|
|
|
|
|
|
|
u32 cost_to_end; |
20882
|
|
|
|
|
|
|
|
20883
|
|
|
|
|
|
|
|
20884
|
|
|
|
|
|
|
#define OPTIMUM_OFFSET_SHIFT 9 |
20885
|
|
|
|
|
|
|
#define OPTIMUM_LEN_MASK (((u32)1 << OPTIMUM_OFFSET_SHIFT) - 1) |
20886
|
|
|
|
|
|
|
u32 item; |
20887
|
|
|
|
|
|
|
|
20888
|
|
|
|
|
|
|
}; |
20889
|
|
|
|
|
|
|
|
20890
|
|
|
|
|
|
|
#endif |
20891
|
|
|
|
|
|
|
|
20892
|
|
|
|
|
|
|
|
20893
|
|
|
|
|
|
|
#define NUM_LITERAL_OBSERVATION_TYPES 8 |
20894
|
|
|
|
|
|
|
#define NUM_MATCH_OBSERVATION_TYPES 2 |
20895
|
|
|
|
|
|
|
#define NUM_OBSERVATION_TYPES (NUM_LITERAL_OBSERVATION_TYPES + \ |
20896
|
|
|
|
|
|
|
NUM_MATCH_OBSERVATION_TYPES) |
20897
|
|
|
|
|
|
|
#define NUM_OBSERVATIONS_PER_BLOCK_CHECK 512 |
20898
|
|
|
|
|
|
|
struct block_split_stats { |
20899
|
|
|
|
|
|
|
u32 new_observations[NUM_OBSERVATION_TYPES]; |
20900
|
|
|
|
|
|
|
u32 observations[NUM_OBSERVATION_TYPES]; |
20901
|
|
|
|
|
|
|
u32 num_new_observations; |
20902
|
|
|
|
|
|
|
u32 num_observations; |
20903
|
|
|
|
|
|
|
}; |
20904
|
|
|
|
|
|
|
|
20905
|
|
|
|
|
|
|
struct deflate_output_bitstream; |
20906
|
|
|
|
|
|
|
|
20907
|
|
|
|
|
|
|
|
20908
|
|
|
|
|
|
|
struct libdeflate_compressor { |
20909
|
|
|
|
|
|
|
|
20910
|
|
|
|
|
|
|
|
20911
|
|
|
|
|
|
|
void (*impl)(struct libdeflate_compressor *restrict c, const u8 *in, |
20912
|
|
|
|
|
|
|
size_t in_nbytes, struct deflate_output_bitstream *os); |
20913
|
|
|
|
|
|
|
|
20914
|
|
|
|
|
|
|
|
20915
|
|
|
|
|
|
|
free_func_t free_func; |
20916
|
|
|
|
|
|
|
|
20917
|
|
|
|
|
|
|
|
20918
|
|
|
|
|
|
|
unsigned compression_level; |
20919
|
|
|
|
|
|
|
|
20920
|
|
|
|
|
|
|
|
20921
|
|
|
|
|
|
|
size_t max_passthrough_size; |
20922
|
|
|
|
|
|
|
|
20923
|
|
|
|
|
|
|
|
20924
|
|
|
|
|
|
|
unsigned max_search_depth; |
20925
|
|
|
|
|
|
|
|
20926
|
|
|
|
|
|
|
|
20927
|
|
|
|
|
|
|
unsigned nice_match_length; |
20928
|
|
|
|
|
|
|
|
20929
|
|
|
|
|
|
|
|
20930
|
|
|
|
|
|
|
struct deflate_freqs freqs; |
20931
|
|
|
|
|
|
|
|
20932
|
|
|
|
|
|
|
|
20933
|
|
|
|
|
|
|
struct block_split_stats split_stats; |
20934
|
|
|
|
|
|
|
|
20935
|
|
|
|
|
|
|
|
20936
|
|
|
|
|
|
|
struct deflate_codes codes; |
20937
|
|
|
|
|
|
|
|
20938
|
|
|
|
|
|
|
|
20939
|
|
|
|
|
|
|
struct deflate_codes static_codes; |
20940
|
|
|
|
|
|
|
|
20941
|
|
|
|
|
|
|
|
20942
|
|
|
|
|
|
|
union { |
20943
|
|
|
|
|
|
|
|
20944
|
|
|
|
|
|
|
struct { |
20945
|
|
|
|
|
|
|
u32 freqs[DEFLATE_NUM_PRECODE_SYMS]; |
20946
|
|
|
|
|
|
|
u32 codewords[DEFLATE_NUM_PRECODE_SYMS]; |
20947
|
|
|
|
|
|
|
u8 lens[DEFLATE_NUM_PRECODE_SYMS]; |
20948
|
|
|
|
|
|
|
unsigned items[DEFLATE_NUM_LITLEN_SYMS + |
20949
|
|
|
|
|
|
|
DEFLATE_NUM_OFFSET_SYMS]; |
20950
|
|
|
|
|
|
|
unsigned num_litlen_syms; |
20951
|
|
|
|
|
|
|
unsigned num_offset_syms; |
20952
|
|
|
|
|
|
|
unsigned num_explicit_lens; |
20953
|
|
|
|
|
|
|
unsigned num_items; |
20954
|
|
|
|
|
|
|
} precode; |
20955
|
|
|
|
|
|
|
|
20956
|
|
|
|
|
|
|
struct { |
20957
|
|
|
|
|
|
|
u32 codewords[DEFLATE_MAX_MATCH_LEN + 1]; |
20958
|
|
|
|
|
|
|
u8 lens[DEFLATE_MAX_MATCH_LEN + 1]; |
20959
|
|
|
|
|
|
|
} length; |
20960
|
|
|
|
|
|
|
} o; |
20961
|
|
|
|
|
|
|
|
20962
|
|
|
|
|
|
|
union { |
20963
|
|
|
|
|
|
|
|
20964
|
|
|
|
|
|
|
struct { |
20965
|
|
|
|
|
|
|
|
20966
|
|
|
|
|
|
|
struct hc_matchfinder hc_mf; |
20967
|
|
|
|
|
|
|
|
20968
|
|
|
|
|
|
|
|
20969
|
|
|
|
|
|
|
struct deflate_sequence sequences[SEQ_STORE_LENGTH + 1]; |
20970
|
|
|
|
|
|
|
|
20971
|
|
|
|
|
|
|
} g; |
20972
|
|
|
|
|
|
|
|
20973
|
|
|
|
|
|
|
|
20974
|
|
|
|
|
|
|
struct { |
20975
|
|
|
|
|
|
|
|
20976
|
|
|
|
|
|
|
struct ht_matchfinder ht_mf; |
20977
|
|
|
|
|
|
|
|
20978
|
|
|
|
|
|
|
|
20979
|
|
|
|
|
|
|
struct deflate_sequence sequences[ |
20980
|
|
|
|
|
|
|
FAST_SEQ_STORE_LENGTH + 1]; |
20981
|
|
|
|
|
|
|
|
20982
|
|
|
|
|
|
|
} f; |
20983
|
|
|
|
|
|
|
|
20984
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
20985
|
|
|
|
|
|
|
|
20986
|
|
|
|
|
|
|
struct { |
20987
|
|
|
|
|
|
|
|
20988
|
|
|
|
|
|
|
|
20989
|
|
|
|
|
|
|
struct bt_matchfinder bt_mf; |
20990
|
|
|
|
|
|
|
|
20991
|
|
|
|
|
|
|
|
20992
|
|
|
|
|
|
|
struct lz_match match_cache[MATCH_CACHE_LENGTH + |
20993
|
|
|
|
|
|
|
MAX_MATCHES_PER_POS + |
20994
|
|
|
|
|
|
|
DEFLATE_MAX_MATCH_LEN - 1]; |
20995
|
|
|
|
|
|
|
|
20996
|
|
|
|
|
|
|
|
20997
|
|
|
|
|
|
|
struct deflate_optimum_node optimum_nodes[ |
20998
|
|
|
|
|
|
|
MAX_BLOCK_LENGTH + 1]; |
20999
|
|
|
|
|
|
|
|
21000
|
|
|
|
|
|
|
|
21001
|
|
|
|
|
|
|
struct deflate_costs costs; |
21002
|
|
|
|
|
|
|
|
21003
|
|
|
|
|
|
|
|
21004
|
|
|
|
|
|
|
struct deflate_costs costs_saved; |
21005
|
|
|
|
|
|
|
|
21006
|
|
|
|
|
|
|
|
21007
|
|
|
|
|
|
|
u8 offset_slot_full[DEFLATE_MAX_MATCH_OFFSET + 1]; |
21008
|
|
|
|
|
|
|
|
21009
|
|
|
|
|
|
|
|
21010
|
|
|
|
|
|
|
u32 prev_observations[NUM_OBSERVATION_TYPES]; |
21011
|
|
|
|
|
|
|
u32 prev_num_observations; |
21012
|
|
|
|
|
|
|
|
21013
|
|
|
|
|
|
|
|
21014
|
|
|
|
|
|
|
u32 new_match_len_freqs[DEFLATE_MAX_MATCH_LEN + 1]; |
21015
|
|
|
|
|
|
|
u32 match_len_freqs[DEFLATE_MAX_MATCH_LEN + 1]; |
21016
|
|
|
|
|
|
|
|
21017
|
|
|
|
|
|
|
|
21018
|
|
|
|
|
|
|
unsigned max_optim_passes; |
21019
|
|
|
|
|
|
|
|
21020
|
|
|
|
|
|
|
|
21021
|
|
|
|
|
|
|
unsigned min_improvement_to_continue; |
21022
|
|
|
|
|
|
|
|
21023
|
|
|
|
|
|
|
|
21024
|
|
|
|
|
|
|
unsigned min_bits_to_use_nonfinal_path; |
21025
|
|
|
|
|
|
|
|
21026
|
|
|
|
|
|
|
|
21027
|
|
|
|
|
|
|
unsigned max_len_to_optimize_static_block; |
21028
|
|
|
|
|
|
|
|
21029
|
|
|
|
|
|
|
} n; |
21030
|
|
|
|
|
|
|
#endif |
21031
|
|
|
|
|
|
|
|
21032
|
|
|
|
|
|
|
} p; |
21033
|
|
|
|
|
|
|
}; |
21034
|
|
|
|
|
|
|
|
21035
|
|
|
|
|
|
|
|
21036
|
|
|
|
|
|
|
typedef machine_word_t bitbuf_t; |
21037
|
|
|
|
|
|
|
|
21038
|
|
|
|
|
|
|
|
21039
|
|
|
|
|
|
|
#define COMPRESS_BITBUF_NBITS (8 * sizeof(bitbuf_t) - 1) |
21040
|
|
|
|
|
|
|
|
21041
|
|
|
|
|
|
|
|
21042
|
|
|
|
|
|
|
#define CAN_BUFFER(n) (7 + (n) <= COMPRESS_BITBUF_NBITS) |
21043
|
|
|
|
|
|
|
|
21044
|
|
|
|
|
|
|
|
21045
|
|
|
|
|
|
|
struct deflate_output_bitstream { |
21046
|
|
|
|
|
|
|
|
21047
|
|
|
|
|
|
|
|
21048
|
|
|
|
|
|
|
bitbuf_t bitbuf; |
21049
|
|
|
|
|
|
|
|
21050
|
|
|
|
|
|
|
|
21051
|
|
|
|
|
|
|
unsigned bitcount; |
21052
|
|
|
|
|
|
|
|
21053
|
|
|
|
|
|
|
|
21054
|
|
|
|
|
|
|
u8 *next; |
21055
|
|
|
|
|
|
|
|
21056
|
|
|
|
|
|
|
|
21057
|
|
|
|
|
|
|
u8 *end; |
21058
|
|
|
|
|
|
|
|
21059
|
|
|
|
|
|
|
|
21060
|
|
|
|
|
|
|
bool overflow; |
21061
|
|
|
|
|
|
|
}; |
21062
|
|
|
|
|
|
|
|
21063
|
|
|
|
|
|
|
|
21064
|
|
|
|
|
|
|
#define ADD_BITS(bits, n) \ |
21065
|
|
|
|
|
|
|
do { \ |
21066
|
|
|
|
|
|
|
bitbuf |= (bitbuf_t)(bits) << bitcount; \ |
21067
|
|
|
|
|
|
|
bitcount += (n); \ |
21068
|
|
|
|
|
|
|
ASSERT(bitcount <= COMPRESS_BITBUF_NBITS); \ |
21069
|
|
|
|
|
|
|
} while (0) |
21070
|
|
|
|
|
|
|
|
21071
|
|
|
|
|
|
|
|
21072
|
|
|
|
|
|
|
#define FLUSH_BITS() \ |
21073
|
|
|
|
|
|
|
do { \ |
21074
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST && likely(out_next < out_fast_end)) { \ |
21075
|
|
|
|
|
|
|
\ |
21076
|
|
|
|
|
|
|
put_unaligned_leword(bitbuf, out_next); \ |
21077
|
|
|
|
|
|
|
bitbuf >>= bitcount & ~7; \ |
21078
|
|
|
|
|
|
|
out_next += bitcount >> 3; \ |
21079
|
|
|
|
|
|
|
bitcount &= 7; \ |
21080
|
|
|
|
|
|
|
} else { \ |
21081
|
|
|
|
|
|
|
\ |
21082
|
|
|
|
|
|
|
while (bitcount >= 8) { \ |
21083
|
|
|
|
|
|
|
ASSERT(out_next < os->end); \ |
21084
|
|
|
|
|
|
|
*out_next++ = bitbuf; \ |
21085
|
|
|
|
|
|
|
bitcount -= 8; \ |
21086
|
|
|
|
|
|
|
bitbuf >>= 8; \ |
21087
|
|
|
|
|
|
|
} \ |
21088
|
|
|
|
|
|
|
} \ |
21089
|
|
|
|
|
|
|
} while (0) |
21090
|
|
|
|
|
|
|
|
21091
|
|
|
|
|
|
|
|
21092
|
|
|
|
|
|
|
static void |
21093
|
35
|
|
|
|
|
|
heapify_subtree(u32 A[], unsigned length, unsigned subtree_idx) |
21094
|
|
|
|
|
|
|
{ |
21095
|
|
|
|
|
|
|
unsigned parent_idx; |
21096
|
|
|
|
|
|
|
unsigned child_idx; |
21097
|
|
|
|
|
|
|
u32 v; |
21098
|
|
|
|
|
|
|
|
21099
|
35
|
|
|
|
|
|
v = A[subtree_idx]; |
21100
|
35
|
|
|
|
|
|
parent_idx = subtree_idx; |
21101
|
87
|
100
|
|
|
|
|
while ((child_idx = parent_idx * 2) <= length) { |
21102
|
63
|
100
|
|
|
|
|
if (child_idx < length && A[child_idx + 1] > A[child_idx]) |
|
|
100
|
|
|
|
|
|
21103
|
26
|
|
|
|
|
|
child_idx++; |
21104
|
63
|
100
|
|
|
|
|
if (v >= A[child_idx]) |
21105
|
11
|
|
|
|
|
|
break; |
21106
|
52
|
|
|
|
|
|
A[parent_idx] = A[child_idx]; |
21107
|
52
|
|
|
|
|
|
parent_idx = child_idx; |
21108
|
|
|
|
|
|
|
} |
21109
|
35
|
|
|
|
|
|
A[parent_idx] = v; |
21110
|
35
|
|
|
|
|
|
} |
21111
|
|
|
|
|
|
|
|
21112
|
|
|
|
|
|
|
|
21113
|
|
|
|
|
|
|
static void |
21114
|
263
|
|
|
|
|
|
heapify_array(u32 A[], unsigned length) |
21115
|
|
|
|
|
|
|
{ |
21116
|
|
|
|
|
|
|
unsigned subtree_idx; |
21117
|
|
|
|
|
|
|
|
21118
|
275
|
100
|
|
|
|
|
for (subtree_idx = length / 2; subtree_idx >= 1; subtree_idx--) |
21119
|
12
|
|
|
|
|
|
heapify_subtree(A, length, subtree_idx); |
21120
|
263
|
|
|
|
|
|
} |
21121
|
|
|
|
|
|
|
|
21122
|
|
|
|
|
|
|
|
21123
|
|
|
|
|
|
|
static void |
21124
|
263
|
|
|
|
|
|
heap_sort(u32 A[], unsigned length) |
21125
|
|
|
|
|
|
|
{ |
21126
|
263
|
|
|
|
|
|
A--; |
21127
|
|
|
|
|
|
|
|
21128
|
263
|
|
|
|
|
|
heapify_array(A, length); |
21129
|
|
|
|
|
|
|
|
21130
|
286
|
100
|
|
|
|
|
while (length >= 2) { |
21131
|
23
|
|
|
|
|
|
u32 tmp = A[length]; |
21132
|
|
|
|
|
|
|
|
21133
|
23
|
|
|
|
|
|
A[length] = A[1]; |
21134
|
23
|
|
|
|
|
|
A[1] = tmp; |
21135
|
23
|
|
|
|
|
|
length--; |
21136
|
23
|
|
|
|
|
|
heapify_subtree(A, length, 1); |
21137
|
|
|
|
|
|
|
} |
21138
|
263
|
|
|
|
|
|
} |
21139
|
|
|
|
|
|
|
|
21140
|
|
|
|
|
|
|
#define NUM_SYMBOL_BITS 10 |
21141
|
|
|
|
|
|
|
#define NUM_FREQ_BITS (32 - NUM_SYMBOL_BITS) |
21142
|
|
|
|
|
|
|
#define SYMBOL_MASK ((1 << NUM_SYMBOL_BITS) - 1) |
21143
|
|
|
|
|
|
|
#define FREQ_MASK (~SYMBOL_MASK) |
21144
|
|
|
|
|
|
|
|
21145
|
|
|
|
|
|
|
#define GET_NUM_COUNTERS(num_syms) (num_syms) |
21146
|
|
|
|
|
|
|
|
21147
|
|
|
|
|
|
|
|
21148
|
|
|
|
|
|
|
static unsigned |
21149
|
263
|
|
|
|
|
|
sort_symbols(unsigned num_syms, const u32 freqs[], u8 lens[], u32 symout[]) |
21150
|
|
|
|
|
|
|
{ |
21151
|
|
|
|
|
|
|
unsigned sym; |
21152
|
|
|
|
|
|
|
unsigned i; |
21153
|
|
|
|
|
|
|
unsigned num_used_syms; |
21154
|
|
|
|
|
|
|
unsigned num_counters; |
21155
|
|
|
|
|
|
|
unsigned counters[GET_NUM_COUNTERS(DEFLATE_MAX_NUM_SYMS)]; |
21156
|
|
|
|
|
|
|
|
21157
|
|
|
|
|
|
|
|
21158
|
|
|
|
|
|
|
|
21159
|
263
|
|
|
|
|
|
num_counters = GET_NUM_COUNTERS(num_syms); |
21160
|
|
|
|
|
|
|
|
21161
|
263
|
|
|
|
|
|
memset(counters, 0, num_counters * sizeof(counters[0])); |
21162
|
|
|
|
|
|
|
|
21163
|
|
|
|
|
|
|
|
21164
|
33178
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) |
21165
|
32915
|
|
|
|
|
|
counters[MIN(freqs[sym], num_counters - 1)]++; |
21166
|
|
|
|
|
|
|
|
21167
|
|
|
|
|
|
|
|
21168
|
263
|
|
|
|
|
|
num_used_syms = 0; |
21169
|
32915
|
100
|
|
|
|
|
for (i = 1; i < num_counters; i++) { |
21170
|
32652
|
|
|
|
|
|
unsigned count = counters[i]; |
21171
|
|
|
|
|
|
|
|
21172
|
32652
|
|
|
|
|
|
counters[i] = num_used_syms; |
21173
|
32652
|
|
|
|
|
|
num_used_syms += count; |
21174
|
|
|
|
|
|
|
} |
21175
|
|
|
|
|
|
|
|
21176
|
|
|
|
|
|
|
|
21177
|
33178
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) { |
21178
|
32915
|
|
|
|
|
|
u32 freq = freqs[sym]; |
21179
|
|
|
|
|
|
|
|
21180
|
32915
|
100
|
|
|
|
|
if (freq != 0) { |
21181
|
13499
|
|
|
|
|
|
symout[counters[MIN(freq, num_counters - 1)]++] = |
21182
|
13499
|
|
|
|
|
|
sym | (freq << NUM_SYMBOL_BITS); |
21183
|
|
|
|
|
|
|
} else { |
21184
|
19416
|
|
|
|
|
|
lens[sym] = 0; |
21185
|
|
|
|
|
|
|
} |
21186
|
|
|
|
|
|
|
} |
21187
|
|
|
|
|
|
|
|
21188
|
|
|
|
|
|
|
|
21189
|
263
|
|
|
|
|
|
heap_sort(symout + counters[num_counters - 2], |
21190
|
263
|
|
|
|
|
|
counters[num_counters - 1] - counters[num_counters - 2]); |
21191
|
|
|
|
|
|
|
|
21192
|
263
|
|
|
|
|
|
return num_used_syms; |
21193
|
|
|
|
|
|
|
} |
21194
|
|
|
|
|
|
|
|
21195
|
|
|
|
|
|
|
|
21196
|
|
|
|
|
|
|
static void |
21197
|
203
|
|
|
|
|
|
build_tree(u32 A[], unsigned sym_count) |
21198
|
|
|
|
|
|
|
{ |
21199
|
203
|
|
|
|
|
|
const unsigned last_idx = sym_count - 1; |
21200
|
|
|
|
|
|
|
|
21201
|
|
|
|
|
|
|
|
21202
|
203
|
|
|
|
|
|
unsigned i = 0; |
21203
|
|
|
|
|
|
|
|
21204
|
|
|
|
|
|
|
|
21205
|
203
|
|
|
|
|
|
unsigned b = 0; |
21206
|
|
|
|
|
|
|
|
21207
|
|
|
|
|
|
|
|
21208
|
203
|
|
|
|
|
|
unsigned e = 0; |
21209
|
|
|
|
|
|
|
|
21210
|
|
|
|
|
|
|
do { |
21211
|
|
|
|
|
|
|
u32 new_freq; |
21212
|
|
|
|
|
|
|
|
21213
|
|
|
|
|
|
|
|
21214
|
13245
|
100
|
|
|
|
|
if (i + 1 <= last_idx && |
|
|
100
|
|
|
|
|
|
21215
|
7767
|
100
|
|
|
|
|
(b == e || (A[i + 1] & FREQ_MASK) <= (A[b] & FREQ_MASK))) { |
21216
|
|
|
|
|
|
|
|
21217
|
6523
|
|
|
|
|
|
new_freq = (A[i] & FREQ_MASK) + (A[i + 1] & FREQ_MASK); |
21218
|
6523
|
|
|
|
|
|
i += 2; |
21219
|
6722
|
100
|
|
|
|
|
} else if (b + 2 <= e && |
|
|
100
|
|
|
|
|
|
21220
|
1526
|
100
|
|
|
|
|
(i > last_idx || |
21221
|
1526
|
|
|
|
|
|
(A[b + 1] & FREQ_MASK) < (A[i] & FREQ_MASK))) { |
21222
|
|
|
|
|
|
|
|
21223
|
6320
|
|
|
|
|
|
new_freq = (A[b] & FREQ_MASK) + (A[b + 1] & FREQ_MASK); |
21224
|
6320
|
|
|
|
|
|
A[b] = (e << NUM_SYMBOL_BITS) | (A[b] & SYMBOL_MASK); |
21225
|
12640
|
|
|
|
|
|
A[b + 1] = (e << NUM_SYMBOL_BITS) | |
21226
|
6320
|
|
|
|
|
|
(A[b + 1] & SYMBOL_MASK); |
21227
|
6320
|
|
|
|
|
|
b += 2; |
21228
|
|
|
|
|
|
|
} else { |
21229
|
|
|
|
|
|
|
|
21230
|
402
|
|
|
|
|
|
new_freq = (A[i] & FREQ_MASK) + (A[b] & FREQ_MASK); |
21231
|
402
|
|
|
|
|
|
A[b] = (e << NUM_SYMBOL_BITS) | (A[b] & SYMBOL_MASK); |
21232
|
402
|
|
|
|
|
|
i++; |
21233
|
402
|
|
|
|
|
|
b++; |
21234
|
|
|
|
|
|
|
} |
21235
|
13245
|
|
|
|
|
|
A[e] = new_freq | (A[e] & SYMBOL_MASK); |
21236
|
|
|
|
|
|
|
|
21237
|
13245
|
100
|
|
|
|
|
} while (++e < last_idx); |
21238
|
203
|
|
|
|
|
|
} |
21239
|
|
|
|
|
|
|
|
21240
|
|
|
|
|
|
|
|
21241
|
|
|
|
|
|
|
static void |
21242
|
203
|
|
|
|
|
|
compute_length_counts(u32 A[], unsigned root_idx, unsigned len_counts[], |
21243
|
|
|
|
|
|
|
unsigned max_codeword_len) |
21244
|
|
|
|
|
|
|
{ |
21245
|
|
|
|
|
|
|
unsigned len; |
21246
|
|
|
|
|
|
|
int node; |
21247
|
|
|
|
|
|
|
|
21248
|
|
|
|
|
|
|
|
21249
|
|
|
|
|
|
|
|
21250
|
2832
|
100
|
|
|
|
|
for (len = 0; len <= max_codeword_len; len++) |
21251
|
2629
|
|
|
|
|
|
len_counts[len] = 0; |
21252
|
203
|
|
|
|
|
|
len_counts[1] = 2; |
21253
|
|
|
|
|
|
|
|
21254
|
|
|
|
|
|
|
|
21255
|
203
|
|
|
|
|
|
A[root_idx] &= SYMBOL_MASK; |
21256
|
|
|
|
|
|
|
|
21257
|
13245
|
100
|
|
|
|
|
for (node = root_idx - 1; node >= 0; node--) { |
21258
|
|
|
|
|
|
|
|
21259
|
|
|
|
|
|
|
|
21260
|
|
|
|
|
|
|
|
21261
|
13042
|
|
|
|
|
|
unsigned parent = A[node] >> NUM_SYMBOL_BITS; |
21262
|
13042
|
|
|
|
|
|
unsigned parent_depth = A[parent] >> NUM_SYMBOL_BITS; |
21263
|
13042
|
|
|
|
|
|
unsigned depth = parent_depth + 1; |
21264
|
|
|
|
|
|
|
|
21265
|
|
|
|
|
|
|
|
21266
|
13042
|
|
|
|
|
|
A[node] = (A[node] & SYMBOL_MASK) | (depth << NUM_SYMBOL_BITS); |
21267
|
|
|
|
|
|
|
|
21268
|
|
|
|
|
|
|
|
21269
|
13042
|
50
|
|
|
|
|
if (depth >= max_codeword_len) { |
21270
|
0
|
|
|
|
|
|
depth = max_codeword_len; |
21271
|
|
|
|
|
|
|
do { |
21272
|
0
|
|
|
|
|
|
depth--; |
21273
|
0
|
0
|
|
|
|
|
} while (len_counts[depth] == 0); |
21274
|
|
|
|
|
|
|
} |
21275
|
|
|
|
|
|
|
|
21276
|
|
|
|
|
|
|
|
21277
|
13042
|
|
|
|
|
|
len_counts[depth]--; |
21278
|
13042
|
|
|
|
|
|
len_counts[depth + 1] += 2; |
21279
|
|
|
|
|
|
|
} |
21280
|
203
|
|
|
|
|
|
} |
21281
|
|
|
|
|
|
|
|
21282
|
|
|
|
|
|
|
|
21283
|
|
|
|
|
|
|
|
21284
|
|
|
|
|
|
|
#ifdef rbit32 |
21285
|
|
|
|
|
|
|
static forceinline u32 reverse_codeword(u32 codeword, u8 len) |
21286
|
|
|
|
|
|
|
{ |
21287
|
|
|
|
|
|
|
return rbit32(codeword) >> ((32 - len) & 31); |
21288
|
|
|
|
|
|
|
} |
21289
|
|
|
|
|
|
|
#else |
21290
|
|
|
|
|
|
|
|
21291
|
|
|
|
|
|
|
static const u8 bitreverse_tab[256] = { |
21292
|
|
|
|
|
|
|
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, |
21293
|
|
|
|
|
|
|
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, |
21294
|
|
|
|
|
|
|
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, |
21295
|
|
|
|
|
|
|
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, |
21296
|
|
|
|
|
|
|
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, |
21297
|
|
|
|
|
|
|
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, |
21298
|
|
|
|
|
|
|
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, |
21299
|
|
|
|
|
|
|
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, |
21300
|
|
|
|
|
|
|
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, |
21301
|
|
|
|
|
|
|
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, |
21302
|
|
|
|
|
|
|
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, |
21303
|
|
|
|
|
|
|
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, |
21304
|
|
|
|
|
|
|
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, |
21305
|
|
|
|
|
|
|
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, |
21306
|
|
|
|
|
|
|
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, |
21307
|
|
|
|
|
|
|
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, |
21308
|
|
|
|
|
|
|
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, |
21309
|
|
|
|
|
|
|
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, |
21310
|
|
|
|
|
|
|
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, |
21311
|
|
|
|
|
|
|
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, |
21312
|
|
|
|
|
|
|
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, |
21313
|
|
|
|
|
|
|
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, |
21314
|
|
|
|
|
|
|
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, |
21315
|
|
|
|
|
|
|
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, |
21316
|
|
|
|
|
|
|
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, |
21317
|
|
|
|
|
|
|
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, |
21318
|
|
|
|
|
|
|
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, |
21319
|
|
|
|
|
|
|
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, |
21320
|
|
|
|
|
|
|
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, |
21321
|
|
|
|
|
|
|
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, |
21322
|
|
|
|
|
|
|
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, |
21323
|
|
|
|
|
|
|
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, |
21324
|
|
|
|
|
|
|
}; |
21325
|
|
|
|
|
|
|
|
21326
|
|
|
|
|
|
|
static forceinline u32 reverse_codeword(u32 codeword, u8 len) |
21327
|
|
|
|
|
|
|
{ |
21328
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_CODEWORD_LEN <= 16); |
21329
|
61990
|
|
|
|
|
|
codeword = ((u32)bitreverse_tab[codeword & 0xff] << 8) | |
21330
|
30995
|
|
|
|
|
|
bitreverse_tab[codeword >> 8]; |
21331
|
30995
|
|
|
|
|
|
return codeword >> (16 - len); |
21332
|
|
|
|
|
|
|
} |
21333
|
|
|
|
|
|
|
#endif |
21334
|
|
|
|
|
|
|
|
21335
|
|
|
|
|
|
|
|
21336
|
|
|
|
|
|
|
static void |
21337
|
203
|
|
|
|
|
|
gen_codewords(u32 A[], u8 lens[], const unsigned len_counts[], |
21338
|
|
|
|
|
|
|
unsigned max_codeword_len, unsigned num_syms) |
21339
|
|
|
|
|
|
|
{ |
21340
|
|
|
|
|
|
|
u32 next_codewords[DEFLATE_MAX_CODEWORD_LEN + 1]; |
21341
|
|
|
|
|
|
|
unsigned i; |
21342
|
|
|
|
|
|
|
unsigned len; |
21343
|
|
|
|
|
|
|
unsigned sym; |
21344
|
|
|
|
|
|
|
|
21345
|
|
|
|
|
|
|
|
21346
|
2629
|
100
|
|
|
|
|
for (i = 0, len = max_codeword_len; len >= 1; len--) { |
21347
|
2426
|
|
|
|
|
|
unsigned count = len_counts[len]; |
21348
|
|
|
|
|
|
|
|
21349
|
15874
|
100
|
|
|
|
|
while (count--) |
21350
|
13448
|
|
|
|
|
|
lens[A[i++] & SYMBOL_MASK] = len; |
21351
|
|
|
|
|
|
|
} |
21352
|
|
|
|
|
|
|
|
21353
|
|
|
|
|
|
|
|
21354
|
203
|
|
|
|
|
|
next_codewords[0] = 0; |
21355
|
203
|
|
|
|
|
|
next_codewords[1] = 0; |
21356
|
2426
|
100
|
|
|
|
|
for (len = 2; len <= max_codeword_len; len++) |
21357
|
2223
|
|
|
|
|
|
next_codewords[len] = |
21358
|
2223
|
|
|
|
|
|
(next_codewords[len - 1] + len_counts[len - 1]) << 1; |
21359
|
|
|
|
|
|
|
|
21360
|
31198
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) { |
21361
|
|
|
|
|
|
|
|
21362
|
92985
|
|
|
|
|
|
A[sym] = reverse_codeword(next_codewords[lens[sym]]++, |
21363
|
30995
|
|
|
|
|
|
lens[sym]); |
21364
|
|
|
|
|
|
|
} |
21365
|
203
|
|
|
|
|
|
} |
21366
|
|
|
|
|
|
|
|
21367
|
|
|
|
|
|
|
|
21368
|
|
|
|
|
|
|
static void |
21369
|
263
|
|
|
|
|
|
deflate_make_huffman_code(unsigned num_syms, unsigned max_codeword_len, |
21370
|
|
|
|
|
|
|
const u32 freqs[], u8 lens[], u32 codewords[]) |
21371
|
|
|
|
|
|
|
{ |
21372
|
263
|
|
|
|
|
|
u32 *A = codewords; |
21373
|
|
|
|
|
|
|
unsigned num_used_syms; |
21374
|
|
|
|
|
|
|
|
21375
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_NUM_SYMS <= 1 << NUM_SYMBOL_BITS); |
21376
|
|
|
|
|
|
|
STATIC_ASSERT(MAX_BLOCK_LENGTH <= ((u32)1 << NUM_FREQ_BITS) - 1); |
21377
|
|
|
|
|
|
|
|
21378
|
|
|
|
|
|
|
|
21379
|
263
|
|
|
|
|
|
num_used_syms = sort_symbols(num_syms, freqs, lens, A); |
21380
|
|
|
|
|
|
|
|
21381
|
|
|
|
|
|
|
|
21382
|
|
|
|
|
|
|
|
21383
|
263
|
100
|
|
|
|
|
if (unlikely(num_used_syms < 2)) { |
21384
|
60
|
100
|
|
|
|
|
unsigned sym = num_used_syms ? (A[0] & SYMBOL_MASK) : 0; |
21385
|
60
|
100
|
|
|
|
|
unsigned nonzero_idx = sym ? sym : 1; |
21386
|
|
|
|
|
|
|
|
21387
|
60
|
|
|
|
|
|
codewords[0] = 0; |
21388
|
60
|
|
|
|
|
|
lens[0] = 1; |
21389
|
60
|
|
|
|
|
|
codewords[nonzero_idx] = 1; |
21390
|
60
|
|
|
|
|
|
lens[nonzero_idx] = 1; |
21391
|
60
|
|
|
|
|
|
return; |
21392
|
|
|
|
|
|
|
} |
21393
|
|
|
|
|
|
|
|
21394
|
|
|
|
|
|
|
|
21395
|
|
|
|
|
|
|
|
21396
|
203
|
|
|
|
|
|
build_tree(A, num_used_syms); |
21397
|
|
|
|
|
|
|
|
21398
|
|
|
|
|
|
|
{ |
21399
|
|
|
|
|
|
|
unsigned len_counts[DEFLATE_MAX_CODEWORD_LEN + 1]; |
21400
|
|
|
|
|
|
|
|
21401
|
203
|
|
|
|
|
|
compute_length_counts(A, num_used_syms - 2, |
21402
|
|
|
|
|
|
|
len_counts, max_codeword_len); |
21403
|
|
|
|
|
|
|
|
21404
|
203
|
|
|
|
|
|
gen_codewords(A, lens, len_counts, max_codeword_len, num_syms); |
21405
|
|
|
|
|
|
|
} |
21406
|
|
|
|
|
|
|
} |
21407
|
|
|
|
|
|
|
|
21408
|
|
|
|
|
|
|
|
21409
|
|
|
|
|
|
|
static void |
21410
|
62
|
|
|
|
|
|
deflate_reset_symbol_frequencies(struct libdeflate_compressor *c) |
21411
|
|
|
|
|
|
|
{ |
21412
|
62
|
|
|
|
|
|
memset(&c->freqs, 0, sizeof(c->freqs)); |
21413
|
62
|
|
|
|
|
|
} |
21414
|
|
|
|
|
|
|
|
21415
|
|
|
|
|
|
|
|
21416
|
|
|
|
|
|
|
static void |
21417
|
99
|
|
|
|
|
|
deflate_make_huffman_codes(const struct deflate_freqs *freqs, |
21418
|
|
|
|
|
|
|
struct deflate_codes *codes) |
21419
|
|
|
|
|
|
|
{ |
21420
|
99
|
|
|
|
|
|
deflate_make_huffman_code(DEFLATE_NUM_LITLEN_SYMS, |
21421
|
|
|
|
|
|
|
MAX_LITLEN_CODEWORD_LEN, |
21422
|
99
|
|
|
|
|
|
freqs->litlen, |
21423
|
99
|
|
|
|
|
|
codes->lens.litlen, |
21424
|
99
|
|
|
|
|
|
codes->codewords.litlen); |
21425
|
|
|
|
|
|
|
|
21426
|
99
|
|
|
|
|
|
deflate_make_huffman_code(DEFLATE_NUM_OFFSET_SYMS, |
21427
|
|
|
|
|
|
|
MAX_OFFSET_CODEWORD_LEN, |
21428
|
99
|
|
|
|
|
|
freqs->offset, |
21429
|
99
|
|
|
|
|
|
codes->lens.offset, |
21430
|
99
|
|
|
|
|
|
codes->codewords.offset); |
21431
|
99
|
|
|
|
|
|
} |
21432
|
|
|
|
|
|
|
|
21433
|
|
|
|
|
|
|
|
21434
|
|
|
|
|
|
|
static void |
21435
|
37
|
|
|
|
|
|
deflate_init_static_codes(struct libdeflate_compressor *c) |
21436
|
|
|
|
|
|
|
{ |
21437
|
|
|
|
|
|
|
unsigned i; |
21438
|
|
|
|
|
|
|
|
21439
|
5365
|
100
|
|
|
|
|
for (i = 0; i < 144; i++) |
21440
|
5328
|
|
|
|
|
|
c->freqs.litlen[i] = 1 << (9 - 8); |
21441
|
4181
|
100
|
|
|
|
|
for (; i < 256; i++) |
21442
|
4144
|
|
|
|
|
|
c->freqs.litlen[i] = 1 << (9 - 9); |
21443
|
925
|
100
|
|
|
|
|
for (; i < 280; i++) |
21444
|
888
|
|
|
|
|
|
c->freqs.litlen[i] = 1 << (9 - 7); |
21445
|
333
|
100
|
|
|
|
|
for (; i < 288; i++) |
21446
|
296
|
|
|
|
|
|
c->freqs.litlen[i] = 1 << (9 - 8); |
21447
|
|
|
|
|
|
|
|
21448
|
1221
|
100
|
|
|
|
|
for (i = 0; i < 32; i++) |
21449
|
1184
|
|
|
|
|
|
c->freqs.offset[i] = 1 << (5 - 5); |
21450
|
|
|
|
|
|
|
|
21451
|
37
|
|
|
|
|
|
deflate_make_huffman_codes(&c->freqs, &c->static_codes); |
21452
|
37
|
|
|
|
|
|
} |
21453
|
|
|
|
|
|
|
|
21454
|
|
|
|
|
|
|
|
21455
|
|
|
|
|
|
|
static forceinline unsigned |
21456
|
|
|
|
|
|
|
deflate_get_offset_slot(u32 offset) |
21457
|
|
|
|
|
|
|
{ |
21458
|
|
|
|
|
|
|
|
21459
|
2091
|
|
|
|
|
|
unsigned n = (256 - offset) >> 29; |
21460
|
|
|
|
|
|
|
|
21461
|
2091
|
|
|
|
|
|
return deflate_offset_slot[(offset - 1) >> n] + (n << 1); |
21462
|
|
|
|
|
|
|
} |
21463
|
|
|
|
|
|
|
|
21464
|
|
|
|
|
|
|
static unsigned |
21465
|
65
|
|
|
|
|
|
deflate_compute_precode_items(const u8 lens[], const unsigned num_lens, |
21466
|
|
|
|
|
|
|
u32 precode_freqs[], unsigned precode_items[]) |
21467
|
|
|
|
|
|
|
{ |
21468
|
|
|
|
|
|
|
unsigned *itemptr; |
21469
|
|
|
|
|
|
|
unsigned run_start; |
21470
|
|
|
|
|
|
|
unsigned run_end; |
21471
|
|
|
|
|
|
|
unsigned extra_bits; |
21472
|
|
|
|
|
|
|
u8 len; |
21473
|
|
|
|
|
|
|
|
21474
|
65
|
|
|
|
|
|
memset(precode_freqs, 0, |
21475
|
|
|
|
|
|
|
DEFLATE_NUM_PRECODE_SYMS * sizeof(precode_freqs[0])); |
21476
|
|
|
|
|
|
|
|
21477
|
65
|
|
|
|
|
|
itemptr = precode_items; |
21478
|
65
|
|
|
|
|
|
run_start = 0; |
21479
|
|
|
|
|
|
|
do { |
21480
|
|
|
|
|
|
|
|
21481
|
|
|
|
|
|
|
|
21482
|
|
|
|
|
|
|
|
21483
|
1973
|
|
|
|
|
|
len = lens[run_start]; |
21484
|
|
|
|
|
|
|
|
21485
|
|
|
|
|
|
|
|
21486
|
1973
|
|
|
|
|
|
run_end = run_start; |
21487
|
|
|
|
|
|
|
do { |
21488
|
18873
|
|
|
|
|
|
run_end++; |
21489
|
18873
|
100
|
|
|
|
|
} while (run_end != num_lens && len == lens[run_end]); |
|
|
100
|
|
|
|
|
|
21490
|
|
|
|
|
|
|
|
21491
|
1973
|
100
|
|
|
|
|
if (len == 0) { |
21492
|
|
|
|
|
|
|
|
21493
|
|
|
|
|
|
|
|
21494
|
|
|
|
|
|
|
|
21495
|
1083
|
100
|
|
|
|
|
while ((run_end - run_start) >= 11) { |
21496
|
249
|
|
|
|
|
|
extra_bits = MIN((run_end - run_start) - 11, |
21497
|
|
|
|
|
|
|
0x7F); |
21498
|
249
|
|
|
|
|
|
precode_freqs[18]++; |
21499
|
249
|
|
|
|
|
|
*itemptr++ = 18 | (extra_bits << 5); |
21500
|
249
|
|
|
|
|
|
run_start += 11 + extra_bits; |
21501
|
|
|
|
|
|
|
} |
21502
|
|
|
|
|
|
|
|
21503
|
|
|
|
|
|
|
|
21504
|
834
|
100
|
|
|
|
|
if ((run_end - run_start) >= 3) { |
21505
|
309
|
|
|
|
|
|
extra_bits = MIN((run_end - run_start) - 3, |
21506
|
|
|
|
|
|
|
0x7); |
21507
|
309
|
|
|
|
|
|
precode_freqs[17]++; |
21508
|
309
|
|
|
|
|
|
*itemptr++ = 17 | (extra_bits << 5); |
21509
|
834
|
|
|
|
|
|
run_start += 3 + extra_bits; |
21510
|
|
|
|
|
|
|
} |
21511
|
|
|
|
|
|
|
} else { |
21512
|
|
|
|
|
|
|
|
21513
|
|
|
|
|
|
|
|
21514
|
|
|
|
|
|
|
|
21515
|
|
|
|
|
|
|
|
21516
|
1139
|
100
|
|
|
|
|
if ((run_end - run_start) >= 4) { |
21517
|
6
|
|
|
|
|
|
precode_freqs[len]++; |
21518
|
6
|
|
|
|
|
|
*itemptr++ = len; |
21519
|
6
|
|
|
|
|
|
run_start++; |
21520
|
|
|
|
|
|
|
do { |
21521
|
6
|
|
|
|
|
|
extra_bits = MIN((run_end - run_start) - |
21522
|
|
|
|
|
|
|
3, 0x3); |
21523
|
6
|
|
|
|
|
|
precode_freqs[16]++; |
21524
|
6
|
|
|
|
|
|
*itemptr++ = 16 | (extra_bits << 5); |
21525
|
6
|
|
|
|
|
|
run_start += 3 + extra_bits; |
21526
|
6
|
50
|
|
|
|
|
} while ((run_end - run_start) >= 3); |
21527
|
|
|
|
|
|
|
} |
21528
|
|
|
|
|
|
|
} |
21529
|
|
|
|
|
|
|
|
21530
|
|
|
|
|
|
|
|
21531
|
3544
|
100
|
|
|
|
|
while (run_start != run_end) { |
21532
|
1571
|
|
|
|
|
|
precode_freqs[len]++; |
21533
|
1571
|
|
|
|
|
|
*itemptr++ = len; |
21534
|
1571
|
|
|
|
|
|
run_start++; |
21535
|
|
|
|
|
|
|
} |
21536
|
1973
|
100
|
|
|
|
|
} while (run_start != num_lens); |
21537
|
|
|
|
|
|
|
|
21538
|
65
|
|
|
|
|
|
return itemptr - precode_items; |
21539
|
|
|
|
|
|
|
} |
21540
|
|
|
|
|
|
|
|
21541
|
|
|
|
|
|
|
|
21542
|
|
|
|
|
|
|
|
21543
|
|
|
|
|
|
|
|
21544
|
|
|
|
|
|
|
static void |
21545
|
65
|
|
|
|
|
|
deflate_precompute_huffman_header(struct libdeflate_compressor *c) |
21546
|
|
|
|
|
|
|
{ |
21547
|
|
|
|
|
|
|
|
21548
|
|
|
|
|
|
|
|
21549
|
475
|
100
|
|
|
|
|
for (c->o.precode.num_litlen_syms = DEFLATE_NUM_LITLEN_SYMS; |
21550
|
475
|
|
|
|
|
|
c->o.precode.num_litlen_syms > 257; |
21551
|
410
|
|
|
|
|
|
c->o.precode.num_litlen_syms--) |
21552
|
466
|
100
|
|
|
|
|
if (c->codes.lens.litlen[c->o.precode.num_litlen_syms - 1] != 0) |
21553
|
56
|
|
|
|
|
|
break; |
21554
|
|
|
|
|
|
|
|
21555
|
1582
|
50
|
|
|
|
|
for (c->o.precode.num_offset_syms = DEFLATE_NUM_OFFSET_SYMS; |
21556
|
1582
|
|
|
|
|
|
c->o.precode.num_offset_syms > 1; |
21557
|
1517
|
|
|
|
|
|
c->o.precode.num_offset_syms--) |
21558
|
1582
|
100
|
|
|
|
|
if (c->codes.lens.offset[c->o.precode.num_offset_syms - 1] != 0) |
21559
|
65
|
|
|
|
|
|
break; |
21560
|
|
|
|
|
|
|
|
21561
|
|
|
|
|
|
|
|
21562
|
|
|
|
|
|
|
STATIC_ASSERT(offsetof(struct deflate_lens, offset) == |
21563
|
|
|
|
|
|
|
DEFLATE_NUM_LITLEN_SYMS); |
21564
|
65
|
50
|
|
|
|
|
if (c->o.precode.num_litlen_syms != DEFLATE_NUM_LITLEN_SYMS) { |
21565
|
65
|
|
|
|
|
|
memmove((u8 *)&c->codes.lens + c->o.precode.num_litlen_syms, |
21566
|
65
|
|
|
|
|
|
(u8 *)&c->codes.lens + DEFLATE_NUM_LITLEN_SYMS, |
21567
|
65
|
|
|
|
|
|
c->o.precode.num_offset_syms); |
21568
|
|
|
|
|
|
|
} |
21569
|
|
|
|
|
|
|
|
21570
|
|
|
|
|
|
|
|
21571
|
65
|
|
|
|
|
|
c->o.precode.num_items = |
21572
|
65
|
|
|
|
|
|
deflate_compute_precode_items((u8 *)&c->codes.lens, |
21573
|
65
|
|
|
|
|
|
c->o.precode.num_litlen_syms + |
21574
|
65
|
|
|
|
|
|
c->o.precode.num_offset_syms, |
21575
|
65
|
|
|
|
|
|
c->o.precode.freqs, |
21576
|
65
|
|
|
|
|
|
c->o.precode.items); |
21577
|
|
|
|
|
|
|
|
21578
|
|
|
|
|
|
|
|
21579
|
65
|
|
|
|
|
|
deflate_make_huffman_code(DEFLATE_NUM_PRECODE_SYMS, |
21580
|
|
|
|
|
|
|
MAX_PRE_CODEWORD_LEN, |
21581
|
65
|
|
|
|
|
|
c->o.precode.freqs, c->o.precode.lens, |
21582
|
65
|
|
|
|
|
|
c->o.precode.codewords); |
21583
|
|
|
|
|
|
|
|
21584
|
|
|
|
|
|
|
|
21585
|
138
|
50
|
|
|
|
|
for (c->o.precode.num_explicit_lens = DEFLATE_NUM_PRECODE_SYMS; |
21586
|
138
|
|
|
|
|
|
c->o.precode.num_explicit_lens > 4; |
21587
|
73
|
|
|
|
|
|
c->o.precode.num_explicit_lens--) |
21588
|
138
|
100
|
|
|
|
|
if (c->o.precode.lens[deflate_precode_lens_permutation[ |
21589
|
138
|
|
|
|
|
|
c->o.precode.num_explicit_lens - 1]] != 0) |
21590
|
65
|
|
|
|
|
|
break; |
21591
|
|
|
|
|
|
|
|
21592
|
|
|
|
|
|
|
|
21593
|
65
|
50
|
|
|
|
|
if (c->o.precode.num_litlen_syms != DEFLATE_NUM_LITLEN_SYMS) { |
21594
|
65
|
|
|
|
|
|
memmove((u8 *)&c->codes.lens + DEFLATE_NUM_LITLEN_SYMS, |
21595
|
65
|
|
|
|
|
|
(u8 *)&c->codes.lens + c->o.precode.num_litlen_syms, |
21596
|
65
|
|
|
|
|
|
c->o.precode.num_offset_syms); |
21597
|
|
|
|
|
|
|
} |
21598
|
65
|
|
|
|
|
|
} |
21599
|
|
|
|
|
|
|
|
21600
|
|
|
|
|
|
|
|
21601
|
|
|
|
|
|
|
static void |
21602
|
38
|
|
|
|
|
|
deflate_compute_full_len_codewords(struct libdeflate_compressor *c, |
21603
|
|
|
|
|
|
|
const struct deflate_codes *codes) |
21604
|
|
|
|
|
|
|
{ |
21605
|
|
|
|
|
|
|
unsigned len; |
21606
|
|
|
|
|
|
|
|
21607
|
|
|
|
|
|
|
STATIC_ASSERT(MAX_LITLEN_CODEWORD_LEN + |
21608
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS <= 32); |
21609
|
|
|
|
|
|
|
|
21610
|
9766
|
100
|
|
|
|
|
for (len = DEFLATE_MIN_MATCH_LEN; len <= DEFLATE_MAX_MATCH_LEN; len++) { |
21611
|
9728
|
|
|
|
|
|
unsigned slot = deflate_length_slot[len]; |
21612
|
9728
|
|
|
|
|
|
unsigned litlen_sym = DEFLATE_FIRST_LEN_SYM + slot; |
21613
|
9728
|
|
|
|
|
|
u32 extra_bits = len - deflate_length_slot_base[slot]; |
21614
|
|
|
|
|
|
|
|
21615
|
9728
|
|
|
|
|
|
c->o.length.codewords[len] = |
21616
|
19456
|
|
|
|
|
|
codes->codewords.litlen[litlen_sym] | |
21617
|
9728
|
|
|
|
|
|
(extra_bits << codes->lens.litlen[litlen_sym]); |
21618
|
19456
|
|
|
|
|
|
c->o.length.lens[len] = codes->lens.litlen[litlen_sym] + |
21619
|
9728
|
|
|
|
|
|
deflate_extra_length_bits[slot]; |
21620
|
|
|
|
|
|
|
} |
21621
|
38
|
|
|
|
|
|
} |
21622
|
|
|
|
|
|
|
|
21623
|
|
|
|
|
|
|
|
21624
|
|
|
|
|
|
|
#define WRITE_MATCH(c_, codes_, length_, offset_, offset_slot_) \ |
21625
|
|
|
|
|
|
|
do { \ |
21626
|
|
|
|
|
|
|
const struct libdeflate_compressor *c__ = (c_); \ |
21627
|
|
|
|
|
|
|
const struct deflate_codes *codes__ = (codes_); \ |
21628
|
|
|
|
|
|
|
unsigned length__ = (length_); \ |
21629
|
|
|
|
|
|
|
unsigned offset__ = (offset_); \ |
21630
|
|
|
|
|
|
|
unsigned offset_slot__ = (offset_slot_); \ |
21631
|
|
|
|
|
|
|
\ |
21632
|
|
|
|
|
|
|
\ |
21633
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_BUFFER(MAX_LITLEN_CODEWORD_LEN + \ |
21634
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS)); \ |
21635
|
|
|
|
|
|
|
ADD_BITS(c__->o.length.codewords[length__], \ |
21636
|
|
|
|
|
|
|
c__->o.length.lens[length__]); \ |
21637
|
|
|
|
|
|
|
\ |
21638
|
|
|
|
|
|
|
if (!CAN_BUFFER(MAX_LITLEN_CODEWORD_LEN + \ |
21639
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS + \ |
21640
|
|
|
|
|
|
|
MAX_OFFSET_CODEWORD_LEN + \ |
21641
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_OFFSET_BITS)) \ |
21642
|
|
|
|
|
|
|
FLUSH_BITS(); \ |
21643
|
|
|
|
|
|
|
\ |
21644
|
|
|
|
|
|
|
\ |
21645
|
|
|
|
|
|
|
ADD_BITS(codes__->codewords.offset[offset_slot__], \ |
21646
|
|
|
|
|
|
|
codes__->lens.offset[offset_slot__]); \ |
21647
|
|
|
|
|
|
|
\ |
21648
|
|
|
|
|
|
|
if (!CAN_BUFFER(MAX_OFFSET_CODEWORD_LEN + \ |
21649
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_OFFSET_BITS)) \ |
21650
|
|
|
|
|
|
|
FLUSH_BITS(); \ |
21651
|
|
|
|
|
|
|
\ |
21652
|
|
|
|
|
|
|
\ |
21653
|
|
|
|
|
|
|
ADD_BITS(offset__ - deflate_offset_slot_base[offset_slot__], \ |
21654
|
|
|
|
|
|
|
deflate_extra_offset_bits[offset_slot__]); \ |
21655
|
|
|
|
|
|
|
\ |
21656
|
|
|
|
|
|
|
FLUSH_BITS(); \ |
21657
|
|
|
|
|
|
|
} while (0) |
21658
|
|
|
|
|
|
|
|
21659
|
|
|
|
|
|
|
|
21660
|
|
|
|
|
|
|
static void |
21661
|
38
|
|
|
|
|
|
deflate_flush_block(struct libdeflate_compressor *c, |
21662
|
|
|
|
|
|
|
struct deflate_output_bitstream *os, |
21663
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
21664
|
|
|
|
|
|
|
const struct deflate_sequence *sequences, |
21665
|
|
|
|
|
|
|
bool is_final_block) |
21666
|
|
|
|
|
|
|
{ |
21667
|
|
|
|
|
|
|
|
21668
|
38
|
|
|
|
|
|
const u8 *in_next = block_begin; |
21669
|
38
|
|
|
|
|
|
const u8 * const in_end = block_begin + block_length; |
21670
|
38
|
|
|
|
|
|
bitbuf_t bitbuf = os->bitbuf; |
21671
|
38
|
|
|
|
|
|
unsigned bitcount = os->bitcount; |
21672
|
38
|
|
|
|
|
|
u8 *out_next = os->next; |
21673
|
38
|
|
|
|
|
|
u8 * const out_fast_end = |
21674
|
38
|
|
|
|
|
|
os->end - MIN(WORDBYTES - 1, os->end - out_next); |
21675
|
|
|
|
|
|
|
|
21676
|
38
|
|
|
|
|
|
u32 dynamic_cost = 3; |
21677
|
38
|
|
|
|
|
|
u32 static_cost = 3; |
21678
|
38
|
|
|
|
|
|
u32 uncompressed_cost = 3; |
21679
|
|
|
|
|
|
|
u32 best_cost; |
21680
|
|
|
|
|
|
|
struct deflate_codes *codes; |
21681
|
|
|
|
|
|
|
unsigned sym; |
21682
|
|
|
|
|
|
|
|
21683
|
38
|
100
|
|
|
|
|
ASSERT(block_length >= MIN_BLOCK_LENGTH || |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
21684
|
|
|
|
|
|
|
(is_final_block && block_length > 0)); |
21685
|
|
|
|
|
|
|
ASSERT(block_length <= MAX_BLOCK_LENGTH); |
21686
|
|
|
|
|
|
|
ASSERT(bitcount <= 7); |
21687
|
38
|
|
|
|
|
|
ASSERT((bitbuf & ~(((bitbuf_t)1 << bitcount) - 1)) == 0); |
21688
|
38
|
|
|
|
|
|
ASSERT(out_next <= os->end); |
21689
|
38
|
|
|
|
|
|
ASSERT(!os->overflow); |
21690
|
|
|
|
|
|
|
|
21691
|
|
|
|
|
|
|
|
21692
|
38
|
|
|
|
|
|
deflate_precompute_huffman_header(c); |
21693
|
|
|
|
|
|
|
|
21694
|
|
|
|
|
|
|
|
21695
|
38
|
|
|
|
|
|
dynamic_cost += 5 + 5 + 4 + (3 * c->o.precode.num_explicit_lens); |
21696
|
760
|
100
|
|
|
|
|
for (sym = 0; sym < DEFLATE_NUM_PRECODE_SYMS; sym++) { |
21697
|
722
|
|
|
|
|
|
u32 extra = deflate_extra_precode_bits[sym]; |
21698
|
|
|
|
|
|
|
|
21699
|
1444
|
|
|
|
|
|
dynamic_cost += c->o.precode.freqs[sym] * |
21700
|
722
|
|
|
|
|
|
(extra + c->o.precode.lens[sym]); |
21701
|
|
|
|
|
|
|
} |
21702
|
|
|
|
|
|
|
|
21703
|
|
|
|
|
|
|
|
21704
|
5510
|
100
|
|
|
|
|
for (sym = 0; sym < 144; sym++) { |
21705
|
10944
|
|
|
|
|
|
dynamic_cost += c->freqs.litlen[sym] * |
21706
|
5472
|
|
|
|
|
|
c->codes.lens.litlen[sym]; |
21707
|
5472
|
|
|
|
|
|
static_cost += c->freqs.litlen[sym] * 8; |
21708
|
|
|
|
|
|
|
} |
21709
|
4294
|
100
|
|
|
|
|
for (; sym < 256; sym++) { |
21710
|
8512
|
|
|
|
|
|
dynamic_cost += c->freqs.litlen[sym] * |
21711
|
4256
|
|
|
|
|
|
c->codes.lens.litlen[sym]; |
21712
|
4256
|
|
|
|
|
|
static_cost += c->freqs.litlen[sym] * 9; |
21713
|
|
|
|
|
|
|
} |
21714
|
|
|
|
|
|
|
|
21715
|
|
|
|
|
|
|
|
21716
|
38
|
|
|
|
|
|
dynamic_cost += c->codes.lens.litlen[DEFLATE_END_OF_BLOCK]; |
21717
|
38
|
|
|
|
|
|
static_cost += 7; |
21718
|
|
|
|
|
|
|
|
21719
|
|
|
|
|
|
|
|
21720
|
1140
|
100
|
|
|
|
|
for (sym = DEFLATE_FIRST_LEN_SYM; |
21721
|
|
|
|
|
|
|
sym < DEFLATE_FIRST_LEN_SYM + ARRAY_LEN(deflate_extra_length_bits); |
21722
|
1102
|
|
|
|
|
|
sym++) { |
21723
|
1102
|
|
|
|
|
|
u32 extra = deflate_extra_length_bits[ |
21724
|
1102
|
|
|
|
|
|
sym - DEFLATE_FIRST_LEN_SYM]; |
21725
|
|
|
|
|
|
|
|
21726
|
2204
|
|
|
|
|
|
dynamic_cost += c->freqs.litlen[sym] * |
21727
|
1102
|
|
|
|
|
|
(extra + c->codes.lens.litlen[sym]); |
21728
|
2204
|
|
|
|
|
|
static_cost += c->freqs.litlen[sym] * |
21729
|
1102
|
|
|
|
|
|
(extra + c->static_codes.lens.litlen[sym]); |
21730
|
|
|
|
|
|
|
} |
21731
|
|
|
|
|
|
|
|
21732
|
|
|
|
|
|
|
|
21733
|
1178
|
100
|
|
|
|
|
for (sym = 0; sym < ARRAY_LEN(deflate_extra_offset_bits); sym++) { |
21734
|
1140
|
|
|
|
|
|
u32 extra = deflate_extra_offset_bits[sym]; |
21735
|
|
|
|
|
|
|
|
21736
|
2280
|
|
|
|
|
|
dynamic_cost += c->freqs.offset[sym] * |
21737
|
1140
|
|
|
|
|
|
(extra + c->codes.lens.offset[sym]); |
21738
|
1140
|
|
|
|
|
|
static_cost += c->freqs.offset[sym] * (extra + 5); |
21739
|
|
|
|
|
|
|
} |
21740
|
|
|
|
|
|
|
|
21741
|
|
|
|
|
|
|
|
21742
|
114
|
|
|
|
|
|
uncompressed_cost += (-(bitcount + 3) & 7) + 32 + |
21743
|
38
|
|
|
|
|
|
(40 * (DIV_ROUND_UP(block_length, |
21744
|
38
|
|
|
|
|
|
UINT16_MAX) - 1)) + |
21745
|
38
|
|
|
|
|
|
(8 * block_length); |
21746
|
|
|
|
|
|
|
|
21747
|
|
|
|
|
|
|
|
21748
|
|
|
|
|
|
|
|
21749
|
38
|
|
|
|
|
|
best_cost = MIN(dynamic_cost, MIN(static_cost, uncompressed_cost)); |
21750
|
|
|
|
|
|
|
|
21751
|
|
|
|
|
|
|
|
21752
|
38
|
50
|
|
|
|
|
if (DIV_ROUND_UP(bitcount + best_cost, 8) > os->end - out_next) { |
21753
|
0
|
|
|
|
|
|
os->overflow = true; |
21754
|
0
|
|
|
|
|
|
return; |
21755
|
|
|
|
|
|
|
} |
21756
|
|
|
|
|
|
|
|
21757
|
|
|
|
|
|
|
|
21758
|
38
|
50
|
|
|
|
|
if (best_cost == uncompressed_cost) { |
21759
|
|
|
|
|
|
|
|
21760
|
|
|
|
|
|
|
do { |
21761
|
0
|
|
|
|
|
|
u8 bfinal = 0; |
21762
|
0
|
|
|
|
|
|
size_t len = UINT16_MAX; |
21763
|
|
|
|
|
|
|
|
21764
|
0
|
0
|
|
|
|
|
if (in_end - in_next <= UINT16_MAX) { |
21765
|
0
|
|
|
|
|
|
bfinal = is_final_block; |
21766
|
0
|
|
|
|
|
|
len = in_end - in_next; |
21767
|
|
|
|
|
|
|
} |
21768
|
|
|
|
|
|
|
|
21769
|
0
|
|
|
|
|
|
ASSERT(os->end - out_next >= |
21770
|
|
|
|
|
|
|
DIV_ROUND_UP(bitcount + 3, 8) + 4 + len); |
21771
|
|
|
|
|
|
|
|
21772
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_BLOCKTYPE_UNCOMPRESSED == 0); |
21773
|
0
|
|
|
|
|
|
*out_next++ = (bfinal << bitcount) | bitbuf; |
21774
|
0
|
0
|
|
|
|
|
if (bitcount > 5) |
21775
|
0
|
|
|
|
|
|
*out_next++ = 0; |
21776
|
0
|
|
|
|
|
|
bitbuf = 0; |
21777
|
0
|
|
|
|
|
|
bitcount = 0; |
21778
|
|
|
|
|
|
|
|
21779
|
0
|
|
|
|
|
|
put_unaligned_le16(len, out_next); |
21780
|
0
|
|
|
|
|
|
out_next += 2; |
21781
|
0
|
|
|
|
|
|
put_unaligned_le16(~len, out_next); |
21782
|
0
|
|
|
|
|
|
out_next += 2; |
21783
|
0
|
|
|
|
|
|
memcpy(out_next, in_next, len); |
21784
|
0
|
|
|
|
|
|
out_next += len; |
21785
|
0
|
|
|
|
|
|
in_next += len; |
21786
|
0
|
0
|
|
|
|
|
} while (in_next != in_end); |
21787
|
|
|
|
|
|
|
|
21788
|
0
|
|
|
|
|
|
goto out; |
21789
|
|
|
|
|
|
|
} |
21790
|
|
|
|
|
|
|
|
21791
|
38
|
100
|
|
|
|
|
if (best_cost == static_cost) { |
21792
|
|
|
|
|
|
|
|
21793
|
36
|
|
|
|
|
|
codes = &c->static_codes; |
21794
|
36
|
|
|
|
|
|
ADD_BITS(is_final_block, 1); |
21795
|
36
|
|
|
|
|
|
ADD_BITS(DEFLATE_BLOCKTYPE_STATIC_HUFFMAN, 2); |
21796
|
36
|
50
|
|
|
|
|
FLUSH_BITS(); |
|
|
0
|
|
|
|
|
|
21797
|
|
|
|
|
|
|
} else { |
21798
|
2
|
|
|
|
|
|
const unsigned num_explicit_lens = c->o.precode.num_explicit_lens; |
21799
|
2
|
|
|
|
|
|
const unsigned num_precode_items = c->o.precode.num_items; |
21800
|
|
|
|
|
|
|
unsigned precode_sym, precode_item; |
21801
|
|
|
|
|
|
|
unsigned i; |
21802
|
|
|
|
|
|
|
|
21803
|
|
|
|
|
|
|
|
21804
|
|
|
|
|
|
|
|
21805
|
2
|
|
|
|
|
|
codes = &c->codes; |
21806
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_BUFFER(1 + 2 + 5 + 5 + 4 + 3)); |
21807
|
2
|
|
|
|
|
|
ADD_BITS(is_final_block, 1); |
21808
|
2
|
|
|
|
|
|
ADD_BITS(DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN, 2); |
21809
|
2
|
|
|
|
|
|
ADD_BITS(c->o.precode.num_litlen_syms - 257, 5); |
21810
|
2
|
|
|
|
|
|
ADD_BITS(c->o.precode.num_offset_syms - 1, 5); |
21811
|
2
|
|
|
|
|
|
ADD_BITS(num_explicit_lens - 4, 4); |
21812
|
|
|
|
|
|
|
|
21813
|
|
|
|
|
|
|
|
21814
|
|
|
|
|
|
|
if (CAN_BUFFER(3 * (DEFLATE_NUM_PRECODE_SYMS - 1))) { |
21815
|
|
|
|
|
|
|
|
21816
|
2
|
|
|
|
|
|
precode_sym = deflate_precode_lens_permutation[0]; |
21817
|
2
|
|
|
|
|
|
ADD_BITS(c->o.precode.lens[precode_sym], 3); |
21818
|
2
|
50
|
|
|
|
|
FLUSH_BITS(); |
|
|
0
|
|
|
|
|
|
21819
|
2
|
|
|
|
|
|
i = 1; |
21820
|
|
|
|
|
|
|
do { |
21821
|
26
|
|
|
|
|
|
precode_sym = |
21822
|
26
|
|
|
|
|
|
deflate_precode_lens_permutation[i]; |
21823
|
26
|
|
|
|
|
|
ADD_BITS(c->o.precode.lens[precode_sym], 3); |
21824
|
26
|
100
|
|
|
|
|
} while (++i < num_explicit_lens); |
21825
|
2
|
50
|
|
|
|
|
FLUSH_BITS(); |
|
|
0
|
|
|
|
|
|
21826
|
|
|
|
|
|
|
} else { |
21827
|
|
|
|
|
|
|
FLUSH_BITS(); |
21828
|
|
|
|
|
|
|
i = 0; |
21829
|
|
|
|
|
|
|
do { |
21830
|
|
|
|
|
|
|
precode_sym = |
21831
|
|
|
|
|
|
|
deflate_precode_lens_permutation[i]; |
21832
|
|
|
|
|
|
|
ADD_BITS(c->o.precode.lens[precode_sym], 3); |
21833
|
|
|
|
|
|
|
FLUSH_BITS(); |
21834
|
|
|
|
|
|
|
} while (++i < num_explicit_lens); |
21835
|
|
|
|
|
|
|
} |
21836
|
|
|
|
|
|
|
|
21837
|
|
|
|
|
|
|
|
21838
|
2
|
|
|
|
|
|
i = 0; |
21839
|
|
|
|
|
|
|
do { |
21840
|
233
|
|
|
|
|
|
precode_item = c->o.precode.items[i]; |
21841
|
233
|
|
|
|
|
|
precode_sym = precode_item & 0x1F; |
21842
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_BUFFER(MAX_PRE_CODEWORD_LEN + 7)); |
21843
|
233
|
|
|
|
|
|
ADD_BITS(c->o.precode.codewords[precode_sym], |
21844
|
|
|
|
|
|
|
c->o.precode.lens[precode_sym]); |
21845
|
233
|
|
|
|
|
|
ADD_BITS(precode_item >> 5, |
21846
|
|
|
|
|
|
|
deflate_extra_precode_bits[precode_sym]); |
21847
|
233
|
50
|
|
|
|
|
FLUSH_BITS(); |
|
|
0
|
|
|
|
|
|
21848
|
233
|
100
|
|
|
|
|
} while (++i < num_precode_items); |
21849
|
|
|
|
|
|
|
} |
21850
|
|
|
|
|
|
|
|
21851
|
|
|
|
|
|
|
|
21852
|
|
|
|
|
|
|
ASSERT(bitcount <= 7); |
21853
|
38
|
|
|
|
|
|
deflate_compute_full_len_codewords(c, codes); |
21854
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
21855
|
38
|
100
|
|
|
|
|
if (sequences == NULL) { |
21856
|
|
|
|
|
|
|
|
21857
|
9
|
|
|
|
|
|
struct deflate_optimum_node *cur_node = |
21858
|
|
|
|
|
|
|
&c->p.n.optimum_nodes[0]; |
21859
|
9
|
|
|
|
|
|
struct deflate_optimum_node * const end_node = |
21860
|
|
|
|
|
|
|
&c->p.n.optimum_nodes[block_length]; |
21861
|
|
|
|
|
|
|
do { |
21862
|
225
|
|
|
|
|
|
unsigned length = cur_node->item & OPTIMUM_LEN_MASK; |
21863
|
225
|
|
|
|
|
|
unsigned offset = cur_node->item >> |
21864
|
|
|
|
|
|
|
OPTIMUM_OFFSET_SHIFT; |
21865
|
225
|
100
|
|
|
|
|
if (length == 1) { |
21866
|
|
|
|
|
|
|
|
21867
|
162
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[offset], |
21868
|
|
|
|
|
|
|
codes->lens.litlen[offset]); |
21869
|
162
|
50
|
|
|
|
|
FLUSH_BITS(); |
|
|
0
|
|
|
|
|
|
21870
|
|
|
|
|
|
|
} else { |
21871
|
|
|
|
|
|
|
|
21872
|
63
|
50
|
|
|
|
|
WRITE_MATCH(c, codes, length, offset, |
|
|
0
|
|
|
|
|
|
21873
|
|
|
|
|
|
|
c->p.n.offset_slot_full[offset]); |
21874
|
|
|
|
|
|
|
} |
21875
|
225
|
|
|
|
|
|
cur_node += length; |
21876
|
225
|
100
|
|
|
|
|
} while (cur_node != end_node); |
21877
|
|
|
|
|
|
|
} else |
21878
|
|
|
|
|
|
|
#endif |
21879
|
|
|
|
|
|
|
{ |
21880
|
|
|
|
|
|
|
|
21881
|
|
|
|
|
|
|
const struct deflate_sequence *seq; |
21882
|
|
|
|
|
|
|
|
21883
|
29
|
|
|
|
|
|
for (seq = sequences; ; seq++) { |
21884
|
2120
|
|
|
|
|
|
u32 litrunlen = seq->litrunlen_and_length & |
21885
|
|
|
|
|
|
|
SEQ_LITRUNLEN_MASK; |
21886
|
2120
|
|
|
|
|
|
unsigned length = seq->litrunlen_and_length >> |
21887
|
|
|
|
|
|
|
SEQ_LENGTH_SHIFT; |
21888
|
|
|
|
|
|
|
unsigned lit; |
21889
|
|
|
|
|
|
|
|
21890
|
|
|
|
|
|
|
|
21891
|
|
|
|
|
|
|
if (CAN_BUFFER(4 * MAX_LITLEN_CODEWORD_LEN)) { |
21892
|
2677
|
100
|
|
|
|
|
for (; litrunlen >= 4; litrunlen -= 4) { |
21893
|
557
|
|
|
|
|
|
lit = *in_next++; |
21894
|
557
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21895
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21896
|
557
|
|
|
|
|
|
lit = *in_next++; |
21897
|
557
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21898
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21899
|
557
|
|
|
|
|
|
lit = *in_next++; |
21900
|
557
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21901
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21902
|
557
|
|
|
|
|
|
lit = *in_next++; |
21903
|
557
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21904
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21905
|
557
|
50
|
|
|
|
|
FLUSH_BITS(); |
|
|
0
|
|
|
|
|
|
21906
|
|
|
|
|
|
|
} |
21907
|
2120
|
100
|
|
|
|
|
if (litrunlen-- != 0) { |
21908
|
509
|
|
|
|
|
|
lit = *in_next++; |
21909
|
509
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21910
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21911
|
509
|
100
|
|
|
|
|
if (litrunlen-- != 0) { |
21912
|
280
|
|
|
|
|
|
lit = *in_next++; |
21913
|
280
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21914
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21915
|
280
|
100
|
|
|
|
|
if (litrunlen-- != 0) { |
21916
|
112
|
|
|
|
|
|
lit = *in_next++; |
21917
|
112
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21918
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21919
|
|
|
|
|
|
|
} |
21920
|
|
|
|
|
|
|
} |
21921
|
509
|
50
|
|
|
|
|
FLUSH_BITS(); |
|
|
0
|
|
|
|
|
|
21922
|
|
|
|
|
|
|
} |
21923
|
|
|
|
|
|
|
} else { |
21924
|
|
|
|
|
|
|
while (litrunlen--) { |
21925
|
|
|
|
|
|
|
lit = *in_next++; |
21926
|
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21927
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21928
|
|
|
|
|
|
|
FLUSH_BITS(); |
21929
|
|
|
|
|
|
|
} |
21930
|
|
|
|
|
|
|
} |
21931
|
|
|
|
|
|
|
|
21932
|
2120
|
100
|
|
|
|
|
if (length == 0) { |
21933
|
|
|
|
|
|
|
ASSERT(in_next == in_end); |
21934
|
29
|
|
|
|
|
|
break; |
21935
|
|
|
|
|
|
|
} |
21936
|
|
|
|
|
|
|
|
21937
|
|
|
|
|
|
|
|
21938
|
2091
|
50
|
|
|
|
|
WRITE_MATCH(c, codes, length, seq->offset, |
|
|
0
|
|
|
|
|
|
21939
|
|
|
|
|
|
|
seq->offset_slot); |
21940
|
2091
|
|
|
|
|
|
in_next += length; |
21941
|
2091
|
|
|
|
|
|
} |
21942
|
|
|
|
|
|
|
} |
21943
|
|
|
|
|
|
|
|
21944
|
|
|
|
|
|
|
|
21945
|
|
|
|
|
|
|
ASSERT(bitcount <= 7); |
21946
|
38
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[DEFLATE_END_OF_BLOCK], |
21947
|
|
|
|
|
|
|
codes->lens.litlen[DEFLATE_END_OF_BLOCK]); |
21948
|
38
|
50
|
|
|
|
|
FLUSH_BITS(); |
|
|
0
|
|
|
|
|
|
21949
|
|
|
|
|
|
|
out: |
21950
|
|
|
|
|
|
|
ASSERT(bitcount <= 7); |
21951
|
|
|
|
|
|
|
|
21952
|
38
|
|
|
|
|
|
ASSERT(8 * (out_next - os->next) + bitcount - os->bitcount == best_cost); |
21953
|
38
|
|
|
|
|
|
os->bitbuf = bitbuf; |
21954
|
38
|
|
|
|
|
|
os->bitcount = bitcount; |
21955
|
38
|
|
|
|
|
|
os->next = out_next; |
21956
|
|
|
|
|
|
|
} |
21957
|
|
|
|
|
|
|
|
21958
|
|
|
|
|
|
|
static void |
21959
|
29
|
|
|
|
|
|
deflate_finish_block(struct libdeflate_compressor *c, |
21960
|
|
|
|
|
|
|
struct deflate_output_bitstream *os, |
21961
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
21962
|
|
|
|
|
|
|
const struct deflate_sequence *sequences, |
21963
|
|
|
|
|
|
|
bool is_final_block) |
21964
|
|
|
|
|
|
|
{ |
21965
|
29
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_END_OF_BLOCK]++; |
21966
|
29
|
|
|
|
|
|
deflate_make_huffman_codes(&c->freqs, &c->codes); |
21967
|
29
|
|
|
|
|
|
deflate_flush_block(c, os, block_begin, block_length, sequences, |
21968
|
|
|
|
|
|
|
is_final_block); |
21969
|
29
|
|
|
|
|
|
} |
21970
|
|
|
|
|
|
|
|
21971
|
|
|
|
|
|
|
|
21972
|
|
|
|
|
|
|
|
21973
|
|
|
|
|
|
|
|
21974
|
|
|
|
|
|
|
|
21975
|
|
|
|
|
|
|
|
21976
|
|
|
|
|
|
|
static void |
21977
|
44
|
|
|
|
|
|
init_block_split_stats(struct block_split_stats *stats) |
21978
|
|
|
|
|
|
|
{ |
21979
|
|
|
|
|
|
|
int i; |
21980
|
|
|
|
|
|
|
|
21981
|
484
|
100
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) { |
21982
|
440
|
|
|
|
|
|
stats->new_observations[i] = 0; |
21983
|
440
|
|
|
|
|
|
stats->observations[i] = 0; |
21984
|
|
|
|
|
|
|
} |
21985
|
44
|
|
|
|
|
|
stats->num_new_observations = 0; |
21986
|
44
|
|
|
|
|
|
stats->num_observations = 0; |
21987
|
44
|
|
|
|
|
|
} |
21988
|
|
|
|
|
|
|
|
21989
|
|
|
|
|
|
|
|
21990
|
|
|
|
|
|
|
static forceinline void |
21991
|
|
|
|
|
|
|
observe_literal(struct block_split_stats *stats, u8 lit) |
21992
|
|
|
|
|
|
|
{ |
21993
|
3237
|
|
|
|
|
|
stats->new_observations[((lit >> 5) & 0x6) | (lit & 1)]++; |
21994
|
3075
|
|
|
|
|
|
stats->num_new_observations++; |
21995
|
|
|
|
|
|
|
} |
21996
|
|
|
|
|
|
|
|
21997
|
|
|
|
|
|
|
|
21998
|
|
|
|
|
|
|
static forceinline void |
21999
|
|
|
|
|
|
|
observe_match(struct block_split_stats *stats, unsigned length) |
22000
|
|
|
|
|
|
|
{ |
22001
|
2133
|
50
|
|
|
|
|
stats->new_observations[NUM_LITERAL_OBSERVATION_TYPES + |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22002
|
2133
|
|
|
|
|
|
(length >= 9)]++; |
22003
|
2070
|
|
|
|
|
|
stats->num_new_observations++; |
22004
|
|
|
|
|
|
|
} |
22005
|
|
|
|
|
|
|
|
22006
|
|
|
|
|
|
|
static void |
22007
|
15
|
|
|
|
|
|
merge_new_observations(struct block_split_stats *stats) |
22008
|
|
|
|
|
|
|
{ |
22009
|
|
|
|
|
|
|
int i; |
22010
|
|
|
|
|
|
|
|
22011
|
165
|
100
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) { |
22012
|
150
|
|
|
|
|
|
stats->observations[i] += stats->new_observations[i]; |
22013
|
150
|
|
|
|
|
|
stats->new_observations[i] = 0; |
22014
|
|
|
|
|
|
|
} |
22015
|
15
|
|
|
|
|
|
stats->num_observations += stats->num_new_observations; |
22016
|
15
|
|
|
|
|
|
stats->num_new_observations = 0; |
22017
|
15
|
|
|
|
|
|
} |
22018
|
|
|
|
|
|
|
|
22019
|
|
|
|
|
|
|
static bool |
22020
|
7
|
|
|
|
|
|
do_end_block_check(struct block_split_stats *stats, u32 block_length) |
22021
|
|
|
|
|
|
|
{ |
22022
|
7
|
100
|
|
|
|
|
if (stats->num_observations > 0) { |
22023
|
|
|
|
|
|
|
|
22024
|
6
|
|
|
|
|
|
u32 total_delta = 0; |
22025
|
|
|
|
|
|
|
u32 num_items; |
22026
|
|
|
|
|
|
|
u32 cutoff; |
22027
|
|
|
|
|
|
|
int i; |
22028
|
|
|
|
|
|
|
|
22029
|
66
|
100
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) { |
22030
|
120
|
|
|
|
|
|
u32 expected = stats->observations[i] * |
22031
|
60
|
|
|
|
|
|
stats->num_new_observations; |
22032
|
120
|
|
|
|
|
|
u32 actual = stats->new_observations[i] * |
22033
|
60
|
|
|
|
|
|
stats->num_observations; |
22034
|
60
|
100
|
|
|
|
|
u32 delta = (actual > expected) ? actual - expected : |
22035
|
|
|
|
|
|
|
expected - actual; |
22036
|
|
|
|
|
|
|
|
22037
|
60
|
|
|
|
|
|
total_delta += delta; |
22038
|
|
|
|
|
|
|
} |
22039
|
|
|
|
|
|
|
|
22040
|
12
|
|
|
|
|
|
num_items = stats->num_observations + |
22041
|
6
|
|
|
|
|
|
stats->num_new_observations; |
22042
|
|
|
|
|
|
|
|
22043
|
12
|
|
|
|
|
|
cutoff = stats->num_new_observations * 200 / 512 * |
22044
|
6
|
|
|
|
|
|
stats->num_observations; |
22045
|
|
|
|
|
|
|
|
22046
|
6
|
100
|
|
|
|
|
if (block_length < 10000 && num_items < 8192) |
|
|
50
|
|
|
|
|
|
22047
|
1
|
|
|
|
|
|
cutoff += (u64)cutoff * (8192 - num_items) / 8192; |
22048
|
|
|
|
|
|
|
|
22049
|
|
|
|
|
|
|
|
22050
|
6
|
100
|
|
|
|
|
if (total_delta + |
22051
|
6
|
|
|
|
|
|
(block_length / 4096) * stats->num_observations >= cutoff) |
22052
|
1
|
|
|
|
|
|
return true; |
22053
|
|
|
|
|
|
|
} |
22054
|
6
|
|
|
|
|
|
merge_new_observations(stats); |
22055
|
6
|
|
|
|
|
|
return false; |
22056
|
|
|
|
|
|
|
} |
22057
|
|
|
|
|
|
|
|
22058
|
|
|
|
|
|
|
static forceinline bool |
22059
|
|
|
|
|
|
|
ready_to_check_block(const struct block_split_stats *stats, |
22060
|
|
|
|
|
|
|
const u8 *in_block_begin, const u8 *in_next, |
22061
|
|
|
|
|
|
|
const u8 *in_end) |
22062
|
|
|
|
|
|
|
{ |
22063
|
5245
|
|
|
|
|
|
return stats->num_new_observations >= NUM_OBSERVATIONS_PER_BLOCK_CHECK |
22064
|
450
|
0
|
|
|
|
|
&& in_next - in_block_begin >= MIN_BLOCK_LENGTH |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22065
|
5695
|
50
|
|
|
|
|
&& in_end - in_next >= MIN_BLOCK_LENGTH; |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22066
|
|
|
|
|
|
|
} |
22067
|
|
|
|
|
|
|
|
22068
|
|
|
|
|
|
|
static forceinline bool |
22069
|
|
|
|
|
|
|
should_end_block(struct block_split_stats *stats, |
22070
|
|
|
|
|
|
|
const u8 *in_block_begin, const u8 *in_next, const u8 *in_end) |
22071
|
|
|
|
|
|
|
{ |
22072
|
|
|
|
|
|
|
|
22073
|
5029
|
50
|
|
|
|
|
if (!ready_to_check_block(stats, in_block_begin, in_next, in_end)) |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
22074
|
5022
|
|
|
|
|
|
return false; |
22075
|
|
|
|
|
|
|
|
22076
|
7
|
|
|
|
|
|
return do_end_block_check(stats, in_next - in_block_begin); |
22077
|
|
|
|
|
|
|
} |
22078
|
|
|
|
|
|
|
|
22079
|
|
|
|
|
|
|
|
22080
|
|
|
|
|
|
|
|
22081
|
|
|
|
|
|
|
static void |
22082
|
29
|
|
|
|
|
|
deflate_begin_sequences(struct libdeflate_compressor *c, |
22083
|
|
|
|
|
|
|
struct deflate_sequence *first_seq) |
22084
|
|
|
|
|
|
|
{ |
22085
|
29
|
|
|
|
|
|
deflate_reset_symbol_frequencies(c); |
22086
|
29
|
|
|
|
|
|
first_seq->litrunlen_and_length = 0; |
22087
|
29
|
|
|
|
|
|
} |
22088
|
|
|
|
|
|
|
|
22089
|
|
|
|
|
|
|
static forceinline void |
22090
|
|
|
|
|
|
|
deflate_choose_literal(struct libdeflate_compressor *c, unsigned literal, |
22091
|
|
|
|
|
|
|
bool gather_split_stats, struct deflate_sequence *seq) |
22092
|
|
|
|
|
|
|
{ |
22093
|
3129
|
|
|
|
|
|
c->freqs.litlen[literal]++; |
22094
|
|
|
|
|
|
|
|
22095
|
3129
|
50
|
|
|
|
|
if (gather_split_stats) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
22096
|
3075
|
|
|
|
|
|
observe_literal(&c->split_stats, literal); |
22097
|
|
|
|
|
|
|
|
22098
|
|
|
|
|
|
|
STATIC_ASSERT(MAX_BLOCK_LENGTH <= SEQ_LITRUNLEN_MASK); |
22099
|
216
|
|
|
|
|
|
seq->litrunlen_and_length++; |
22100
|
|
|
|
|
|
|
} |
22101
|
|
|
|
|
|
|
|
22102
|
|
|
|
|
|
|
static forceinline void |
22103
|
|
|
|
|
|
|
deflate_choose_match(struct libdeflate_compressor *c, |
22104
|
|
|
|
|
|
|
unsigned length, unsigned offset, bool gather_split_stats, |
22105
|
|
|
|
|
|
|
struct deflate_sequence **seq_p) |
22106
|
|
|
|
|
|
|
{ |
22107
|
2091
|
|
|
|
|
|
struct deflate_sequence *seq = *seq_p; |
22108
|
2091
|
|
|
|
|
|
unsigned length_slot = deflate_length_slot[length]; |
22109
|
2091
|
|
|
|
|
|
unsigned offset_slot = deflate_get_offset_slot(offset); |
22110
|
|
|
|
|
|
|
|
22111
|
2091
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_FIRST_LEN_SYM + length_slot]++; |
22112
|
2091
|
|
|
|
|
|
c->freqs.offset[offset_slot]++; |
22113
|
2091
|
50
|
|
|
|
|
if (gather_split_stats) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
22114
|
2070
|
|
|
|
|
|
observe_match(&c->split_stats, length); |
22115
|
|
|
|
|
|
|
|
22116
|
2091
|
|
|
|
|
|
seq->litrunlen_and_length |= (u32)length << SEQ_LENGTH_SHIFT; |
22117
|
2091
|
|
|
|
|
|
seq->offset = offset; |
22118
|
2091
|
|
|
|
|
|
seq->offset_slot = offset_slot; |
22119
|
|
|
|
|
|
|
|
22120
|
2091
|
|
|
|
|
|
seq++; |
22121
|
2091
|
|
|
|
|
|
seq->litrunlen_and_length = 0; |
22122
|
2091
|
|
|
|
|
|
*seq_p = seq; |
22123
|
|
|
|
|
|
|
} |
22124
|
|
|
|
|
|
|
|
22125
|
|
|
|
|
|
|
|
22126
|
|
|
|
|
|
|
static forceinline void |
22127
|
|
|
|
|
|
|
adjust_max_and_nice_len(unsigned *max_len, unsigned *nice_len, size_t remaining) |
22128
|
|
|
|
|
|
|
{ |
22129
|
22346
|
100
|
|
|
|
|
if (unlikely(remaining < DEFLATE_MAX_MATCH_LEN)) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
22130
|
2389
|
|
|
|
|
|
*max_len = remaining; |
22131
|
2389
|
|
|
|
|
|
*nice_len = MIN(*nice_len, *max_len); |
22132
|
|
|
|
|
|
|
} |
22133
|
|
|
|
|
|
|
} |
22134
|
|
|
|
|
|
|
|
22135
|
|
|
|
|
|
|
|
22136
|
|
|
|
|
|
|
static unsigned |
22137
|
46
|
|
|
|
|
|
choose_min_match_len(unsigned num_used_literals, unsigned max_search_depth) |
22138
|
|
|
|
|
|
|
{ |
22139
|
|
|
|
|
|
|
|
22140
|
|
|
|
|
|
|
static const u8 min_lens[] = { |
22141
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 8, 8, 7, 7, 6, 6, 6, 6, 6, 6, |
22142
|
|
|
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
22143
|
|
|
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, |
22144
|
|
|
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
22145
|
|
|
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
22146
|
|
|
|
|
|
|
|
22147
|
|
|
|
|
|
|
}; |
22148
|
|
|
|
|
|
|
unsigned min_len; |
22149
|
|
|
|
|
|
|
|
22150
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MIN_MATCH_LEN <= 3); |
22151
|
|
|
|
|
|
|
STATIC_ASSERT(ARRAY_LEN(min_lens) <= DEFLATE_NUM_LITERALS + 1); |
22152
|
|
|
|
|
|
|
|
22153
|
46
|
50
|
|
|
|
|
if (num_used_literals >= ARRAY_LEN(min_lens)) |
22154
|
0
|
|
|
|
|
|
return 3; |
22155
|
46
|
|
|
|
|
|
min_len = min_lens[num_used_literals]; |
22156
|
|
|
|
|
|
|
|
22157
|
46
|
100
|
|
|
|
|
if (max_search_depth < 16) { |
22158
|
6
|
50
|
|
|
|
|
if (max_search_depth < 5) |
22159
|
0
|
|
|
|
|
|
min_len = MIN(min_len, 4); |
22160
|
6
|
100
|
|
|
|
|
else if (max_search_depth < 10) |
22161
|
3
|
|
|
|
|
|
min_len = MIN(min_len, 5); |
22162
|
|
|
|
|
|
|
else |
22163
|
3
|
|
|
|
|
|
min_len = MIN(min_len, 7); |
22164
|
|
|
|
|
|
|
} |
22165
|
46
|
|
|
|
|
|
return min_len; |
22166
|
|
|
|
|
|
|
} |
22167
|
|
|
|
|
|
|
|
22168
|
|
|
|
|
|
|
static unsigned |
22169
|
35
|
|
|
|
|
|
calculate_min_match_len(const u8 *data, size_t data_len, |
22170
|
|
|
|
|
|
|
unsigned max_search_depth) |
22171
|
|
|
|
|
|
|
{ |
22172
|
35
|
|
|
|
|
|
u8 used[256] = { 0 }; |
22173
|
35
|
|
|
|
|
|
unsigned num_used_literals = 0; |
22174
|
|
|
|
|
|
|
size_t i; |
22175
|
|
|
|
|
|
|
|
22176
|
|
|
|
|
|
|
|
22177
|
35
|
50
|
|
|
|
|
if (data_len < 512) |
22178
|
0
|
|
|
|
|
|
return DEFLATE_MIN_MATCH_LEN; |
22179
|
|
|
|
|
|
|
|
22180
|
|
|
|
|
|
|
|
22181
|
35
|
|
|
|
|
|
data_len = MIN(data_len, 4096); |
22182
|
64327
|
100
|
|
|
|
|
for (i = 0; i < data_len; i++) |
22183
|
64292
|
|
|
|
|
|
used[data[i]] = 1; |
22184
|
8995
|
100
|
|
|
|
|
for (i = 0; i < 256; i++) |
22185
|
8960
|
|
|
|
|
|
num_used_literals += used[i]; |
22186
|
35
|
|
|
|
|
|
return choose_min_match_len(num_used_literals, max_search_depth); |
22187
|
|
|
|
|
|
|
} |
22188
|
|
|
|
|
|
|
|
22189
|
|
|
|
|
|
|
|
22190
|
|
|
|
|
|
|
static unsigned |
22191
|
2
|
|
|
|
|
|
recalculate_min_match_len(const struct deflate_freqs *freqs, |
22192
|
|
|
|
|
|
|
unsigned max_search_depth) |
22193
|
|
|
|
|
|
|
{ |
22194
|
2
|
|
|
|
|
|
u32 literal_freq = 0; |
22195
|
|
|
|
|
|
|
u32 cutoff; |
22196
|
2
|
|
|
|
|
|
unsigned num_used_literals = 0; |
22197
|
|
|
|
|
|
|
int i; |
22198
|
|
|
|
|
|
|
|
22199
|
514
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) |
22200
|
512
|
|
|
|
|
|
literal_freq += freqs->litlen[i]; |
22201
|
|
|
|
|
|
|
|
22202
|
2
|
|
|
|
|
|
cutoff = literal_freq >> 10; |
22203
|
|
|
|
|
|
|
|
22204
|
514
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) { |
22205
|
512
|
100
|
|
|
|
|
if (freqs->litlen[i] > cutoff) |
22206
|
119
|
|
|
|
|
|
num_used_literals++; |
22207
|
|
|
|
|
|
|
} |
22208
|
2
|
|
|
|
|
|
return choose_min_match_len(num_used_literals, max_search_depth); |
22209
|
|
|
|
|
|
|
} |
22210
|
|
|
|
|
|
|
|
22211
|
|
|
|
|
|
|
static forceinline const u8 * |
22212
|
|
|
|
|
|
|
choose_max_block_end(const u8 *in_block_begin, const u8 *in_end, |
22213
|
|
|
|
|
|
|
size_t soft_max_len) |
22214
|
|
|
|
|
|
|
{ |
22215
|
38
|
50
|
|
|
|
|
if (in_end - in_block_begin < soft_max_len + MIN_BLOCK_LENGTH) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
22216
|
38
|
|
|
|
|
|
return in_end; |
22217
|
0
|
|
|
|
|
|
return in_block_begin + soft_max_len; |
22218
|
|
|
|
|
|
|
} |
22219
|
|
|
|
|
|
|
|
22220
|
|
|
|
|
|
|
|
22221
|
|
|
|
|
|
|
static size_t |
22222
|
0
|
|
|
|
|
|
deflate_compress_none(const u8 *in, size_t in_nbytes, |
22223
|
|
|
|
|
|
|
u8 *out, size_t out_nbytes_avail) |
22224
|
|
|
|
|
|
|
{ |
22225
|
0
|
|
|
|
|
|
const u8 *in_next = in; |
22226
|
0
|
|
|
|
|
|
const u8 * const in_end = in + in_nbytes; |
22227
|
0
|
|
|
|
|
|
u8 *out_next = out; |
22228
|
0
|
|
|
|
|
|
u8 * const out_end = out + out_nbytes_avail; |
22229
|
|
|
|
|
|
|
|
22230
|
|
|
|
|
|
|
|
22231
|
0
|
0
|
|
|
|
|
if (unlikely(in_nbytes == 0)) { |
22232
|
0
|
0
|
|
|
|
|
if (out_nbytes_avail < 5) |
22233
|
0
|
|
|
|
|
|
return 0; |
22234
|
|
|
|
|
|
|
|
22235
|
0
|
|
|
|
|
|
*out_next++ = 1 | (DEFLATE_BLOCKTYPE_UNCOMPRESSED << 1); |
22236
|
|
|
|
|
|
|
|
22237
|
|
|
|
|
|
|
put_unaligned_le32(0xFFFF0000, out_next); |
22238
|
0
|
|
|
|
|
|
return 5; |
22239
|
|
|
|
|
|
|
} |
22240
|
|
|
|
|
|
|
|
22241
|
|
|
|
|
|
|
do { |
22242
|
0
|
|
|
|
|
|
u8 bfinal = 0; |
22243
|
0
|
|
|
|
|
|
size_t len = UINT16_MAX; |
22244
|
|
|
|
|
|
|
|
22245
|
0
|
0
|
|
|
|
|
if (in_end - in_next <= UINT16_MAX) { |
22246
|
0
|
|
|
|
|
|
bfinal = 1; |
22247
|
0
|
|
|
|
|
|
len = in_end - in_next; |
22248
|
|
|
|
|
|
|
} |
22249
|
0
|
0
|
|
|
|
|
if (out_end - out_next < 5 + len) |
22250
|
0
|
|
|
|
|
|
return 0; |
22251
|
|
|
|
|
|
|
|
22252
|
0
|
|
|
|
|
|
*out_next++ = bfinal | (DEFLATE_BLOCKTYPE_UNCOMPRESSED << 1); |
22253
|
|
|
|
|
|
|
|
22254
|
|
|
|
|
|
|
|
22255
|
0
|
|
|
|
|
|
put_unaligned_le16(len, out_next); |
22256
|
0
|
|
|
|
|
|
out_next += 2; |
22257
|
0
|
|
|
|
|
|
put_unaligned_le16(~len, out_next); |
22258
|
0
|
|
|
|
|
|
out_next += 2; |
22259
|
0
|
|
|
|
|
|
memcpy(out_next, in_next, len); |
22260
|
0
|
|
|
|
|
|
out_next += len; |
22261
|
0
|
|
|
|
|
|
in_next += len; |
22262
|
0
|
0
|
|
|
|
|
} while (in_next != in_end); |
22263
|
|
|
|
|
|
|
|
22264
|
0
|
|
|
|
|
|
return out_next - out; |
22265
|
|
|
|
|
|
|
} |
22266
|
|
|
|
|
|
|
|
22267
|
|
|
|
|
|
|
|
22268
|
|
|
|
|
|
|
static void |
22269
|
3
|
|
|
|
|
|
deflate_compress_fastest(struct libdeflate_compressor * restrict c, |
22270
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
22271
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
22272
|
|
|
|
|
|
|
{ |
22273
|
3
|
|
|
|
|
|
const u8 *in_next = in; |
22274
|
3
|
|
|
|
|
|
const u8 *in_end = in_next + in_nbytes; |
22275
|
3
|
|
|
|
|
|
const u8 *in_cur_base = in_next; |
22276
|
3
|
|
|
|
|
|
unsigned max_len = DEFLATE_MAX_MATCH_LEN; |
22277
|
3
|
|
|
|
|
|
unsigned nice_len = MIN(c->nice_match_length, max_len); |
22278
|
3
|
|
|
|
|
|
u32 next_hash = 0; |
22279
|
|
|
|
|
|
|
|
22280
|
3
|
|
|
|
|
|
ht_matchfinder_init(&c->p.f.ht_mf); |
22281
|
|
|
|
|
|
|
|
22282
|
|
|
|
|
|
|
do { |
22283
|
|
|
|
|
|
|
|
22284
|
|
|
|
|
|
|
|
22285
|
3
|
|
|
|
|
|
const u8 * const in_block_begin = in_next; |
22286
|
3
|
|
|
|
|
|
const u8 * const in_max_block_end = choose_max_block_end( |
22287
|
|
|
|
|
|
|
in_next, in_end, FAST_SOFT_MAX_BLOCK_LENGTH); |
22288
|
3
|
|
|
|
|
|
struct deflate_sequence *seq = c->p.f.sequences; |
22289
|
|
|
|
|
|
|
|
22290
|
3
|
|
|
|
|
|
deflate_begin_sequences(c, seq); |
22291
|
|
|
|
|
|
|
|
22292
|
|
|
|
|
|
|
do { |
22293
|
|
|
|
|
|
|
u32 length; |
22294
|
|
|
|
|
|
|
u32 offset; |
22295
|
75
|
|
|
|
|
|
size_t remaining = in_end - in_next; |
22296
|
|
|
|
|
|
|
|
22297
|
75
|
100
|
|
|
|
|
if (unlikely(remaining < DEFLATE_MAX_MATCH_LEN)) { |
22298
|
3
|
|
|
|
|
|
max_len = remaining; |
22299
|
3
|
50
|
|
|
|
|
if (max_len < HT_MATCHFINDER_REQUIRED_NBYTES) { |
22300
|
|
|
|
|
|
|
do { |
22301
|
0
|
|
|
|
|
|
deflate_choose_literal(c, |
22302
|
0
|
|
|
|
|
|
*in_next++, false, seq); |
22303
|
0
|
0
|
|
|
|
|
} while (--max_len); |
22304
|
0
|
|
|
|
|
|
break; |
22305
|
|
|
|
|
|
|
} |
22306
|
3
|
|
|
|
|
|
nice_len = MIN(nice_len, max_len); |
22307
|
|
|
|
|
|
|
} |
22308
|
150
|
|
|
|
|
|
length = ht_matchfinder_longest_match(&c->p.f.ht_mf, |
22309
|
|
|
|
|
|
|
&in_cur_base, |
22310
|
|
|
|
|
|
|
in_next, |
22311
|
|
|
|
|
|
|
max_len, |
22312
|
|
|
|
|
|
|
nice_len, |
22313
|
|
|
|
|
|
|
&next_hash, |
22314
|
|
|
|
|
|
|
&offset); |
22315
|
75
|
100
|
|
|
|
|
if (length) { |
22316
|
|
|
|
|
|
|
|
22317
|
21
|
|
|
|
|
|
deflate_choose_match(c, length, offset, false, |
22318
|
|
|
|
|
|
|
&seq); |
22319
|
21
|
|
|
|
|
|
ht_matchfinder_skip_bytes(&c->p.f.ht_mf, |
22320
|
|
|
|
|
|
|
&in_cur_base, |
22321
|
|
|
|
|
|
|
in_next + 1, |
22322
|
|
|
|
|
|
|
in_end, |
22323
|
|
|
|
|
|
|
length - 1, |
22324
|
|
|
|
|
|
|
&next_hash); |
22325
|
21
|
|
|
|
|
|
in_next += length; |
22326
|
|
|
|
|
|
|
} else { |
22327
|
|
|
|
|
|
|
|
22328
|
54
|
|
|
|
|
|
deflate_choose_literal(c, *in_next++, false, |
22329
|
|
|
|
|
|
|
seq); |
22330
|
|
|
|
|
|
|
} |
22331
|
|
|
|
|
|
|
|
22332
|
|
|
|
|
|
|
|
22333
|
72
|
50
|
|
|
|
|
} while (in_next < in_max_block_end && |
22334
|
75
|
100
|
|
|
|
|
seq < &c->p.f.sequences[FAST_SEQ_STORE_LENGTH]); |
22335
|
|
|
|
|
|
|
|
22336
|
3
|
|
|
|
|
|
deflate_finish_block(c, os, in_block_begin, |
22337
|
3
|
|
|
|
|
|
in_next - in_block_begin, |
22338
|
3
|
|
|
|
|
|
c->p.f.sequences, in_next == in_end); |
22339
|
3
|
50
|
|
|
|
|
} while (in_next != in_end && !os->overflow); |
|
|
0
|
|
|
|
|
|
22340
|
3
|
|
|
|
|
|
} |
22341
|
|
|
|
|
|
|
|
22342
|
|
|
|
|
|
|
|
22343
|
|
|
|
|
|
|
static void |
22344
|
9
|
|
|
|
|
|
deflate_compress_greedy(struct libdeflate_compressor * restrict c, |
22345
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
22346
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
22347
|
|
|
|
|
|
|
{ |
22348
|
9
|
|
|
|
|
|
const u8 *in_next = in; |
22349
|
9
|
|
|
|
|
|
const u8 *in_end = in_next + in_nbytes; |
22350
|
9
|
|
|
|
|
|
const u8 *in_cur_base = in_next; |
22351
|
9
|
|
|
|
|
|
unsigned max_len = DEFLATE_MAX_MATCH_LEN; |
22352
|
9
|
|
|
|
|
|
unsigned nice_len = MIN(c->nice_match_length, max_len); |
22353
|
9
|
|
|
|
|
|
u32 next_hashes[2] = {0, 0}; |
22354
|
|
|
|
|
|
|
|
22355
|
9
|
|
|
|
|
|
hc_matchfinder_init(&c->p.g.hc_mf); |
22356
|
|
|
|
|
|
|
|
22357
|
|
|
|
|
|
|
do { |
22358
|
|
|
|
|
|
|
|
22359
|
|
|
|
|
|
|
|
22360
|
9
|
|
|
|
|
|
const u8 * const in_block_begin = in_next; |
22361
|
9
|
|
|
|
|
|
const u8 * const in_max_block_end = choose_max_block_end( |
22362
|
|
|
|
|
|
|
in_next, in_end, SOFT_MAX_BLOCK_LENGTH); |
22363
|
9
|
|
|
|
|
|
struct deflate_sequence *seq = c->p.g.sequences; |
22364
|
|
|
|
|
|
|
unsigned min_len; |
22365
|
|
|
|
|
|
|
|
22366
|
9
|
|
|
|
|
|
init_block_split_stats(&c->split_stats); |
22367
|
9
|
|
|
|
|
|
deflate_begin_sequences(c, seq); |
22368
|
9
|
|
|
|
|
|
min_len = calculate_min_match_len(in_next, |
22369
|
9
|
|
|
|
|
|
in_max_block_end - in_next, |
22370
|
|
|
|
|
|
|
c->max_search_depth); |
22371
|
|
|
|
|
|
|
do { |
22372
|
|
|
|
|
|
|
u32 length; |
22373
|
|
|
|
|
|
|
u32 offset; |
22374
|
|
|
|
|
|
|
|
22375
|
225
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, |
22376
|
225
|
|
|
|
|
|
in_end - in_next); |
22377
|
450
|
|
|
|
|
|
length = hc_matchfinder_longest_match( |
22378
|
|
|
|
|
|
|
&c->p.g.hc_mf, |
22379
|
|
|
|
|
|
|
&in_cur_base, |
22380
|
|
|
|
|
|
|
in_next, |
22381
|
|
|
|
|
|
|
min_len - 1, |
22382
|
|
|
|
|
|
|
max_len, |
22383
|
|
|
|
|
|
|
nice_len, |
22384
|
|
|
|
|
|
|
c->max_search_depth, |
22385
|
|
|
|
|
|
|
next_hashes, |
22386
|
|
|
|
|
|
|
&offset); |
22387
|
|
|
|
|
|
|
|
22388
|
225
|
100
|
|
|
|
|
if (length >= min_len && |
|
|
50
|
|
|
|
|
|
22389
|
0
|
0
|
|
|
|
|
(length > DEFLATE_MIN_MATCH_LEN || |
22390
|
0
|
|
|
|
|
|
offset <= 4096)) { |
22391
|
|
|
|
|
|
|
|
22392
|
63
|
|
|
|
|
|
deflate_choose_match(c, length, offset, true, |
22393
|
|
|
|
|
|
|
&seq); |
22394
|
63
|
|
|
|
|
|
hc_matchfinder_skip_bytes(&c->p.g.hc_mf, |
22395
|
|
|
|
|
|
|
&in_cur_base, |
22396
|
|
|
|
|
|
|
in_next + 1, |
22397
|
|
|
|
|
|
|
in_end, |
22398
|
|
|
|
|
|
|
length - 1, |
22399
|
|
|
|
|
|
|
next_hashes); |
22400
|
63
|
|
|
|
|
|
in_next += length; |
22401
|
|
|
|
|
|
|
} else { |
22402
|
|
|
|
|
|
|
|
22403
|
162
|
|
|
|
|
|
deflate_choose_literal(c, *in_next++, true, |
22404
|
|
|
|
|
|
|
seq); |
22405
|
|
|
|
|
|
|
} |
22406
|
|
|
|
|
|
|
|
22407
|
|
|
|
|
|
|
|
22408
|
216
|
50
|
|
|
|
|
} while (in_next < in_max_block_end && |
22409
|
216
|
50
|
|
|
|
|
seq < &c->p.g.sequences[SEQ_STORE_LENGTH] && |
22410
|
432
|
|
|
|
|
|
!should_end_block(&c->split_stats, |
22411
|
225
|
100
|
|
|
|
|
in_block_begin, in_next, in_end)); |
22412
|
|
|
|
|
|
|
|
22413
|
9
|
|
|
|
|
|
deflate_finish_block(c, os, in_block_begin, |
22414
|
9
|
|
|
|
|
|
in_next - in_block_begin, |
22415
|
9
|
|
|
|
|
|
c->p.g.sequences, in_next == in_end); |
22416
|
9
|
50
|
|
|
|
|
} while (in_next != in_end && !os->overflow); |
|
|
0
|
|
|
|
|
|
22417
|
9
|
|
|
|
|
|
} |
22418
|
|
|
|
|
|
|
|
22419
|
|
|
|
|
|
|
static forceinline void |
22420
|
|
|
|
|
|
|
deflate_compress_lazy_generic(struct libdeflate_compressor * restrict c, |
22421
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
22422
|
|
|
|
|
|
|
struct deflate_output_bitstream *os, bool lazy2) |
22423
|
|
|
|
|
|
|
{ |
22424
|
16
|
|
|
|
|
|
const u8 *in_next = in; |
22425
|
16
|
|
|
|
|
|
const u8 *in_end = in_next + in_nbytes; |
22426
|
16
|
|
|
|
|
|
const u8 *in_cur_base = in_next; |
22427
|
16
|
|
|
|
|
|
unsigned max_len = DEFLATE_MAX_MATCH_LEN; |
22428
|
16
|
|
|
|
|
|
unsigned nice_len = MIN(c->nice_match_length, max_len); |
22429
|
16
|
|
|
|
|
|
u32 next_hashes[2] = {0, 0}; |
22430
|
|
|
|
|
|
|
|
22431
|
16
|
|
|
|
|
|
hc_matchfinder_init(&c->p.g.hc_mf); |
22432
|
|
|
|
|
|
|
|
22433
|
|
|
|
|
|
|
do { |
22434
|
|
|
|
|
|
|
|
22435
|
|
|
|
|
|
|
|
22436
|
17
|
|
|
|
|
|
const u8 * const in_block_begin = in_next; |
22437
|
17
|
|
|
|
|
|
const u8 * const in_max_block_end = choose_max_block_end( |
22438
|
|
|
|
|
|
|
in_next, in_end, SOFT_MAX_BLOCK_LENGTH); |
22439
|
17
|
|
|
|
|
|
const u8 *next_recalc_min_len = |
22440
|
17
|
|
|
|
|
|
in_next + MIN(in_end - in_next, 10000); |
22441
|
17
|
|
|
|
|
|
struct deflate_sequence *seq = c->p.g.sequences; |
22442
|
|
|
|
|
|
|
unsigned min_len; |
22443
|
|
|
|
|
|
|
|
22444
|
17
|
|
|
|
|
|
init_block_split_stats(&c->split_stats); |
22445
|
17
|
|
|
|
|
|
deflate_begin_sequences(c, seq); |
22446
|
17
|
|
|
|
|
|
min_len = calculate_min_match_len(in_next, |
22447
|
17
|
|
|
|
|
|
in_max_block_end - in_next, |
22448
|
|
|
|
|
|
|
c->max_search_depth); |
22449
|
|
|
|
|
|
|
do { |
22450
|
|
|
|
|
|
|
unsigned cur_len; |
22451
|
|
|
|
|
|
|
unsigned cur_offset; |
22452
|
|
|
|
|
|
|
unsigned next_len; |
22453
|
|
|
|
|
|
|
unsigned next_offset; |
22454
|
|
|
|
|
|
|
|
22455
|
|
|
|
|
|
|
|
22456
|
4829
|
50
|
|
|
|
|
if (in_next >= next_recalc_min_len) { |
|
|
100
|
|
|
|
|
|
22457
|
2
|
|
|
|
|
|
min_len = recalculate_min_match_len( |
22458
|
2
|
|
|
|
|
|
&c->freqs, |
22459
|
|
|
|
|
|
|
c->max_search_depth); |
22460
|
2
|
|
|
|
|
|
next_recalc_min_len += |
22461
|
2
|
|
|
|
|
|
MIN(in_end - next_recalc_min_len, |
22462
|
|
|
|
|
|
|
in_next - in_block_begin); |
22463
|
|
|
|
|
|
|
} |
22464
|
|
|
|
|
|
|
|
22465
|
|
|
|
|
|
|
|
22466
|
4829
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, |
22467
|
4829
|
|
|
|
|
|
in_end - in_next); |
22468
|
9658
|
|
|
|
|
|
cur_len = hc_matchfinder_longest_match( |
22469
|
|
|
|
|
|
|
&c->p.g.hc_mf, |
22470
|
|
|
|
|
|
|
&in_cur_base, |
22471
|
|
|
|
|
|
|
in_next, |
22472
|
|
|
|
|
|
|
min_len - 1, |
22473
|
|
|
|
|
|
|
max_len, |
22474
|
|
|
|
|
|
|
nice_len, |
22475
|
|
|
|
|
|
|
c->max_search_depth, |
22476
|
|
|
|
|
|
|
next_hashes, |
22477
|
|
|
|
|
|
|
&cur_offset); |
22478
|
4829
|
100
|
|
|
|
|
if (cur_len < min_len || |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
22479
|
0
|
0
|
|
|
|
|
(cur_len == DEFLATE_MIN_MATCH_LEN && |
|
|
0
|
|
|
|
|
|
22480
|
0
|
|
|
|
|
|
cur_offset > 8192)) { |
22481
|
|
|
|
|
|
|
|
22482
|
2822
|
|
|
|
|
|
deflate_choose_literal(c, *in_next++, true, |
22483
|
|
|
|
|
|
|
seq); |
22484
|
2928
|
|
|
|
|
|
continue; |
22485
|
|
|
|
|
|
|
} |
22486
|
2007
|
|
|
|
|
|
in_next++; |
22487
|
|
|
|
|
|
|
|
22488
|
|
|
|
|
|
|
have_cur_match: |
22489
|
|
|
|
|
|
|
|
22490
|
2098
|
50
|
|
|
|
|
if (cur_len >= nice_len) { |
|
|
100
|
|
|
|
|
|
22491
|
106
|
|
|
|
|
|
deflate_choose_match(c, cur_len, cur_offset, |
22492
|
|
|
|
|
|
|
true, &seq); |
22493
|
106
|
|
|
|
|
|
hc_matchfinder_skip_bytes(&c->p.g.hc_mf, |
22494
|
|
|
|
|
|
|
&in_cur_base, |
22495
|
|
|
|
|
|
|
in_next, |
22496
|
|
|
|
|
|
|
in_end, |
22497
|
|
|
|
|
|
|
cur_len - 1, |
22498
|
|
|
|
|
|
|
next_hashes); |
22499
|
106
|
|
|
|
|
|
in_next += cur_len - 1; |
22500
|
106
|
|
|
|
|
|
continue; |
22501
|
|
|
|
|
|
|
} |
22502
|
|
|
|
|
|
|
|
22503
|
|
|
|
|
|
|
|
22504
|
1992
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, |
22505
|
1992
|
|
|
|
|
|
in_end - in_next); |
22506
|
3984
|
|
|
|
|
|
next_len = hc_matchfinder_longest_match( |
22507
|
|
|
|
|
|
|
&c->p.g.hc_mf, |
22508
|
|
|
|
|
|
|
&in_cur_base, |
22509
|
|
|
|
|
|
|
in_next++, |
22510
|
|
|
|
|
|
|
cur_len - 1, |
22511
|
|
|
|
|
|
|
max_len, |
22512
|
|
|
|
|
|
|
nice_len, |
22513
|
1992
|
|
|
|
|
|
c->max_search_depth >> 1, |
22514
|
|
|
|
|
|
|
next_hashes, |
22515
|
|
|
|
|
|
|
&next_offset); |
22516
|
2130
|
0
|
|
|
|
|
if (next_len >= cur_len && |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
22517
|
276
|
|
|
|
|
|
4 * (int)(next_len - cur_len) + |
22518
|
414
|
|
|
|
|
|
((int)bsr32(cur_offset) - |
22519
|
276
|
|
|
|
|
|
(int)bsr32(next_offset)) > 2) { |
22520
|
|
|
|
|
|
|
|
22521
|
91
|
|
|
|
|
|
deflate_choose_literal(c, *(in_next - 2), true, |
22522
|
|
|
|
|
|
|
seq); |
22523
|
91
|
|
|
|
|
|
cur_len = next_len; |
22524
|
91
|
|
|
|
|
|
cur_offset = next_offset; |
22525
|
|
|
|
|
|
|
goto have_cur_match; |
22526
|
|
|
|
|
|
|
} |
22527
|
|
|
|
|
|
|
|
22528
|
1901
|
0
|
|
|
|
|
if (lazy2) { |
|
|
50
|
|
|
|
|
|
22529
|
|
|
|
|
|
|
|
22530
|
0
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, |
22531
|
0
|
|
|
|
|
|
in_end - in_next); |
22532
|
0
|
|
|
|
|
|
next_len = hc_matchfinder_longest_match( |
22533
|
|
|
|
|
|
|
&c->p.g.hc_mf, |
22534
|
|
|
|
|
|
|
&in_cur_base, |
22535
|
|
|
|
|
|
|
in_next++, |
22536
|
|
|
|
|
|
|
cur_len - 1, |
22537
|
|
|
|
|
|
|
max_len, |
22538
|
|
|
|
|
|
|
nice_len, |
22539
|
0
|
|
|
|
|
|
c->max_search_depth >> 2, |
22540
|
|
|
|
|
|
|
next_hashes, |
22541
|
|
|
|
|
|
|
&next_offset); |
22542
|
0
|
0
|
|
|
|
|
if (next_len >= cur_len && |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22543
|
0
|
|
|
|
|
|
4 * (int)(next_len - cur_len) + |
22544
|
0
|
|
|
|
|
|
((int)bsr32(cur_offset) - |
22545
|
0
|
|
|
|
|
|
(int)bsr32(next_offset)) > 6) { |
22546
|
|
|
|
|
|
|
|
22547
|
0
|
|
|
|
|
|
deflate_choose_literal( |
22548
|
0
|
|
|
|
|
|
c, *(in_next - 3), true, seq); |
22549
|
0
|
|
|
|
|
|
deflate_choose_literal( |
22550
|
0
|
|
|
|
|
|
c, *(in_next - 2), true, seq); |
22551
|
0
|
|
|
|
|
|
cur_len = next_len; |
22552
|
0
|
|
|
|
|
|
cur_offset = next_offset; |
22553
|
|
|
|
|
|
|
goto have_cur_match; |
22554
|
|
|
|
|
|
|
} |
22555
|
|
|
|
|
|
|
|
22556
|
0
|
|
|
|
|
|
deflate_choose_match(c, cur_len, cur_offset, |
22557
|
|
|
|
|
|
|
true, &seq); |
22558
|
0
|
0
|
|
|
|
|
if (cur_len > 3) { |
|
|
0
|
|
|
|
|
|
22559
|
0
|
|
|
|
|
|
hc_matchfinder_skip_bytes(&c->p.g.hc_mf, |
22560
|
|
|
|
|
|
|
&in_cur_base, |
22561
|
|
|
|
|
|
|
in_next, |
22562
|
|
|
|
|
|
|
in_end, |
22563
|
|
|
|
|
|
|
cur_len - 3, |
22564
|
|
|
|
|
|
|
next_hashes); |
22565
|
0
|
|
|
|
|
|
in_next += cur_len - 3; |
22566
|
|
|
|
|
|
|
} |
22567
|
|
|
|
|
|
|
} else { |
22568
|
|
|
|
|
|
|
|
22569
|
1901
|
|
|
|
|
|
deflate_choose_match(c, cur_len, cur_offset, |
22570
|
|
|
|
|
|
|
true, &seq); |
22571
|
1901
|
|
|
|
|
|
hc_matchfinder_skip_bytes(&c->p.g.hc_mf, |
22572
|
|
|
|
|
|
|
&in_cur_base, |
22573
|
|
|
|
|
|
|
in_next, |
22574
|
|
|
|
|
|
|
in_end, |
22575
|
|
|
|
|
|
|
cur_len - 2, |
22576
|
|
|
|
|
|
|
next_hashes); |
22577
|
1901
|
|
|
|
|
|
in_next += cur_len - 2; |
22578
|
|
|
|
|
|
|
} |
22579
|
|
|
|
|
|
|
|
22580
|
4813
|
50
|
|
|
|
|
} while (in_next < in_max_block_end && |
|
|
50
|
|
|
|
|
|
22581
|
4813
|
50
|
|
|
|
|
seq < &c->p.g.sequences[SEQ_STORE_LENGTH] && |
|
|
100
|
|
|
|
|
|
22582
|
9626
|
|
|
|
|
|
!should_end_block(&c->split_stats, |
22583
|
4829
|
100
|
|
|
|
|
in_block_begin, in_next, in_end)); |
|
|
100
|
|
|
|
|
|
22584
|
|
|
|
|
|
|
|
22585
|
17
|
|
|
|
|
|
deflate_finish_block(c, os, in_block_begin, |
22586
|
17
|
|
|
|
|
|
in_next - in_block_begin, |
22587
|
17
|
|
|
|
|
|
c->p.g.sequences, in_next == in_end); |
22588
|
17
|
50
|
|
|
|
|
} while (in_next != in_end && !os->overflow); |
|
|
50
|
|
|
|
|
|
22589
|
|
|
|
|
|
|
} |
22590
|
|
|
|
|
|
|
|
22591
|
|
|
|
|
|
|
|
22592
|
|
|
|
|
|
|
static void |
22593
|
10
|
|
|
|
|
|
deflate_compress_lazy(struct libdeflate_compressor * restrict c, |
22594
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
22595
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
22596
|
|
|
|
|
|
|
{ |
22597
|
|
|
|
|
|
|
deflate_compress_lazy_generic(c, in, in_nbytes, os, false); |
22598
|
10
|
|
|
|
|
|
} |
22599
|
|
|
|
|
|
|
|
22600
|
|
|
|
|
|
|
|
22601
|
|
|
|
|
|
|
static void |
22602
|
6
|
|
|
|
|
|
deflate_compress_lazy2(struct libdeflate_compressor * restrict c, |
22603
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
22604
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
22605
|
|
|
|
|
|
|
{ |
22606
|
|
|
|
|
|
|
deflate_compress_lazy_generic(c, in, in_nbytes, os, true); |
22607
|
6
|
|
|
|
|
|
} |
22608
|
|
|
|
|
|
|
|
22609
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
22610
|
|
|
|
|
|
|
|
22611
|
|
|
|
|
|
|
|
22612
|
|
|
|
|
|
|
static void |
22613
|
24
|
|
|
|
|
|
deflate_tally_item_list(struct libdeflate_compressor *c, u32 block_length) |
22614
|
|
|
|
|
|
|
{ |
22615
|
24
|
|
|
|
|
|
struct deflate_optimum_node *cur_node = &c->p.n.optimum_nodes[0]; |
22616
|
24
|
|
|
|
|
|
struct deflate_optimum_node *end_node = |
22617
|
|
|
|
|
|
|
&c->p.n.optimum_nodes[block_length]; |
22618
|
|
|
|
|
|
|
|
22619
|
|
|
|
|
|
|
do { |
22620
|
600
|
|
|
|
|
|
unsigned length = cur_node->item & OPTIMUM_LEN_MASK; |
22621
|
600
|
|
|
|
|
|
unsigned offset = cur_node->item >> OPTIMUM_OFFSET_SHIFT; |
22622
|
|
|
|
|
|
|
|
22623
|
600
|
100
|
|
|
|
|
if (length == 1) { |
22624
|
|
|
|
|
|
|
|
22625
|
432
|
|
|
|
|
|
c->freqs.litlen[offset]++; |
22626
|
|
|
|
|
|
|
} else { |
22627
|
|
|
|
|
|
|
|
22628
|
168
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_FIRST_LEN_SYM + |
22629
|
336
|
|
|
|
|
|
deflate_length_slot[length]]++; |
22630
|
168
|
|
|
|
|
|
c->freqs.offset[c->p.n.offset_slot_full[offset]]++; |
22631
|
|
|
|
|
|
|
} |
22632
|
600
|
|
|
|
|
|
cur_node += length; |
22633
|
600
|
100
|
|
|
|
|
} while (cur_node != end_node); |
22634
|
|
|
|
|
|
|
|
22635
|
|
|
|
|
|
|
|
22636
|
24
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_END_OF_BLOCK]++; |
22637
|
24
|
|
|
|
|
|
} |
22638
|
|
|
|
|
|
|
|
22639
|
|
|
|
|
|
|
static void |
22640
|
9
|
|
|
|
|
|
deflate_choose_all_literals(struct libdeflate_compressor *c, |
22641
|
|
|
|
|
|
|
const u8 *block, u32 block_length) |
22642
|
|
|
|
|
|
|
{ |
22643
|
|
|
|
|
|
|
u32 i; |
22644
|
|
|
|
|
|
|
|
22645
|
9
|
|
|
|
|
|
deflate_reset_symbol_frequencies(c); |
22646
|
15309
|
100
|
|
|
|
|
for (i = 0; i < block_length; i++) |
22647
|
15300
|
|
|
|
|
|
c->freqs.litlen[block[i]]++; |
22648
|
9
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_END_OF_BLOCK]++; |
22649
|
|
|
|
|
|
|
|
22650
|
9
|
|
|
|
|
|
deflate_make_huffman_codes(&c->freqs, &c->codes); |
22651
|
9
|
|
|
|
|
|
} |
22652
|
|
|
|
|
|
|
|
22653
|
|
|
|
|
|
|
|
22654
|
|
|
|
|
|
|
static u32 |
22655
|
27
|
|
|
|
|
|
deflate_compute_true_cost(struct libdeflate_compressor *c) |
22656
|
|
|
|
|
|
|
{ |
22657
|
27
|
|
|
|
|
|
u32 cost = 0; |
22658
|
|
|
|
|
|
|
unsigned sym; |
22659
|
|
|
|
|
|
|
|
22660
|
27
|
|
|
|
|
|
deflate_precompute_huffman_header(c); |
22661
|
|
|
|
|
|
|
|
22662
|
27
|
|
|
|
|
|
memset(&c->codes.lens.litlen[c->o.precode.num_litlen_syms], 0, |
22663
|
27
|
|
|
|
|
|
DEFLATE_NUM_LITLEN_SYMS - c->o.precode.num_litlen_syms); |
22664
|
|
|
|
|
|
|
|
22665
|
27
|
|
|
|
|
|
cost += 5 + 5 + 4 + (3 * c->o.precode.num_explicit_lens); |
22666
|
540
|
100
|
|
|
|
|
for (sym = 0; sym < DEFLATE_NUM_PRECODE_SYMS; sym++) { |
22667
|
1026
|
|
|
|
|
|
cost += c->o.precode.freqs[sym] * |
22668
|
1026
|
|
|
|
|
|
(c->o.precode.lens[sym] + |
22669
|
513
|
|
|
|
|
|
deflate_extra_precode_bits[sym]); |
22670
|
|
|
|
|
|
|
} |
22671
|
|
|
|
|
|
|
|
22672
|
6966
|
100
|
|
|
|
|
for (sym = 0; sym < DEFLATE_FIRST_LEN_SYM; sym++) |
22673
|
6939
|
|
|
|
|
|
cost += c->freqs.litlen[sym] * c->codes.lens.litlen[sym]; |
22674
|
|
|
|
|
|
|
|
22675
|
810
|
100
|
|
|
|
|
for (; sym < DEFLATE_FIRST_LEN_SYM + |
22676
|
783
|
|
|
|
|
|
ARRAY_LEN(deflate_extra_length_bits); sym++) |
22677
|
1566
|
|
|
|
|
|
cost += c->freqs.litlen[sym] * |
22678
|
1566
|
|
|
|
|
|
(c->codes.lens.litlen[sym] + |
22679
|
783
|
|
|
|
|
|
deflate_extra_length_bits[sym - DEFLATE_FIRST_LEN_SYM]); |
22680
|
|
|
|
|
|
|
|
22681
|
837
|
100
|
|
|
|
|
for (sym = 0; sym < ARRAY_LEN(deflate_extra_offset_bits); sym++) |
22682
|
1620
|
|
|
|
|
|
cost += c->freqs.offset[sym] * |
22683
|
1620
|
|
|
|
|
|
(c->codes.lens.offset[sym] + |
22684
|
810
|
|
|
|
|
|
deflate_extra_offset_bits[sym]); |
22685
|
27
|
|
|
|
|
|
return cost; |
22686
|
|
|
|
|
|
|
} |
22687
|
|
|
|
|
|
|
|
22688
|
|
|
|
|
|
|
|
22689
|
|
|
|
|
|
|
static void |
22690
|
15
|
|
|
|
|
|
deflate_set_costs_from_codes(struct libdeflate_compressor *c, |
22691
|
|
|
|
|
|
|
const struct deflate_lens *lens) |
22692
|
|
|
|
|
|
|
{ |
22693
|
|
|
|
|
|
|
unsigned i; |
22694
|
|
|
|
|
|
|
|
22695
|
|
|
|
|
|
|
|
22696
|
3855
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) { |
22697
|
3840
|
100
|
|
|
|
|
u32 bits = (lens->litlen[i] ? |
22698
|
1644
|
|
|
|
|
|
lens->litlen[i] : LITERAL_NOSTAT_BITS); |
22699
|
|
|
|
|
|
|
|
22700
|
3840
|
|
|
|
|
|
c->p.n.costs.literal[i] = bits * BIT_COST; |
22701
|
|
|
|
|
|
|
} |
22702
|
|
|
|
|
|
|
|
22703
|
|
|
|
|
|
|
|
22704
|
3855
|
100
|
|
|
|
|
for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++) { |
22705
|
3840
|
|
|
|
|
|
unsigned length_slot = deflate_length_slot[i]; |
22706
|
3840
|
|
|
|
|
|
unsigned litlen_sym = DEFLATE_FIRST_LEN_SYM + length_slot; |
22707
|
3840
|
100
|
|
|
|
|
u32 bits = (lens->litlen[litlen_sym] ? |
22708
|
1833
|
|
|
|
|
|
lens->litlen[litlen_sym] : LENGTH_NOSTAT_BITS); |
22709
|
|
|
|
|
|
|
|
22710
|
3840
|
|
|
|
|
|
bits += deflate_extra_length_bits[length_slot]; |
22711
|
3840
|
|
|
|
|
|
c->p.n.costs.length[i] = bits * BIT_COST; |
22712
|
|
|
|
|
|
|
} |
22713
|
|
|
|
|
|
|
|
22714
|
|
|
|
|
|
|
|
22715
|
465
|
100
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++) { |
22716
|
450
|
100
|
|
|
|
|
u32 bits = (lens->offset[i] ? |
22717
|
198
|
|
|
|
|
|
lens->offset[i] : OFFSET_NOSTAT_BITS); |
22718
|
|
|
|
|
|
|
|
22719
|
450
|
|
|
|
|
|
bits += deflate_extra_offset_bits[i]; |
22720
|
450
|
|
|
|
|
|
c->p.n.costs.offset_slot[i] = bits * BIT_COST; |
22721
|
|
|
|
|
|
|
} |
22722
|
15
|
|
|
|
|
|
} |
22723
|
|
|
|
|
|
|
|
22724
|
|
|
|
|
|
|
|
22725
|
|
|
|
|
|
|
static const struct { |
22726
|
|
|
|
|
|
|
u8 used_lits_to_lit_cost[257]; |
22727
|
|
|
|
|
|
|
u8 len_sym_cost; |
22728
|
|
|
|
|
|
|
} default_litlen_costs[] = { |
22729
|
|
|
|
|
|
|
{ |
22730
|
|
|
|
|
|
|
.used_lits_to_lit_cost = { |
22731
|
|
|
|
|
|
|
6, 6, 22, 32, 38, 43, 48, 51, |
22732
|
|
|
|
|
|
|
54, 57, 59, 61, 64, 65, 67, 69, |
22733
|
|
|
|
|
|
|
70, 72, 73, 74, 75, 76, 77, 79, |
22734
|
|
|
|
|
|
|
80, 80, 81, 82, 83, 84, 85, 85, |
22735
|
|
|
|
|
|
|
86, 87, 88, 88, 89, 89, 90, 91, |
22736
|
|
|
|
|
|
|
91, 92, 92, 93, 93, 94, 95, 95, |
22737
|
|
|
|
|
|
|
96, 96, 96, 97, 97, 98, 98, 99, |
22738
|
|
|
|
|
|
|
99, 99, 100, 100, 101, 101, 101, 102, |
22739
|
|
|
|
|
|
|
102, 102, 103, 103, 104, 104, 104, 105, |
22740
|
|
|
|
|
|
|
105, 105, 105, 106, 106, 106, 107, 107, |
22741
|
|
|
|
|
|
|
107, 108, 108, 108, 108, 109, 109, 109, |
22742
|
|
|
|
|
|
|
109, 110, 110, 110, 111, 111, 111, 111, |
22743
|
|
|
|
|
|
|
112, 112, 112, 112, 112, 113, 113, 113, |
22744
|
|
|
|
|
|
|
113, 114, 114, 114, 114, 114, 115, 115, |
22745
|
|
|
|
|
|
|
115, 115, 115, 116, 116, 116, 116, 116, |
22746
|
|
|
|
|
|
|
117, 117, 117, 117, 117, 118, 118, 118, |
22747
|
|
|
|
|
|
|
118, 118, 118, 119, 119, 119, 119, 119, |
22748
|
|
|
|
|
|
|
120, 120, 120, 120, 120, 120, 121, 121, |
22749
|
|
|
|
|
|
|
121, 121, 121, 121, 121, 122, 122, 122, |
22750
|
|
|
|
|
|
|
122, 122, 122, 123, 123, 123, 123, 123, |
22751
|
|
|
|
|
|
|
123, 123, 124, 124, 124, 124, 124, 124, |
22752
|
|
|
|
|
|
|
124, 125, 125, 125, 125, 125, 125, 125, |
22753
|
|
|
|
|
|
|
125, 126, 126, 126, 126, 126, 126, 126, |
22754
|
|
|
|
|
|
|
127, 127, 127, 127, 127, 127, 127, 127, |
22755
|
|
|
|
|
|
|
128, 128, 128, 128, 128, 128, 128, 128, |
22756
|
|
|
|
|
|
|
128, 129, 129, 129, 129, 129, 129, 129, |
22757
|
|
|
|
|
|
|
129, 129, 130, 130, 130, 130, 130, 130, |
22758
|
|
|
|
|
|
|
130, 130, 130, 131, 131, 131, 131, 131, |
22759
|
|
|
|
|
|
|
131, 131, 131, 131, 131, 132, 132, 132, |
22760
|
|
|
|
|
|
|
132, 132, 132, 132, 132, 132, 132, 133, |
22761
|
|
|
|
|
|
|
133, 133, 133, 133, 133, 133, 133, 133, |
22762
|
|
|
|
|
|
|
133, 134, 134, 134, 134, 134, 134, 134, |
22763
|
|
|
|
|
|
|
134, |
22764
|
|
|
|
|
|
|
}, |
22765
|
|
|
|
|
|
|
.len_sym_cost = 109, |
22766
|
|
|
|
|
|
|
}, { |
22767
|
|
|
|
|
|
|
.used_lits_to_lit_cost = { |
22768
|
|
|
|
|
|
|
16, 16, 32, 41, 48, 53, 57, 60, |
22769
|
|
|
|
|
|
|
64, 66, 69, 71, 73, 75, 76, 78, |
22770
|
|
|
|
|
|
|
80, 81, 82, 83, 85, 86, 87, 88, |
22771
|
|
|
|
|
|
|
89, 90, 91, 92, 92, 93, 94, 95, |
22772
|
|
|
|
|
|
|
96, 96, 97, 98, 98, 99, 99, 100, |
22773
|
|
|
|
|
|
|
101, 101, 102, 102, 103, 103, 104, 104, |
22774
|
|
|
|
|
|
|
105, 105, 106, 106, 107, 107, 108, 108, |
22775
|
|
|
|
|
|
|
108, 109, 109, 110, 110, 110, 111, 111, |
22776
|
|
|
|
|
|
|
112, 112, 112, 113, 113, 113, 114, 114, |
22777
|
|
|
|
|
|
|
114, 115, 115, 115, 115, 116, 116, 116, |
22778
|
|
|
|
|
|
|
117, 117, 117, 118, 118, 118, 118, 119, |
22779
|
|
|
|
|
|
|
119, 119, 119, 120, 120, 120, 120, 121, |
22780
|
|
|
|
|
|
|
121, 121, 121, 122, 122, 122, 122, 122, |
22781
|
|
|
|
|
|
|
123, 123, 123, 123, 124, 124, 124, 124, |
22782
|
|
|
|
|
|
|
124, 125, 125, 125, 125, 125, 126, 126, |
22783
|
|
|
|
|
|
|
126, 126, 126, 127, 127, 127, 127, 127, |
22784
|
|
|
|
|
|
|
128, 128, 128, 128, 128, 128, 129, 129, |
22785
|
|
|
|
|
|
|
129, 129, 129, 129, 130, 130, 130, 130, |
22786
|
|
|
|
|
|
|
130, 130, 131, 131, 131, 131, 131, 131, |
22787
|
|
|
|
|
|
|
131, 132, 132, 132, 132, 132, 132, 133, |
22788
|
|
|
|
|
|
|
133, 133, 133, 133, 133, 133, 134, 134, |
22789
|
|
|
|
|
|
|
134, 134, 134, 134, 134, 134, 135, 135, |
22790
|
|
|
|
|
|
|
135, 135, 135, 135, 135, 135, 136, 136, |
22791
|
|
|
|
|
|
|
136, 136, 136, 136, 136, 136, 137, 137, |
22792
|
|
|
|
|
|
|
137, 137, 137, 137, 137, 137, 138, 138, |
22793
|
|
|
|
|
|
|
138, 138, 138, 138, 138, 138, 138, 139, |
22794
|
|
|
|
|
|
|
139, 139, 139, 139, 139, 139, 139, 139, |
22795
|
|
|
|
|
|
|
140, 140, 140, 140, 140, 140, 140, 140, |
22796
|
|
|
|
|
|
|
140, 141, 141, 141, 141, 141, 141, 141, |
22797
|
|
|
|
|
|
|
141, 141, 141, 142, 142, 142, 142, 142, |
22798
|
|
|
|
|
|
|
142, 142, 142, 142, 142, 142, 143, 143, |
22799
|
|
|
|
|
|
|
143, 143, 143, 143, 143, 143, 143, 143, |
22800
|
|
|
|
|
|
|
144, |
22801
|
|
|
|
|
|
|
}, |
22802
|
|
|
|
|
|
|
.len_sym_cost = 93, |
22803
|
|
|
|
|
|
|
}, { |
22804
|
|
|
|
|
|
|
.used_lits_to_lit_cost = { |
22805
|
|
|
|
|
|
|
32, 32, 48, 57, 64, 69, 73, 76, |
22806
|
|
|
|
|
|
|
80, 82, 85, 87, 89, 91, 92, 94, |
22807
|
|
|
|
|
|
|
96, 97, 98, 99, 101, 102, 103, 104, |
22808
|
|
|
|
|
|
|
105, 106, 107, 108, 108, 109, 110, 111, |
22809
|
|
|
|
|
|
|
112, 112, 113, 114, 114, 115, 115, 116, |
22810
|
|
|
|
|
|
|
117, 117, 118, 118, 119, 119, 120, 120, |
22811
|
|
|
|
|
|
|
121, 121, 122, 122, 123, 123, 124, 124, |
22812
|
|
|
|
|
|
|
124, 125, 125, 126, 126, 126, 127, 127, |
22813
|
|
|
|
|
|
|
128, 128, 128, 129, 129, 129, 130, 130, |
22814
|
|
|
|
|
|
|
130, 131, 131, 131, 131, 132, 132, 132, |
22815
|
|
|
|
|
|
|
133, 133, 133, 134, 134, 134, 134, 135, |
22816
|
|
|
|
|
|
|
135, 135, 135, 136, 136, 136, 136, 137, |
22817
|
|
|
|
|
|
|
137, 137, 137, 138, 138, 138, 138, 138, |
22818
|
|
|
|
|
|
|
139, 139, 139, 139, 140, 140, 140, 140, |
22819
|
|
|
|
|
|
|
140, 141, 141, 141, 141, 141, 142, 142, |
22820
|
|
|
|
|
|
|
142, 142, 142, 143, 143, 143, 143, 143, |
22821
|
|
|
|
|
|
|
144, 144, 144, 144, 144, 144, 145, 145, |
22822
|
|
|
|
|
|
|
145, 145, 145, 145, 146, 146, 146, 146, |
22823
|
|
|
|
|
|
|
146, 146, 147, 147, 147, 147, 147, 147, |
22824
|
|
|
|
|
|
|
147, 148, 148, 148, 148, 148, 148, 149, |
22825
|
|
|
|
|
|
|
149, 149, 149, 149, 149, 149, 150, 150, |
22826
|
|
|
|
|
|
|
150, 150, 150, 150, 150, 150, 151, 151, |
22827
|
|
|
|
|
|
|
151, 151, 151, 151, 151, 151, 152, 152, |
22828
|
|
|
|
|
|
|
152, 152, 152, 152, 152, 152, 153, 153, |
22829
|
|
|
|
|
|
|
153, 153, 153, 153, 153, 153, 154, 154, |
22830
|
|
|
|
|
|
|
154, 154, 154, 154, 154, 154, 154, 155, |
22831
|
|
|
|
|
|
|
155, 155, 155, 155, 155, 155, 155, 155, |
22832
|
|
|
|
|
|
|
156, 156, 156, 156, 156, 156, 156, 156, |
22833
|
|
|
|
|
|
|
156, 157, 157, 157, 157, 157, 157, 157, |
22834
|
|
|
|
|
|
|
157, 157, 157, 158, 158, 158, 158, 158, |
22835
|
|
|
|
|
|
|
158, 158, 158, 158, 158, 158, 159, 159, |
22836
|
|
|
|
|
|
|
159, 159, 159, 159, 159, 159, 159, 159, |
22837
|
|
|
|
|
|
|
160, |
22838
|
|
|
|
|
|
|
}, |
22839
|
|
|
|
|
|
|
.len_sym_cost = 84, |
22840
|
|
|
|
|
|
|
}, |
22841
|
|
|
|
|
|
|
}; |
22842
|
|
|
|
|
|
|
|
22843
|
|
|
|
|
|
|
|
22844
|
|
|
|
|
|
|
static void |
22845
|
9
|
|
|
|
|
|
deflate_choose_default_litlen_costs(struct libdeflate_compressor *c, |
22846
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
22847
|
|
|
|
|
|
|
u32 *lit_cost, u32 *len_sym_cost) |
22848
|
|
|
|
|
|
|
{ |
22849
|
9
|
|
|
|
|
|
unsigned num_used_literals = 0; |
22850
|
9
|
|
|
|
|
|
u32 literal_freq = block_length; |
22851
|
9
|
|
|
|
|
|
u32 match_freq = 0; |
22852
|
|
|
|
|
|
|
u32 cutoff; |
22853
|
|
|
|
|
|
|
u32 i; |
22854
|
|
|
|
|
|
|
|
22855
|
|
|
|
|
|
|
|
22856
|
9
|
|
|
|
|
|
memset(c->freqs.litlen, 0, |
22857
|
|
|
|
|
|
|
DEFLATE_NUM_LITERALS * sizeof(c->freqs.litlen[0])); |
22858
|
9
|
|
|
|
|
|
cutoff = literal_freq >> 11; |
22859
|
15309
|
100
|
|
|
|
|
for (i = 0; i < block_length; i++) |
22860
|
15300
|
|
|
|
|
|
c->freqs.litlen[block_begin[i]]++; |
22861
|
2313
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) { |
22862
|
2304
|
100
|
|
|
|
|
if (c->freqs.litlen[i] > cutoff) |
22863
|
108
|
|
|
|
|
|
num_used_literals++; |
22864
|
|
|
|
|
|
|
} |
22865
|
9
|
50
|
|
|
|
|
if (num_used_literals == 0) |
22866
|
0
|
|
|
|
|
|
num_used_literals = 1; |
22867
|
|
|
|
|
|
|
|
22868
|
|
|
|
|
|
|
|
22869
|
9
|
|
|
|
|
|
match_freq = 0; |
22870
|
9
|
|
|
|
|
|
i = choose_min_match_len(num_used_literals, c->max_search_depth); |
22871
|
2286
|
100
|
|
|
|
|
for (; i < ARRAY_LEN(c->p.n.match_len_freqs); i++) { |
22872
|
2277
|
|
|
|
|
|
match_freq += c->p.n.match_len_freqs[i]; |
22873
|
2277
|
|
|
|
|
|
literal_freq -= i * c->p.n.match_len_freqs[i]; |
22874
|
|
|
|
|
|
|
} |
22875
|
9
|
50
|
|
|
|
|
if ((s32)literal_freq < 0) |
22876
|
0
|
|
|
|
|
|
literal_freq = 0; |
22877
|
|
|
|
|
|
|
|
22878
|
9
|
50
|
|
|
|
|
if (match_freq > literal_freq) |
22879
|
0
|
|
|
|
|
|
i = 2; |
22880
|
9
|
50
|
|
|
|
|
else if (match_freq * 4 > literal_freq) |
22881
|
9
|
|
|
|
|
|
i = 1; |
22882
|
|
|
|
|
|
|
else |
22883
|
0
|
|
|
|
|
|
i = 0; |
22884
|
|
|
|
|
|
|
|
22885
|
|
|
|
|
|
|
STATIC_ASSERT(BIT_COST == 16); |
22886
|
9
|
|
|
|
|
|
*lit_cost = default_litlen_costs[i].used_lits_to_lit_cost[ |
22887
|
|
|
|
|
|
|
num_used_literals]; |
22888
|
9
|
|
|
|
|
|
*len_sym_cost = default_litlen_costs[i].len_sym_cost; |
22889
|
9
|
|
|
|
|
|
} |
22890
|
|
|
|
|
|
|
|
22891
|
|
|
|
|
|
|
static forceinline u32 |
22892
|
|
|
|
|
|
|
deflate_default_length_cost(unsigned len, u32 len_sym_cost) |
22893
|
|
|
|
|
|
|
{ |
22894
|
2304
|
|
|
|
|
|
unsigned slot = deflate_length_slot[len]; |
22895
|
2304
|
|
|
|
|
|
u32 num_extra_bits = deflate_extra_length_bits[slot]; |
22896
|
|
|
|
|
|
|
|
22897
|
2304
|
|
|
|
|
|
return len_sym_cost + (num_extra_bits * BIT_COST); |
22898
|
|
|
|
|
|
|
} |
22899
|
|
|
|
|
|
|
|
22900
|
|
|
|
|
|
|
static forceinline u32 |
22901
|
|
|
|
|
|
|
deflate_default_offset_slot_cost(unsigned slot) |
22902
|
|
|
|
|
|
|
{ |
22903
|
270
|
|
|
|
|
|
u32 num_extra_bits = deflate_extra_offset_bits[slot]; |
22904
|
|
|
|
|
|
|
|
22905
|
270
|
|
|
|
|
|
u32 offset_sym_cost = 4*BIT_COST + (907*BIT_COST)/1000; |
22906
|
|
|
|
|
|
|
|
22907
|
270
|
|
|
|
|
|
return offset_sym_cost + (num_extra_bits * BIT_COST); |
22908
|
|
|
|
|
|
|
} |
22909
|
|
|
|
|
|
|
|
22910
|
|
|
|
|
|
|
|
22911
|
|
|
|
|
|
|
static void |
22912
|
9
|
|
|
|
|
|
deflate_set_default_costs(struct libdeflate_compressor *c, |
22913
|
|
|
|
|
|
|
u32 lit_cost, u32 len_sym_cost) |
22914
|
|
|
|
|
|
|
{ |
22915
|
|
|
|
|
|
|
unsigned i; |
22916
|
|
|
|
|
|
|
|
22917
|
|
|
|
|
|
|
|
22918
|
2313
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) |
22919
|
2304
|
|
|
|
|
|
c->p.n.costs.literal[i] = lit_cost; |
22920
|
|
|
|
|
|
|
|
22921
|
|
|
|
|
|
|
|
22922
|
2313
|
100
|
|
|
|
|
for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++) |
22923
|
2304
|
|
|
|
|
|
c->p.n.costs.length[i] = |
22924
|
2304
|
|
|
|
|
|
deflate_default_length_cost(i, len_sym_cost); |
22925
|
|
|
|
|
|
|
|
22926
|
|
|
|
|
|
|
|
22927
|
279
|
100
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++) |
22928
|
270
|
|
|
|
|
|
c->p.n.costs.offset_slot[i] = |
22929
|
270
|
|
|
|
|
|
deflate_default_offset_slot_cost(i); |
22930
|
9
|
|
|
|
|
|
} |
22931
|
|
|
|
|
|
|
|
22932
|
|
|
|
|
|
|
static forceinline void |
22933
|
|
|
|
|
|
|
deflate_adjust_cost(u32 *cost_p, u32 default_cost, int change_amount) |
22934
|
|
|
|
|
|
|
{ |
22935
|
0
|
0
|
|
|
|
|
if (change_amount == 0) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22936
|
|
|
|
|
|
|
|
22937
|
0
|
|
|
|
|
|
*cost_p = (default_cost + 3 * *cost_p) / 4; |
22938
|
0
|
0
|
|
|
|
|
else if (change_amount == 1) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22939
|
0
|
|
|
|
|
|
*cost_p = (default_cost + *cost_p) / 2; |
22940
|
0
|
0
|
|
|
|
|
else if (change_amount == 2) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22941
|
0
|
|
|
|
|
|
*cost_p = (5 * default_cost + 3 * *cost_p) / 8; |
22942
|
|
|
|
|
|
|
else |
22943
|
|
|
|
|
|
|
|
22944
|
0
|
|
|
|
|
|
*cost_p = (3 * default_cost + *cost_p) / 4; |
22945
|
|
|
|
|
|
|
} |
22946
|
|
|
|
|
|
|
|
22947
|
|
|
|
|
|
|
static forceinline void |
22948
|
|
|
|
|
|
|
deflate_adjust_costs_impl(struct libdeflate_compressor *c, |
22949
|
|
|
|
|
|
|
u32 lit_cost, u32 len_sym_cost, int change_amount) |
22950
|
|
|
|
|
|
|
{ |
22951
|
|
|
|
|
|
|
unsigned i; |
22952
|
|
|
|
|
|
|
|
22953
|
|
|
|
|
|
|
|
22954
|
0
|
0
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22955
|
0
|
|
|
|
|
|
deflate_adjust_cost(&c->p.n.costs.literal[i], lit_cost, |
22956
|
|
|
|
|
|
|
change_amount); |
22957
|
|
|
|
|
|
|
|
22958
|
|
|
|
|
|
|
|
22959
|
0
|
0
|
|
|
|
|
for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22960
|
0
|
|
|
|
|
|
deflate_adjust_cost(&c->p.n.costs.length[i], |
22961
|
|
|
|
|
|
|
deflate_default_length_cost(i, |
22962
|
|
|
|
|
|
|
len_sym_cost), |
22963
|
|
|
|
|
|
|
change_amount); |
22964
|
|
|
|
|
|
|
|
22965
|
|
|
|
|
|
|
|
22966
|
0
|
0
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22967
|
0
|
|
|
|
|
|
deflate_adjust_cost(&c->p.n.costs.offset_slot[i], |
22968
|
|
|
|
|
|
|
deflate_default_offset_slot_cost(i), |
22969
|
|
|
|
|
|
|
change_amount); |
22970
|
|
|
|
|
|
|
} |
22971
|
|
|
|
|
|
|
|
22972
|
|
|
|
|
|
|
|
22973
|
|
|
|
|
|
|
static void |
22974
|
0
|
|
|
|
|
|
deflate_adjust_costs(struct libdeflate_compressor *c, |
22975
|
|
|
|
|
|
|
u32 lit_cost, u32 len_sym_cost) |
22976
|
|
|
|
|
|
|
{ |
22977
|
0
|
|
|
|
|
|
u64 total_delta = 0; |
22978
|
|
|
|
|
|
|
u64 cutoff; |
22979
|
|
|
|
|
|
|
int i; |
22980
|
|
|
|
|
|
|
|
22981
|
|
|
|
|
|
|
|
22982
|
0
|
0
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) { |
22983
|
0
|
|
|
|
|
|
u64 prev = (u64)c->p.n.prev_observations[i] * |
22984
|
0
|
|
|
|
|
|
c->split_stats.num_observations; |
22985
|
0
|
|
|
|
|
|
u64 cur = (u64)c->split_stats.observations[i] * |
22986
|
0
|
|
|
|
|
|
c->p.n.prev_num_observations; |
22987
|
|
|
|
|
|
|
|
22988
|
0
|
0
|
|
|
|
|
total_delta += prev > cur ? prev - cur : cur - prev; |
22989
|
|
|
|
|
|
|
} |
22990
|
0
|
|
|
|
|
|
cutoff = ((u64)c->p.n.prev_num_observations * |
22991
|
0
|
|
|
|
|
|
c->split_stats.num_observations * 200) / 512; |
22992
|
|
|
|
|
|
|
|
22993
|
0
|
0
|
|
|
|
|
if (total_delta > 3 * cutoff) |
22994
|
|
|
|
|
|
|
|
22995
|
0
|
|
|
|
|
|
deflate_set_default_costs(c, lit_cost, len_sym_cost); |
22996
|
0
|
0
|
|
|
|
|
else if (4 * total_delta > 9 * cutoff) |
22997
|
|
|
|
|
|
|
deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 3); |
22998
|
0
|
0
|
|
|
|
|
else if (2 * total_delta > 3 * cutoff) |
22999
|
|
|
|
|
|
|
deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 2); |
23000
|
0
|
0
|
|
|
|
|
else if (2 * total_delta > cutoff) |
23001
|
|
|
|
|
|
|
deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 1); |
23002
|
|
|
|
|
|
|
else |
23003
|
|
|
|
|
|
|
deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 0); |
23004
|
0
|
|
|
|
|
|
} |
23005
|
|
|
|
|
|
|
|
23006
|
|
|
|
|
|
|
static void |
23007
|
9
|
|
|
|
|
|
deflate_set_initial_costs(struct libdeflate_compressor *c, |
23008
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
23009
|
|
|
|
|
|
|
bool is_first_block) |
23010
|
|
|
|
|
|
|
{ |
23011
|
|
|
|
|
|
|
u32 lit_cost, len_sym_cost; |
23012
|
|
|
|
|
|
|
|
23013
|
9
|
|
|
|
|
|
deflate_choose_default_litlen_costs(c, block_begin, block_length, |
23014
|
|
|
|
|
|
|
&lit_cost, &len_sym_cost); |
23015
|
9
|
50
|
|
|
|
|
if (is_first_block) |
23016
|
9
|
|
|
|
|
|
deflate_set_default_costs(c, lit_cost, len_sym_cost); |
23017
|
|
|
|
|
|
|
else |
23018
|
0
|
|
|
|
|
|
deflate_adjust_costs(c, lit_cost, len_sym_cost); |
23019
|
9
|
|
|
|
|
|
} |
23020
|
|
|
|
|
|
|
|
23021
|
|
|
|
|
|
|
|
23022
|
|
|
|
|
|
|
static void |
23023
|
24
|
|
|
|
|
|
deflate_find_min_cost_path(struct libdeflate_compressor *c, |
23024
|
|
|
|
|
|
|
const u32 block_length, |
23025
|
|
|
|
|
|
|
const struct lz_match *cache_ptr) |
23026
|
|
|
|
|
|
|
{ |
23027
|
24
|
|
|
|
|
|
struct deflate_optimum_node *end_node = |
23028
|
|
|
|
|
|
|
&c->p.n.optimum_nodes[block_length]; |
23029
|
24
|
|
|
|
|
|
struct deflate_optimum_node *cur_node = end_node; |
23030
|
|
|
|
|
|
|
|
23031
|
24
|
|
|
|
|
|
cur_node->cost_to_end = 0; |
23032
|
|
|
|
|
|
|
do { |
23033
|
|
|
|
|
|
|
unsigned num_matches; |
23034
|
|
|
|
|
|
|
unsigned literal; |
23035
|
|
|
|
|
|
|
u32 best_cost_to_end; |
23036
|
|
|
|
|
|
|
|
23037
|
40800
|
|
|
|
|
|
cur_node--; |
23038
|
40800
|
|
|
|
|
|
cache_ptr--; |
23039
|
|
|
|
|
|
|
|
23040
|
40800
|
|
|
|
|
|
num_matches = cache_ptr->length; |
23041
|
40800
|
|
|
|
|
|
literal = cache_ptr->offset; |
23042
|
|
|
|
|
|
|
|
23043
|
|
|
|
|
|
|
|
23044
|
81600
|
|
|
|
|
|
best_cost_to_end = c->p.n.costs.literal[literal] + |
23045
|
40800
|
|
|
|
|
|
(cur_node + 1)->cost_to_end; |
23046
|
40800
|
|
|
|
|
|
cur_node->item = ((u32)literal << OPTIMUM_OFFSET_SHIFT) | 1; |
23047
|
|
|
|
|
|
|
|
23048
|
|
|
|
|
|
|
|
23049
|
40800
|
100
|
|
|
|
|
if (num_matches) { |
23050
|
|
|
|
|
|
|
const struct lz_match *match; |
23051
|
|
|
|
|
|
|
unsigned len; |
23052
|
|
|
|
|
|
|
unsigned offset; |
23053
|
|
|
|
|
|
|
unsigned offset_slot; |
23054
|
|
|
|
|
|
|
u32 offset_cost; |
23055
|
|
|
|
|
|
|
u32 cost_to_end; |
23056
|
|
|
|
|
|
|
|
23057
|
|
|
|
|
|
|
|
23058
|
168
|
|
|
|
|
|
match = cache_ptr - num_matches; |
23059
|
168
|
|
|
|
|
|
len = DEFLATE_MIN_MATCH_LEN; |
23060
|
|
|
|
|
|
|
do { |
23061
|
336
|
|
|
|
|
|
offset = match->offset; |
23062
|
336
|
|
|
|
|
|
offset_slot = c->p.n.offset_slot_full[offset]; |
23063
|
336
|
|
|
|
|
|
offset_cost = |
23064
|
|
|
|
|
|
|
c->p.n.costs.offset_slot[offset_slot]; |
23065
|
|
|
|
|
|
|
do { |
23066
|
80064
|
|
|
|
|
|
cost_to_end = offset_cost + |
23067
|
40032
|
|
|
|
|
|
c->p.n.costs.length[len] + |
23068
|
40032
|
|
|
|
|
|
(cur_node + len)->cost_to_end; |
23069
|
40032
|
100
|
|
|
|
|
if (cost_to_end < best_cost_to_end) { |
23070
|
39753
|
|
|
|
|
|
best_cost_to_end = cost_to_end; |
23071
|
39753
|
|
|
|
|
|
cur_node->item = len | |
23072
|
39753
|
|
|
|
|
|
((u32)offset << |
23073
|
|
|
|
|
|
|
OPTIMUM_OFFSET_SHIFT); |
23074
|
|
|
|
|
|
|
} |
23075
|
40032
|
100
|
|
|
|
|
} while (++len <= match->length); |
23076
|
336
|
100
|
|
|
|
|
} while (++match != cache_ptr); |
23077
|
168
|
|
|
|
|
|
cache_ptr -= num_matches; |
23078
|
|
|
|
|
|
|
} |
23079
|
40800
|
|
|
|
|
|
cur_node->cost_to_end = best_cost_to_end; |
23080
|
40800
|
100
|
|
|
|
|
} while (cur_node != &c->p.n.optimum_nodes[0]); |
23081
|
|
|
|
|
|
|
|
23082
|
24
|
|
|
|
|
|
deflate_reset_symbol_frequencies(c); |
23083
|
24
|
|
|
|
|
|
deflate_tally_item_list(c, block_length); |
23084
|
24
|
|
|
|
|
|
deflate_make_huffman_codes(&c->freqs, &c->codes); |
23085
|
24
|
|
|
|
|
|
} |
23086
|
|
|
|
|
|
|
|
23087
|
|
|
|
|
|
|
|
23088
|
|
|
|
|
|
|
static void |
23089
|
9
|
|
|
|
|
|
deflate_optimize_and_flush_block(struct libdeflate_compressor *c, |
23090
|
|
|
|
|
|
|
struct deflate_output_bitstream *os, |
23091
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
23092
|
|
|
|
|
|
|
const struct lz_match *cache_ptr, |
23093
|
|
|
|
|
|
|
bool is_first_block, bool is_final_block, |
23094
|
|
|
|
|
|
|
bool *used_only_literals) |
23095
|
|
|
|
|
|
|
{ |
23096
|
9
|
|
|
|
|
|
unsigned num_passes_remaining = c->p.n.max_optim_passes; |
23097
|
9
|
|
|
|
|
|
u32 best_true_cost = UINT32_MAX; |
23098
|
|
|
|
|
|
|
u32 true_cost; |
23099
|
|
|
|
|
|
|
u32 only_lits_cost; |
23100
|
9
|
|
|
|
|
|
u32 static_cost = UINT32_MAX; |
23101
|
|
|
|
|
|
|
struct deflate_sequence seq_; |
23102
|
9
|
|
|
|
|
|
struct deflate_sequence *seq = NULL; |
23103
|
|
|
|
|
|
|
u32 i; |
23104
|
|
|
|
|
|
|
|
23105
|
|
|
|
|
|
|
|
23106
|
9
|
|
|
|
|
|
deflate_choose_all_literals(c, block_begin, block_length); |
23107
|
9
|
|
|
|
|
|
only_lits_cost = deflate_compute_true_cost(c); |
23108
|
|
|
|
|
|
|
|
23109
|
|
|
|
|
|
|
|
23110
|
2340
|
100
|
|
|
|
|
for (i = block_length; |
23111
|
2331
|
50
|
|
|
|
|
i <= MIN(block_length - 1 + DEFLATE_MAX_MATCH_LEN, |
23112
|
2322
|
|
|
|
|
|
ARRAY_LEN(c->p.n.optimum_nodes) - 1); i++) |
23113
|
2322
|
|
|
|
|
|
c->p.n.optimum_nodes[i].cost_to_end = 0x80000000; |
23114
|
|
|
|
|
|
|
|
23115
|
|
|
|
|
|
|
|
23116
|
9
|
100
|
|
|
|
|
if (block_length <= c->p.n.max_len_to_optimize_static_block) { |
23117
|
|
|
|
|
|
|
|
23118
|
3
|
|
|
|
|
|
c->p.n.costs_saved = c->p.n.costs; |
23119
|
|
|
|
|
|
|
|
23120
|
3
|
|
|
|
|
|
deflate_set_costs_from_codes(c, &c->static_codes.lens); |
23121
|
3
|
|
|
|
|
|
deflate_find_min_cost_path(c, block_length, cache_ptr); |
23122
|
3
|
|
|
|
|
|
static_cost = c->p.n.optimum_nodes[0].cost_to_end / BIT_COST; |
23123
|
3
|
|
|
|
|
|
static_cost += 7; |
23124
|
|
|
|
|
|
|
|
23125
|
|
|
|
|
|
|
|
23126
|
3
|
|
|
|
|
|
c->p.n.costs = c->p.n.costs_saved; |
23127
|
|
|
|
|
|
|
} |
23128
|
|
|
|
|
|
|
|
23129
|
|
|
|
|
|
|
|
23130
|
9
|
|
|
|
|
|
deflate_set_initial_costs(c, block_begin, block_length, is_first_block); |
23131
|
|
|
|
|
|
|
|
23132
|
|
|
|
|
|
|
do { |
23133
|
|
|
|
|
|
|
|
23134
|
18
|
|
|
|
|
|
deflate_find_min_cost_path(c, block_length, cache_ptr); |
23135
|
|
|
|
|
|
|
|
23136
|
|
|
|
|
|
|
|
23137
|
18
|
|
|
|
|
|
true_cost = deflate_compute_true_cost(c); |
23138
|
|
|
|
|
|
|
|
23139
|
|
|
|
|
|
|
|
23140
|
18
|
100
|
|
|
|
|
if (true_cost + c->p.n.min_improvement_to_continue > |
23141
|
|
|
|
|
|
|
best_true_cost) |
23142
|
9
|
|
|
|
|
|
break; |
23143
|
|
|
|
|
|
|
|
23144
|
9
|
|
|
|
|
|
best_true_cost = true_cost; |
23145
|
|
|
|
|
|
|
|
23146
|
|
|
|
|
|
|
|
23147
|
9
|
|
|
|
|
|
c->p.n.costs_saved = c->p.n.costs; |
23148
|
|
|
|
|
|
|
|
23149
|
|
|
|
|
|
|
|
23150
|
9
|
|
|
|
|
|
deflate_set_costs_from_codes(c, &c->codes.lens); |
23151
|
|
|
|
|
|
|
|
23152
|
9
|
50
|
|
|
|
|
} while (--num_passes_remaining); |
23153
|
|
|
|
|
|
|
|
23154
|
9
|
|
|
|
|
|
*used_only_literals = false; |
23155
|
9
|
100
|
|
|
|
|
if (MIN(only_lits_cost, static_cost) < best_true_cost) { |
23156
|
3
|
50
|
|
|
|
|
if (only_lits_cost < static_cost) { |
23157
|
|
|
|
|
|
|
|
23158
|
0
|
|
|
|
|
|
deflate_choose_all_literals(c, block_begin, block_length); |
23159
|
0
|
|
|
|
|
|
deflate_set_costs_from_codes(c, &c->codes.lens); |
23160
|
0
|
|
|
|
|
|
seq_.litrunlen_and_length = block_length; |
23161
|
0
|
|
|
|
|
|
seq = &seq_; |
23162
|
0
|
|
|
|
|
|
*used_only_literals = true; |
23163
|
|
|
|
|
|
|
} else { |
23164
|
|
|
|
|
|
|
|
23165
|
3
|
|
|
|
|
|
deflate_set_costs_from_codes(c, &c->static_codes.lens); |
23166
|
3
|
|
|
|
|
|
deflate_find_min_cost_path(c, block_length, cache_ptr); |
23167
|
|
|
|
|
|
|
} |
23168
|
6
|
50
|
|
|
|
|
} else if (true_cost >= |
23169
|
6
|
|
|
|
|
|
best_true_cost + c->p.n.min_bits_to_use_nonfinal_path) { |
23170
|
|
|
|
|
|
|
|
23171
|
0
|
|
|
|
|
|
c->p.n.costs = c->p.n.costs_saved; |
23172
|
0
|
|
|
|
|
|
deflate_find_min_cost_path(c, block_length, cache_ptr); |
23173
|
0
|
|
|
|
|
|
deflate_set_costs_from_codes(c, &c->codes.lens); |
23174
|
|
|
|
|
|
|
} |
23175
|
9
|
|
|
|
|
|
deflate_flush_block(c, os, block_begin, block_length, seq, |
23176
|
|
|
|
|
|
|
is_final_block); |
23177
|
9
|
|
|
|
|
|
} |
23178
|
|
|
|
|
|
|
|
23179
|
|
|
|
|
|
|
static void |
23180
|
18
|
|
|
|
|
|
deflate_near_optimal_init_stats(struct libdeflate_compressor *c) |
23181
|
|
|
|
|
|
|
{ |
23182
|
18
|
|
|
|
|
|
init_block_split_stats(&c->split_stats); |
23183
|
18
|
|
|
|
|
|
memset(c->p.n.new_match_len_freqs, 0, |
23184
|
|
|
|
|
|
|
sizeof(c->p.n.new_match_len_freqs)); |
23185
|
18
|
|
|
|
|
|
memset(c->p.n.match_len_freqs, 0, sizeof(c->p.n.match_len_freqs)); |
23186
|
18
|
|
|
|
|
|
} |
23187
|
|
|
|
|
|
|
|
23188
|
|
|
|
|
|
|
static void |
23189
|
9
|
|
|
|
|
|
deflate_near_optimal_merge_stats(struct libdeflate_compressor *c) |
23190
|
|
|
|
|
|
|
{ |
23191
|
|
|
|
|
|
|
unsigned i; |
23192
|
|
|
|
|
|
|
|
23193
|
9
|
|
|
|
|
|
merge_new_observations(&c->split_stats); |
23194
|
2340
|
100
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(c->p.n.match_len_freqs); i++) { |
23195
|
2331
|
|
|
|
|
|
c->p.n.match_len_freqs[i] += c->p.n.new_match_len_freqs[i]; |
23196
|
2331
|
|
|
|
|
|
c->p.n.new_match_len_freqs[i] = 0; |
23197
|
|
|
|
|
|
|
} |
23198
|
9
|
|
|
|
|
|
} |
23199
|
|
|
|
|
|
|
|
23200
|
|
|
|
|
|
|
|
23201
|
|
|
|
|
|
|
static void |
23202
|
9
|
|
|
|
|
|
deflate_near_optimal_save_stats(struct libdeflate_compressor *c) |
23203
|
|
|
|
|
|
|
{ |
23204
|
|
|
|
|
|
|
int i; |
23205
|
|
|
|
|
|
|
|
23206
|
99
|
100
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) |
23207
|
90
|
|
|
|
|
|
c->p.n.prev_observations[i] = c->split_stats.observations[i]; |
23208
|
9
|
|
|
|
|
|
c->p.n.prev_num_observations = c->split_stats.num_observations; |
23209
|
9
|
|
|
|
|
|
} |
23210
|
|
|
|
|
|
|
|
23211
|
|
|
|
|
|
|
static void |
23212
|
0
|
|
|
|
|
|
deflate_near_optimal_clear_old_stats(struct libdeflate_compressor *c) |
23213
|
|
|
|
|
|
|
{ |
23214
|
|
|
|
|
|
|
int i; |
23215
|
|
|
|
|
|
|
|
23216
|
0
|
0
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) |
23217
|
0
|
|
|
|
|
|
c->split_stats.observations[i] = 0; |
23218
|
0
|
|
|
|
|
|
c->split_stats.num_observations = 0; |
23219
|
0
|
|
|
|
|
|
memset(c->p.n.match_len_freqs, 0, sizeof(c->p.n.match_len_freqs)); |
23220
|
0
|
|
|
|
|
|
} |
23221
|
|
|
|
|
|
|
|
23222
|
|
|
|
|
|
|
|
23223
|
|
|
|
|
|
|
static void |
23224
|
9
|
|
|
|
|
|
deflate_compress_near_optimal(struct libdeflate_compressor * restrict c, |
23225
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
23226
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
23227
|
|
|
|
|
|
|
{ |
23228
|
9
|
|
|
|
|
|
const u8 *in_next = in; |
23229
|
9
|
|
|
|
|
|
const u8 *in_block_begin = in_next; |
23230
|
9
|
|
|
|
|
|
const u8 *in_end = in_next + in_nbytes; |
23231
|
9
|
|
|
|
|
|
const u8 *in_cur_base = in_next; |
23232
|
9
|
|
|
|
|
|
const u8 *in_next_slide = |
23233
|
9
|
|
|
|
|
|
in_next + MIN(in_end - in_next, MATCHFINDER_WINDOW_SIZE); |
23234
|
9
|
|
|
|
|
|
unsigned max_len = DEFLATE_MAX_MATCH_LEN; |
23235
|
9
|
|
|
|
|
|
unsigned nice_len = MIN(c->nice_match_length, max_len); |
23236
|
9
|
|
|
|
|
|
struct lz_match *cache_ptr = c->p.n.match_cache; |
23237
|
9
|
|
|
|
|
|
u32 next_hashes[2] = {0, 0}; |
23238
|
9
|
|
|
|
|
|
bool prev_block_used_only_literals = false; |
23239
|
|
|
|
|
|
|
|
23240
|
9
|
|
|
|
|
|
bt_matchfinder_init(&c->p.n.bt_mf); |
23241
|
9
|
|
|
|
|
|
deflate_near_optimal_init_stats(c); |
23242
|
|
|
|
|
|
|
|
23243
|
|
|
|
|
|
|
do { |
23244
|
|
|
|
|
|
|
|
23245
|
9
|
|
|
|
|
|
const u8 * const in_max_block_end = choose_max_block_end( |
23246
|
|
|
|
|
|
|
in_block_begin, in_end, SOFT_MAX_BLOCK_LENGTH); |
23247
|
9
|
|
|
|
|
|
const u8 *prev_end_block_check = NULL; |
23248
|
9
|
|
|
|
|
|
bool change_detected = false; |
23249
|
9
|
|
|
|
|
|
const u8 *next_observation = in_next; |
23250
|
|
|
|
|
|
|
unsigned min_len; |
23251
|
|
|
|
|
|
|
|
23252
|
|
|
|
|
|
|
|
23253
|
9
|
50
|
|
|
|
|
if (prev_block_used_only_literals) |
23254
|
0
|
|
|
|
|
|
min_len = DEFLATE_MAX_MATCH_LEN + 1; |
23255
|
|
|
|
|
|
|
else |
23256
|
9
|
|
|
|
|
|
min_len = calculate_min_match_len( |
23257
|
|
|
|
|
|
|
in_block_begin, |
23258
|
9
|
|
|
|
|
|
in_max_block_end - in_block_begin, |
23259
|
|
|
|
|
|
|
c->max_search_depth); |
23260
|
|
|
|
|
|
|
|
23261
|
|
|
|
|
|
|
|
23262
|
|
|
|
|
|
|
for (;;) { |
23263
|
|
|
|
|
|
|
struct lz_match *matches; |
23264
|
|
|
|
|
|
|
unsigned best_len; |
23265
|
225
|
|
|
|
|
|
size_t remaining = in_end - in_next; |
23266
|
|
|
|
|
|
|
|
23267
|
|
|
|
|
|
|
|
23268
|
225
|
50
|
|
|
|
|
if (in_next == in_next_slide) { |
23269
|
0
|
|
|
|
|
|
bt_matchfinder_slide_window(&c->p.n.bt_mf); |
23270
|
0
|
|
|
|
|
|
in_cur_base = in_next; |
23271
|
0
|
|
|
|
|
|
in_next_slide = in_next + |
23272
|
|
|
|
|
|
|
MIN(remaining, MATCHFINDER_WINDOW_SIZE); |
23273
|
|
|
|
|
|
|
} |
23274
|
|
|
|
|
|
|
|
23275
|
|
|
|
|
|
|
|
23276
|
225
|
|
|
|
|
|
matches = cache_ptr; |
23277
|
225
|
|
|
|
|
|
best_len = 0; |
23278
|
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, remaining); |
23279
|
225
|
50
|
|
|
|
|
if (likely(max_len >= BT_MATCHFINDER_REQUIRED_NBYTES)) { |
23280
|
450
|
|
|
|
|
|
cache_ptr = bt_matchfinder_get_matches( |
23281
|
|
|
|
|
|
|
&c->p.n.bt_mf, |
23282
|
|
|
|
|
|
|
in_cur_base, |
23283
|
|
|
|
|
|
|
in_next - in_cur_base, |
23284
|
|
|
|
|
|
|
max_len, |
23285
|
|
|
|
|
|
|
nice_len, |
23286
|
|
|
|
|
|
|
c->max_search_depth, |
23287
|
|
|
|
|
|
|
next_hashes, |
23288
|
|
|
|
|
|
|
matches); |
23289
|
225
|
100
|
|
|
|
|
if (cache_ptr > matches) |
23290
|
63
|
|
|
|
|
|
best_len = cache_ptr[-1].length; |
23291
|
|
|
|
|
|
|
} |
23292
|
225
|
50
|
|
|
|
|
if (in_next >= next_observation) { |
23293
|
225
|
100
|
|
|
|
|
if (best_len >= min_len) { |
23294
|
63
|
|
|
|
|
|
observe_match(&c->split_stats, |
23295
|
|
|
|
|
|
|
best_len); |
23296
|
63
|
|
|
|
|
|
next_observation = in_next + best_len; |
23297
|
63
|
|
|
|
|
|
c->p.n.new_match_len_freqs[best_len]++; |
23298
|
|
|
|
|
|
|
} else { |
23299
|
162
|
|
|
|
|
|
observe_literal(&c->split_stats, |
23300
|
162
|
|
|
|
|
|
*in_next); |
23301
|
162
|
|
|
|
|
|
next_observation = in_next + 1; |
23302
|
|
|
|
|
|
|
} |
23303
|
|
|
|
|
|
|
} |
23304
|
|
|
|
|
|
|
|
23305
|
225
|
|
|
|
|
|
cache_ptr->length = cache_ptr - matches; |
23306
|
225
|
|
|
|
|
|
cache_ptr->offset = *in_next; |
23307
|
225
|
|
|
|
|
|
in_next++; |
23308
|
225
|
|
|
|
|
|
cache_ptr++; |
23309
|
|
|
|
|
|
|
|
23310
|
|
|
|
|
|
|
|
23311
|
225
|
100
|
|
|
|
|
if (best_len >= DEFLATE_MIN_MATCH_LEN && |
|
|
50
|
|
|
|
|
|
23312
|
63
|
|
|
|
|
|
best_len >= nice_len) { |
23313
|
63
|
|
|
|
|
|
--best_len; |
23314
|
|
|
|
|
|
|
do { |
23315
|
15075
|
|
|
|
|
|
remaining = in_end - in_next; |
23316
|
15075
|
50
|
|
|
|
|
if (in_next == in_next_slide) { |
23317
|
0
|
|
|
|
|
|
bt_matchfinder_slide_window( |
23318
|
|
|
|
|
|
|
&c->p.n.bt_mf); |
23319
|
0
|
|
|
|
|
|
in_cur_base = in_next; |
23320
|
0
|
|
|
|
|
|
in_next_slide = in_next + |
23321
|
|
|
|
|
|
|
MIN(remaining, |
23322
|
|
|
|
|
|
|
MATCHFINDER_WINDOW_SIZE); |
23323
|
|
|
|
|
|
|
} |
23324
|
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, |
23325
|
|
|
|
|
|
|
&nice_len, |
23326
|
|
|
|
|
|
|
remaining); |
23327
|
15075
|
100
|
|
|
|
|
if (max_len >= |
23328
|
|
|
|
|
|
|
BT_MATCHFINDER_REQUIRED_NBYTES) { |
23329
|
15039
|
|
|
|
|
|
bt_matchfinder_skip_byte( |
23330
|
|
|
|
|
|
|
&c->p.n.bt_mf, |
23331
|
|
|
|
|
|
|
in_cur_base, |
23332
|
|
|
|
|
|
|
in_next - in_cur_base, |
23333
|
|
|
|
|
|
|
nice_len, |
23334
|
|
|
|
|
|
|
c->max_search_depth, |
23335
|
|
|
|
|
|
|
next_hashes); |
23336
|
|
|
|
|
|
|
} |
23337
|
15075
|
|
|
|
|
|
cache_ptr->length = 0; |
23338
|
15075
|
|
|
|
|
|
cache_ptr->offset = *in_next; |
23339
|
15075
|
|
|
|
|
|
in_next++; |
23340
|
15075
|
|
|
|
|
|
cache_ptr++; |
23341
|
15075
|
100
|
|
|
|
|
} while (--best_len); |
23342
|
|
|
|
|
|
|
} |
23343
|
|
|
|
|
|
|
|
23344
|
225
|
100
|
|
|
|
|
if (in_next >= in_max_block_end) |
23345
|
9
|
|
|
|
|
|
break; |
23346
|
|
|
|
|
|
|
|
23347
|
216
|
50
|
|
|
|
|
if (cache_ptr >= |
23348
|
216
|
|
|
|
|
|
&c->p.n.match_cache[MATCH_CACHE_LENGTH]) |
23349
|
0
|
|
|
|
|
|
break; |
23350
|
|
|
|
|
|
|
|
23351
|
216
|
50
|
|
|
|
|
if (!ready_to_check_block(&c->split_stats, |
23352
|
|
|
|
|
|
|
in_block_begin, in_next, |
23353
|
|
|
|
|
|
|
in_end)) |
23354
|
216
|
|
|
|
|
|
continue; |
23355
|
|
|
|
|
|
|
|
23356
|
0
|
0
|
|
|
|
|
if (do_end_block_check(&c->split_stats, |
23357
|
0
|
|
|
|
|
|
in_next - in_block_begin)) { |
23358
|
0
|
|
|
|
|
|
change_detected = true; |
23359
|
0
|
|
|
|
|
|
break; |
23360
|
|
|
|
|
|
|
} |
23361
|
|
|
|
|
|
|
|
23362
|
0
|
|
|
|
|
|
deflate_near_optimal_merge_stats(c); |
23363
|
0
|
|
|
|
|
|
prev_end_block_check = in_next; |
23364
|
216
|
|
|
|
|
|
} |
23365
|
|
|
|
|
|
|
|
23366
|
9
|
50
|
|
|
|
|
if (change_detected && prev_end_block_check != NULL) { |
|
|
0
|
|
|
|
|
|
23367
|
|
|
|
|
|
|
|
23368
|
0
|
|
|
|
|
|
struct lz_match *orig_cache_ptr = cache_ptr; |
23369
|
0
|
|
|
|
|
|
const u8 *in_block_end = prev_end_block_check; |
23370
|
0
|
|
|
|
|
|
u32 block_length = in_block_end - in_block_begin; |
23371
|
0
|
|
|
|
|
|
bool is_first = (in_block_begin == in); |
23372
|
0
|
|
|
|
|
|
bool is_final = false; |
23373
|
0
|
|
|
|
|
|
u32 num_bytes_to_rewind = in_next - in_block_end; |
23374
|
|
|
|
|
|
|
size_t cache_len_rewound; |
23375
|
|
|
|
|
|
|
|
23376
|
|
|
|
|
|
|
|
23377
|
|
|
|
|
|
|
do { |
23378
|
0
|
|
|
|
|
|
cache_ptr--; |
23379
|
0
|
|
|
|
|
|
cache_ptr -= cache_ptr->length; |
23380
|
0
|
0
|
|
|
|
|
} while (--num_bytes_to_rewind); |
23381
|
0
|
|
|
|
|
|
cache_len_rewound = orig_cache_ptr - cache_ptr; |
23382
|
|
|
|
|
|
|
|
23383
|
0
|
|
|
|
|
|
deflate_optimize_and_flush_block( |
23384
|
|
|
|
|
|
|
c, os, in_block_begin, |
23385
|
|
|
|
|
|
|
block_length, cache_ptr, |
23386
|
|
|
|
|
|
|
is_first, is_final, |
23387
|
|
|
|
|
|
|
&prev_block_used_only_literals); |
23388
|
0
|
|
|
|
|
|
memmove(c->p.n.match_cache, cache_ptr, |
23389
|
|
|
|
|
|
|
cache_len_rewound * sizeof(*cache_ptr)); |
23390
|
0
|
|
|
|
|
|
cache_ptr = &c->p.n.match_cache[cache_len_rewound]; |
23391
|
0
|
|
|
|
|
|
deflate_near_optimal_save_stats(c); |
23392
|
|
|
|
|
|
|
|
23393
|
0
|
|
|
|
|
|
deflate_near_optimal_clear_old_stats(c); |
23394
|
0
|
|
|
|
|
|
in_block_begin = in_block_end; |
23395
|
|
|
|
|
|
|
} else { |
23396
|
|
|
|
|
|
|
|
23397
|
9
|
|
|
|
|
|
u32 block_length = in_next - in_block_begin; |
23398
|
9
|
|
|
|
|
|
bool is_first = (in_block_begin == in); |
23399
|
9
|
|
|
|
|
|
bool is_final = (in_next == in_end); |
23400
|
|
|
|
|
|
|
|
23401
|
9
|
|
|
|
|
|
deflate_near_optimal_merge_stats(c); |
23402
|
9
|
|
|
|
|
|
deflate_optimize_and_flush_block( |
23403
|
|
|
|
|
|
|
c, os, in_block_begin, |
23404
|
|
|
|
|
|
|
block_length, cache_ptr, |
23405
|
|
|
|
|
|
|
is_first, is_final, |
23406
|
|
|
|
|
|
|
&prev_block_used_only_literals); |
23407
|
9
|
|
|
|
|
|
cache_ptr = &c->p.n.match_cache[0]; |
23408
|
9
|
|
|
|
|
|
deflate_near_optimal_save_stats(c); |
23409
|
9
|
|
|
|
|
|
deflate_near_optimal_init_stats(c); |
23410
|
9
|
|
|
|
|
|
in_block_begin = in_next; |
23411
|
|
|
|
|
|
|
} |
23412
|
9
|
50
|
|
|
|
|
} while (in_next != in_end && !os->overflow); |
|
|
0
|
|
|
|
|
|
23413
|
9
|
|
|
|
|
|
} |
23414
|
|
|
|
|
|
|
|
23415
|
|
|
|
|
|
|
|
23416
|
|
|
|
|
|
|
static void |
23417
|
9
|
|
|
|
|
|
deflate_init_offset_slot_full(struct libdeflate_compressor *c) |
23418
|
|
|
|
|
|
|
{ |
23419
|
|
|
|
|
|
|
unsigned offset_slot; |
23420
|
|
|
|
|
|
|
unsigned offset; |
23421
|
|
|
|
|
|
|
unsigned offset_end; |
23422
|
|
|
|
|
|
|
|
23423
|
279
|
100
|
|
|
|
|
for (offset_slot = 0; offset_slot < ARRAY_LEN(deflate_offset_slot_base); |
23424
|
270
|
|
|
|
|
|
offset_slot++) { |
23425
|
270
|
|
|
|
|
|
offset = deflate_offset_slot_base[offset_slot]; |
23426
|
270
|
|
|
|
|
|
offset_end = offset + |
23427
|
270
|
|
|
|
|
|
(1 << deflate_extra_offset_bits[offset_slot]); |
23428
|
|
|
|
|
|
|
do { |
23429
|
294912
|
|
|
|
|
|
c->p.n.offset_slot_full[offset] = offset_slot; |
23430
|
294912
|
100
|
|
|
|
|
} while (++offset != offset_end); |
23431
|
|
|
|
|
|
|
} |
23432
|
9
|
|
|
|
|
|
} |
23433
|
|
|
|
|
|
|
|
23434
|
|
|
|
|
|
|
#endif |
23435
|
|
|
|
|
|
|
|
23436
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
23437
|
37
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
23438
|
|
|
|
|
|
|
const struct libdeflate_options *options) |
23439
|
|
|
|
|
|
|
{ |
23440
|
|
|
|
|
|
|
struct libdeflate_compressor *c; |
23441
|
37
|
|
|
|
|
|
size_t size = offsetof(struct libdeflate_compressor, p); |
23442
|
|
|
|
|
|
|
|
23443
|
|
|
|
|
|
|
check_buildtime_parameters(); |
23444
|
|
|
|
|
|
|
|
23445
|
|
|
|
|
|
|
|
23446
|
37
|
50
|
|
|
|
|
if (options->sizeof_options != sizeof(*options)) |
23447
|
0
|
|
|
|
|
|
return NULL; |
23448
|
|
|
|
|
|
|
|
23449
|
37
|
50
|
|
|
|
|
if (compression_level < 0 || compression_level > 12) |
|
|
50
|
|
|
|
|
|
23450
|
0
|
|
|
|
|
|
return NULL; |
23451
|
|
|
|
|
|
|
|
23452
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
23453
|
37
|
100
|
|
|
|
|
if (compression_level >= 10) |
23454
|
9
|
|
|
|
|
|
size += sizeof(c->p.n); |
23455
|
|
|
|
|
|
|
else |
23456
|
|
|
|
|
|
|
#endif |
23457
|
|
|
|
|
|
|
{ |
23458
|
28
|
100
|
|
|
|
|
if (compression_level >= 2) |
23459
|
25
|
|
|
|
|
|
size += sizeof(c->p.g); |
23460
|
3
|
50
|
|
|
|
|
else if (compression_level == 1) |
23461
|
3
|
|
|
|
|
|
size += sizeof(c->p.f); |
23462
|
|
|
|
|
|
|
} |
23463
|
|
|
|
|
|
|
|
23464
|
37
|
50
|
|
|
|
|
c = libdeflate_aligned_malloc(options->malloc_func ? |
23465
|
|
|
|
|
|
|
options->malloc_func : |
23466
|
|
|
|
|
|
|
libdeflate_default_malloc_func, |
23467
|
|
|
|
|
|
|
MATCHFINDER_MEM_ALIGNMENT, size); |
23468
|
37
|
50
|
|
|
|
|
if (!c) |
23469
|
0
|
|
|
|
|
|
return NULL; |
23470
|
74
|
|
|
|
|
|
c->free_func = options->free_func ? |
23471
|
37
|
50
|
|
|
|
|
options->free_func : libdeflate_default_free_func; |
23472
|
|
|
|
|
|
|
|
23473
|
37
|
|
|
|
|
|
c->compression_level = compression_level; |
23474
|
|
|
|
|
|
|
|
23475
|
|
|
|
|
|
|
|
23476
|
37
|
|
|
|
|
|
c->max_passthrough_size = 55 - (compression_level * 4); |
23477
|
|
|
|
|
|
|
|
23478
|
37
|
|
|
|
|
|
switch (compression_level) { |
23479
|
|
|
|
|
|
|
case 0: |
23480
|
0
|
|
|
|
|
|
c->max_passthrough_size = SIZE_MAX; |
23481
|
0
|
|
|
|
|
|
c->impl = NULL; |
23482
|
0
|
|
|
|
|
|
break; |
23483
|
|
|
|
|
|
|
case 1: |
23484
|
3
|
|
|
|
|
|
c->impl = deflate_compress_fastest; |
23485
|
|
|
|
|
|
|
|
23486
|
3
|
|
|
|
|
|
c->nice_match_length = 32; |
23487
|
3
|
|
|
|
|
|
break; |
23488
|
|
|
|
|
|
|
case 2: |
23489
|
3
|
|
|
|
|
|
c->impl = deflate_compress_greedy; |
23490
|
3
|
|
|
|
|
|
c->max_search_depth = 6; |
23491
|
3
|
|
|
|
|
|
c->nice_match_length = 10; |
23492
|
3
|
|
|
|
|
|
break; |
23493
|
|
|
|
|
|
|
case 3: |
23494
|
3
|
|
|
|
|
|
c->impl = deflate_compress_greedy; |
23495
|
3
|
|
|
|
|
|
c->max_search_depth = 12; |
23496
|
3
|
|
|
|
|
|
c->nice_match_length = 14; |
23497
|
3
|
|
|
|
|
|
break; |
23498
|
|
|
|
|
|
|
case 4: |
23499
|
3
|
|
|
|
|
|
c->impl = deflate_compress_greedy; |
23500
|
3
|
|
|
|
|
|
c->max_search_depth = 16; |
23501
|
3
|
|
|
|
|
|
c->nice_match_length = 30; |
23502
|
3
|
|
|
|
|
|
break; |
23503
|
|
|
|
|
|
|
case 5: |
23504
|
3
|
|
|
|
|
|
c->impl = deflate_compress_lazy; |
23505
|
3
|
|
|
|
|
|
c->max_search_depth = 16; |
23506
|
3
|
|
|
|
|
|
c->nice_match_length = 30; |
23507
|
3
|
|
|
|
|
|
break; |
23508
|
|
|
|
|
|
|
case 6: |
23509
|
4
|
|
|
|
|
|
c->impl = deflate_compress_lazy; |
23510
|
4
|
|
|
|
|
|
c->max_search_depth = 35; |
23511
|
4
|
|
|
|
|
|
c->nice_match_length = 65; |
23512
|
4
|
|
|
|
|
|
break; |
23513
|
|
|
|
|
|
|
case 7: |
23514
|
3
|
|
|
|
|
|
c->impl = deflate_compress_lazy; |
23515
|
3
|
|
|
|
|
|
c->max_search_depth = 100; |
23516
|
3
|
|
|
|
|
|
c->nice_match_length = 130; |
23517
|
3
|
|
|
|
|
|
break; |
23518
|
|
|
|
|
|
|
case 8: |
23519
|
3
|
|
|
|
|
|
c->impl = deflate_compress_lazy2; |
23520
|
3
|
|
|
|
|
|
c->max_search_depth = 300; |
23521
|
3
|
|
|
|
|
|
c->nice_match_length = DEFLATE_MAX_MATCH_LEN; |
23522
|
3
|
|
|
|
|
|
break; |
23523
|
|
|
|
|
|
|
case 9: |
23524
|
|
|
|
|
|
|
#if !SUPPORT_NEAR_OPTIMAL_PARSING |
23525
|
|
|
|
|
|
|
default: |
23526
|
|
|
|
|
|
|
#endif |
23527
|
3
|
|
|
|
|
|
c->impl = deflate_compress_lazy2; |
23528
|
3
|
|
|
|
|
|
c->max_search_depth = 600; |
23529
|
3
|
|
|
|
|
|
c->nice_match_length = DEFLATE_MAX_MATCH_LEN; |
23530
|
3
|
|
|
|
|
|
break; |
23531
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
23532
|
|
|
|
|
|
|
case 10: |
23533
|
3
|
|
|
|
|
|
c->impl = deflate_compress_near_optimal; |
23534
|
3
|
|
|
|
|
|
c->max_search_depth = 35; |
23535
|
3
|
|
|
|
|
|
c->nice_match_length = 75; |
23536
|
3
|
|
|
|
|
|
c->p.n.max_optim_passes = 2; |
23537
|
3
|
|
|
|
|
|
c->p.n.min_improvement_to_continue = 32; |
23538
|
3
|
|
|
|
|
|
c->p.n.min_bits_to_use_nonfinal_path = 32; |
23539
|
3
|
|
|
|
|
|
c->p.n.max_len_to_optimize_static_block = 0; |
23540
|
3
|
|
|
|
|
|
deflate_init_offset_slot_full(c); |
23541
|
3
|
|
|
|
|
|
break; |
23542
|
|
|
|
|
|
|
case 11: |
23543
|
3
|
|
|
|
|
|
c->impl = deflate_compress_near_optimal; |
23544
|
3
|
|
|
|
|
|
c->max_search_depth = 100; |
23545
|
3
|
|
|
|
|
|
c->nice_match_length = 150; |
23546
|
3
|
|
|
|
|
|
c->p.n.max_optim_passes = 4; |
23547
|
3
|
|
|
|
|
|
c->p.n.min_improvement_to_continue = 16; |
23548
|
3
|
|
|
|
|
|
c->p.n.min_bits_to_use_nonfinal_path = 16; |
23549
|
3
|
|
|
|
|
|
c->p.n.max_len_to_optimize_static_block = 1000; |
23550
|
3
|
|
|
|
|
|
deflate_init_offset_slot_full(c); |
23551
|
3
|
|
|
|
|
|
break; |
23552
|
|
|
|
|
|
|
case 12: |
23553
|
|
|
|
|
|
|
default: |
23554
|
3
|
|
|
|
|
|
c->impl = deflate_compress_near_optimal; |
23555
|
3
|
|
|
|
|
|
c->max_search_depth = 300; |
23556
|
3
|
|
|
|
|
|
c->nice_match_length = DEFLATE_MAX_MATCH_LEN; |
23557
|
3
|
|
|
|
|
|
c->p.n.max_optim_passes = 10; |
23558
|
3
|
|
|
|
|
|
c->p.n.min_improvement_to_continue = 1; |
23559
|
3
|
|
|
|
|
|
c->p.n.min_bits_to_use_nonfinal_path = 1; |
23560
|
3
|
|
|
|
|
|
c->p.n.max_len_to_optimize_static_block = 10000; |
23561
|
3
|
|
|
|
|
|
deflate_init_offset_slot_full(c); |
23562
|
3
|
|
|
|
|
|
break; |
23563
|
|
|
|
|
|
|
#endif |
23564
|
|
|
|
|
|
|
} |
23565
|
|
|
|
|
|
|
|
23566
|
37
|
|
|
|
|
|
deflate_init_static_codes(c); |
23567
|
|
|
|
|
|
|
|
23568
|
37
|
|
|
|
|
|
return c; |
23569
|
|
|
|
|
|
|
} |
23570
|
|
|
|
|
|
|
|
23571
|
|
|
|
|
|
|
|
23572
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
23573
|
37
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level) |
23574
|
|
|
|
|
|
|
{ |
23575
|
|
|
|
|
|
|
static const struct libdeflate_options defaults = { |
23576
|
|
|
|
|
|
|
.sizeof_options = sizeof(defaults), |
23577
|
|
|
|
|
|
|
}; |
23578
|
37
|
|
|
|
|
|
return libdeflate_alloc_compressor_ex(compression_level, &defaults); |
23579
|
|
|
|
|
|
|
} |
23580
|
|
|
|
|
|
|
|
23581
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23582
|
37
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *c, |
23583
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23584
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail) |
23585
|
|
|
|
|
|
|
{ |
23586
|
|
|
|
|
|
|
struct deflate_output_bitstream os; |
23587
|
|
|
|
|
|
|
|
23588
|
|
|
|
|
|
|
|
23589
|
37
|
50
|
|
|
|
|
if (unlikely(in_nbytes <= c->max_passthrough_size)) |
23590
|
0
|
|
|
|
|
|
return deflate_compress_none(in, in_nbytes, |
23591
|
|
|
|
|
|
|
out, out_nbytes_avail); |
23592
|
|
|
|
|
|
|
|
23593
|
|
|
|
|
|
|
|
23594
|
37
|
|
|
|
|
|
os.bitbuf = 0; |
23595
|
37
|
|
|
|
|
|
os.bitcount = 0; |
23596
|
37
|
|
|
|
|
|
os.next = out; |
23597
|
37
|
|
|
|
|
|
os.end = os.next + out_nbytes_avail; |
23598
|
37
|
|
|
|
|
|
os.overflow = false; |
23599
|
|
|
|
|
|
|
|
23600
|
|
|
|
|
|
|
|
23601
|
37
|
|
|
|
|
|
(*c->impl)(c, in, in_nbytes, &os); |
23602
|
|
|
|
|
|
|
|
23603
|
|
|
|
|
|
|
|
23604
|
37
|
50
|
|
|
|
|
if (os.overflow) |
23605
|
0
|
|
|
|
|
|
return 0; |
23606
|
|
|
|
|
|
|
|
23607
|
|
|
|
|
|
|
|
23608
|
37
|
|
|
|
|
|
ASSERT(os.bitcount <= 7); |
23609
|
37
|
50
|
|
|
|
|
if (os.bitcount) { |
23610
|
37
|
|
|
|
|
|
ASSERT(os.next < os.end); |
23611
|
37
|
|
|
|
|
|
*os.next++ = os.bitbuf; |
23612
|
|
|
|
|
|
|
} |
23613
|
|
|
|
|
|
|
|
23614
|
|
|
|
|
|
|
|
23615
|
37
|
|
|
|
|
|
return os.next - (u8 *)out; |
23616
|
|
|
|
|
|
|
} |
23617
|
|
|
|
|
|
|
|
23618
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
23619
|
37
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *c) |
23620
|
|
|
|
|
|
|
{ |
23621
|
37
|
50
|
|
|
|
|
if (c) |
23622
|
37
|
|
|
|
|
|
libdeflate_aligned_free(c->free_func, c); |
23623
|
37
|
|
|
|
|
|
} |
23624
|
|
|
|
|
|
|
|
23625
|
|
|
|
|
|
|
unsigned int |
23626
|
25
|
|
|
|
|
|
libdeflate_get_compression_level(struct libdeflate_compressor *c) |
23627
|
|
|
|
|
|
|
{ |
23628
|
25
|
|
|
|
|
|
return c->compression_level; |
23629
|
|
|
|
|
|
|
} |
23630
|
|
|
|
|
|
|
|
23631
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23632
|
37
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *c, |
23633
|
|
|
|
|
|
|
size_t in_nbytes) |
23634
|
|
|
|
|
|
|
{ |
23635
|
|
|
|
|
|
|
size_t max_blocks; |
23636
|
|
|
|
|
|
|
|
23637
|
|
|
|
|
|
|
|
23638
|
|
|
|
|
|
|
|
23639
|
|
|
|
|
|
|
|
23640
|
|
|
|
|
|
|
STATIC_ASSERT(2 * MIN_BLOCK_LENGTH <= UINT16_MAX); |
23641
|
37
|
50
|
|
|
|
|
max_blocks = MAX(DIV_ROUND_UP(in_nbytes, MIN_BLOCK_LENGTH), 1); |
23642
|
|
|
|
|
|
|
|
23643
|
|
|
|
|
|
|
|
23644
|
37
|
|
|
|
|
|
return (5 * max_blocks) + in_nbytes; |
23645
|
|
|
|
|
|
|
} |
23646
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/deflate_decompress.c */ |
23647
|
|
|
|
|
|
|
|
23648
|
|
|
|
|
|
|
|
23649
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
23650
|
|
|
|
|
|
|
|
23651
|
|
|
|
|
|
|
|
23652
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
23653
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
23654
|
|
|
|
|
|
|
|
23655
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
23656
|
|
|
|
|
|
|
|
23657
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
23658
|
|
|
|
|
|
|
#endif |
23659
|
|
|
|
|
|
|
|
23660
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
23661
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
23662
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
23663
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
23664
|
|
|
|
|
|
|
#else |
23665
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
23666
|
|
|
|
|
|
|
#endif |
23667
|
|
|
|
|
|
|
|
23668
|
|
|
|
|
|
|
|
23669
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
23670
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
23671
|
|
|
|
|
|
|
#else |
23672
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
23673
|
|
|
|
|
|
|
#endif |
23674
|
|
|
|
|
|
|
|
23675
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
23676
|
|
|
|
|
|
|
|
23677
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
23678
|
|
|
|
|
|
|
|
23679
|
|
|
|
|
|
|
|
23680
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
23681
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
23682
|
|
|
|
|
|
|
|
23683
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
23684
|
|
|
|
|
|
|
|
23685
|
|
|
|
|
|
|
|
23686
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
23687
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
23688
|
|
|
|
|
|
|
|
23689
|
|
|
|
|
|
|
#include |
23690
|
|
|
|
|
|
|
#include |
23691
|
|
|
|
|
|
|
|
23692
|
|
|
|
|
|
|
#ifdef __cplusplus |
23693
|
|
|
|
|
|
|
extern "C" { |
23694
|
|
|
|
|
|
|
#endif |
23695
|
|
|
|
|
|
|
|
23696
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
23697
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
23698
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
23699
|
|
|
|
|
|
|
|
23700
|
|
|
|
|
|
|
|
23701
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
23702
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
23703
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
23704
|
|
|
|
|
|
|
# else |
23705
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
23706
|
|
|
|
|
|
|
# endif |
23707
|
|
|
|
|
|
|
#endif |
23708
|
|
|
|
|
|
|
|
23709
|
|
|
|
|
|
|
|
23710
|
|
|
|
|
|
|
|
23711
|
|
|
|
|
|
|
|
23712
|
|
|
|
|
|
|
|
23713
|
|
|
|
|
|
|
struct libdeflate_compressor; |
23714
|
|
|
|
|
|
|
struct libdeflate_options; |
23715
|
|
|
|
|
|
|
|
23716
|
|
|
|
|
|
|
|
23717
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
23718
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
23719
|
|
|
|
|
|
|
|
23720
|
|
|
|
|
|
|
|
23721
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
23722
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
23723
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
23724
|
|
|
|
|
|
|
|
23725
|
|
|
|
|
|
|
|
23726
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23727
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
23728
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23729
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
23730
|
|
|
|
|
|
|
|
23731
|
|
|
|
|
|
|
|
23732
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23733
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
23734
|
|
|
|
|
|
|
size_t in_nbytes); |
23735
|
|
|
|
|
|
|
|
23736
|
|
|
|
|
|
|
|
23737
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23738
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
23739
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23740
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
23741
|
|
|
|
|
|
|
|
23742
|
|
|
|
|
|
|
|
23743
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23744
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
23745
|
|
|
|
|
|
|
size_t in_nbytes); |
23746
|
|
|
|
|
|
|
|
23747
|
|
|
|
|
|
|
|
23748
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23749
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
23750
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23751
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
23752
|
|
|
|
|
|
|
|
23753
|
|
|
|
|
|
|
|
23754
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23755
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
23756
|
|
|
|
|
|
|
size_t in_nbytes); |
23757
|
|
|
|
|
|
|
|
23758
|
|
|
|
|
|
|
|
23759
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
23760
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
23761
|
|
|
|
|
|
|
|
23762
|
|
|
|
|
|
|
|
23763
|
|
|
|
|
|
|
|
23764
|
|
|
|
|
|
|
|
23765
|
|
|
|
|
|
|
|
23766
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
23767
|
|
|
|
|
|
|
struct libdeflate_options; |
23768
|
|
|
|
|
|
|
|
23769
|
|
|
|
|
|
|
|
23770
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
23771
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
23772
|
|
|
|
|
|
|
|
23773
|
|
|
|
|
|
|
|
23774
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
23775
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
23776
|
|
|
|
|
|
|
|
23777
|
|
|
|
|
|
|
|
23778
|
|
|
|
|
|
|
enum libdeflate_result { |
23779
|
|
|
|
|
|
|
|
23780
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
23781
|
|
|
|
|
|
|
|
23782
|
|
|
|
|
|
|
|
23783
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
23784
|
|
|
|
|
|
|
|
23785
|
|
|
|
|
|
|
|
23786
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
23787
|
|
|
|
|
|
|
|
23788
|
|
|
|
|
|
|
|
23789
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
23790
|
|
|
|
|
|
|
}; |
23791
|
|
|
|
|
|
|
|
23792
|
|
|
|
|
|
|
|
23793
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23794
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
23795
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23796
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23797
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23798
|
|
|
|
|
|
|
|
23799
|
|
|
|
|
|
|
|
23800
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23801
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
23802
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23803
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23804
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
23805
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23806
|
|
|
|
|
|
|
|
23807
|
|
|
|
|
|
|
|
23808
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23809
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
23810
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23811
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23812
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23813
|
|
|
|
|
|
|
|
23814
|
|
|
|
|
|
|
|
23815
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23816
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
23817
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23818
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23819
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
23820
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23821
|
|
|
|
|
|
|
|
23822
|
|
|
|
|
|
|
|
23823
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23824
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
23825
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23826
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23827
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23828
|
|
|
|
|
|
|
|
23829
|
|
|
|
|
|
|
|
23830
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23831
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
23832
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23833
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23834
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
23835
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23836
|
|
|
|
|
|
|
|
23837
|
|
|
|
|
|
|
|
23838
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
23839
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
23840
|
|
|
|
|
|
|
|
23841
|
|
|
|
|
|
|
|
23842
|
|
|
|
|
|
|
|
23843
|
|
|
|
|
|
|
|
23844
|
|
|
|
|
|
|
|
23845
|
|
|
|
|
|
|
|
23846
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
23847
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
23848
|
|
|
|
|
|
|
|
23849
|
|
|
|
|
|
|
|
23850
|
|
|
|
|
|
|
|
23851
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
23852
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
23853
|
|
|
|
|
|
|
|
23854
|
|
|
|
|
|
|
|
23855
|
|
|
|
|
|
|
|
23856
|
|
|
|
|
|
|
|
23857
|
|
|
|
|
|
|
|
23858
|
|
|
|
|
|
|
|
23859
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
23860
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
23861
|
|
|
|
|
|
|
void (*free_func)(void *)); |
23862
|
|
|
|
|
|
|
|
23863
|
|
|
|
|
|
|
|
23864
|
|
|
|
|
|
|
struct libdeflate_options { |
23865
|
|
|
|
|
|
|
|
23866
|
|
|
|
|
|
|
|
23867
|
|
|
|
|
|
|
size_t sizeof_options; |
23868
|
|
|
|
|
|
|
|
23869
|
|
|
|
|
|
|
|
23870
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
23871
|
|
|
|
|
|
|
void (*free_func)(void *); |
23872
|
|
|
|
|
|
|
}; |
23873
|
|
|
|
|
|
|
|
23874
|
|
|
|
|
|
|
#ifdef __cplusplus |
23875
|
|
|
|
|
|
|
} |
23876
|
|
|
|
|
|
|
#endif |
23877
|
|
|
|
|
|
|
|
23878
|
|
|
|
|
|
|
#endif |
23879
|
|
|
|
|
|
|
|
23880
|
|
|
|
|
|
|
|
23881
|
|
|
|
|
|
|
#include |
23882
|
|
|
|
|
|
|
#include |
23883
|
|
|
|
|
|
|
#include |
23884
|
|
|
|
|
|
|
#ifdef _MSC_VER |
23885
|
|
|
|
|
|
|
# include |
23886
|
|
|
|
|
|
|
# include |
23887
|
|
|
|
|
|
|
|
23888
|
|
|
|
|
|
|
|
23889
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
23890
|
|
|
|
|
|
|
|
23891
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
23892
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
23893
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
23894
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
23895
|
|
|
|
|
|
|
|
23896
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
23897
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
23898
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
23899
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
23900
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
23901
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
23902
|
|
|
|
|
|
|
#endif |
23903
|
|
|
|
|
|
|
#ifndef FREESTANDING |
23904
|
|
|
|
|
|
|
# include |
23905
|
|
|
|
|
|
|
#endif |
23906
|
|
|
|
|
|
|
|
23907
|
|
|
|
|
|
|
|
23908
|
|
|
|
|
|
|
|
23909
|
|
|
|
|
|
|
|
23910
|
|
|
|
|
|
|
|
23911
|
|
|
|
|
|
|
|
23912
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
23913
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
23914
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
23915
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
23916
|
|
|
|
|
|
|
#ifdef _MSC_VER |
23917
|
|
|
|
|
|
|
# if defined(_M_X64) |
23918
|
|
|
|
|
|
|
# define ARCH_X86_64 |
23919
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
23920
|
|
|
|
|
|
|
# define ARCH_X86_32 |
23921
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
23922
|
|
|
|
|
|
|
# define ARCH_ARM64 |
23923
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
23924
|
|
|
|
|
|
|
# define ARCH_ARM32 |
23925
|
|
|
|
|
|
|
# endif |
23926
|
|
|
|
|
|
|
#else |
23927
|
|
|
|
|
|
|
# if defined(__x86_64__) |
23928
|
|
|
|
|
|
|
# define ARCH_X86_64 |
23929
|
|
|
|
|
|
|
# elif defined(__i386__) |
23930
|
|
|
|
|
|
|
# define ARCH_X86_32 |
23931
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
23932
|
|
|
|
|
|
|
# define ARCH_ARM64 |
23933
|
|
|
|
|
|
|
# elif defined(__arm__) |
23934
|
|
|
|
|
|
|
# define ARCH_ARM32 |
23935
|
|
|
|
|
|
|
# endif |
23936
|
|
|
|
|
|
|
#endif |
23937
|
|
|
|
|
|
|
|
23938
|
|
|
|
|
|
|
|
23939
|
|
|
|
|
|
|
|
23940
|
|
|
|
|
|
|
|
23941
|
|
|
|
|
|
|
|
23942
|
|
|
|
|
|
|
|
23943
|
|
|
|
|
|
|
typedef uint8_t u8; |
23944
|
|
|
|
|
|
|
typedef uint16_t u16; |
23945
|
|
|
|
|
|
|
typedef uint32_t u32; |
23946
|
|
|
|
|
|
|
typedef uint64_t u64; |
23947
|
|
|
|
|
|
|
typedef int8_t s8; |
23948
|
|
|
|
|
|
|
typedef int16_t s16; |
23949
|
|
|
|
|
|
|
typedef int32_t s32; |
23950
|
|
|
|
|
|
|
typedef int64_t s64; |
23951
|
|
|
|
|
|
|
|
23952
|
|
|
|
|
|
|
|
23953
|
|
|
|
|
|
|
#ifdef _MSC_VER |
23954
|
|
|
|
|
|
|
# ifdef _WIN64 |
23955
|
|
|
|
|
|
|
typedef long long ssize_t; |
23956
|
|
|
|
|
|
|
# else |
23957
|
|
|
|
|
|
|
typedef long ssize_t; |
23958
|
|
|
|
|
|
|
# endif |
23959
|
|
|
|
|
|
|
#endif |
23960
|
|
|
|
|
|
|
|
23961
|
|
|
|
|
|
|
|
23962
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
23963
|
|
|
|
|
|
|
|
23964
|
|
|
|
|
|
|
|
23965
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
23966
|
|
|
|
|
|
|
|
23967
|
|
|
|
|
|
|
|
23968
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
23969
|
|
|
|
|
|
|
|
23970
|
|
|
|
|
|
|
|
23971
|
|
|
|
|
|
|
|
23972
|
|
|
|
|
|
|
|
23973
|
|
|
|
|
|
|
|
23974
|
|
|
|
|
|
|
|
23975
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
23976
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
23977
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
23978
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
23979
|
|
|
|
|
|
|
#else |
23980
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
23981
|
|
|
|
|
|
|
#endif |
23982
|
|
|
|
|
|
|
#ifdef __clang__ |
23983
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
23984
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
23985
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
23986
|
|
|
|
|
|
|
# else |
23987
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
23988
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
23989
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
23990
|
|
|
|
|
|
|
# endif |
23991
|
|
|
|
|
|
|
#else |
23992
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
23993
|
|
|
|
|
|
|
#endif |
23994
|
|
|
|
|
|
|
|
23995
|
|
|
|
|
|
|
|
23996
|
|
|
|
|
|
|
#ifndef __has_attribute |
23997
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
23998
|
|
|
|
|
|
|
#endif |
23999
|
|
|
|
|
|
|
#ifndef __has_builtin |
24000
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
24001
|
|
|
|
|
|
|
#endif |
24002
|
|
|
|
|
|
|
|
24003
|
|
|
|
|
|
|
|
24004
|
|
|
|
|
|
|
#ifdef _MSC_VER |
24005
|
|
|
|
|
|
|
# define inline __inline |
24006
|
|
|
|
|
|
|
#endif |
24007
|
|
|
|
|
|
|
|
24008
|
|
|
|
|
|
|
|
24009
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
24010
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
24011
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24012
|
|
|
|
|
|
|
# define forceinline __forceinline |
24013
|
|
|
|
|
|
|
#else |
24014
|
|
|
|
|
|
|
# define forceinline inline |
24015
|
|
|
|
|
|
|
#endif |
24016
|
|
|
|
|
|
|
|
24017
|
|
|
|
|
|
|
|
24018
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
24019
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
24020
|
|
|
|
|
|
|
#else |
24021
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
24022
|
|
|
|
|
|
|
#endif |
24023
|
|
|
|
|
|
|
|
24024
|
|
|
|
|
|
|
|
24025
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
24026
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
24027
|
|
|
|
|
|
|
# define restrict __restrict__ |
24028
|
|
|
|
|
|
|
# else |
24029
|
|
|
|
|
|
|
# define restrict |
24030
|
|
|
|
|
|
|
# endif |
24031
|
|
|
|
|
|
|
#endif |
24032
|
|
|
|
|
|
|
|
24033
|
|
|
|
|
|
|
|
24034
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
24035
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
24036
|
|
|
|
|
|
|
#else |
24037
|
|
|
|
|
|
|
# define likely(expr) (expr) |
24038
|
|
|
|
|
|
|
#endif |
24039
|
|
|
|
|
|
|
|
24040
|
|
|
|
|
|
|
|
24041
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
24042
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
24043
|
|
|
|
|
|
|
#else |
24044
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
24045
|
|
|
|
|
|
|
#endif |
24046
|
|
|
|
|
|
|
|
24047
|
|
|
|
|
|
|
|
24048
|
|
|
|
|
|
|
#undef prefetchr |
24049
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
24050
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
24051
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24052
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
24053
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
24054
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
24055
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
24056
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
24057
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
24058
|
|
|
|
|
|
|
# endif |
24059
|
|
|
|
|
|
|
#endif |
24060
|
|
|
|
|
|
|
#ifndef prefetchr |
24061
|
|
|
|
|
|
|
# define prefetchr(addr) |
24062
|
|
|
|
|
|
|
#endif |
24063
|
|
|
|
|
|
|
|
24064
|
|
|
|
|
|
|
|
24065
|
|
|
|
|
|
|
#undef prefetchw |
24066
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
24067
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
24068
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24069
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
24070
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
24071
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
24072
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
24073
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
24074
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
24075
|
|
|
|
|
|
|
# endif |
24076
|
|
|
|
|
|
|
#endif |
24077
|
|
|
|
|
|
|
#ifndef prefetchw |
24078
|
|
|
|
|
|
|
# define prefetchw(addr) |
24079
|
|
|
|
|
|
|
#endif |
24080
|
|
|
|
|
|
|
|
24081
|
|
|
|
|
|
|
|
24082
|
|
|
|
|
|
|
#undef _aligned_attribute |
24083
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
24084
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
24085
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24086
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
24087
|
|
|
|
|
|
|
#endif |
24088
|
|
|
|
|
|
|
|
24089
|
|
|
|
|
|
|
|
24090
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
24091
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
24092
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
24093
|
|
|
|
|
|
|
#else |
24094
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
24095
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
24096
|
|
|
|
|
|
|
#endif |
24097
|
|
|
|
|
|
|
|
24098
|
|
|
|
|
|
|
|
24099
|
|
|
|
|
|
|
|
24100
|
|
|
|
|
|
|
|
24101
|
|
|
|
|
|
|
|
24102
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
24103
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
24104
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
24105
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
24106
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
24107
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
24108
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
24109
|
|
|
|
|
|
|
|
24110
|
|
|
|
|
|
|
|
24111
|
|
|
|
|
|
|
|
24112
|
|
|
|
|
|
|
|
24113
|
|
|
|
|
|
|
|
24114
|
|
|
|
|
|
|
|
24115
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
24116
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
24117
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24118
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
24119
|
|
|
|
|
|
|
#else |
24120
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
24121
|
|
|
|
|
|
|
{ |
24122
|
|
|
|
|
|
|
union { |
24123
|
|
|
|
|
|
|
u32 w; |
24124
|
|
|
|
|
|
|
u8 b; |
24125
|
|
|
|
|
|
|
} u; |
24126
|
|
|
|
|
|
|
|
24127
|
|
|
|
|
|
|
u.w = 1; |
24128
|
|
|
|
|
|
|
return u.b; |
24129
|
|
|
|
|
|
|
} |
24130
|
|
|
|
|
|
|
#endif |
24131
|
|
|
|
|
|
|
|
24132
|
|
|
|
|
|
|
|
24133
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
24134
|
|
|
|
|
|
|
{ |
24135
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
24136
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
24137
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24138
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
24139
|
|
|
|
|
|
|
#else |
24140
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
24141
|
|
|
|
|
|
|
#endif |
24142
|
|
|
|
|
|
|
} |
24143
|
|
|
|
|
|
|
|
24144
|
|
|
|
|
|
|
|
24145
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
24146
|
|
|
|
|
|
|
{ |
24147
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
24148
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
24149
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24150
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
24151
|
|
|
|
|
|
|
#else |
24152
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
24153
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
24154
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
24155
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
24156
|
|
|
|
|
|
|
#endif |
24157
|
|
|
|
|
|
|
} |
24158
|
|
|
|
|
|
|
|
24159
|
|
|
|
|
|
|
|
24160
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
24161
|
|
|
|
|
|
|
{ |
24162
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
24163
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
24164
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24165
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
24166
|
|
|
|
|
|
|
#else |
24167
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
24168
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
24169
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
24170
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
24171
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
24172
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
24173
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
24174
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
24175
|
|
|
|
|
|
|
#endif |
24176
|
|
|
|
|
|
|
} |
24177
|
|
|
|
|
|
|
|
24178
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
24179
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
24180
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
24181
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
24182
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
24183
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
24184
|
|
|
|
|
|
|
|
24185
|
|
|
|
|
|
|
|
24186
|
|
|
|
|
|
|
|
24187
|
|
|
|
|
|
|
|
24188
|
|
|
|
|
|
|
|
24189
|
|
|
|
|
|
|
|
24190
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
24191
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
24192
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
24193
|
|
|
|
|
|
|
defined(__wasm__)) |
24194
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
24195
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24196
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
24197
|
|
|
|
|
|
|
#else |
24198
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
24199
|
|
|
|
|
|
|
#endif |
24200
|
|
|
|
|
|
|
|
24201
|
|
|
|
|
|
|
|
24202
|
|
|
|
|
|
|
|
24203
|
|
|
|
|
|
|
#ifdef FREESTANDING |
24204
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
24205
|
|
|
|
|
|
|
#else |
24206
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
24207
|
|
|
|
|
|
|
#endif |
24208
|
|
|
|
|
|
|
|
24209
|
|
|
|
|
|
|
|
24210
|
|
|
|
|
|
|
|
24211
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
24212
|
|
|
|
|
|
|
static forceinline type \ |
24213
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
24214
|
|
|
|
|
|
|
{ \ |
24215
|
|
|
|
|
|
|
type v; \ |
24216
|
|
|
|
|
|
|
\ |
24217
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
24218
|
|
|
|
|
|
|
return v; \ |
24219
|
|
|
|
|
|
|
} \ |
24220
|
|
|
|
|
|
|
\ |
24221
|
|
|
|
|
|
|
static forceinline void \ |
24222
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
24223
|
|
|
|
|
|
|
{ \ |
24224
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
24225
|
|
|
|
|
|
|
} |
24226
|
|
|
|
|
|
|
|
24227
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
24228
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
24229
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
24230
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
24231
|
|
|
|
|
|
|
|
24232
|
|
|
|
|
|
|
#undef MEMCOPY |
24233
|
|
|
|
|
|
|
|
24234
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
24235
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
24236
|
|
|
|
|
|
|
|
24237
|
|
|
|
|
|
|
|
24238
|
|
|
|
|
|
|
|
24239
|
|
|
|
|
|
|
static forceinline u16 |
24240
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
24241
|
|
|
|
|
|
|
{ |
24242
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
24243
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
24244
|
|
|
|
|
|
|
else |
24245
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
24246
|
|
|
|
|
|
|
} |
24247
|
|
|
|
|
|
|
|
24248
|
|
|
|
|
|
|
static forceinline u16 |
24249
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
24250
|
|
|
|
|
|
|
{ |
24251
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
24252
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
24253
|
|
|
|
|
|
|
else |
24254
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
24255
|
|
|
|
|
|
|
} |
24256
|
|
|
|
|
|
|
|
24257
|
|
|
|
|
|
|
static forceinline u32 |
24258
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
24259
|
|
|
|
|
|
|
{ |
24260
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
24261
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
24262
|
|
|
|
|
|
|
else |
24263
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
24264
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
24265
|
|
|
|
|
|
|
} |
24266
|
|
|
|
|
|
|
|
24267
|
|
|
|
|
|
|
static forceinline u32 |
24268
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
24269
|
|
|
|
|
|
|
{ |
24270
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
24271
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
24272
|
|
|
|
|
|
|
else |
24273
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
24274
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
24275
|
|
|
|
|
|
|
} |
24276
|
|
|
|
|
|
|
|
24277
|
|
|
|
|
|
|
static forceinline u64 |
24278
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
24279
|
|
|
|
|
|
|
{ |
24280
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
24281
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
24282
|
|
|
|
|
|
|
else |
24283
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
24284
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
24285
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
24286
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
24287
|
|
|
|
|
|
|
} |
24288
|
|
|
|
|
|
|
|
24289
|
|
|
|
|
|
|
static forceinline machine_word_t |
24290
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
24291
|
|
|
|
|
|
|
{ |
24292
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
24293
|
|
|
|
|
|
|
if (WORDBITS == 32) |
24294
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
24295
|
|
|
|
|
|
|
else |
24296
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
24297
|
|
|
|
|
|
|
} |
24298
|
|
|
|
|
|
|
|
24299
|
|
|
|
|
|
|
|
24300
|
|
|
|
|
|
|
|
24301
|
|
|
|
|
|
|
static forceinline void |
24302
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
24303
|
|
|
|
|
|
|
{ |
24304
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
24305
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
24306
|
|
|
|
|
|
|
} else { |
24307
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
24308
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
24309
|
|
|
|
|
|
|
} |
24310
|
|
|
|
|
|
|
} |
24311
|
|
|
|
|
|
|
|
24312
|
|
|
|
|
|
|
static forceinline void |
24313
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
24314
|
|
|
|
|
|
|
{ |
24315
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
24316
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
24317
|
|
|
|
|
|
|
} else { |
24318
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
24319
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
24320
|
|
|
|
|
|
|
} |
24321
|
|
|
|
|
|
|
} |
24322
|
|
|
|
|
|
|
|
24323
|
|
|
|
|
|
|
static forceinline void |
24324
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
24325
|
|
|
|
|
|
|
{ |
24326
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
24327
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
24328
|
|
|
|
|
|
|
} else { |
24329
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
24330
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
24331
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
24332
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
24333
|
|
|
|
|
|
|
} |
24334
|
|
|
|
|
|
|
} |
24335
|
|
|
|
|
|
|
|
24336
|
|
|
|
|
|
|
static forceinline void |
24337
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
24338
|
|
|
|
|
|
|
{ |
24339
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
24340
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
24341
|
|
|
|
|
|
|
} else { |
24342
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
24343
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
24344
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
24345
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
24346
|
|
|
|
|
|
|
} |
24347
|
|
|
|
|
|
|
} |
24348
|
|
|
|
|
|
|
|
24349
|
|
|
|
|
|
|
static forceinline void |
24350
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
24351
|
|
|
|
|
|
|
{ |
24352
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
24353
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
24354
|
|
|
|
|
|
|
} else { |
24355
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
24356
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
24357
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
24358
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
24359
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
24360
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
24361
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
24362
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
24363
|
|
|
|
|
|
|
} |
24364
|
|
|
|
|
|
|
} |
24365
|
|
|
|
|
|
|
|
24366
|
|
|
|
|
|
|
static forceinline void |
24367
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
24368
|
|
|
|
|
|
|
{ |
24369
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
24370
|
|
|
|
|
|
|
if (WORDBITS == 32) |
24371
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
24372
|
|
|
|
|
|
|
else |
24373
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
24374
|
|
|
|
|
|
|
} |
24375
|
|
|
|
|
|
|
|
24376
|
|
|
|
|
|
|
|
24377
|
|
|
|
|
|
|
|
24378
|
|
|
|
|
|
|
|
24379
|
|
|
|
|
|
|
|
24380
|
|
|
|
|
|
|
|
24381
|
|
|
|
|
|
|
|
24382
|
|
|
|
|
|
|
static forceinline unsigned |
24383
|
|
|
|
|
|
|
bsr32(u32 v) |
24384
|
|
|
|
|
|
|
{ |
24385
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
24386
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
24387
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24388
|
|
|
|
|
|
|
unsigned long i; |
24389
|
|
|
|
|
|
|
|
24390
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
24391
|
|
|
|
|
|
|
return i; |
24392
|
|
|
|
|
|
|
#else |
24393
|
|
|
|
|
|
|
unsigned i = 0; |
24394
|
|
|
|
|
|
|
|
24395
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
24396
|
|
|
|
|
|
|
i++; |
24397
|
|
|
|
|
|
|
return i; |
24398
|
|
|
|
|
|
|
#endif |
24399
|
|
|
|
|
|
|
} |
24400
|
|
|
|
|
|
|
|
24401
|
|
|
|
|
|
|
static forceinline unsigned |
24402
|
|
|
|
|
|
|
bsr64(u64 v) |
24403
|
|
|
|
|
|
|
{ |
24404
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
24405
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
24406
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
24407
|
|
|
|
|
|
|
unsigned long i; |
24408
|
|
|
|
|
|
|
|
24409
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
24410
|
|
|
|
|
|
|
return i; |
24411
|
|
|
|
|
|
|
#else |
24412
|
|
|
|
|
|
|
unsigned i = 0; |
24413
|
|
|
|
|
|
|
|
24414
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
24415
|
|
|
|
|
|
|
i++; |
24416
|
|
|
|
|
|
|
return i; |
24417
|
|
|
|
|
|
|
#endif |
24418
|
|
|
|
|
|
|
} |
24419
|
|
|
|
|
|
|
|
24420
|
|
|
|
|
|
|
static forceinline unsigned |
24421
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
24422
|
|
|
|
|
|
|
{ |
24423
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
24424
|
|
|
|
|
|
|
if (WORDBITS == 32) |
24425
|
|
|
|
|
|
|
return bsr32(v); |
24426
|
|
|
|
|
|
|
else |
24427
|
|
|
|
|
|
|
return bsr64(v); |
24428
|
|
|
|
|
|
|
} |
24429
|
|
|
|
|
|
|
|
24430
|
|
|
|
|
|
|
|
24431
|
|
|
|
|
|
|
|
24432
|
|
|
|
|
|
|
static forceinline unsigned |
24433
|
|
|
|
|
|
|
bsf32(u32 v) |
24434
|
|
|
|
|
|
|
{ |
24435
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
24436
|
|
|
|
|
|
|
return __builtin_ctz(v); |
24437
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
24438
|
|
|
|
|
|
|
unsigned long i; |
24439
|
|
|
|
|
|
|
|
24440
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
24441
|
|
|
|
|
|
|
return i; |
24442
|
|
|
|
|
|
|
#else |
24443
|
|
|
|
|
|
|
unsigned i = 0; |
24444
|
|
|
|
|
|
|
|
24445
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
24446
|
|
|
|
|
|
|
i++; |
24447
|
|
|
|
|
|
|
return i; |
24448
|
|
|
|
|
|
|
#endif |
24449
|
|
|
|
|
|
|
} |
24450
|
|
|
|
|
|
|
|
24451
|
|
|
|
|
|
|
static forceinline unsigned |
24452
|
|
|
|
|
|
|
bsf64(u64 v) |
24453
|
|
|
|
|
|
|
{ |
24454
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
24455
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
24456
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
24457
|
|
|
|
|
|
|
unsigned long i; |
24458
|
|
|
|
|
|
|
|
24459
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
24460
|
|
|
|
|
|
|
return i; |
24461
|
|
|
|
|
|
|
#else |
24462
|
|
|
|
|
|
|
unsigned i = 0; |
24463
|
|
|
|
|
|
|
|
24464
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
24465
|
|
|
|
|
|
|
i++; |
24466
|
|
|
|
|
|
|
return i; |
24467
|
|
|
|
|
|
|
#endif |
24468
|
|
|
|
|
|
|
} |
24469
|
|
|
|
|
|
|
|
24470
|
|
|
|
|
|
|
static forceinline unsigned |
24471
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
24472
|
|
|
|
|
|
|
{ |
24473
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
24474
|
|
|
|
|
|
|
if (WORDBITS == 32) |
24475
|
|
|
|
|
|
|
return bsf32(v); |
24476
|
|
|
|
|
|
|
else |
24477
|
|
|
|
|
|
|
return bsf64(v); |
24478
|
|
|
|
|
|
|
} |
24479
|
|
|
|
|
|
|
|
24480
|
|
|
|
|
|
|
|
24481
|
|
|
|
|
|
|
#undef rbit32 |
24482
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
24483
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
24484
|
|
|
|
|
|
|
static forceinline u32 |
24485
|
|
|
|
|
|
|
rbit32(u32 v) |
24486
|
|
|
|
|
|
|
{ |
24487
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
24488
|
|
|
|
|
|
|
return v; |
24489
|
|
|
|
|
|
|
} |
24490
|
|
|
|
|
|
|
#define rbit32 rbit32 |
24491
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
24492
|
|
|
|
|
|
|
static forceinline u32 |
24493
|
|
|
|
|
|
|
rbit32(u32 v) |
24494
|
|
|
|
|
|
|
{ |
24495
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
24496
|
|
|
|
|
|
|
return v; |
24497
|
|
|
|
|
|
|
} |
24498
|
|
|
|
|
|
|
#define rbit32 rbit32 |
24499
|
|
|
|
|
|
|
#endif |
24500
|
|
|
|
|
|
|
|
24501
|
|
|
|
|
|
|
#endif |
24502
|
|
|
|
|
|
|
|
24503
|
|
|
|
|
|
|
|
24504
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
24505
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
24506
|
|
|
|
|
|
|
|
24507
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
24508
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
24509
|
|
|
|
|
|
|
|
24510
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
24511
|
|
|
|
|
|
|
size_t alignment, size_t size); |
24512
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
24513
|
|
|
|
|
|
|
|
24514
|
|
|
|
|
|
|
#ifdef FREESTANDING |
24515
|
|
|
|
|
|
|
|
24516
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
24517
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
24518
|
|
|
|
|
|
|
|
24519
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
24520
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
24521
|
|
|
|
|
|
|
|
24522
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
24523
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
24524
|
|
|
|
|
|
|
|
24525
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
24526
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
24527
|
|
|
|
|
|
|
|
24528
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
24529
|
|
|
|
|
|
|
#else |
24530
|
|
|
|
|
|
|
#include |
24531
|
|
|
|
|
|
|
#endif |
24532
|
|
|
|
|
|
|
|
24533
|
|
|
|
|
|
|
|
24534
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
24535
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
24536
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
24537
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
24538
|
|
|
|
|
|
|
#else |
24539
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
24540
|
|
|
|
|
|
|
#endif |
24541
|
|
|
|
|
|
|
|
24542
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
24543
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
24544
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
24545
|
|
|
|
|
|
|
|
24546
|
|
|
|
|
|
|
#endif |
24547
|
|
|
|
|
|
|
|
24548
|
|
|
|
|
|
|
/* #include "deflate_constants.h" */ |
24549
|
|
|
|
|
|
|
|
24550
|
|
|
|
|
|
|
|
24551
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_CONSTANTS_H |
24552
|
|
|
|
|
|
|
#define LIB_DEFLATE_CONSTANTS_H |
24553
|
|
|
|
|
|
|
|
24554
|
|
|
|
|
|
|
|
24555
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_UNCOMPRESSED 0 |
24556
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_STATIC_HUFFMAN 1 |
24557
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN 2 |
24558
|
|
|
|
|
|
|
|
24559
|
|
|
|
|
|
|
|
24560
|
|
|
|
|
|
|
#define DEFLATE_MIN_MATCH_LEN 3 |
24561
|
|
|
|
|
|
|
#define DEFLATE_MAX_MATCH_LEN 258 |
24562
|
|
|
|
|
|
|
|
24563
|
|
|
|
|
|
|
|
24564
|
|
|
|
|
|
|
#define DEFLATE_MAX_MATCH_OFFSET 32768 |
24565
|
|
|
|
|
|
|
|
24566
|
|
|
|
|
|
|
|
24567
|
|
|
|
|
|
|
#define DEFLATE_WINDOW_ORDER 15 |
24568
|
|
|
|
|
|
|
|
24569
|
|
|
|
|
|
|
|
24570
|
|
|
|
|
|
|
#define DEFLATE_NUM_PRECODE_SYMS 19 |
24571
|
|
|
|
|
|
|
#define DEFLATE_NUM_LITLEN_SYMS 288 |
24572
|
|
|
|
|
|
|
#define DEFLATE_NUM_OFFSET_SYMS 32 |
24573
|
|
|
|
|
|
|
|
24574
|
|
|
|
|
|
|
|
24575
|
|
|
|
|
|
|
#define DEFLATE_MAX_NUM_SYMS 288 |
24576
|
|
|
|
|
|
|
|
24577
|
|
|
|
|
|
|
|
24578
|
|
|
|
|
|
|
#define DEFLATE_NUM_LITERALS 256 |
24579
|
|
|
|
|
|
|
#define DEFLATE_END_OF_BLOCK 256 |
24580
|
|
|
|
|
|
|
#define DEFLATE_FIRST_LEN_SYM 257 |
24581
|
|
|
|
|
|
|
|
24582
|
|
|
|
|
|
|
|
24583
|
|
|
|
|
|
|
#define DEFLATE_MAX_PRE_CODEWORD_LEN 7 |
24584
|
|
|
|
|
|
|
#define DEFLATE_MAX_LITLEN_CODEWORD_LEN 15 |
24585
|
|
|
|
|
|
|
#define DEFLATE_MAX_OFFSET_CODEWORD_LEN 15 |
24586
|
|
|
|
|
|
|
|
24587
|
|
|
|
|
|
|
|
24588
|
|
|
|
|
|
|
#define DEFLATE_MAX_CODEWORD_LEN 15 |
24589
|
|
|
|
|
|
|
|
24590
|
|
|
|
|
|
|
|
24591
|
|
|
|
|
|
|
#define DEFLATE_MAX_LENS_OVERRUN 137 |
24592
|
|
|
|
|
|
|
|
24593
|
|
|
|
|
|
|
|
24594
|
|
|
|
|
|
|
#define DEFLATE_MAX_EXTRA_LENGTH_BITS 5 |
24595
|
|
|
|
|
|
|
#define DEFLATE_MAX_EXTRA_OFFSET_BITS 13 |
24596
|
|
|
|
|
|
|
|
24597
|
|
|
|
|
|
|
#endif |
24598
|
|
|
|
|
|
|
|
24599
|
|
|
|
|
|
|
|
24600
|
|
|
|
|
|
|
|
24601
|
|
|
|
|
|
|
#if 0 |
24602
|
|
|
|
|
|
|
# pragma message("UNSAFE DECOMPRESSION IS ENABLED. THIS MUST ONLY BE USED IF THE DECOMPRESSOR INPUT WILL ALWAYS BE TRUSTED!") |
24603
|
|
|
|
|
|
|
# define SAFETY_CHECK(expr) (void)(expr) |
24604
|
|
|
|
|
|
|
#else |
24605
|
|
|
|
|
|
|
# define SAFETY_CHECK(expr) if (unlikely(!(expr))) return LIBDEFLATE_BAD_DATA |
24606
|
|
|
|
|
|
|
#endif |
24607
|
|
|
|
|
|
|
|
24608
|
|
|
|
|
|
|
|
24609
|
|
|
|
|
|
|
|
24610
|
|
|
|
|
|
|
|
24611
|
|
|
|
|
|
|
|
24612
|
|
|
|
|
|
|
|
24613
|
|
|
|
|
|
|
/* typedef machine_word_t bitbuf_t; */ |
24614
|
|
|
|
|
|
|
#define DECOMPRESS_BITBUF_NBITS (8 * (int)sizeof(bitbuf_t)) |
24615
|
|
|
|
|
|
|
|
24616
|
|
|
|
|
|
|
|
24617
|
|
|
|
|
|
|
#define BITMASK(n) (((bitbuf_t)1 << (n)) - 1) |
24618
|
|
|
|
|
|
|
|
24619
|
|
|
|
|
|
|
|
24620
|
|
|
|
|
|
|
#define MAX_BITSLEFT \ |
24621
|
|
|
|
|
|
|
(UNALIGNED_ACCESS_IS_FAST ? DECOMPRESS_BITBUF_NBITS - 1 : DECOMPRESS_BITBUF_NBITS) |
24622
|
|
|
|
|
|
|
|
24623
|
|
|
|
|
|
|
|
24624
|
|
|
|
|
|
|
#define CONSUMABLE_NBITS (MAX_BITSLEFT - 7) |
24625
|
|
|
|
|
|
|
|
24626
|
|
|
|
|
|
|
|
24627
|
|
|
|
|
|
|
#define FASTLOOP_PRELOADABLE_NBITS \ |
24628
|
|
|
|
|
|
|
(UNALIGNED_ACCESS_IS_FAST ? DECOMPRESS_BITBUF_NBITS : CONSUMABLE_NBITS) |
24629
|
|
|
|
|
|
|
|
24630
|
|
|
|
|
|
|
|
24631
|
|
|
|
|
|
|
#define PRELOAD_SLACK MAX(0, FASTLOOP_PRELOADABLE_NBITS - MAX_BITSLEFT) |
24632
|
|
|
|
|
|
|
|
24633
|
|
|
|
|
|
|
|
24634
|
|
|
|
|
|
|
#define CAN_CONSUME(n) (CONSUMABLE_NBITS >= (n)) |
24635
|
|
|
|
|
|
|
|
24636
|
|
|
|
|
|
|
|
24637
|
|
|
|
|
|
|
#define CAN_CONSUME_AND_THEN_PRELOAD(consume_nbits, preload_nbits) \ |
24638
|
|
|
|
|
|
|
(CONSUMABLE_NBITS >= (consume_nbits) && \ |
24639
|
|
|
|
|
|
|
FASTLOOP_PRELOADABLE_NBITS >= (consume_nbits) + (preload_nbits)) |
24640
|
|
|
|
|
|
|
|
24641
|
|
|
|
|
|
|
|
24642
|
|
|
|
|
|
|
#define REFILL_BITS_BRANCHLESS() \ |
24643
|
|
|
|
|
|
|
do { \ |
24644
|
|
|
|
|
|
|
bitbuf |= get_unaligned_leword(in_next) << (u8)bitsleft; \ |
24645
|
|
|
|
|
|
|
in_next += sizeof(bitbuf_t) - 1; \ |
24646
|
|
|
|
|
|
|
in_next -= (bitsleft >> 3) & 0x7; \ |
24647
|
|
|
|
|
|
|
bitsleft |= MAX_BITSLEFT & ~7; \ |
24648
|
|
|
|
|
|
|
} while (0) |
24649
|
|
|
|
|
|
|
|
24650
|
|
|
|
|
|
|
|
24651
|
|
|
|
|
|
|
#define REFILL_BITS() \ |
24652
|
|
|
|
|
|
|
do { \ |
24653
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST && \ |
24654
|
|
|
|
|
|
|
likely(in_end - in_next >= sizeof(bitbuf_t))) { \ |
24655
|
|
|
|
|
|
|
REFILL_BITS_BRANCHLESS(); \ |
24656
|
|
|
|
|
|
|
} else { \ |
24657
|
|
|
|
|
|
|
while ((u8)bitsleft < CONSUMABLE_NBITS) { \ |
24658
|
|
|
|
|
|
|
if (likely(in_next != in_end)) { \ |
24659
|
|
|
|
|
|
|
bitbuf |= (bitbuf_t)*in_next++ << \ |
24660
|
|
|
|
|
|
|
(u8)bitsleft; \ |
24661
|
|
|
|
|
|
|
} else { \ |
24662
|
|
|
|
|
|
|
overread_count++; \ |
24663
|
|
|
|
|
|
|
SAFETY_CHECK(overread_count <= \ |
24664
|
|
|
|
|
|
|
sizeof(bitbuf_t)); \ |
24665
|
|
|
|
|
|
|
} \ |
24666
|
|
|
|
|
|
|
bitsleft += 8; \ |
24667
|
|
|
|
|
|
|
} \ |
24668
|
|
|
|
|
|
|
} \ |
24669
|
|
|
|
|
|
|
} while (0) |
24670
|
|
|
|
|
|
|
|
24671
|
|
|
|
|
|
|
|
24672
|
|
|
|
|
|
|
#define REFILL_BITS_IN_FASTLOOP() \ |
24673
|
|
|
|
|
|
|
do { \ |
24674
|
|
|
|
|
|
|
STATIC_ASSERT(UNALIGNED_ACCESS_IS_FAST || \ |
24675
|
|
|
|
|
|
|
FASTLOOP_PRELOADABLE_NBITS == CONSUMABLE_NBITS); \ |
24676
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { \ |
24677
|
|
|
|
|
|
|
REFILL_BITS_BRANCHLESS(); \ |
24678
|
|
|
|
|
|
|
} else { \ |
24679
|
|
|
|
|
|
|
while ((u8)bitsleft < CONSUMABLE_NBITS) { \ |
24680
|
|
|
|
|
|
|
bitbuf |= (bitbuf_t)*in_next++ << (u8)bitsleft; \ |
24681
|
|
|
|
|
|
|
bitsleft += 8; \ |
24682
|
|
|
|
|
|
|
} \ |
24683
|
|
|
|
|
|
|
} \ |
24684
|
|
|
|
|
|
|
} while (0) |
24685
|
|
|
|
|
|
|
|
24686
|
|
|
|
|
|
|
|
24687
|
|
|
|
|
|
|
#define FASTLOOP_MAX_BYTES_WRITTEN \ |
24688
|
|
|
|
|
|
|
(2 + DEFLATE_MAX_MATCH_LEN + (5 * WORDBYTES) - 1) |
24689
|
|
|
|
|
|
|
|
24690
|
|
|
|
|
|
|
|
24691
|
|
|
|
|
|
|
#define FASTLOOP_MAX_BYTES_READ \ |
24692
|
|
|
|
|
|
|
(DIV_ROUND_UP(MAX_BITSLEFT + (2 * LITLEN_TABLEBITS) + \ |
24693
|
|
|
|
|
|
|
LENGTH_MAXBITS + OFFSET_MAXBITS, 8) + \ |
24694
|
|
|
|
|
|
|
sizeof(bitbuf_t)) |
24695
|
|
|
|
|
|
|
|
24696
|
|
|
|
|
|
|
|
24697
|
|
|
|
|
|
|
|
24698
|
|
|
|
|
|
|
|
24699
|
|
|
|
|
|
|
|
24700
|
|
|
|
|
|
|
|
24701
|
|
|
|
|
|
|
|
24702
|
|
|
|
|
|
|
#define PRECODE_TABLEBITS 7 |
24703
|
|
|
|
|
|
|
#define PRECODE_ENOUGH 128 |
24704
|
|
|
|
|
|
|
#define LITLEN_TABLEBITS 11 |
24705
|
|
|
|
|
|
|
#define LITLEN_ENOUGH 2342 |
24706
|
|
|
|
|
|
|
#define OFFSET_TABLEBITS 8 |
24707
|
|
|
|
|
|
|
#define OFFSET_ENOUGH 402 |
24708
|
|
|
|
|
|
|
|
24709
|
|
|
|
|
|
|
|
24710
|
|
|
|
|
|
|
static forceinline u32 |
24711
|
|
|
|
|
|
|
make_decode_table_entry(const u32 decode_results[], u32 sym, u32 len) |
24712
|
|
|
|
|
|
|
{ |
24713
|
12198
|
|
|
|
|
|
return decode_results[sym] + (len << 8) + len; |
24714
|
|
|
|
|
|
|
} |
24715
|
|
|
|
|
|
|
|
24716
|
|
|
|
|
|
|
|
24717
|
|
|
|
|
|
|
static const u32 precode_decode_results[] = { |
24718
|
|
|
|
|
|
|
#define ENTRY(presym) ((u32)presym << 16) |
24719
|
|
|
|
|
|
|
ENTRY(0) , ENTRY(1) , ENTRY(2) , ENTRY(3) , |
24720
|
|
|
|
|
|
|
ENTRY(4) , ENTRY(5) , ENTRY(6) , ENTRY(7) , |
24721
|
|
|
|
|
|
|
ENTRY(8) , ENTRY(9) , ENTRY(10) , ENTRY(11) , |
24722
|
|
|
|
|
|
|
ENTRY(12) , ENTRY(13) , ENTRY(14) , ENTRY(15) , |
24723
|
|
|
|
|
|
|
ENTRY(16) , ENTRY(17) , ENTRY(18) , |
24724
|
|
|
|
|
|
|
#undef ENTRY |
24725
|
|
|
|
|
|
|
}; |
24726
|
|
|
|
|
|
|
|
24727
|
|
|
|
|
|
|
|
24728
|
|
|
|
|
|
|
|
24729
|
|
|
|
|
|
|
|
24730
|
|
|
|
|
|
|
#define HUFFDEC_LITERAL 0x80000000 |
24731
|
|
|
|
|
|
|
|
24732
|
|
|
|
|
|
|
|
24733
|
|
|
|
|
|
|
#define HUFFDEC_EXCEPTIONAL 0x00008000 |
24734
|
|
|
|
|
|
|
|
24735
|
|
|
|
|
|
|
|
24736
|
|
|
|
|
|
|
#define HUFFDEC_SUBTABLE_POINTER 0x00004000 |
24737
|
|
|
|
|
|
|
|
24738
|
|
|
|
|
|
|
|
24739
|
|
|
|
|
|
|
#define HUFFDEC_END_OF_BLOCK 0x00002000 |
24740
|
|
|
|
|
|
|
|
24741
|
|
|
|
|
|
|
|
24742
|
|
|
|
|
|
|
#define LENGTH_MAXBITS (DEFLATE_MAX_LITLEN_CODEWORD_LEN + \ |
24743
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS) |
24744
|
|
|
|
|
|
|
#define LENGTH_MAXFASTBITS (LITLEN_TABLEBITS + \ |
24745
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS) |
24746
|
|
|
|
|
|
|
|
24747
|
|
|
|
|
|
|
|
24748
|
|
|
|
|
|
|
static const u32 litlen_decode_results[] = { |
24749
|
|
|
|
|
|
|
|
24750
|
|
|
|
|
|
|
|
24751
|
|
|
|
|
|
|
#define ENTRY(literal) (HUFFDEC_LITERAL | ((u32)literal << 16)) |
24752
|
|
|
|
|
|
|
ENTRY(0) , ENTRY(1) , ENTRY(2) , ENTRY(3) , |
24753
|
|
|
|
|
|
|
ENTRY(4) , ENTRY(5) , ENTRY(6) , ENTRY(7) , |
24754
|
|
|
|
|
|
|
ENTRY(8) , ENTRY(9) , ENTRY(10) , ENTRY(11) , |
24755
|
|
|
|
|
|
|
ENTRY(12) , ENTRY(13) , ENTRY(14) , ENTRY(15) , |
24756
|
|
|
|
|
|
|
ENTRY(16) , ENTRY(17) , ENTRY(18) , ENTRY(19) , |
24757
|
|
|
|
|
|
|
ENTRY(20) , ENTRY(21) , ENTRY(22) , ENTRY(23) , |
24758
|
|
|
|
|
|
|
ENTRY(24) , ENTRY(25) , ENTRY(26) , ENTRY(27) , |
24759
|
|
|
|
|
|
|
ENTRY(28) , ENTRY(29) , ENTRY(30) , ENTRY(31) , |
24760
|
|
|
|
|
|
|
ENTRY(32) , ENTRY(33) , ENTRY(34) , ENTRY(35) , |
24761
|
|
|
|
|
|
|
ENTRY(36) , ENTRY(37) , ENTRY(38) , ENTRY(39) , |
24762
|
|
|
|
|
|
|
ENTRY(40) , ENTRY(41) , ENTRY(42) , ENTRY(43) , |
24763
|
|
|
|
|
|
|
ENTRY(44) , ENTRY(45) , ENTRY(46) , ENTRY(47) , |
24764
|
|
|
|
|
|
|
ENTRY(48) , ENTRY(49) , ENTRY(50) , ENTRY(51) , |
24765
|
|
|
|
|
|
|
ENTRY(52) , ENTRY(53) , ENTRY(54) , ENTRY(55) , |
24766
|
|
|
|
|
|
|
ENTRY(56) , ENTRY(57) , ENTRY(58) , ENTRY(59) , |
24767
|
|
|
|
|
|
|
ENTRY(60) , ENTRY(61) , ENTRY(62) , ENTRY(63) , |
24768
|
|
|
|
|
|
|
ENTRY(64) , ENTRY(65) , ENTRY(66) , ENTRY(67) , |
24769
|
|
|
|
|
|
|
ENTRY(68) , ENTRY(69) , ENTRY(70) , ENTRY(71) , |
24770
|
|
|
|
|
|
|
ENTRY(72) , ENTRY(73) , ENTRY(74) , ENTRY(75) , |
24771
|
|
|
|
|
|
|
ENTRY(76) , ENTRY(77) , ENTRY(78) , ENTRY(79) , |
24772
|
|
|
|
|
|
|
ENTRY(80) , ENTRY(81) , ENTRY(82) , ENTRY(83) , |
24773
|
|
|
|
|
|
|
ENTRY(84) , ENTRY(85) , ENTRY(86) , ENTRY(87) , |
24774
|
|
|
|
|
|
|
ENTRY(88) , ENTRY(89) , ENTRY(90) , ENTRY(91) , |
24775
|
|
|
|
|
|
|
ENTRY(92) , ENTRY(93) , ENTRY(94) , ENTRY(95) , |
24776
|
|
|
|
|
|
|
ENTRY(96) , ENTRY(97) , ENTRY(98) , ENTRY(99) , |
24777
|
|
|
|
|
|
|
ENTRY(100) , ENTRY(101) , ENTRY(102) , ENTRY(103) , |
24778
|
|
|
|
|
|
|
ENTRY(104) , ENTRY(105) , ENTRY(106) , ENTRY(107) , |
24779
|
|
|
|
|
|
|
ENTRY(108) , ENTRY(109) , ENTRY(110) , ENTRY(111) , |
24780
|
|
|
|
|
|
|
ENTRY(112) , ENTRY(113) , ENTRY(114) , ENTRY(115) , |
24781
|
|
|
|
|
|
|
ENTRY(116) , ENTRY(117) , ENTRY(118) , ENTRY(119) , |
24782
|
|
|
|
|
|
|
ENTRY(120) , ENTRY(121) , ENTRY(122) , ENTRY(123) , |
24783
|
|
|
|
|
|
|
ENTRY(124) , ENTRY(125) , ENTRY(126) , ENTRY(127) , |
24784
|
|
|
|
|
|
|
ENTRY(128) , ENTRY(129) , ENTRY(130) , ENTRY(131) , |
24785
|
|
|
|
|
|
|
ENTRY(132) , ENTRY(133) , ENTRY(134) , ENTRY(135) , |
24786
|
|
|
|
|
|
|
ENTRY(136) , ENTRY(137) , ENTRY(138) , ENTRY(139) , |
24787
|
|
|
|
|
|
|
ENTRY(140) , ENTRY(141) , ENTRY(142) , ENTRY(143) , |
24788
|
|
|
|
|
|
|
ENTRY(144) , ENTRY(145) , ENTRY(146) , ENTRY(147) , |
24789
|
|
|
|
|
|
|
ENTRY(148) , ENTRY(149) , ENTRY(150) , ENTRY(151) , |
24790
|
|
|
|
|
|
|
ENTRY(152) , ENTRY(153) , ENTRY(154) , ENTRY(155) , |
24791
|
|
|
|
|
|
|
ENTRY(156) , ENTRY(157) , ENTRY(158) , ENTRY(159) , |
24792
|
|
|
|
|
|
|
ENTRY(160) , ENTRY(161) , ENTRY(162) , ENTRY(163) , |
24793
|
|
|
|
|
|
|
ENTRY(164) , ENTRY(165) , ENTRY(166) , ENTRY(167) , |
24794
|
|
|
|
|
|
|
ENTRY(168) , ENTRY(169) , ENTRY(170) , ENTRY(171) , |
24795
|
|
|
|
|
|
|
ENTRY(172) , ENTRY(173) , ENTRY(174) , ENTRY(175) , |
24796
|
|
|
|
|
|
|
ENTRY(176) , ENTRY(177) , ENTRY(178) , ENTRY(179) , |
24797
|
|
|
|
|
|
|
ENTRY(180) , ENTRY(181) , ENTRY(182) , ENTRY(183) , |
24798
|
|
|
|
|
|
|
ENTRY(184) , ENTRY(185) , ENTRY(186) , ENTRY(187) , |
24799
|
|
|
|
|
|
|
ENTRY(188) , ENTRY(189) , ENTRY(190) , ENTRY(191) , |
24800
|
|
|
|
|
|
|
ENTRY(192) , ENTRY(193) , ENTRY(194) , ENTRY(195) , |
24801
|
|
|
|
|
|
|
ENTRY(196) , ENTRY(197) , ENTRY(198) , ENTRY(199) , |
24802
|
|
|
|
|
|
|
ENTRY(200) , ENTRY(201) , ENTRY(202) , ENTRY(203) , |
24803
|
|
|
|
|
|
|
ENTRY(204) , ENTRY(205) , ENTRY(206) , ENTRY(207) , |
24804
|
|
|
|
|
|
|
ENTRY(208) , ENTRY(209) , ENTRY(210) , ENTRY(211) , |
24805
|
|
|
|
|
|
|
ENTRY(212) , ENTRY(213) , ENTRY(214) , ENTRY(215) , |
24806
|
|
|
|
|
|
|
ENTRY(216) , ENTRY(217) , ENTRY(218) , ENTRY(219) , |
24807
|
|
|
|
|
|
|
ENTRY(220) , ENTRY(221) , ENTRY(222) , ENTRY(223) , |
24808
|
|
|
|
|
|
|
ENTRY(224) , ENTRY(225) , ENTRY(226) , ENTRY(227) , |
24809
|
|
|
|
|
|
|
ENTRY(228) , ENTRY(229) , ENTRY(230) , ENTRY(231) , |
24810
|
|
|
|
|
|
|
ENTRY(232) , ENTRY(233) , ENTRY(234) , ENTRY(235) , |
24811
|
|
|
|
|
|
|
ENTRY(236) , ENTRY(237) , ENTRY(238) , ENTRY(239) , |
24812
|
|
|
|
|
|
|
ENTRY(240) , ENTRY(241) , ENTRY(242) , ENTRY(243) , |
24813
|
|
|
|
|
|
|
ENTRY(244) , ENTRY(245) , ENTRY(246) , ENTRY(247) , |
24814
|
|
|
|
|
|
|
ENTRY(248) , ENTRY(249) , ENTRY(250) , ENTRY(251) , |
24815
|
|
|
|
|
|
|
ENTRY(252) , ENTRY(253) , ENTRY(254) , ENTRY(255) , |
24816
|
|
|
|
|
|
|
#undef ENTRY |
24817
|
|
|
|
|
|
|
|
24818
|
|
|
|
|
|
|
|
24819
|
|
|
|
|
|
|
HUFFDEC_EXCEPTIONAL | HUFFDEC_END_OF_BLOCK, |
24820
|
|
|
|
|
|
|
|
24821
|
|
|
|
|
|
|
|
24822
|
|
|
|
|
|
|
#define ENTRY(length_base, num_extra_bits) \ |
24823
|
|
|
|
|
|
|
(((u32)(length_base) << 16) | (num_extra_bits)) |
24824
|
|
|
|
|
|
|
ENTRY(3 , 0) , ENTRY(4 , 0) , ENTRY(5 , 0) , ENTRY(6 , 0), |
24825
|
|
|
|
|
|
|
ENTRY(7 , 0) , ENTRY(8 , 0) , ENTRY(9 , 0) , ENTRY(10 , 0), |
24826
|
|
|
|
|
|
|
ENTRY(11 , 1) , ENTRY(13 , 1) , ENTRY(15 , 1) , ENTRY(17 , 1), |
24827
|
|
|
|
|
|
|
ENTRY(19 , 2) , ENTRY(23 , 2) , ENTRY(27 , 2) , ENTRY(31 , 2), |
24828
|
|
|
|
|
|
|
ENTRY(35 , 3) , ENTRY(43 , 3) , ENTRY(51 , 3) , ENTRY(59 , 3), |
24829
|
|
|
|
|
|
|
ENTRY(67 , 4) , ENTRY(83 , 4) , ENTRY(99 , 4) , ENTRY(115, 4), |
24830
|
|
|
|
|
|
|
ENTRY(131, 5) , ENTRY(163, 5) , ENTRY(195, 5) , ENTRY(227, 5), |
24831
|
|
|
|
|
|
|
ENTRY(258, 0) , ENTRY(258, 0) , ENTRY(258, 0) , |
24832
|
|
|
|
|
|
|
#undef ENTRY |
24833
|
|
|
|
|
|
|
}; |
24834
|
|
|
|
|
|
|
|
24835
|
|
|
|
|
|
|
|
24836
|
|
|
|
|
|
|
#define OFFSET_MAXBITS (DEFLATE_MAX_OFFSET_CODEWORD_LEN + \ |
24837
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_OFFSET_BITS) |
24838
|
|
|
|
|
|
|
#define OFFSET_MAXFASTBITS (OFFSET_TABLEBITS + \ |
24839
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_OFFSET_BITS) |
24840
|
|
|
|
|
|
|
|
24841
|
|
|
|
|
|
|
|
24842
|
|
|
|
|
|
|
static const u32 offset_decode_results[] = { |
24843
|
|
|
|
|
|
|
#define ENTRY(offset_base, num_extra_bits) \ |
24844
|
|
|
|
|
|
|
(((u32)(offset_base) << 16) | (num_extra_bits)) |
24845
|
|
|
|
|
|
|
ENTRY(1 , 0) , ENTRY(2 , 0) , ENTRY(3 , 0) , ENTRY(4 , 0) , |
24846
|
|
|
|
|
|
|
ENTRY(5 , 1) , ENTRY(7 , 1) , ENTRY(9 , 2) , ENTRY(13 , 2) , |
24847
|
|
|
|
|
|
|
ENTRY(17 , 3) , ENTRY(25 , 3) , ENTRY(33 , 4) , ENTRY(49 , 4) , |
24848
|
|
|
|
|
|
|
ENTRY(65 , 5) , ENTRY(97 , 5) , ENTRY(129 , 6) , ENTRY(193 , 6) , |
24849
|
|
|
|
|
|
|
ENTRY(257 , 7) , ENTRY(385 , 7) , ENTRY(513 , 8) , ENTRY(769 , 8) , |
24850
|
|
|
|
|
|
|
ENTRY(1025 , 9) , ENTRY(1537 , 9) , ENTRY(2049 , 10) , ENTRY(3073 , 10) , |
24851
|
|
|
|
|
|
|
ENTRY(4097 , 11) , ENTRY(6145 , 11) , ENTRY(8193 , 12) , ENTRY(12289 , 12) , |
24852
|
|
|
|
|
|
|
ENTRY(16385 , 13) , ENTRY(24577 , 13) , ENTRY(24577 , 13) , ENTRY(24577 , 13) , |
24853
|
|
|
|
|
|
|
#undef ENTRY |
24854
|
|
|
|
|
|
|
}; |
24855
|
|
|
|
|
|
|
|
24856
|
|
|
|
|
|
|
|
24857
|
|
|
|
|
|
|
struct libdeflate_decompressor { |
24858
|
|
|
|
|
|
|
|
24859
|
|
|
|
|
|
|
|
24860
|
|
|
|
|
|
|
|
24861
|
|
|
|
|
|
|
union { |
24862
|
|
|
|
|
|
|
u8 precode_lens[DEFLATE_NUM_PRECODE_SYMS]; |
24863
|
|
|
|
|
|
|
|
24864
|
|
|
|
|
|
|
struct { |
24865
|
|
|
|
|
|
|
u8 lens[DEFLATE_NUM_LITLEN_SYMS + |
24866
|
|
|
|
|
|
|
DEFLATE_NUM_OFFSET_SYMS + |
24867
|
|
|
|
|
|
|
DEFLATE_MAX_LENS_OVERRUN]; |
24868
|
|
|
|
|
|
|
|
24869
|
|
|
|
|
|
|
u32 precode_decode_table[PRECODE_ENOUGH]; |
24870
|
|
|
|
|
|
|
} l; |
24871
|
|
|
|
|
|
|
|
24872
|
|
|
|
|
|
|
u32 litlen_decode_table[LITLEN_ENOUGH]; |
24873
|
|
|
|
|
|
|
} u; |
24874
|
|
|
|
|
|
|
|
24875
|
|
|
|
|
|
|
u32 offset_decode_table[OFFSET_ENOUGH]; |
24876
|
|
|
|
|
|
|
|
24877
|
|
|
|
|
|
|
|
24878
|
|
|
|
|
|
|
u16 sorted_syms[DEFLATE_MAX_NUM_SYMS]; |
24879
|
|
|
|
|
|
|
|
24880
|
|
|
|
|
|
|
bool static_codes_loaded; |
24881
|
|
|
|
|
|
|
unsigned litlen_tablebits; |
24882
|
|
|
|
|
|
|
|
24883
|
|
|
|
|
|
|
|
24884
|
|
|
|
|
|
|
free_func_t free_func; |
24885
|
|
|
|
|
|
|
}; |
24886
|
|
|
|
|
|
|
|
24887
|
|
|
|
|
|
|
|
24888
|
|
|
|
|
|
|
static bool |
24889
|
87
|
|
|
|
|
|
build_decode_table(u32 decode_table[], |
24890
|
|
|
|
|
|
|
const u8 lens[], |
24891
|
|
|
|
|
|
|
const unsigned num_syms, |
24892
|
|
|
|
|
|
|
const u32 decode_results[], |
24893
|
|
|
|
|
|
|
unsigned table_bits, |
24894
|
|
|
|
|
|
|
unsigned max_codeword_len, |
24895
|
|
|
|
|
|
|
u16 *sorted_syms, |
24896
|
|
|
|
|
|
|
unsigned *table_bits_ret) |
24897
|
|
|
|
|
|
|
{ |
24898
|
|
|
|
|
|
|
unsigned len_counts[DEFLATE_MAX_CODEWORD_LEN + 1]; |
24899
|
|
|
|
|
|
|
unsigned offsets[DEFLATE_MAX_CODEWORD_LEN + 1]; |
24900
|
|
|
|
|
|
|
unsigned sym; |
24901
|
|
|
|
|
|
|
unsigned codeword; |
24902
|
|
|
|
|
|
|
unsigned len; |
24903
|
|
|
|
|
|
|
unsigned count; |
24904
|
|
|
|
|
|
|
u32 codespace_used; |
24905
|
|
|
|
|
|
|
unsigned cur_table_end; |
24906
|
|
|
|
|
|
|
unsigned subtable_prefix; |
24907
|
|
|
|
|
|
|
unsigned subtable_start; |
24908
|
|
|
|
|
|
|
unsigned subtable_bits; |
24909
|
|
|
|
|
|
|
|
24910
|
|
|
|
|
|
|
|
24911
|
1439
|
100
|
|
|
|
|
for (len = 0; len <= max_codeword_len; len++) |
24912
|
1352
|
|
|
|
|
|
len_counts[len] = 0; |
24913
|
13235
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) |
24914
|
13148
|
|
|
|
|
|
len_counts[lens[sym]]++; |
24915
|
|
|
|
|
|
|
|
24916
|
|
|
|
|
|
|
|
24917
|
715
|
50
|
|
|
|
|
while (max_codeword_len > 1 && len_counts[max_codeword_len] == 0) |
|
|
100
|
|
|
|
|
|
24918
|
628
|
|
|
|
|
|
max_codeword_len--; |
24919
|
87
|
100
|
|
|
|
|
if (table_bits_ret != NULL) { |
24920
|
41
|
|
|
|
|
|
table_bits = MIN(table_bits, max_codeword_len); |
24921
|
41
|
|
|
|
|
|
*table_bits_ret = table_bits; |
24922
|
|
|
|
|
|
|
} |
24923
|
|
|
|
|
|
|
|
24924
|
|
|
|
|
|
|
|
24925
|
|
|
|
|
|
|
|
24926
|
|
|
|
|
|
|
|
24927
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(codespace_used) == 4); |
24928
|
|
|
|
|
|
|
STATIC_ASSERT(UINT32_MAX / (1U << (DEFLATE_MAX_CODEWORD_LEN - 1)) >= |
24929
|
|
|
|
|
|
|
DEFLATE_MAX_NUM_SYMS); |
24930
|
|
|
|
|
|
|
|
24931
|
87
|
|
|
|
|
|
offsets[0] = 0; |
24932
|
87
|
|
|
|
|
|
offsets[1] = len_counts[0]; |
24933
|
87
|
|
|
|
|
|
codespace_used = 0; |
24934
|
637
|
100
|
|
|
|
|
for (len = 1; len < max_codeword_len; len++) { |
24935
|
550
|
|
|
|
|
|
offsets[len + 1] = offsets[len] + len_counts[len]; |
24936
|
550
|
|
|
|
|
|
codespace_used = (codespace_used << 1) + len_counts[len]; |
24937
|
|
|
|
|
|
|
} |
24938
|
87
|
|
|
|
|
|
codespace_used = (codespace_used << 1) + len_counts[len]; |
24939
|
|
|
|
|
|
|
|
24940
|
13235
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) |
24941
|
13148
|
|
|
|
|
|
sorted_syms[offsets[lens[sym]]++] = sym; |
24942
|
|
|
|
|
|
|
|
24943
|
87
|
|
|
|
|
|
sorted_syms += offsets[0]; |
24944
|
|
|
|
|
|
|
|
24945
|
|
|
|
|
|
|
|
24946
|
|
|
|
|
|
|
|
24947
|
|
|
|
|
|
|
|
24948
|
|
|
|
|
|
|
|
24949
|
|
|
|
|
|
|
|
24950
|
87
|
50
|
|
|
|
|
if (unlikely(codespace_used > (1U << max_codeword_len))) |
24951
|
0
|
|
|
|
|
|
return false; |
24952
|
|
|
|
|
|
|
|
24953
|
|
|
|
|
|
|
|
24954
|
87
|
50
|
|
|
|
|
if (unlikely(codespace_used < (1U << max_codeword_len))) { |
24955
|
|
|
|
|
|
|
u32 entry; |
24956
|
|
|
|
|
|
|
unsigned i; |
24957
|
|
|
|
|
|
|
|
24958
|
|
|
|
|
|
|
|
24959
|
0
|
0
|
|
|
|
|
if (codespace_used == 0) { |
24960
|
0
|
|
|
|
|
|
sym = 0; |
24961
|
|
|
|
|
|
|
} else { |
24962
|
0
|
0
|
|
|
|
|
if (codespace_used != (1U << (max_codeword_len - 1)) || |
|
|
0
|
|
|
|
|
|
24963
|
0
|
|
|
|
|
|
len_counts[1] != 1) |
24964
|
0
|
|
|
|
|
|
return false; |
24965
|
0
|
|
|
|
|
|
sym = sorted_syms[0]; |
24966
|
|
|
|
|
|
|
} |
24967
|
0
|
|
|
|
|
|
entry = make_decode_table_entry(decode_results, sym, 1); |
24968
|
0
|
0
|
|
|
|
|
for (i = 0; i < (1U << table_bits); i++) |
24969
|
0
|
|
|
|
|
|
decode_table[i] = entry; |
24970
|
0
|
|
|
|
|
|
return true; |
24971
|
|
|
|
|
|
|
} |
24972
|
|
|
|
|
|
|
|
24973
|
|
|
|
|
|
|
|
24974
|
87
|
|
|
|
|
|
codeword = 0; |
24975
|
87
|
|
|
|
|
|
len = 1; |
24976
|
480
|
100
|
|
|
|
|
while ((count = len_counts[len]) == 0) |
24977
|
393
|
|
|
|
|
|
len++; |
24978
|
87
|
|
|
|
|
|
cur_table_end = 1U << len; |
24979
|
241
|
100
|
|
|
|
|
while (len <= table_bits) { |
24980
|
|
|
|
|
|
|
|
24981
|
|
|
|
|
|
|
do { |
24982
|
|
|
|
|
|
|
unsigned bit; |
24983
|
|
|
|
|
|
|
|
24984
|
|
|
|
|
|
|
|
24985
|
24320
|
|
|
|
|
|
decode_table[codeword] = |
24986
|
24320
|
|
|
|
|
|
make_decode_table_entry(decode_results, |
24987
|
12160
|
|
|
|
|
|
*sorted_syms++, len); |
24988
|
|
|
|
|
|
|
|
24989
|
12160
|
100
|
|
|
|
|
if (codeword == cur_table_end - 1) { |
24990
|
|
|
|
|
|
|
|
24991
|
190
|
100
|
|
|
|
|
for (; len < table_bits; len++) { |
24992
|
111
|
|
|
|
|
|
memcpy(&decode_table[cur_table_end], |
24993
|
|
|
|
|
|
|
decode_table, |
24994
|
|
|
|
|
|
|
cur_table_end * |
24995
|
|
|
|
|
|
|
sizeof(decode_table[0])); |
24996
|
111
|
|
|
|
|
|
cur_table_end <<= 1; |
24997
|
|
|
|
|
|
|
} |
24998
|
79
|
|
|
|
|
|
return true; |
24999
|
|
|
|
|
|
|
} |
25000
|
|
|
|
|
|
|
|
25001
|
24162
|
|
|
|
|
|
bit = 1U << bsr32(codeword ^ (cur_table_end - 1)); |
25002
|
12081
|
|
|
|
|
|
codeword &= bit - 1; |
25003
|
12081
|
|
|
|
|
|
codeword |= bit; |
25004
|
12081
|
100
|
|
|
|
|
} while (--count); |
25005
|
|
|
|
|
|
|
|
25006
|
|
|
|
|
|
|
|
25007
|
|
|
|
|
|
|
do { |
25008
|
157
|
100
|
|
|
|
|
if (++len <= table_bits) { |
25009
|
149
|
|
|
|
|
|
memcpy(&decode_table[cur_table_end], |
25010
|
|
|
|
|
|
|
decode_table, |
25011
|
|
|
|
|
|
|
cur_table_end * sizeof(decode_table[0])); |
25012
|
149
|
|
|
|
|
|
cur_table_end <<= 1; |
25013
|
|
|
|
|
|
|
} |
25014
|
157
|
100
|
|
|
|
|
} while ((count = len_counts[len]) == 0); |
25015
|
|
|
|
|
|
|
} |
25016
|
|
|
|
|
|
|
|
25017
|
|
|
|
|
|
|
|
25018
|
8
|
|
|
|
|
|
cur_table_end = 1U << table_bits; |
25019
|
8
|
|
|
|
|
|
subtable_prefix = -1; |
25020
|
8
|
|
|
|
|
|
subtable_start = 0; |
25021
|
|
|
|
|
|
|
for (;;) { |
25022
|
|
|
|
|
|
|
u32 entry; |
25023
|
|
|
|
|
|
|
unsigned i; |
25024
|
|
|
|
|
|
|
unsigned stride; |
25025
|
|
|
|
|
|
|
unsigned bit; |
25026
|
|
|
|
|
|
|
|
25027
|
|
|
|
|
|
|
|
25028
|
38
|
100
|
|
|
|
|
if ((codeword & ((1U << table_bits) - 1)) != subtable_prefix) { |
25029
|
19
|
|
|
|
|
|
subtable_prefix = (codeword & ((1U << table_bits) - 1)); |
25030
|
19
|
|
|
|
|
|
subtable_start = cur_table_end; |
25031
|
|
|
|
|
|
|
|
25032
|
19
|
|
|
|
|
|
subtable_bits = len - table_bits; |
25033
|
19
|
|
|
|
|
|
codespace_used = count; |
25034
|
19
|
50
|
|
|
|
|
while (codespace_used < (1U << subtable_bits)) { |
25035
|
0
|
|
|
|
|
|
subtable_bits++; |
25036
|
0
|
|
|
|
|
|
codespace_used = (codespace_used << 1) + |
25037
|
0
|
|
|
|
|
|
len_counts[table_bits + subtable_bits]; |
25038
|
|
|
|
|
|
|
} |
25039
|
19
|
|
|
|
|
|
cur_table_end = subtable_start + (1U << subtable_bits); |
25040
|
|
|
|
|
|
|
|
25041
|
|
|
|
|
|
|
|
25042
|
19
|
|
|
|
|
|
decode_table[subtable_prefix] = |
25043
|
19
|
|
|
|
|
|
((u32)subtable_start << 16) | |
25044
|
|
|
|
|
|
|
HUFFDEC_EXCEPTIONAL | |
25045
|
19
|
|
|
|
|
|
HUFFDEC_SUBTABLE_POINTER | |
25046
|
38
|
|
|
|
|
|
(subtable_bits << 8) | table_bits; |
25047
|
|
|
|
|
|
|
} |
25048
|
|
|
|
|
|
|
|
25049
|
|
|
|
|
|
|
|
25050
|
76
|
|
|
|
|
|
entry = make_decode_table_entry(decode_results, *sorted_syms++, |
25051
|
|
|
|
|
|
|
len - table_bits); |
25052
|
38
|
|
|
|
|
|
i = subtable_start + (codeword >> table_bits); |
25053
|
38
|
|
|
|
|
|
stride = 1U << (len - table_bits); |
25054
|
|
|
|
|
|
|
do { |
25055
|
38
|
|
|
|
|
|
decode_table[i] = entry; |
25056
|
38
|
|
|
|
|
|
i += stride; |
25057
|
38
|
50
|
|
|
|
|
} while (i < cur_table_end); |
25058
|
|
|
|
|
|
|
|
25059
|
|
|
|
|
|
|
|
25060
|
38
|
100
|
|
|
|
|
if (codeword == (1U << len) - 1) |
25061
|
8
|
|
|
|
|
|
return true; |
25062
|
60
|
|
|
|
|
|
bit = 1U << bsr32(codeword ^ ((1U << len) - 1)); |
25063
|
30
|
|
|
|
|
|
codeword &= bit - 1; |
25064
|
30
|
|
|
|
|
|
codeword |= bit; |
25065
|
30
|
|
|
|
|
|
count--; |
25066
|
30
|
50
|
|
|
|
|
while (count == 0) |
25067
|
0
|
|
|
|
|
|
count = len_counts[++len]; |
25068
|
117
|
|
|
|
|
|
} |
25069
|
|
|
|
|
|
|
} |
25070
|
|
|
|
|
|
|
|
25071
|
|
|
|
|
|
|
|
25072
|
|
|
|
|
|
|
static bool |
25073
|
5
|
|
|
|
|
|
build_precode_decode_table(struct libdeflate_decompressor *d) |
25074
|
|
|
|
|
|
|
{ |
25075
|
|
|
|
|
|
|
|
25076
|
|
|
|
|
|
|
STATIC_ASSERT(PRECODE_TABLEBITS == 7 && PRECODE_ENOUGH == 128); |
25077
|
|
|
|
|
|
|
|
25078
|
|
|
|
|
|
|
STATIC_ASSERT(ARRAY_LEN(precode_decode_results) == |
25079
|
|
|
|
|
|
|
DEFLATE_NUM_PRECODE_SYMS); |
25080
|
|
|
|
|
|
|
|
25081
|
5
|
|
|
|
|
|
return build_decode_table(d->u.l.precode_decode_table, |
25082
|
5
|
|
|
|
|
|
d->u.precode_lens, |
25083
|
|
|
|
|
|
|
DEFLATE_NUM_PRECODE_SYMS, |
25084
|
|
|
|
|
|
|
precode_decode_results, |
25085
|
|
|
|
|
|
|
PRECODE_TABLEBITS, |
25086
|
|
|
|
|
|
|
DEFLATE_MAX_PRE_CODEWORD_LEN, |
25087
|
5
|
|
|
|
|
|
d->sorted_syms, |
25088
|
|
|
|
|
|
|
NULL); |
25089
|
|
|
|
|
|
|
} |
25090
|
|
|
|
|
|
|
|
25091
|
|
|
|
|
|
|
|
25092
|
|
|
|
|
|
|
static bool |
25093
|
41
|
|
|
|
|
|
build_litlen_decode_table(struct libdeflate_decompressor *d, |
25094
|
|
|
|
|
|
|
unsigned num_litlen_syms, unsigned num_offset_syms) |
25095
|
|
|
|
|
|
|
{ |
25096
|
|
|
|
|
|
|
|
25097
|
|
|
|
|
|
|
STATIC_ASSERT(LITLEN_TABLEBITS == 11 && LITLEN_ENOUGH == 2342); |
25098
|
|
|
|
|
|
|
|
25099
|
|
|
|
|
|
|
STATIC_ASSERT(ARRAY_LEN(litlen_decode_results) == |
25100
|
|
|
|
|
|
|
DEFLATE_NUM_LITLEN_SYMS); |
25101
|
|
|
|
|
|
|
|
25102
|
41
|
|
|
|
|
|
return build_decode_table(d->u.litlen_decode_table, |
25103
|
41
|
|
|
|
|
|
d->u.l.lens, |
25104
|
|
|
|
|
|
|
num_litlen_syms, |
25105
|
|
|
|
|
|
|
litlen_decode_results, |
25106
|
|
|
|
|
|
|
LITLEN_TABLEBITS, |
25107
|
|
|
|
|
|
|
DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
25108
|
41
|
|
|
|
|
|
d->sorted_syms, |
25109
|
|
|
|
|
|
|
&d->litlen_tablebits); |
25110
|
|
|
|
|
|
|
} |
25111
|
|
|
|
|
|
|
|
25112
|
|
|
|
|
|
|
|
25113
|
|
|
|
|
|
|
static bool |
25114
|
41
|
|
|
|
|
|
build_offset_decode_table(struct libdeflate_decompressor *d, |
25115
|
|
|
|
|
|
|
unsigned num_litlen_syms, unsigned num_offset_syms) |
25116
|
|
|
|
|
|
|
{ |
25117
|
|
|
|
|
|
|
|
25118
|
|
|
|
|
|
|
STATIC_ASSERT(OFFSET_TABLEBITS == 8 && OFFSET_ENOUGH == 402); |
25119
|
|
|
|
|
|
|
|
25120
|
|
|
|
|
|
|
STATIC_ASSERT(ARRAY_LEN(offset_decode_results) == |
25121
|
|
|
|
|
|
|
DEFLATE_NUM_OFFSET_SYMS); |
25122
|
|
|
|
|
|
|
|
25123
|
41
|
|
|
|
|
|
return build_decode_table(d->offset_decode_table, |
25124
|
41
|
|
|
|
|
|
d->u.l.lens + num_litlen_syms, |
25125
|
|
|
|
|
|
|
num_offset_syms, |
25126
|
|
|
|
|
|
|
offset_decode_results, |
25127
|
|
|
|
|
|
|
OFFSET_TABLEBITS, |
25128
|
|
|
|
|
|
|
DEFLATE_MAX_OFFSET_CODEWORD_LEN, |
25129
|
41
|
|
|
|
|
|
d->sorted_syms, |
25130
|
|
|
|
|
|
|
NULL); |
25131
|
|
|
|
|
|
|
} |
25132
|
|
|
|
|
|
|
|
25133
|
|
|
|
|
|
|
|
25134
|
|
|
|
|
|
|
|
25135
|
|
|
|
|
|
|
typedef enum libdeflate_result (*decompress_func_t) |
25136
|
|
|
|
|
|
|
(struct libdeflate_decompressor * restrict d, |
25137
|
|
|
|
|
|
|
const void * restrict in, size_t in_nbytes, |
25138
|
|
|
|
|
|
|
void * restrict out, size_t out_nbytes_avail, |
25139
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret); |
25140
|
|
|
|
|
|
|
|
25141
|
|
|
|
|
|
|
#define FUNCNAME deflate_decompress_default |
25142
|
|
|
|
|
|
|
#undef ATTRIBUTES |
25143
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS |
25144
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS8 |
25145
|
|
|
|
|
|
|
/* #include "decompress_template.h" */ |
25146
|
|
|
|
|
|
|
|
25147
|
|
|
|
|
|
|
|
25148
|
|
|
|
|
|
|
|
25149
|
|
|
|
|
|
|
|
25150
|
|
|
|
|
|
|
#ifndef ATTRIBUTES |
25151
|
|
|
|
|
|
|
# define ATTRIBUTES |
25152
|
|
|
|
|
|
|
#endif |
25153
|
|
|
|
|
|
|
#ifndef EXTRACT_VARBITS |
25154
|
|
|
|
|
|
|
# define EXTRACT_VARBITS(word, count) ((word) & BITMASK(count)) |
25155
|
|
|
|
|
|
|
#endif |
25156
|
|
|
|
|
|
|
#ifndef EXTRACT_VARBITS8 |
25157
|
|
|
|
|
|
|
# define EXTRACT_VARBITS8(word, count) ((word) & BITMASK((u8)(count))) |
25158
|
|
|
|
|
|
|
#endif |
25159
|
|
|
|
|
|
|
|
25160
|
|
|
|
|
|
|
static enum libdeflate_result ATTRIBUTES MAYBE_UNUSED |
25161
|
40
|
|
|
|
|
|
FUNCNAME(struct libdeflate_decompressor * restrict d, |
25162
|
|
|
|
|
|
|
const void * restrict in, size_t in_nbytes, |
25163
|
|
|
|
|
|
|
void * restrict out, size_t out_nbytes_avail, |
25164
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret) |
25165
|
|
|
|
|
|
|
{ |
25166
|
40
|
|
|
|
|
|
u8 *out_next = out; |
25167
|
40
|
|
|
|
|
|
u8 * const out_end = out_next + out_nbytes_avail; |
25168
|
40
|
|
|
|
|
|
u8 * const out_fastloop_end = |
25169
|
40
|
|
|
|
|
|
out_end - MIN(out_nbytes_avail, FASTLOOP_MAX_BYTES_WRITTEN); |
25170
|
|
|
|
|
|
|
|
25171
|
|
|
|
|
|
|
|
25172
|
40
|
|
|
|
|
|
const u8 *in_next = in; |
25173
|
40
|
|
|
|
|
|
const u8 * const in_end = in_next + in_nbytes; |
25174
|
40
|
|
|
|
|
|
const u8 * const in_fastloop_end = |
25175
|
40
|
|
|
|
|
|
in_end - MIN(in_nbytes, FASTLOOP_MAX_BYTES_READ); |
25176
|
40
|
|
|
|
|
|
bitbuf_t bitbuf = 0; |
25177
|
|
|
|
|
|
|
bitbuf_t saved_bitbuf; |
25178
|
40
|
|
|
|
|
|
u32 bitsleft = 0; |
25179
|
40
|
|
|
|
|
|
size_t overread_count = 0; |
25180
|
|
|
|
|
|
|
|
25181
|
|
|
|
|
|
|
bool is_final_block; |
25182
|
|
|
|
|
|
|
unsigned block_type; |
25183
|
|
|
|
|
|
|
unsigned num_litlen_syms; |
25184
|
|
|
|
|
|
|
unsigned num_offset_syms; |
25185
|
|
|
|
|
|
|
bitbuf_t litlen_tablemask; |
25186
|
|
|
|
|
|
|
u32 entry; |
25187
|
|
|
|
|
|
|
|
25188
|
|
|
|
|
|
|
next_block: |
25189
|
|
|
|
|
|
|
|
25190
|
|
|
|
|
|
|
; |
25191
|
|
|
|
|
|
|
|
25192
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME(1 + 2 + 5 + 5 + 4 + 3)); |
25193
|
82
|
50
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
25194
|
|
|
|
|
|
|
|
25195
|
|
|
|
|
|
|
|
25196
|
41
|
|
|
|
|
|
is_final_block = bitbuf & BITMASK(1); |
25197
|
|
|
|
|
|
|
|
25198
|
|
|
|
|
|
|
|
25199
|
41
|
|
|
|
|
|
block_type = (bitbuf >> 1) & BITMASK(2); |
25200
|
|
|
|
|
|
|
|
25201
|
41
|
100
|
|
|
|
|
if (block_type == DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN) { |
25202
|
|
|
|
|
|
|
|
25203
|
|
|
|
|
|
|
|
25204
|
|
|
|
|
|
|
|
25205
|
|
|
|
|
|
|
|
25206
|
|
|
|
|
|
|
static const u8 deflate_precode_lens_permutation[DEFLATE_NUM_PRECODE_SYMS] = { |
25207
|
|
|
|
|
|
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
25208
|
|
|
|
|
|
|
}; |
25209
|
|
|
|
|
|
|
|
25210
|
|
|
|
|
|
|
unsigned num_explicit_precode_lens; |
25211
|
|
|
|
|
|
|
unsigned i; |
25212
|
|
|
|
|
|
|
|
25213
|
|
|
|
|
|
|
|
25214
|
|
|
|
|
|
|
|
25215
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_LITLEN_SYMS == 257 + BITMASK(5)); |
25216
|
5
|
|
|
|
|
|
num_litlen_syms = 257 + ((bitbuf >> 3) & BITMASK(5)); |
25217
|
|
|
|
|
|
|
|
25218
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_OFFSET_SYMS == 1 + BITMASK(5)); |
25219
|
5
|
|
|
|
|
|
num_offset_syms = 1 + ((bitbuf >> 8) & BITMASK(5)); |
25220
|
|
|
|
|
|
|
|
25221
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_PRECODE_SYMS == 4 + BITMASK(4)); |
25222
|
5
|
|
|
|
|
|
num_explicit_precode_lens = 4 + ((bitbuf >> 13) & BITMASK(4)); |
25223
|
|
|
|
|
|
|
|
25224
|
5
|
|
|
|
|
|
d->static_codes_loaded = false; |
25225
|
|
|
|
|
|
|
|
25226
|
|
|
|
|
|
|
|
25227
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_PRE_CODEWORD_LEN == (1 << 3) - 1); |
25228
|
|
|
|
|
|
|
if (CAN_CONSUME(3 * (DEFLATE_NUM_PRECODE_SYMS - 1))) { |
25229
|
10
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[0]] = |
25230
|
5
|
|
|
|
|
|
(bitbuf >> 17) & BITMASK(3); |
25231
|
5
|
|
|
|
|
|
bitbuf >>= 20; |
25232
|
5
|
|
|
|
|
|
bitsleft -= 20; |
25233
|
10
|
50
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
25234
|
5
|
|
|
|
|
|
i = 1; |
25235
|
|
|
|
|
|
|
do { |
25236
|
65
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = |
25237
|
|
|
|
|
|
|
bitbuf & BITMASK(3); |
25238
|
65
|
|
|
|
|
|
bitbuf >>= 3; |
25239
|
65
|
|
|
|
|
|
bitsleft -= 3; |
25240
|
65
|
100
|
|
|
|
|
} while (++i < num_explicit_precode_lens); |
25241
|
|
|
|
|
|
|
} else { |
25242
|
|
|
|
|
|
|
bitbuf >>= 17; |
25243
|
|
|
|
|
|
|
bitsleft -= 17; |
25244
|
|
|
|
|
|
|
i = 0; |
25245
|
|
|
|
|
|
|
do { |
25246
|
|
|
|
|
|
|
if ((u8)bitsleft < 3) |
25247
|
|
|
|
|
|
|
REFILL_BITS(); |
25248
|
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = |
25249
|
|
|
|
|
|
|
bitbuf & BITMASK(3); |
25250
|
|
|
|
|
|
|
bitbuf >>= 3; |
25251
|
|
|
|
|
|
|
bitsleft -= 3; |
25252
|
|
|
|
|
|
|
} while (++i < num_explicit_precode_lens); |
25253
|
|
|
|
|
|
|
} |
25254
|
30
|
100
|
|
|
|
|
for (; i < DEFLATE_NUM_PRECODE_SYMS; i++) |
25255
|
25
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = 0; |
25256
|
|
|
|
|
|
|
|
25257
|
|
|
|
|
|
|
|
25258
|
5
|
50
|
|
|
|
|
SAFETY_CHECK(build_precode_decode_table(d)); |
25259
|
|
|
|
|
|
|
|
25260
|
|
|
|
|
|
|
|
25261
|
5
|
|
|
|
|
|
i = 0; |
25262
|
|
|
|
|
|
|
do { |
25263
|
|
|
|
|
|
|
unsigned presym; |
25264
|
|
|
|
|
|
|
u8 rep_val; |
25265
|
|
|
|
|
|
|
unsigned rep_count; |
25266
|
|
|
|
|
|
|
|
25267
|
674
|
100
|
|
|
|
|
if ((u8)bitsleft < DEFLATE_MAX_PRE_CODEWORD_LEN + 7) |
25268
|
110
|
50
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
25269
|
|
|
|
|
|
|
|
25270
|
|
|
|
|
|
|
|
25271
|
|
|
|
|
|
|
STATIC_ASSERT(PRECODE_TABLEBITS == DEFLATE_MAX_PRE_CODEWORD_LEN); |
25272
|
|
|
|
|
|
|
|
25273
|
|
|
|
|
|
|
|
25274
|
674
|
|
|
|
|
|
entry = d->u.l.precode_decode_table[ |
25275
|
674
|
|
|
|
|
|
bitbuf & BITMASK(DEFLATE_MAX_PRE_CODEWORD_LEN)]; |
25276
|
674
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25277
|
674
|
|
|
|
|
|
bitsleft -= entry; |
25278
|
674
|
|
|
|
|
|
presym = entry >> 16; |
25279
|
|
|
|
|
|
|
|
25280
|
674
|
100
|
|
|
|
|
if (presym < 16) { |
25281
|
|
|
|
|
|
|
|
25282
|
626
|
|
|
|
|
|
d->u.l.lens[i++] = presym; |
25283
|
626
|
|
|
|
|
|
continue; |
25284
|
|
|
|
|
|
|
} |
25285
|
|
|
|
|
|
|
|
25286
|
|
|
|
|
|
|
|
25287
|
|
|
|
|
|
|
|
25288
|
|
|
|
|
|
|
|
25289
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_LENS_OVERRUN == 138 - 1); |
25290
|
|
|
|
|
|
|
|
25291
|
48
|
100
|
|
|
|
|
if (presym == 16) { |
25292
|
|
|
|
|
|
|
|
25293
|
15
|
50
|
|
|
|
|
SAFETY_CHECK(i != 0); |
25294
|
15
|
|
|
|
|
|
rep_val = d->u.l.lens[i - 1]; |
25295
|
|
|
|
|
|
|
STATIC_ASSERT(3 + BITMASK(2) == 6); |
25296
|
15
|
|
|
|
|
|
rep_count = 3 + (bitbuf & BITMASK(2)); |
25297
|
15
|
|
|
|
|
|
bitbuf >>= 2; |
25298
|
15
|
|
|
|
|
|
bitsleft -= 2; |
25299
|
15
|
|
|
|
|
|
d->u.l.lens[i + 0] = rep_val; |
25300
|
15
|
|
|
|
|
|
d->u.l.lens[i + 1] = rep_val; |
25301
|
15
|
|
|
|
|
|
d->u.l.lens[i + 2] = rep_val; |
25302
|
15
|
|
|
|
|
|
d->u.l.lens[i + 3] = rep_val; |
25303
|
15
|
|
|
|
|
|
d->u.l.lens[i + 4] = rep_val; |
25304
|
15
|
|
|
|
|
|
d->u.l.lens[i + 5] = rep_val; |
25305
|
15
|
|
|
|
|
|
i += rep_count; |
25306
|
33
|
100
|
|
|
|
|
} else if (presym == 17) { |
25307
|
|
|
|
|
|
|
|
25308
|
|
|
|
|
|
|
STATIC_ASSERT(3 + BITMASK(3) == 10); |
25309
|
15
|
|
|
|
|
|
rep_count = 3 + (bitbuf & BITMASK(3)); |
25310
|
15
|
|
|
|
|
|
bitbuf >>= 3; |
25311
|
15
|
|
|
|
|
|
bitsleft -= 3; |
25312
|
15
|
|
|
|
|
|
d->u.l.lens[i + 0] = 0; |
25313
|
15
|
|
|
|
|
|
d->u.l.lens[i + 1] = 0; |
25314
|
15
|
|
|
|
|
|
d->u.l.lens[i + 2] = 0; |
25315
|
15
|
|
|
|
|
|
d->u.l.lens[i + 3] = 0; |
25316
|
15
|
|
|
|
|
|
d->u.l.lens[i + 4] = 0; |
25317
|
15
|
|
|
|
|
|
d->u.l.lens[i + 5] = 0; |
25318
|
15
|
|
|
|
|
|
d->u.l.lens[i + 6] = 0; |
25319
|
15
|
|
|
|
|
|
d->u.l.lens[i + 7] = 0; |
25320
|
15
|
|
|
|
|
|
d->u.l.lens[i + 8] = 0; |
25321
|
15
|
|
|
|
|
|
d->u.l.lens[i + 9] = 0; |
25322
|
15
|
|
|
|
|
|
i += rep_count; |
25323
|
|
|
|
|
|
|
} else { |
25324
|
|
|
|
|
|
|
|
25325
|
|
|
|
|
|
|
STATIC_ASSERT(11 + BITMASK(7) == 138); |
25326
|
18
|
|
|
|
|
|
rep_count = 11 + (bitbuf & BITMASK(7)); |
25327
|
18
|
|
|
|
|
|
bitbuf >>= 7; |
25328
|
18
|
|
|
|
|
|
bitsleft -= 7; |
25329
|
18
|
|
|
|
|
|
memset(&d->u.l.lens[i], 0, |
25330
|
|
|
|
|
|
|
rep_count * sizeof(d->u.l.lens[i])); |
25331
|
18
|
|
|
|
|
|
i += rep_count; |
25332
|
|
|
|
|
|
|
} |
25333
|
674
|
100
|
|
|
|
|
} while (i < num_litlen_syms + num_offset_syms); |
25334
|
|
|
|
|
|
|
|
25335
|
|
|
|
|
|
|
|
25336
|
5
|
50
|
|
|
|
|
SAFETY_CHECK(i == num_litlen_syms + num_offset_syms); |
25337
|
|
|
|
|
|
|
|
25338
|
36
|
50
|
|
|
|
|
} else if (block_type == DEFLATE_BLOCKTYPE_UNCOMPRESSED) { |
25339
|
|
|
|
|
|
|
u16 len, nlen; |
25340
|
|
|
|
|
|
|
|
25341
|
|
|
|
|
|
|
|
25342
|
|
|
|
|
|
|
|
25343
|
0
|
|
|
|
|
|
bitsleft -= 3; |
25344
|
|
|
|
|
|
|
|
25345
|
|
|
|
|
|
|
|
25346
|
0
|
|
|
|
|
|
bitsleft = (u8)bitsleft; |
25347
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(overread_count <= (bitsleft >> 3)); |
25348
|
0
|
|
|
|
|
|
in_next -= (bitsleft >> 3) - overread_count; |
25349
|
0
|
|
|
|
|
|
overread_count = 0; |
25350
|
0
|
|
|
|
|
|
bitbuf = 0; |
25351
|
0
|
|
|
|
|
|
bitsleft = 0; |
25352
|
|
|
|
|
|
|
|
25353
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(in_end - in_next >= 4); |
25354
|
0
|
|
|
|
|
|
len = get_unaligned_le16(in_next); |
25355
|
0
|
|
|
|
|
|
nlen = get_unaligned_le16(in_next + 2); |
25356
|
0
|
|
|
|
|
|
in_next += 4; |
25357
|
|
|
|
|
|
|
|
25358
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(len == (u16)~nlen); |
25359
|
0
|
0
|
|
|
|
|
if (unlikely(len > out_end - out_next)) |
25360
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
25361
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(len <= in_end - in_next); |
25362
|
|
|
|
|
|
|
|
25363
|
0
|
|
|
|
|
|
memcpy(out_next, in_next, len); |
25364
|
0
|
|
|
|
|
|
in_next += len; |
25365
|
0
|
|
|
|
|
|
out_next += len; |
25366
|
|
|
|
|
|
|
|
25367
|
0
|
|
|
|
|
|
goto block_done; |
25368
|
|
|
|
|
|
|
|
25369
|
|
|
|
|
|
|
} else { |
25370
|
|
|
|
|
|
|
unsigned i; |
25371
|
|
|
|
|
|
|
|
25372
|
36
|
50
|
|
|
|
|
SAFETY_CHECK(block_type == DEFLATE_BLOCKTYPE_STATIC_HUFFMAN); |
25373
|
|
|
|
|
|
|
|
25374
|
|
|
|
|
|
|
|
25375
|
|
|
|
|
|
|
|
25376
|
36
|
|
|
|
|
|
bitbuf >>= 3; |
25377
|
36
|
|
|
|
|
|
bitsleft -= 3; |
25378
|
|
|
|
|
|
|
|
25379
|
36
|
50
|
|
|
|
|
if (d->static_codes_loaded) |
25380
|
0
|
|
|
|
|
|
goto have_decode_tables; |
25381
|
|
|
|
|
|
|
|
25382
|
36
|
|
|
|
|
|
d->static_codes_loaded = true; |
25383
|
|
|
|
|
|
|
|
25384
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_LITLEN_SYMS == 288); |
25385
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_OFFSET_SYMS == 32); |
25386
|
|
|
|
|
|
|
|
25387
|
5220
|
100
|
|
|
|
|
for (i = 0; i < 144; i++) |
25388
|
5184
|
|
|
|
|
|
d->u.l.lens[i] = 8; |
25389
|
4068
|
100
|
|
|
|
|
for (; i < 256; i++) |
25390
|
4032
|
|
|
|
|
|
d->u.l.lens[i] = 9; |
25391
|
900
|
100
|
|
|
|
|
for (; i < 280; i++) |
25392
|
864
|
|
|
|
|
|
d->u.l.lens[i] = 7; |
25393
|
324
|
100
|
|
|
|
|
for (; i < 288; i++) |
25394
|
288
|
|
|
|
|
|
d->u.l.lens[i] = 8; |
25395
|
|
|
|
|
|
|
|
25396
|
1188
|
100
|
|
|
|
|
for (; i < 288 + 32; i++) |
25397
|
1152
|
|
|
|
|
|
d->u.l.lens[i] = 5; |
25398
|
|
|
|
|
|
|
|
25399
|
36
|
|
|
|
|
|
num_litlen_syms = 288; |
25400
|
36
|
|
|
|
|
|
num_offset_syms = 32; |
25401
|
|
|
|
|
|
|
} |
25402
|
|
|
|
|
|
|
|
25403
|
|
|
|
|
|
|
|
25404
|
|
|
|
|
|
|
|
25405
|
41
|
50
|
|
|
|
|
SAFETY_CHECK(build_offset_decode_table(d, num_litlen_syms, num_offset_syms)); |
25406
|
41
|
50
|
|
|
|
|
SAFETY_CHECK(build_litlen_decode_table(d, num_litlen_syms, num_offset_syms)); |
25407
|
|
|
|
|
|
|
have_decode_tables: |
25408
|
41
|
|
|
|
|
|
litlen_tablemask = BITMASK(d->litlen_tablebits); |
25409
|
|
|
|
|
|
|
|
25410
|
|
|
|
|
|
|
|
25411
|
41
|
50
|
|
|
|
|
if (in_next >= in_fastloop_end || out_next >= out_fastloop_end) |
|
|
50
|
|
|
|
|
|
25412
|
|
|
|
|
|
|
goto generic_loop; |
25413
|
41
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25414
|
41
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25415
|
|
|
|
|
|
|
do { |
25416
|
|
|
|
|
|
|
u32 length, offset, lit; |
25417
|
|
|
|
|
|
|
const u8 *src; |
25418
|
|
|
|
|
|
|
u8 *dst; |
25419
|
|
|
|
|
|
|
|
25420
|
|
|
|
|
|
|
|
25421
|
10151
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25422
|
10151
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25423
|
10151
|
|
|
|
|
|
bitsleft -= entry; |
25424
|
|
|
|
|
|
|
|
25425
|
|
|
|
|
|
|
|
25426
|
10151
|
100
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
25427
|
|
|
|
|
|
|
|
25428
|
|
|
|
|
|
|
if ( |
25429
|
|
|
|
|
|
|
CAN_CONSUME_AND_THEN_PRELOAD(2 * LITLEN_TABLEBITS + |
25430
|
|
|
|
|
|
|
LENGTH_MAXBITS, |
25431
|
|
|
|
|
|
|
OFFSET_TABLEBITS) && |
25432
|
|
|
|
|
|
|
|
25433
|
|
|
|
|
|
|
CAN_CONSUME_AND_THEN_PRELOAD(2 * LITLEN_TABLEBITS + |
25434
|
|
|
|
|
|
|
DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
25435
|
|
|
|
|
|
|
LITLEN_TABLEBITS)) { |
25436
|
|
|
|
|
|
|
|
25437
|
3886
|
|
|
|
|
|
lit = entry >> 16; |
25438
|
3886
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25439
|
3886
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25440
|
3886
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25441
|
3886
|
|
|
|
|
|
bitsleft -= entry; |
25442
|
3886
|
|
|
|
|
|
*out_next++ = lit; |
25443
|
3886
|
100
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
25444
|
|
|
|
|
|
|
|
25445
|
2617
|
|
|
|
|
|
lit = entry >> 16; |
25446
|
2617
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25447
|
2617
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25448
|
2617
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25449
|
2617
|
|
|
|
|
|
bitsleft -= entry; |
25450
|
2617
|
|
|
|
|
|
*out_next++ = lit; |
25451
|
2617
|
100
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
25452
|
|
|
|
|
|
|
|
25453
|
1951
|
|
|
|
|
|
lit = entry >> 16; |
25454
|
1951
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25455
|
1951
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25456
|
1951
|
|
|
|
|
|
*out_next++ = lit; |
25457
|
1951
|
|
|
|
|
|
continue; |
25458
|
|
|
|
|
|
|
} |
25459
|
|
|
|
|
|
|
} |
25460
|
|
|
|
|
|
|
} else { |
25461
|
|
|
|
|
|
|
|
25462
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME_AND_THEN_PRELOAD( |
25463
|
|
|
|
|
|
|
LITLEN_TABLEBITS, LITLEN_TABLEBITS)); |
25464
|
|
|
|
|
|
|
lit = entry >> 16; |
25465
|
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25466
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25467
|
|
|
|
|
|
|
*out_next++ = lit; |
25468
|
|
|
|
|
|
|
continue; |
25469
|
|
|
|
|
|
|
} |
25470
|
|
|
|
|
|
|
} |
25471
|
|
|
|
|
|
|
|
25472
|
|
|
|
|
|
|
|
25473
|
8200
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
25474
|
|
|
|
|
|
|
|
25475
|
|
|
|
|
|
|
|
25476
|
28
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
25477
|
1
|
|
|
|
|
|
goto block_done; |
25478
|
|
|
|
|
|
|
|
25479
|
|
|
|
|
|
|
|
25480
|
54
|
|
|
|
|
|
entry = d->u.litlen_decode_table[(entry >> 16) + |
25481
|
27
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25482
|
27
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25483
|
27
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25484
|
27
|
|
|
|
|
|
bitsleft -= entry; |
25485
|
|
|
|
|
|
|
|
25486
|
|
|
|
|
|
|
|
25487
|
|
|
|
|
|
|
if (!CAN_CONSUME_AND_THEN_PRELOAD(DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
25488
|
|
|
|
|
|
|
LITLEN_TABLEBITS) || |
25489
|
|
|
|
|
|
|
!CAN_CONSUME_AND_THEN_PRELOAD(LENGTH_MAXBITS, |
25490
|
|
|
|
|
|
|
OFFSET_TABLEBITS)) |
25491
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25492
|
27
|
50
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
25493
|
|
|
|
|
|
|
|
25494
|
27
|
|
|
|
|
|
lit = entry >> 16; |
25495
|
27
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25496
|
27
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25497
|
27
|
|
|
|
|
|
*out_next++ = lit; |
25498
|
27
|
|
|
|
|
|
continue; |
25499
|
|
|
|
|
|
|
} |
25500
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
25501
|
0
|
|
|
|
|
|
goto block_done; |
25502
|
|
|
|
|
|
|
|
25503
|
|
|
|
|
|
|
} |
25504
|
|
|
|
|
|
|
|
25505
|
|
|
|
|
|
|
|
25506
|
8172
|
|
|
|
|
|
length = entry >> 16; |
25507
|
8172
|
|
|
|
|
|
length += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
25508
|
|
|
|
|
|
|
|
25509
|
|
|
|
|
|
|
|
25510
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME_AND_THEN_PRELOAD(LENGTH_MAXFASTBITS, |
25511
|
|
|
|
|
|
|
OFFSET_TABLEBITS)); |
25512
|
8172
|
|
|
|
|
|
entry = d->offset_decode_table[bitbuf & BITMASK(OFFSET_TABLEBITS)]; |
25513
|
|
|
|
|
|
|
if (CAN_CONSUME_AND_THEN_PRELOAD(OFFSET_MAXBITS, |
25514
|
|
|
|
|
|
|
LITLEN_TABLEBITS)) { |
25515
|
|
|
|
|
|
|
|
25516
|
8172
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
25517
|
|
|
|
|
|
|
|
25518
|
17
|
50
|
|
|
|
|
if (unlikely((u8)bitsleft < OFFSET_MAXBITS + |
25519
|
|
|
|
|
|
|
LITLEN_TABLEBITS - PRELOAD_SLACK)) |
25520
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25521
|
17
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
25522
|
17
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
25523
|
17
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
25524
|
17
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25525
|
8155
|
100
|
|
|
|
|
} else if (unlikely((u8)bitsleft < OFFSET_MAXFASTBITS + |
25526
|
|
|
|
|
|
|
LITLEN_TABLEBITS - PRELOAD_SLACK)) |
25527
|
1
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25528
|
|
|
|
|
|
|
} else { |
25529
|
|
|
|
|
|
|
|
25530
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25531
|
|
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
25532
|
|
|
|
|
|
|
|
25533
|
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
25534
|
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
25535
|
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
25536
|
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25537
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25538
|
|
|
|
|
|
|
|
25539
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME( |
25540
|
|
|
|
|
|
|
OFFSET_MAXBITS - OFFSET_TABLEBITS)); |
25541
|
|
|
|
|
|
|
} else { |
25542
|
|
|
|
|
|
|
|
25543
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME(OFFSET_MAXFASTBITS)); |
25544
|
|
|
|
|
|
|
} |
25545
|
|
|
|
|
|
|
} |
25546
|
8172
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25547
|
8172
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25548
|
8172
|
|
|
|
|
|
bitsleft -= entry; |
25549
|
8172
|
|
|
|
|
|
offset = entry >> 16; |
25550
|
8172
|
|
|
|
|
|
offset += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
25551
|
|
|
|
|
|
|
|
25552
|
|
|
|
|
|
|
|
25553
|
8172
|
50
|
|
|
|
|
SAFETY_CHECK(offset <= out_next - (const u8 *)out); |
25554
|
8172
|
|
|
|
|
|
src = out_next - offset; |
25555
|
8172
|
|
|
|
|
|
dst = out_next; |
25556
|
8172
|
|
|
|
|
|
out_next += length; |
25557
|
|
|
|
|
|
|
|
25558
|
|
|
|
|
|
|
|
25559
|
|
|
|
|
|
|
if (!CAN_CONSUME_AND_THEN_PRELOAD( |
25560
|
|
|
|
|
|
|
MAX(OFFSET_MAXBITS - OFFSET_TABLEBITS, |
25561
|
|
|
|
|
|
|
OFFSET_MAXFASTBITS), |
25562
|
|
|
|
|
|
|
LITLEN_TABLEBITS) && |
25563
|
|
|
|
|
|
|
unlikely((u8)bitsleft < LITLEN_TABLEBITS - PRELOAD_SLACK)) |
25564
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25565
|
8172
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25566
|
8172
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25567
|
|
|
|
|
|
|
|
25568
|
|
|
|
|
|
|
|
25569
|
8172
|
100
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST && offset >= WORDBYTES) { |
25570
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25571
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25572
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25573
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25574
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25575
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25576
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25577
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25578
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25579
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25580
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25581
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25582
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25583
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25584
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25585
|
8430
|
100
|
|
|
|
|
while (dst < out_next) { |
25586
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25587
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25588
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25589
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25590
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25591
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25592
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25593
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25594
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25595
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25596
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25597
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25598
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25599
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25600
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25601
|
|
|
|
|
|
|
} |
25602
|
9
|
50
|
|
|
|
|
} else if (UNALIGNED_ACCESS_IS_FAST && offset == 1) { |
25603
|
|
|
|
|
|
|
machine_word_t v; |
25604
|
|
|
|
|
|
|
|
25605
|
|
|
|
|
|
|
|
25606
|
0
|
|
|
|
|
|
v = (machine_word_t)0x0101010101010101 * src[0]; |
25607
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25608
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25609
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25610
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25611
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25612
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25613
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25614
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25615
|
0
|
0
|
|
|
|
|
while (dst < out_next) { |
25616
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25617
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25618
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25619
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25620
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25621
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25622
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25623
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25624
|
|
|
|
|
|
|
} |
25625
|
|
|
|
|
|
|
} else if (UNALIGNED_ACCESS_IS_FAST) { |
25626
|
9
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25627
|
9
|
|
|
|
|
|
src += offset; |
25628
|
9
|
|
|
|
|
|
dst += offset; |
25629
|
9
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25630
|
9
|
|
|
|
|
|
src += offset; |
25631
|
9
|
|
|
|
|
|
dst += offset; |
25632
|
|
|
|
|
|
|
do { |
25633
|
9
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25634
|
9
|
|
|
|
|
|
src += offset; |
25635
|
9
|
|
|
|
|
|
dst += offset; |
25636
|
9
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25637
|
9
|
|
|
|
|
|
src += offset; |
25638
|
9
|
|
|
|
|
|
dst += offset; |
25639
|
9
|
50
|
|
|
|
|
} while (dst < out_next); |
25640
|
|
|
|
|
|
|
} else { |
25641
|
|
|
|
|
|
|
*dst++ = *src++; |
25642
|
|
|
|
|
|
|
*dst++ = *src++; |
25643
|
|
|
|
|
|
|
do { |
25644
|
|
|
|
|
|
|
*dst++ = *src++; |
25645
|
|
|
|
|
|
|
} while (dst < out_next); |
25646
|
|
|
|
|
|
|
} |
25647
|
10150
|
100
|
|
|
|
|
} while (in_next < in_fastloop_end && out_next < out_fastloop_end); |
|
|
100
|
|
|
|
|
|
25648
|
|
|
|
|
|
|
|
25649
|
|
|
|
|
|
|
|
25650
|
|
|
|
|
|
|
generic_loop: |
25651
|
|
|
|
|
|
|
for (;;) { |
25652
|
|
|
|
|
|
|
u32 length, offset; |
25653
|
|
|
|
|
|
|
const u8 *src; |
25654
|
|
|
|
|
|
|
u8 *dst; |
25655
|
|
|
|
|
|
|
|
25656
|
2172
|
100
|
|
|
|
|
REFILL_BITS(); |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
25657
|
970
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25658
|
970
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25659
|
970
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25660
|
970
|
|
|
|
|
|
bitsleft -= entry; |
25661
|
970
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_SUBTABLE_POINTER)) { |
25662
|
6
|
|
|
|
|
|
entry = d->u.litlen_decode_table[(entry >> 16) + |
25663
|
3
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25664
|
3
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25665
|
3
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25666
|
3
|
|
|
|
|
|
bitsleft -= entry; |
25667
|
|
|
|
|
|
|
} |
25668
|
970
|
|
|
|
|
|
length = entry >> 16; |
25669
|
970
|
100
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
25670
|
588
|
50
|
|
|
|
|
if (unlikely(out_next == out_end)) |
25671
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
25672
|
588
|
|
|
|
|
|
*out_next++ = length; |
25673
|
588
|
|
|
|
|
|
continue; |
25674
|
|
|
|
|
|
|
} |
25675
|
382
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
25676
|
40
|
|
|
|
|
|
goto block_done; |
25677
|
342
|
|
|
|
|
|
length += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
25678
|
342
|
50
|
|
|
|
|
if (unlikely(length > out_end - out_next)) |
25679
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
25680
|
|
|
|
|
|
|
|
25681
|
|
|
|
|
|
|
if (!CAN_CONSUME(LENGTH_MAXBITS + OFFSET_MAXBITS)) |
25682
|
|
|
|
|
|
|
REFILL_BITS(); |
25683
|
342
|
|
|
|
|
|
entry = d->offset_decode_table[bitbuf & BITMASK(OFFSET_TABLEBITS)]; |
25684
|
342
|
50
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
25685
|
0
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
25686
|
0
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
25687
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
25688
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25689
|
|
|
|
|
|
|
if (!CAN_CONSUME(OFFSET_MAXBITS)) |
25690
|
|
|
|
|
|
|
REFILL_BITS(); |
25691
|
|
|
|
|
|
|
} |
25692
|
342
|
|
|
|
|
|
offset = entry >> 16; |
25693
|
342
|
|
|
|
|
|
offset += EXTRACT_VARBITS8(bitbuf, entry) >> (u8)(entry >> 8); |
25694
|
342
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25695
|
342
|
|
|
|
|
|
bitsleft -= entry; |
25696
|
|
|
|
|
|
|
|
25697
|
342
|
50
|
|
|
|
|
SAFETY_CHECK(offset <= out_next - (const u8 *)out); |
25698
|
342
|
|
|
|
|
|
src = out_next - offset; |
25699
|
342
|
|
|
|
|
|
dst = out_next; |
25700
|
342
|
|
|
|
|
|
out_next += length; |
25701
|
|
|
|
|
|
|
|
25702
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MIN_MATCH_LEN == 3); |
25703
|
342
|
|
|
|
|
|
*dst++ = *src++; |
25704
|
342
|
|
|
|
|
|
*dst++ = *src++; |
25705
|
|
|
|
|
|
|
do { |
25706
|
60992
|
|
|
|
|
|
*dst++ = *src++; |
25707
|
60992
|
100
|
|
|
|
|
} while (dst < out_next); |
25708
|
930
|
|
|
|
|
|
} |
25709
|
|
|
|
|
|
|
|
25710
|
|
|
|
|
|
|
block_done: |
25711
|
|
|
|
|
|
|
|
25712
|
|
|
|
|
|
|
|
25713
|
41
|
100
|
|
|
|
|
if (!is_final_block) |
25714
|
1
|
|
|
|
|
|
goto next_block; |
25715
|
|
|
|
|
|
|
|
25716
|
|
|
|
|
|
|
|
25717
|
|
|
|
|
|
|
|
25718
|
40
|
|
|
|
|
|
bitsleft = (u8)bitsleft; |
25719
|
|
|
|
|
|
|
|
25720
|
|
|
|
|
|
|
|
25721
|
40
|
50
|
|
|
|
|
SAFETY_CHECK(overread_count <= (bitsleft >> 3)); |
25722
|
|
|
|
|
|
|
|
25723
|
|
|
|
|
|
|
|
25724
|
40
|
50
|
|
|
|
|
if (actual_in_nbytes_ret) { |
25725
|
|
|
|
|
|
|
|
25726
|
40
|
|
|
|
|
|
in_next -= (bitsleft >> 3) - overread_count; |
25727
|
|
|
|
|
|
|
|
25728
|
40
|
|
|
|
|
|
*actual_in_nbytes_ret = in_next - (u8 *)in; |
25729
|
|
|
|
|
|
|
} |
25730
|
|
|
|
|
|
|
|
25731
|
|
|
|
|
|
|
|
25732
|
40
|
50
|
|
|
|
|
if (actual_out_nbytes_ret) { |
25733
|
40
|
|
|
|
|
|
*actual_out_nbytes_ret = out_next - (u8 *)out; |
25734
|
|
|
|
|
|
|
} else { |
25735
|
0
|
0
|
|
|
|
|
if (out_next != out_end) |
25736
|
0
|
|
|
|
|
|
return LIBDEFLATE_SHORT_OUTPUT; |
25737
|
|
|
|
|
|
|
} |
25738
|
40
|
|
|
|
|
|
return LIBDEFLATE_SUCCESS; |
25739
|
|
|
|
|
|
|
} |
25740
|
|
|
|
|
|
|
|
25741
|
|
|
|
|
|
|
#undef FUNCNAME |
25742
|
|
|
|
|
|
|
#undef ATTRIBUTES |
25743
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS |
25744
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS8 |
25745
|
|
|
|
|
|
|
|
25746
|
|
|
|
|
|
|
|
25747
|
|
|
|
|
|
|
|
25748
|
|
|
|
|
|
|
#undef DEFAULT_IMPL |
25749
|
|
|
|
|
|
|
#undef arch_select_decompress_func |
25750
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
25751
|
|
|
|
|
|
|
/* # include "x86/decompress_impl.h" */ |
25752
|
|
|
|
|
|
|
#ifndef LIB_X86_DECOMPRESS_IMPL_H |
25753
|
|
|
|
|
|
|
#define LIB_X86_DECOMPRESS_IMPL_H |
25754
|
|
|
|
|
|
|
|
25755
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
25756
|
|
|
|
|
|
|
|
25757
|
|
|
|
|
|
|
|
25758
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
25759
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
25760
|
|
|
|
|
|
|
|
25761
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
25762
|
|
|
|
|
|
|
|
25763
|
|
|
|
|
|
|
|
25764
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
25765
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
25766
|
|
|
|
|
|
|
|
25767
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
25768
|
|
|
|
|
|
|
|
25769
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
25770
|
|
|
|
|
|
|
#endif |
25771
|
|
|
|
|
|
|
|
25772
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
25773
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
25774
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
25775
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
25776
|
|
|
|
|
|
|
#else |
25777
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
25778
|
|
|
|
|
|
|
#endif |
25779
|
|
|
|
|
|
|
|
25780
|
|
|
|
|
|
|
|
25781
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
25782
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
25783
|
|
|
|
|
|
|
#else |
25784
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
25785
|
|
|
|
|
|
|
#endif |
25786
|
|
|
|
|
|
|
|
25787
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
25788
|
|
|
|
|
|
|
|
25789
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
25790
|
|
|
|
|
|
|
|
25791
|
|
|
|
|
|
|
|
25792
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
25793
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
25794
|
|
|
|
|
|
|
|
25795
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
25796
|
|
|
|
|
|
|
|
25797
|
|
|
|
|
|
|
|
25798
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
25799
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
25800
|
|
|
|
|
|
|
|
25801
|
|
|
|
|
|
|
#include |
25802
|
|
|
|
|
|
|
#include |
25803
|
|
|
|
|
|
|
|
25804
|
|
|
|
|
|
|
#ifdef __cplusplus |
25805
|
|
|
|
|
|
|
extern "C" { |
25806
|
|
|
|
|
|
|
#endif |
25807
|
|
|
|
|
|
|
|
25808
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
25809
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
25810
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
25811
|
|
|
|
|
|
|
|
25812
|
|
|
|
|
|
|
|
25813
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
25814
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
25815
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
25816
|
|
|
|
|
|
|
# else |
25817
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
25818
|
|
|
|
|
|
|
# endif |
25819
|
|
|
|
|
|
|
#endif |
25820
|
|
|
|
|
|
|
|
25821
|
|
|
|
|
|
|
|
25822
|
|
|
|
|
|
|
|
25823
|
|
|
|
|
|
|
|
25824
|
|
|
|
|
|
|
|
25825
|
|
|
|
|
|
|
struct libdeflate_compressor; |
25826
|
|
|
|
|
|
|
struct libdeflate_options; |
25827
|
|
|
|
|
|
|
|
25828
|
|
|
|
|
|
|
|
25829
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
25830
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
25831
|
|
|
|
|
|
|
|
25832
|
|
|
|
|
|
|
|
25833
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
25834
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
25835
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
25836
|
|
|
|
|
|
|
|
25837
|
|
|
|
|
|
|
|
25838
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25839
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
25840
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25841
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
25842
|
|
|
|
|
|
|
|
25843
|
|
|
|
|
|
|
|
25844
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25845
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
25846
|
|
|
|
|
|
|
size_t in_nbytes); |
25847
|
|
|
|
|
|
|
|
25848
|
|
|
|
|
|
|
|
25849
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25850
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
25851
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25852
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
25853
|
|
|
|
|
|
|
|
25854
|
|
|
|
|
|
|
|
25855
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25856
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
25857
|
|
|
|
|
|
|
size_t in_nbytes); |
25858
|
|
|
|
|
|
|
|
25859
|
|
|
|
|
|
|
|
25860
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25861
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
25862
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25863
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
25864
|
|
|
|
|
|
|
|
25865
|
|
|
|
|
|
|
|
25866
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25867
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
25868
|
|
|
|
|
|
|
size_t in_nbytes); |
25869
|
|
|
|
|
|
|
|
25870
|
|
|
|
|
|
|
|
25871
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
25872
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
25873
|
|
|
|
|
|
|
|
25874
|
|
|
|
|
|
|
|
25875
|
|
|
|
|
|
|
|
25876
|
|
|
|
|
|
|
|
25877
|
|
|
|
|
|
|
|
25878
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
25879
|
|
|
|
|
|
|
struct libdeflate_options; |
25880
|
|
|
|
|
|
|
|
25881
|
|
|
|
|
|
|
|
25882
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
25883
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
25884
|
|
|
|
|
|
|
|
25885
|
|
|
|
|
|
|
|
25886
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
25887
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
25888
|
|
|
|
|
|
|
|
25889
|
|
|
|
|
|
|
|
25890
|
|
|
|
|
|
|
enum libdeflate_result { |
25891
|
|
|
|
|
|
|
|
25892
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
25893
|
|
|
|
|
|
|
|
25894
|
|
|
|
|
|
|
|
25895
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
25896
|
|
|
|
|
|
|
|
25897
|
|
|
|
|
|
|
|
25898
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
25899
|
|
|
|
|
|
|
|
25900
|
|
|
|
|
|
|
|
25901
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
25902
|
|
|
|
|
|
|
}; |
25903
|
|
|
|
|
|
|
|
25904
|
|
|
|
|
|
|
|
25905
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25906
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
25907
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25908
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25909
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25910
|
|
|
|
|
|
|
|
25911
|
|
|
|
|
|
|
|
25912
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25913
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
25914
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25915
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25916
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
25917
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25918
|
|
|
|
|
|
|
|
25919
|
|
|
|
|
|
|
|
25920
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25921
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
25922
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25923
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25924
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25925
|
|
|
|
|
|
|
|
25926
|
|
|
|
|
|
|
|
25927
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25928
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
25929
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25930
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25931
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
25932
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25933
|
|
|
|
|
|
|
|
25934
|
|
|
|
|
|
|
|
25935
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25936
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
25937
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25938
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25939
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25940
|
|
|
|
|
|
|
|
25941
|
|
|
|
|
|
|
|
25942
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25943
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
25944
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25945
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25946
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
25947
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25948
|
|
|
|
|
|
|
|
25949
|
|
|
|
|
|
|
|
25950
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
25951
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
25952
|
|
|
|
|
|
|
|
25953
|
|
|
|
|
|
|
|
25954
|
|
|
|
|
|
|
|
25955
|
|
|
|
|
|
|
|
25956
|
|
|
|
|
|
|
|
25957
|
|
|
|
|
|
|
|
25958
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
25959
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
25960
|
|
|
|
|
|
|
|
25961
|
|
|
|
|
|
|
|
25962
|
|
|
|
|
|
|
|
25963
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
25964
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
25965
|
|
|
|
|
|
|
|
25966
|
|
|
|
|
|
|
|
25967
|
|
|
|
|
|
|
|
25968
|
|
|
|
|
|
|
|
25969
|
|
|
|
|
|
|
|
25970
|
|
|
|
|
|
|
|
25971
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
25972
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
25973
|
|
|
|
|
|
|
void (*free_func)(void *)); |
25974
|
|
|
|
|
|
|
|
25975
|
|
|
|
|
|
|
|
25976
|
|
|
|
|
|
|
struct libdeflate_options { |
25977
|
|
|
|
|
|
|
|
25978
|
|
|
|
|
|
|
|
25979
|
|
|
|
|
|
|
size_t sizeof_options; |
25980
|
|
|
|
|
|
|
|
25981
|
|
|
|
|
|
|
|
25982
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
25983
|
|
|
|
|
|
|
void (*free_func)(void *); |
25984
|
|
|
|
|
|
|
}; |
25985
|
|
|
|
|
|
|
|
25986
|
|
|
|
|
|
|
#ifdef __cplusplus |
25987
|
|
|
|
|
|
|
} |
25988
|
|
|
|
|
|
|
#endif |
25989
|
|
|
|
|
|
|
|
25990
|
|
|
|
|
|
|
#endif |
25991
|
|
|
|
|
|
|
|
25992
|
|
|
|
|
|
|
|
25993
|
|
|
|
|
|
|
#include |
25994
|
|
|
|
|
|
|
#include |
25995
|
|
|
|
|
|
|
#include |
25996
|
|
|
|
|
|
|
#ifdef _MSC_VER |
25997
|
|
|
|
|
|
|
# include |
25998
|
|
|
|
|
|
|
# include |
25999
|
|
|
|
|
|
|
|
26000
|
|
|
|
|
|
|
|
26001
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
26002
|
|
|
|
|
|
|
|
26003
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
26004
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
26005
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
26006
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
26007
|
|
|
|
|
|
|
|
26008
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
26009
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
26010
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
26011
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
26012
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
26013
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
26014
|
|
|
|
|
|
|
#endif |
26015
|
|
|
|
|
|
|
#ifndef FREESTANDING |
26016
|
|
|
|
|
|
|
# include |
26017
|
|
|
|
|
|
|
#endif |
26018
|
|
|
|
|
|
|
|
26019
|
|
|
|
|
|
|
|
26020
|
|
|
|
|
|
|
|
26021
|
|
|
|
|
|
|
|
26022
|
|
|
|
|
|
|
|
26023
|
|
|
|
|
|
|
|
26024
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
26025
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
26026
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
26027
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
26028
|
|
|
|
|
|
|
#ifdef _MSC_VER |
26029
|
|
|
|
|
|
|
# if defined(_M_X64) |
26030
|
|
|
|
|
|
|
# define ARCH_X86_64 |
26031
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
26032
|
|
|
|
|
|
|
# define ARCH_X86_32 |
26033
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
26034
|
|
|
|
|
|
|
# define ARCH_ARM64 |
26035
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
26036
|
|
|
|
|
|
|
# define ARCH_ARM32 |
26037
|
|
|
|
|
|
|
# endif |
26038
|
|
|
|
|
|
|
#else |
26039
|
|
|
|
|
|
|
# if defined(__x86_64__) |
26040
|
|
|
|
|
|
|
# define ARCH_X86_64 |
26041
|
|
|
|
|
|
|
# elif defined(__i386__) |
26042
|
|
|
|
|
|
|
# define ARCH_X86_32 |
26043
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
26044
|
|
|
|
|
|
|
# define ARCH_ARM64 |
26045
|
|
|
|
|
|
|
# elif defined(__arm__) |
26046
|
|
|
|
|
|
|
# define ARCH_ARM32 |
26047
|
|
|
|
|
|
|
# endif |
26048
|
|
|
|
|
|
|
#endif |
26049
|
|
|
|
|
|
|
|
26050
|
|
|
|
|
|
|
|
26051
|
|
|
|
|
|
|
|
26052
|
|
|
|
|
|
|
|
26053
|
|
|
|
|
|
|
|
26054
|
|
|
|
|
|
|
|
26055
|
|
|
|
|
|
|
typedef uint8_t u8; |
26056
|
|
|
|
|
|
|
typedef uint16_t u16; |
26057
|
|
|
|
|
|
|
typedef uint32_t u32; |
26058
|
|
|
|
|
|
|
typedef uint64_t u64; |
26059
|
|
|
|
|
|
|
typedef int8_t s8; |
26060
|
|
|
|
|
|
|
typedef int16_t s16; |
26061
|
|
|
|
|
|
|
typedef int32_t s32; |
26062
|
|
|
|
|
|
|
typedef int64_t s64; |
26063
|
|
|
|
|
|
|
|
26064
|
|
|
|
|
|
|
|
26065
|
|
|
|
|
|
|
#ifdef _MSC_VER |
26066
|
|
|
|
|
|
|
# ifdef _WIN64 |
26067
|
|
|
|
|
|
|
typedef long long ssize_t; |
26068
|
|
|
|
|
|
|
# else |
26069
|
|
|
|
|
|
|
typedef long ssize_t; |
26070
|
|
|
|
|
|
|
# endif |
26071
|
|
|
|
|
|
|
#endif |
26072
|
|
|
|
|
|
|
|
26073
|
|
|
|
|
|
|
|
26074
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
26075
|
|
|
|
|
|
|
|
26076
|
|
|
|
|
|
|
|
26077
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
26078
|
|
|
|
|
|
|
|
26079
|
|
|
|
|
|
|
|
26080
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
26081
|
|
|
|
|
|
|
|
26082
|
|
|
|
|
|
|
|
26083
|
|
|
|
|
|
|
|
26084
|
|
|
|
|
|
|
|
26085
|
|
|
|
|
|
|
|
26086
|
|
|
|
|
|
|
|
26087
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
26088
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
26089
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
26090
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
26091
|
|
|
|
|
|
|
#else |
26092
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
26093
|
|
|
|
|
|
|
#endif |
26094
|
|
|
|
|
|
|
#ifdef __clang__ |
26095
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
26096
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
26097
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
26098
|
|
|
|
|
|
|
# else |
26099
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
26100
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
26101
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
26102
|
|
|
|
|
|
|
# endif |
26103
|
|
|
|
|
|
|
#else |
26104
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
26105
|
|
|
|
|
|
|
#endif |
26106
|
|
|
|
|
|
|
|
26107
|
|
|
|
|
|
|
|
26108
|
|
|
|
|
|
|
#ifndef __has_attribute |
26109
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
26110
|
|
|
|
|
|
|
#endif |
26111
|
|
|
|
|
|
|
#ifndef __has_builtin |
26112
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
26113
|
|
|
|
|
|
|
#endif |
26114
|
|
|
|
|
|
|
|
26115
|
|
|
|
|
|
|
|
26116
|
|
|
|
|
|
|
#ifdef _MSC_VER |
26117
|
|
|
|
|
|
|
# define inline __inline |
26118
|
|
|
|
|
|
|
#endif |
26119
|
|
|
|
|
|
|
|
26120
|
|
|
|
|
|
|
|
26121
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
26122
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
26123
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26124
|
|
|
|
|
|
|
# define forceinline __forceinline |
26125
|
|
|
|
|
|
|
#else |
26126
|
|
|
|
|
|
|
# define forceinline inline |
26127
|
|
|
|
|
|
|
#endif |
26128
|
|
|
|
|
|
|
|
26129
|
|
|
|
|
|
|
|
26130
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
26131
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
26132
|
|
|
|
|
|
|
#else |
26133
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
26134
|
|
|
|
|
|
|
#endif |
26135
|
|
|
|
|
|
|
|
26136
|
|
|
|
|
|
|
|
26137
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
26138
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
26139
|
|
|
|
|
|
|
# define restrict __restrict__ |
26140
|
|
|
|
|
|
|
# else |
26141
|
|
|
|
|
|
|
# define restrict |
26142
|
|
|
|
|
|
|
# endif |
26143
|
|
|
|
|
|
|
#endif |
26144
|
|
|
|
|
|
|
|
26145
|
|
|
|
|
|
|
|
26146
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
26147
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
26148
|
|
|
|
|
|
|
#else |
26149
|
|
|
|
|
|
|
# define likely(expr) (expr) |
26150
|
|
|
|
|
|
|
#endif |
26151
|
|
|
|
|
|
|
|
26152
|
|
|
|
|
|
|
|
26153
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
26154
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
26155
|
|
|
|
|
|
|
#else |
26156
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
26157
|
|
|
|
|
|
|
#endif |
26158
|
|
|
|
|
|
|
|
26159
|
|
|
|
|
|
|
|
26160
|
|
|
|
|
|
|
#undef prefetchr |
26161
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
26162
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
26163
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26164
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
26165
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
26166
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
26167
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
26168
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
26169
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
26170
|
|
|
|
|
|
|
# endif |
26171
|
|
|
|
|
|
|
#endif |
26172
|
|
|
|
|
|
|
#ifndef prefetchr |
26173
|
|
|
|
|
|
|
# define prefetchr(addr) |
26174
|
|
|
|
|
|
|
#endif |
26175
|
|
|
|
|
|
|
|
26176
|
|
|
|
|
|
|
|
26177
|
|
|
|
|
|
|
#undef prefetchw |
26178
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
26179
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
26180
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26181
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
26182
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
26183
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
26184
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
26185
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
26186
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
26187
|
|
|
|
|
|
|
# endif |
26188
|
|
|
|
|
|
|
#endif |
26189
|
|
|
|
|
|
|
#ifndef prefetchw |
26190
|
|
|
|
|
|
|
# define prefetchw(addr) |
26191
|
|
|
|
|
|
|
#endif |
26192
|
|
|
|
|
|
|
|
26193
|
|
|
|
|
|
|
|
26194
|
|
|
|
|
|
|
#undef _aligned_attribute |
26195
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
26196
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
26197
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26198
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
26199
|
|
|
|
|
|
|
#endif |
26200
|
|
|
|
|
|
|
|
26201
|
|
|
|
|
|
|
|
26202
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
26203
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
26204
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
26205
|
|
|
|
|
|
|
#else |
26206
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
26207
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
26208
|
|
|
|
|
|
|
#endif |
26209
|
|
|
|
|
|
|
|
26210
|
|
|
|
|
|
|
|
26211
|
|
|
|
|
|
|
|
26212
|
|
|
|
|
|
|
|
26213
|
|
|
|
|
|
|
|
26214
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
26215
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
26216
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
26217
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
26218
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
26219
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
26220
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
26221
|
|
|
|
|
|
|
|
26222
|
|
|
|
|
|
|
|
26223
|
|
|
|
|
|
|
|
26224
|
|
|
|
|
|
|
|
26225
|
|
|
|
|
|
|
|
26226
|
|
|
|
|
|
|
|
26227
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
26228
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
26229
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26230
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
26231
|
|
|
|
|
|
|
#else |
26232
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
26233
|
|
|
|
|
|
|
{ |
26234
|
|
|
|
|
|
|
union { |
26235
|
|
|
|
|
|
|
u32 w; |
26236
|
|
|
|
|
|
|
u8 b; |
26237
|
|
|
|
|
|
|
} u; |
26238
|
|
|
|
|
|
|
|
26239
|
|
|
|
|
|
|
u.w = 1; |
26240
|
|
|
|
|
|
|
return u.b; |
26241
|
|
|
|
|
|
|
} |
26242
|
|
|
|
|
|
|
#endif |
26243
|
|
|
|
|
|
|
|
26244
|
|
|
|
|
|
|
|
26245
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
26246
|
|
|
|
|
|
|
{ |
26247
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
26248
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
26249
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26250
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
26251
|
|
|
|
|
|
|
#else |
26252
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
26253
|
|
|
|
|
|
|
#endif |
26254
|
|
|
|
|
|
|
} |
26255
|
|
|
|
|
|
|
|
26256
|
|
|
|
|
|
|
|
26257
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
26258
|
|
|
|
|
|
|
{ |
26259
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
26260
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
26261
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26262
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
26263
|
|
|
|
|
|
|
#else |
26264
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
26265
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
26266
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
26267
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
26268
|
|
|
|
|
|
|
#endif |
26269
|
|
|
|
|
|
|
} |
26270
|
|
|
|
|
|
|
|
26271
|
|
|
|
|
|
|
|
26272
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
26273
|
|
|
|
|
|
|
{ |
26274
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
26275
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
26276
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26277
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
26278
|
|
|
|
|
|
|
#else |
26279
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
26280
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
26281
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
26282
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
26283
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
26284
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
26285
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
26286
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
26287
|
|
|
|
|
|
|
#endif |
26288
|
|
|
|
|
|
|
} |
26289
|
|
|
|
|
|
|
|
26290
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
26291
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
26292
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
26293
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
26294
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
26295
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
26296
|
|
|
|
|
|
|
|
26297
|
|
|
|
|
|
|
|
26298
|
|
|
|
|
|
|
|
26299
|
|
|
|
|
|
|
|
26300
|
|
|
|
|
|
|
|
26301
|
|
|
|
|
|
|
|
26302
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
26303
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
26304
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
26305
|
|
|
|
|
|
|
defined(__wasm__)) |
26306
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
26307
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26308
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
26309
|
|
|
|
|
|
|
#else |
26310
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
26311
|
|
|
|
|
|
|
#endif |
26312
|
|
|
|
|
|
|
|
26313
|
|
|
|
|
|
|
|
26314
|
|
|
|
|
|
|
|
26315
|
|
|
|
|
|
|
#ifdef FREESTANDING |
26316
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
26317
|
|
|
|
|
|
|
#else |
26318
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
26319
|
|
|
|
|
|
|
#endif |
26320
|
|
|
|
|
|
|
|
26321
|
|
|
|
|
|
|
|
26322
|
|
|
|
|
|
|
|
26323
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
26324
|
|
|
|
|
|
|
static forceinline type \ |
26325
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
26326
|
|
|
|
|
|
|
{ \ |
26327
|
|
|
|
|
|
|
type v; \ |
26328
|
|
|
|
|
|
|
\ |
26329
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
26330
|
|
|
|
|
|
|
return v; \ |
26331
|
|
|
|
|
|
|
} \ |
26332
|
|
|
|
|
|
|
\ |
26333
|
|
|
|
|
|
|
static forceinline void \ |
26334
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
26335
|
|
|
|
|
|
|
{ \ |
26336
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
26337
|
|
|
|
|
|
|
} |
26338
|
|
|
|
|
|
|
|
26339
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
26340
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
26341
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
26342
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
26343
|
|
|
|
|
|
|
|
26344
|
|
|
|
|
|
|
#undef MEMCOPY |
26345
|
|
|
|
|
|
|
|
26346
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
26347
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
26348
|
|
|
|
|
|
|
|
26349
|
|
|
|
|
|
|
|
26350
|
|
|
|
|
|
|
|
26351
|
|
|
|
|
|
|
static forceinline u16 |
26352
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
26353
|
|
|
|
|
|
|
{ |
26354
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
26355
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
26356
|
|
|
|
|
|
|
else |
26357
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
26358
|
|
|
|
|
|
|
} |
26359
|
|
|
|
|
|
|
|
26360
|
|
|
|
|
|
|
static forceinline u16 |
26361
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
26362
|
|
|
|
|
|
|
{ |
26363
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
26364
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
26365
|
|
|
|
|
|
|
else |
26366
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
26367
|
|
|
|
|
|
|
} |
26368
|
|
|
|
|
|
|
|
26369
|
|
|
|
|
|
|
static forceinline u32 |
26370
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
26371
|
|
|
|
|
|
|
{ |
26372
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
26373
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
26374
|
|
|
|
|
|
|
else |
26375
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
26376
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
26377
|
|
|
|
|
|
|
} |
26378
|
|
|
|
|
|
|
|
26379
|
|
|
|
|
|
|
static forceinline u32 |
26380
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
26381
|
|
|
|
|
|
|
{ |
26382
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
26383
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
26384
|
|
|
|
|
|
|
else |
26385
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
26386
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
26387
|
|
|
|
|
|
|
} |
26388
|
|
|
|
|
|
|
|
26389
|
|
|
|
|
|
|
static forceinline u64 |
26390
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
26391
|
|
|
|
|
|
|
{ |
26392
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
26393
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
26394
|
|
|
|
|
|
|
else |
26395
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
26396
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
26397
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
26398
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
26399
|
|
|
|
|
|
|
} |
26400
|
|
|
|
|
|
|
|
26401
|
|
|
|
|
|
|
static forceinline machine_word_t |
26402
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
26403
|
|
|
|
|
|
|
{ |
26404
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
26405
|
|
|
|
|
|
|
if (WORDBITS == 32) |
26406
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
26407
|
|
|
|
|
|
|
else |
26408
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
26409
|
|
|
|
|
|
|
} |
26410
|
|
|
|
|
|
|
|
26411
|
|
|
|
|
|
|
|
26412
|
|
|
|
|
|
|
|
26413
|
|
|
|
|
|
|
static forceinline void |
26414
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
26415
|
|
|
|
|
|
|
{ |
26416
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
26417
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
26418
|
|
|
|
|
|
|
} else { |
26419
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
26420
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
26421
|
|
|
|
|
|
|
} |
26422
|
|
|
|
|
|
|
} |
26423
|
|
|
|
|
|
|
|
26424
|
|
|
|
|
|
|
static forceinline void |
26425
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
26426
|
|
|
|
|
|
|
{ |
26427
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
26428
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
26429
|
|
|
|
|
|
|
} else { |
26430
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
26431
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
26432
|
|
|
|
|
|
|
} |
26433
|
|
|
|
|
|
|
} |
26434
|
|
|
|
|
|
|
|
26435
|
|
|
|
|
|
|
static forceinline void |
26436
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
26437
|
|
|
|
|
|
|
{ |
26438
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
26439
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
26440
|
|
|
|
|
|
|
} else { |
26441
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
26442
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
26443
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
26444
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
26445
|
|
|
|
|
|
|
} |
26446
|
|
|
|
|
|
|
} |
26447
|
|
|
|
|
|
|
|
26448
|
|
|
|
|
|
|
static forceinline void |
26449
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
26450
|
|
|
|
|
|
|
{ |
26451
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
26452
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
26453
|
|
|
|
|
|
|
} else { |
26454
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
26455
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
26456
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
26457
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
26458
|
|
|
|
|
|
|
} |
26459
|
|
|
|
|
|
|
} |
26460
|
|
|
|
|
|
|
|
26461
|
|
|
|
|
|
|
static forceinline void |
26462
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
26463
|
|
|
|
|
|
|
{ |
26464
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
26465
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
26466
|
|
|
|
|
|
|
} else { |
26467
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
26468
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
26469
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
26470
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
26471
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
26472
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
26473
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
26474
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
26475
|
|
|
|
|
|
|
} |
26476
|
|
|
|
|
|
|
} |
26477
|
|
|
|
|
|
|
|
26478
|
|
|
|
|
|
|
static forceinline void |
26479
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
26480
|
|
|
|
|
|
|
{ |
26481
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
26482
|
|
|
|
|
|
|
if (WORDBITS == 32) |
26483
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
26484
|
|
|
|
|
|
|
else |
26485
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
26486
|
|
|
|
|
|
|
} |
26487
|
|
|
|
|
|
|
|
26488
|
|
|
|
|
|
|
|
26489
|
|
|
|
|
|
|
|
26490
|
|
|
|
|
|
|
|
26491
|
|
|
|
|
|
|
|
26492
|
|
|
|
|
|
|
|
26493
|
|
|
|
|
|
|
|
26494
|
|
|
|
|
|
|
static forceinline unsigned |
26495
|
|
|
|
|
|
|
bsr32(u32 v) |
26496
|
|
|
|
|
|
|
{ |
26497
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
26498
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
26499
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26500
|
|
|
|
|
|
|
unsigned long i; |
26501
|
|
|
|
|
|
|
|
26502
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
26503
|
|
|
|
|
|
|
return i; |
26504
|
|
|
|
|
|
|
#else |
26505
|
|
|
|
|
|
|
unsigned i = 0; |
26506
|
|
|
|
|
|
|
|
26507
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
26508
|
|
|
|
|
|
|
i++; |
26509
|
|
|
|
|
|
|
return i; |
26510
|
|
|
|
|
|
|
#endif |
26511
|
|
|
|
|
|
|
} |
26512
|
|
|
|
|
|
|
|
26513
|
|
|
|
|
|
|
static forceinline unsigned |
26514
|
|
|
|
|
|
|
bsr64(u64 v) |
26515
|
|
|
|
|
|
|
{ |
26516
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
26517
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
26518
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
26519
|
|
|
|
|
|
|
unsigned long i; |
26520
|
|
|
|
|
|
|
|
26521
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
26522
|
|
|
|
|
|
|
return i; |
26523
|
|
|
|
|
|
|
#else |
26524
|
|
|
|
|
|
|
unsigned i = 0; |
26525
|
|
|
|
|
|
|
|
26526
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
26527
|
|
|
|
|
|
|
i++; |
26528
|
|
|
|
|
|
|
return i; |
26529
|
|
|
|
|
|
|
#endif |
26530
|
|
|
|
|
|
|
} |
26531
|
|
|
|
|
|
|
|
26532
|
|
|
|
|
|
|
static forceinline unsigned |
26533
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
26534
|
|
|
|
|
|
|
{ |
26535
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
26536
|
|
|
|
|
|
|
if (WORDBITS == 32) |
26537
|
|
|
|
|
|
|
return bsr32(v); |
26538
|
|
|
|
|
|
|
else |
26539
|
|
|
|
|
|
|
return bsr64(v); |
26540
|
|
|
|
|
|
|
} |
26541
|
|
|
|
|
|
|
|
26542
|
|
|
|
|
|
|
|
26543
|
|
|
|
|
|
|
|
26544
|
|
|
|
|
|
|
static forceinline unsigned |
26545
|
|
|
|
|
|
|
bsf32(u32 v) |
26546
|
|
|
|
|
|
|
{ |
26547
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
26548
|
|
|
|
|
|
|
return __builtin_ctz(v); |
26549
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26550
|
|
|
|
|
|
|
unsigned long i; |
26551
|
|
|
|
|
|
|
|
26552
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
26553
|
|
|
|
|
|
|
return i; |
26554
|
|
|
|
|
|
|
#else |
26555
|
|
|
|
|
|
|
unsigned i = 0; |
26556
|
|
|
|
|
|
|
|
26557
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
26558
|
|
|
|
|
|
|
i++; |
26559
|
|
|
|
|
|
|
return i; |
26560
|
|
|
|
|
|
|
#endif |
26561
|
|
|
|
|
|
|
} |
26562
|
|
|
|
|
|
|
|
26563
|
|
|
|
|
|
|
static forceinline unsigned |
26564
|
|
|
|
|
|
|
bsf64(u64 v) |
26565
|
|
|
|
|
|
|
{ |
26566
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
26567
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
26568
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
26569
|
|
|
|
|
|
|
unsigned long i; |
26570
|
|
|
|
|
|
|
|
26571
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
26572
|
|
|
|
|
|
|
return i; |
26573
|
|
|
|
|
|
|
#else |
26574
|
|
|
|
|
|
|
unsigned i = 0; |
26575
|
|
|
|
|
|
|
|
26576
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
26577
|
|
|
|
|
|
|
i++; |
26578
|
|
|
|
|
|
|
return i; |
26579
|
|
|
|
|
|
|
#endif |
26580
|
|
|
|
|
|
|
} |
26581
|
|
|
|
|
|
|
|
26582
|
|
|
|
|
|
|
static forceinline unsigned |
26583
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
26584
|
|
|
|
|
|
|
{ |
26585
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
26586
|
|
|
|
|
|
|
if (WORDBITS == 32) |
26587
|
|
|
|
|
|
|
return bsf32(v); |
26588
|
|
|
|
|
|
|
else |
26589
|
|
|
|
|
|
|
return bsf64(v); |
26590
|
|
|
|
|
|
|
} |
26591
|
|
|
|
|
|
|
|
26592
|
|
|
|
|
|
|
|
26593
|
|
|
|
|
|
|
#undef rbit32 |
26594
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
26595
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
26596
|
|
|
|
|
|
|
static forceinline u32 |
26597
|
|
|
|
|
|
|
rbit32(u32 v) |
26598
|
|
|
|
|
|
|
{ |
26599
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
26600
|
|
|
|
|
|
|
return v; |
26601
|
|
|
|
|
|
|
} |
26602
|
|
|
|
|
|
|
#define rbit32 rbit32 |
26603
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
26604
|
|
|
|
|
|
|
static forceinline u32 |
26605
|
|
|
|
|
|
|
rbit32(u32 v) |
26606
|
|
|
|
|
|
|
{ |
26607
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
26608
|
|
|
|
|
|
|
return v; |
26609
|
|
|
|
|
|
|
} |
26610
|
|
|
|
|
|
|
#define rbit32 rbit32 |
26611
|
|
|
|
|
|
|
#endif |
26612
|
|
|
|
|
|
|
|
26613
|
|
|
|
|
|
|
#endif |
26614
|
|
|
|
|
|
|
|
26615
|
|
|
|
|
|
|
|
26616
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
26617
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
26618
|
|
|
|
|
|
|
|
26619
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
26620
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
26621
|
|
|
|
|
|
|
|
26622
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
26623
|
|
|
|
|
|
|
size_t alignment, size_t size); |
26624
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
26625
|
|
|
|
|
|
|
|
26626
|
|
|
|
|
|
|
#ifdef FREESTANDING |
26627
|
|
|
|
|
|
|
|
26628
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
26629
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
26630
|
|
|
|
|
|
|
|
26631
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
26632
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
26633
|
|
|
|
|
|
|
|
26634
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
26635
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
26636
|
|
|
|
|
|
|
|
26637
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
26638
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
26639
|
|
|
|
|
|
|
|
26640
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
26641
|
|
|
|
|
|
|
#else |
26642
|
|
|
|
|
|
|
#include |
26643
|
|
|
|
|
|
|
#endif |
26644
|
|
|
|
|
|
|
|
26645
|
|
|
|
|
|
|
|
26646
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
26647
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
26648
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
26649
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
26650
|
|
|
|
|
|
|
#else |
26651
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
26652
|
|
|
|
|
|
|
#endif |
26653
|
|
|
|
|
|
|
|
26654
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
26655
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
26656
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
26657
|
|
|
|
|
|
|
|
26658
|
|
|
|
|
|
|
#endif |
26659
|
|
|
|
|
|
|
|
26660
|
|
|
|
|
|
|
|
26661
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
26662
|
|
|
|
|
|
|
|
26663
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
26664
|
|
|
|
|
|
|
|
26665
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
26666
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
26667
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
26668
|
|
|
|
|
|
|
#endif |
26669
|
|
|
|
|
|
|
|
26670
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
26671
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
26672
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
26673
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
26674
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
26675
|
|
|
|
|
|
|
|
26676
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
26677
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
26678
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
26679
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
26680
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
26681
|
|
|
|
|
|
|
|
26682
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
26683
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
26684
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
26685
|
|
|
|
|
|
|
|
26686
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
26687
|
|
|
|
|
|
|
|
26688
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
26689
|
|
|
|
|
|
|
{ |
26690
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
26691
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
26692
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
26693
|
|
|
|
|
|
|
} |
26694
|
|
|
|
|
|
|
#else |
26695
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
26696
|
|
|
|
|
|
|
#endif |
26697
|
|
|
|
|
|
|
|
26698
|
|
|
|
|
|
|
|
26699
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
26700
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
26701
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
26702
|
|
|
|
|
|
|
#else |
26703
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
26704
|
|
|
|
|
|
|
#endif |
26705
|
|
|
|
|
|
|
|
26706
|
|
|
|
|
|
|
|
26707
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
26708
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
26709
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
26710
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
26711
|
|
|
|
|
|
|
#else |
26712
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
26713
|
|
|
|
|
|
|
#endif |
26714
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
26715
|
|
|
|
|
|
|
|
26716
|
|
|
|
|
|
|
|
26717
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
26718
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
26719
|
|
|
|
|
|
|
#else |
26720
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
26721
|
|
|
|
|
|
|
#endif |
26722
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
26723
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
26724
|
|
|
|
|
|
|
defined(_MSC_VER))) |
26725
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
26726
|
|
|
|
|
|
|
#else |
26727
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
26728
|
|
|
|
|
|
|
#endif |
26729
|
|
|
|
|
|
|
|
26730
|
|
|
|
|
|
|
|
26731
|
|
|
|
|
|
|
#ifdef __AVX__ |
26732
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
26733
|
|
|
|
|
|
|
#else |
26734
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
26735
|
|
|
|
|
|
|
#endif |
26736
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
26737
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
26738
|
|
|
|
|
|
|
defined(_MSC_VER))) |
26739
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
26740
|
|
|
|
|
|
|
#else |
26741
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
26742
|
|
|
|
|
|
|
#endif |
26743
|
|
|
|
|
|
|
|
26744
|
|
|
|
|
|
|
|
26745
|
|
|
|
|
|
|
#ifdef __AVX2__ |
26746
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
26747
|
|
|
|
|
|
|
#else |
26748
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
26749
|
|
|
|
|
|
|
#endif |
26750
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
26751
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
26752
|
|
|
|
|
|
|
defined(_MSC_VER))) |
26753
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
26754
|
|
|
|
|
|
|
#else |
26755
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
26756
|
|
|
|
|
|
|
#endif |
26757
|
|
|
|
|
|
|
|
26758
|
|
|
|
|
|
|
|
26759
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
26760
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
26761
|
|
|
|
|
|
|
#else |
26762
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
26763
|
|
|
|
|
|
|
#endif |
26764
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
26765
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
26766
|
|
|
|
|
|
|
defined(_MSC_VER))) |
26767
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
26768
|
|
|
|
|
|
|
#else |
26769
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
26770
|
|
|
|
|
|
|
#endif |
26771
|
|
|
|
|
|
|
|
26772
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1930 |
26773
|
|
|
|
|
|
|
# undef HAVE_BMI2_NATIVE |
26774
|
|
|
|
|
|
|
# undef HAVE_BMI2_INTRIN |
26775
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
26776
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
26777
|
|
|
|
|
|
|
#endif |
26778
|
|
|
|
|
|
|
|
26779
|
|
|
|
|
|
|
#endif |
26780
|
|
|
|
|
|
|
|
26781
|
|
|
|
|
|
|
#endif |
26782
|
|
|
|
|
|
|
|
26783
|
|
|
|
|
|
|
|
26784
|
|
|
|
|
|
|
|
26785
|
|
|
|
|
|
|
#if HAVE_BMI2_INTRIN |
26786
|
|
|
|
|
|
|
# define deflate_decompress_bmi2 deflate_decompress_bmi2 |
26787
|
|
|
|
|
|
|
# define FUNCNAME deflate_decompress_bmi2 |
26788
|
|
|
|
|
|
|
# if !HAVE_BMI2_NATIVE |
26789
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("bmi2") |
26790
|
|
|
|
|
|
|
# endif |
26791
|
|
|
|
|
|
|
|
26792
|
|
|
|
|
|
|
# ifndef __clang__ |
26793
|
|
|
|
|
|
|
# include |
26794
|
|
|
|
|
|
|
# ifdef ARCH_X86_64 |
26795
|
|
|
|
|
|
|
# define EXTRACT_VARBITS(word, count) _bzhi_u64((word), (count)) |
26796
|
|
|
|
|
|
|
# define EXTRACT_VARBITS8(word, count) _bzhi_u64((word), (count)) |
26797
|
|
|
|
|
|
|
# else |
26798
|
|
|
|
|
|
|
# define EXTRACT_VARBITS(word, count) _bzhi_u32((word), (count)) |
26799
|
|
|
|
|
|
|
# define EXTRACT_VARBITS8(word, count) _bzhi_u32((word), (count)) |
26800
|
|
|
|
|
|
|
# endif |
26801
|
|
|
|
|
|
|
# endif |
26802
|
|
|
|
|
|
|
/* #include "decompress_template.h" */ |
26803
|
|
|
|
|
|
|
|
26804
|
|
|
|
|
|
|
|
26805
|
|
|
|
|
|
|
|
26806
|
|
|
|
|
|
|
|
26807
|
|
|
|
|
|
|
#ifndef ATTRIBUTES |
26808
|
|
|
|
|
|
|
# define ATTRIBUTES |
26809
|
|
|
|
|
|
|
#endif |
26810
|
|
|
|
|
|
|
#ifndef EXTRACT_VARBITS |
26811
|
|
|
|
|
|
|
# define EXTRACT_VARBITS(word, count) ((word) & BITMASK(count)) |
26812
|
|
|
|
|
|
|
#endif |
26813
|
|
|
|
|
|
|
#ifndef EXTRACT_VARBITS8 |
26814
|
|
|
|
|
|
|
# define EXTRACT_VARBITS8(word, count) ((word) & BITMASK((u8)(count))) |
26815
|
|
|
|
|
|
|
#endif |
26816
|
|
|
|
|
|
|
|
26817
|
|
|
|
|
|
|
static enum libdeflate_result ATTRIBUTES MAYBE_UNUSED |
26818
|
0
|
|
|
|
|
|
FUNCNAME(struct libdeflate_decompressor * restrict d, |
26819
|
|
|
|
|
|
|
const void * restrict in, size_t in_nbytes, |
26820
|
|
|
|
|
|
|
void * restrict out, size_t out_nbytes_avail, |
26821
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret) |
26822
|
|
|
|
|
|
|
{ |
26823
|
0
|
|
|
|
|
|
u8 *out_next = out; |
26824
|
0
|
|
|
|
|
|
u8 * const out_end = out_next + out_nbytes_avail; |
26825
|
0
|
|
|
|
|
|
u8 * const out_fastloop_end = |
26826
|
0
|
|
|
|
|
|
out_end - MIN(out_nbytes_avail, FASTLOOP_MAX_BYTES_WRITTEN); |
26827
|
|
|
|
|
|
|
|
26828
|
|
|
|
|
|
|
|
26829
|
0
|
|
|
|
|
|
const u8 *in_next = in; |
26830
|
0
|
|
|
|
|
|
const u8 * const in_end = in_next + in_nbytes; |
26831
|
0
|
|
|
|
|
|
const u8 * const in_fastloop_end = |
26832
|
0
|
|
|
|
|
|
in_end - MIN(in_nbytes, FASTLOOP_MAX_BYTES_READ); |
26833
|
0
|
|
|
|
|
|
bitbuf_t bitbuf = 0; |
26834
|
|
|
|
|
|
|
bitbuf_t saved_bitbuf; |
26835
|
0
|
|
|
|
|
|
u32 bitsleft = 0; |
26836
|
0
|
|
|
|
|
|
size_t overread_count = 0; |
26837
|
|
|
|
|
|
|
|
26838
|
|
|
|
|
|
|
bool is_final_block; |
26839
|
|
|
|
|
|
|
unsigned block_type; |
26840
|
|
|
|
|
|
|
unsigned num_litlen_syms; |
26841
|
|
|
|
|
|
|
unsigned num_offset_syms; |
26842
|
|
|
|
|
|
|
bitbuf_t litlen_tablemask; |
26843
|
|
|
|
|
|
|
u32 entry; |
26844
|
|
|
|
|
|
|
|
26845
|
|
|
|
|
|
|
next_block: |
26846
|
|
|
|
|
|
|
|
26847
|
|
|
|
|
|
|
; |
26848
|
|
|
|
|
|
|
|
26849
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME(1 + 2 + 5 + 5 + 4 + 3)); |
26850
|
0
|
0
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26851
|
|
|
|
|
|
|
|
26852
|
|
|
|
|
|
|
|
26853
|
0
|
|
|
|
|
|
is_final_block = bitbuf & BITMASK(1); |
26854
|
|
|
|
|
|
|
|
26855
|
|
|
|
|
|
|
|
26856
|
0
|
|
|
|
|
|
block_type = (bitbuf >> 1) & BITMASK(2); |
26857
|
|
|
|
|
|
|
|
26858
|
0
|
0
|
|
|
|
|
if (block_type == DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN) { |
26859
|
|
|
|
|
|
|
|
26860
|
|
|
|
|
|
|
|
26861
|
|
|
|
|
|
|
|
26862
|
|
|
|
|
|
|
|
26863
|
|
|
|
|
|
|
static const u8 deflate_precode_lens_permutation[DEFLATE_NUM_PRECODE_SYMS] = { |
26864
|
|
|
|
|
|
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
26865
|
|
|
|
|
|
|
}; |
26866
|
|
|
|
|
|
|
|
26867
|
|
|
|
|
|
|
unsigned num_explicit_precode_lens; |
26868
|
|
|
|
|
|
|
unsigned i; |
26869
|
|
|
|
|
|
|
|
26870
|
|
|
|
|
|
|
|
26871
|
|
|
|
|
|
|
|
26872
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_LITLEN_SYMS == 257 + BITMASK(5)); |
26873
|
0
|
|
|
|
|
|
num_litlen_syms = 257 + ((bitbuf >> 3) & BITMASK(5)); |
26874
|
|
|
|
|
|
|
|
26875
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_OFFSET_SYMS == 1 + BITMASK(5)); |
26876
|
0
|
|
|
|
|
|
num_offset_syms = 1 + ((bitbuf >> 8) & BITMASK(5)); |
26877
|
|
|
|
|
|
|
|
26878
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_PRECODE_SYMS == 4 + BITMASK(4)); |
26879
|
0
|
|
|
|
|
|
num_explicit_precode_lens = 4 + ((bitbuf >> 13) & BITMASK(4)); |
26880
|
|
|
|
|
|
|
|
26881
|
0
|
|
|
|
|
|
d->static_codes_loaded = false; |
26882
|
|
|
|
|
|
|
|
26883
|
|
|
|
|
|
|
|
26884
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_PRE_CODEWORD_LEN == (1 << 3) - 1); |
26885
|
|
|
|
|
|
|
if (CAN_CONSUME(3 * (DEFLATE_NUM_PRECODE_SYMS - 1))) { |
26886
|
0
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[0]] = |
26887
|
0
|
|
|
|
|
|
(bitbuf >> 17) & BITMASK(3); |
26888
|
0
|
|
|
|
|
|
bitbuf >>= 20; |
26889
|
0
|
|
|
|
|
|
bitsleft -= 20; |
26890
|
0
|
0
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26891
|
0
|
|
|
|
|
|
i = 1; |
26892
|
|
|
|
|
|
|
do { |
26893
|
0
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = |
26894
|
|
|
|
|
|
|
bitbuf & BITMASK(3); |
26895
|
0
|
|
|
|
|
|
bitbuf >>= 3; |
26896
|
0
|
|
|
|
|
|
bitsleft -= 3; |
26897
|
0
|
0
|
|
|
|
|
} while (++i < num_explicit_precode_lens); |
26898
|
|
|
|
|
|
|
} else { |
26899
|
|
|
|
|
|
|
bitbuf >>= 17; |
26900
|
|
|
|
|
|
|
bitsleft -= 17; |
26901
|
|
|
|
|
|
|
i = 0; |
26902
|
|
|
|
|
|
|
do { |
26903
|
|
|
|
|
|
|
if ((u8)bitsleft < 3) |
26904
|
|
|
|
|
|
|
REFILL_BITS(); |
26905
|
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = |
26906
|
|
|
|
|
|
|
bitbuf & BITMASK(3); |
26907
|
|
|
|
|
|
|
bitbuf >>= 3; |
26908
|
|
|
|
|
|
|
bitsleft -= 3; |
26909
|
|
|
|
|
|
|
} while (++i < num_explicit_precode_lens); |
26910
|
|
|
|
|
|
|
} |
26911
|
0
|
0
|
|
|
|
|
for (; i < DEFLATE_NUM_PRECODE_SYMS; i++) |
26912
|
0
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = 0; |
26913
|
|
|
|
|
|
|
|
26914
|
|
|
|
|
|
|
|
26915
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(build_precode_decode_table(d)); |
26916
|
|
|
|
|
|
|
|
26917
|
|
|
|
|
|
|
|
26918
|
0
|
|
|
|
|
|
i = 0; |
26919
|
|
|
|
|
|
|
do { |
26920
|
|
|
|
|
|
|
unsigned presym; |
26921
|
|
|
|
|
|
|
u8 rep_val; |
26922
|
|
|
|
|
|
|
unsigned rep_count; |
26923
|
|
|
|
|
|
|
|
26924
|
0
|
0
|
|
|
|
|
if ((u8)bitsleft < DEFLATE_MAX_PRE_CODEWORD_LEN + 7) |
26925
|
0
|
0
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26926
|
|
|
|
|
|
|
|
26927
|
|
|
|
|
|
|
|
26928
|
|
|
|
|
|
|
STATIC_ASSERT(PRECODE_TABLEBITS == DEFLATE_MAX_PRE_CODEWORD_LEN); |
26929
|
|
|
|
|
|
|
|
26930
|
|
|
|
|
|
|
|
26931
|
0
|
|
|
|
|
|
entry = d->u.l.precode_decode_table[ |
26932
|
0
|
|
|
|
|
|
bitbuf & BITMASK(DEFLATE_MAX_PRE_CODEWORD_LEN)]; |
26933
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26934
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26935
|
0
|
|
|
|
|
|
presym = entry >> 16; |
26936
|
|
|
|
|
|
|
|
26937
|
0
|
0
|
|
|
|
|
if (presym < 16) { |
26938
|
|
|
|
|
|
|
|
26939
|
0
|
|
|
|
|
|
d->u.l.lens[i++] = presym; |
26940
|
0
|
|
|
|
|
|
continue; |
26941
|
|
|
|
|
|
|
} |
26942
|
|
|
|
|
|
|
|
26943
|
|
|
|
|
|
|
|
26944
|
|
|
|
|
|
|
|
26945
|
|
|
|
|
|
|
|
26946
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_LENS_OVERRUN == 138 - 1); |
26947
|
|
|
|
|
|
|
|
26948
|
0
|
0
|
|
|
|
|
if (presym == 16) { |
26949
|
|
|
|
|
|
|
|
26950
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(i != 0); |
26951
|
0
|
|
|
|
|
|
rep_val = d->u.l.lens[i - 1]; |
26952
|
|
|
|
|
|
|
STATIC_ASSERT(3 + BITMASK(2) == 6); |
26953
|
0
|
|
|
|
|
|
rep_count = 3 + (bitbuf & BITMASK(2)); |
26954
|
0
|
|
|
|
|
|
bitbuf >>= 2; |
26955
|
0
|
|
|
|
|
|
bitsleft -= 2; |
26956
|
0
|
|
|
|
|
|
d->u.l.lens[i + 0] = rep_val; |
26957
|
0
|
|
|
|
|
|
d->u.l.lens[i + 1] = rep_val; |
26958
|
0
|
|
|
|
|
|
d->u.l.lens[i + 2] = rep_val; |
26959
|
0
|
|
|
|
|
|
d->u.l.lens[i + 3] = rep_val; |
26960
|
0
|
|
|
|
|
|
d->u.l.lens[i + 4] = rep_val; |
26961
|
0
|
|
|
|
|
|
d->u.l.lens[i + 5] = rep_val; |
26962
|
0
|
|
|
|
|
|
i += rep_count; |
26963
|
0
|
0
|
|
|
|
|
} else if (presym == 17) { |
26964
|
|
|
|
|
|
|
|
26965
|
|
|
|
|
|
|
STATIC_ASSERT(3 + BITMASK(3) == 10); |
26966
|
0
|
|
|
|
|
|
rep_count = 3 + (bitbuf & BITMASK(3)); |
26967
|
0
|
|
|
|
|
|
bitbuf >>= 3; |
26968
|
0
|
|
|
|
|
|
bitsleft -= 3; |
26969
|
0
|
|
|
|
|
|
d->u.l.lens[i + 0] = 0; |
26970
|
0
|
|
|
|
|
|
d->u.l.lens[i + 1] = 0; |
26971
|
0
|
|
|
|
|
|
d->u.l.lens[i + 2] = 0; |
26972
|
0
|
|
|
|
|
|
d->u.l.lens[i + 3] = 0; |
26973
|
0
|
|
|
|
|
|
d->u.l.lens[i + 4] = 0; |
26974
|
0
|
|
|
|
|
|
d->u.l.lens[i + 5] = 0; |
26975
|
0
|
|
|
|
|
|
d->u.l.lens[i + 6] = 0; |
26976
|
0
|
|
|
|
|
|
d->u.l.lens[i + 7] = 0; |
26977
|
0
|
|
|
|
|
|
d->u.l.lens[i + 8] = 0; |
26978
|
0
|
|
|
|
|
|
d->u.l.lens[i + 9] = 0; |
26979
|
0
|
|
|
|
|
|
i += rep_count; |
26980
|
|
|
|
|
|
|
} else { |
26981
|
|
|
|
|
|
|
|
26982
|
|
|
|
|
|
|
STATIC_ASSERT(11 + BITMASK(7) == 138); |
26983
|
0
|
|
|
|
|
|
rep_count = 11 + (bitbuf & BITMASK(7)); |
26984
|
0
|
|
|
|
|
|
bitbuf >>= 7; |
26985
|
0
|
|
|
|
|
|
bitsleft -= 7; |
26986
|
0
|
|
|
|
|
|
memset(&d->u.l.lens[i], 0, |
26987
|
|
|
|
|
|
|
rep_count * sizeof(d->u.l.lens[i])); |
26988
|
0
|
|
|
|
|
|
i += rep_count; |
26989
|
|
|
|
|
|
|
} |
26990
|
0
|
0
|
|
|
|
|
} while (i < num_litlen_syms + num_offset_syms); |
26991
|
|
|
|
|
|
|
|
26992
|
|
|
|
|
|
|
|
26993
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(i == num_litlen_syms + num_offset_syms); |
26994
|
|
|
|
|
|
|
|
26995
|
0
|
0
|
|
|
|
|
} else if (block_type == DEFLATE_BLOCKTYPE_UNCOMPRESSED) { |
26996
|
|
|
|
|
|
|
u16 len, nlen; |
26997
|
|
|
|
|
|
|
|
26998
|
|
|
|
|
|
|
|
26999
|
|
|
|
|
|
|
|
27000
|
0
|
|
|
|
|
|
bitsleft -= 3; |
27001
|
|
|
|
|
|
|
|
27002
|
|
|
|
|
|
|
|
27003
|
0
|
|
|
|
|
|
bitsleft = (u8)bitsleft; |
27004
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(overread_count <= (bitsleft >> 3)); |
27005
|
0
|
|
|
|
|
|
in_next -= (bitsleft >> 3) - overread_count; |
27006
|
0
|
|
|
|
|
|
overread_count = 0; |
27007
|
0
|
|
|
|
|
|
bitbuf = 0; |
27008
|
0
|
|
|
|
|
|
bitsleft = 0; |
27009
|
|
|
|
|
|
|
|
27010
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(in_end - in_next >= 4); |
27011
|
0
|
|
|
|
|
|
len = get_unaligned_le16(in_next); |
27012
|
0
|
|
|
|
|
|
nlen = get_unaligned_le16(in_next + 2); |
27013
|
0
|
|
|
|
|
|
in_next += 4; |
27014
|
|
|
|
|
|
|
|
27015
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(len == (u16)~nlen); |
27016
|
0
|
0
|
|
|
|
|
if (unlikely(len > out_end - out_next)) |
27017
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
27018
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(len <= in_end - in_next); |
27019
|
|
|
|
|
|
|
|
27020
|
0
|
|
|
|
|
|
memcpy(out_next, in_next, len); |
27021
|
0
|
|
|
|
|
|
in_next += len; |
27022
|
0
|
|
|
|
|
|
out_next += len; |
27023
|
|
|
|
|
|
|
|
27024
|
0
|
|
|
|
|
|
goto block_done; |
27025
|
|
|
|
|
|
|
|
27026
|
|
|
|
|
|
|
} else { |
27027
|
|
|
|
|
|
|
unsigned i; |
27028
|
|
|
|
|
|
|
|
27029
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(block_type == DEFLATE_BLOCKTYPE_STATIC_HUFFMAN); |
27030
|
|
|
|
|
|
|
|
27031
|
|
|
|
|
|
|
|
27032
|
|
|
|
|
|
|
|
27033
|
0
|
|
|
|
|
|
bitbuf >>= 3; |
27034
|
0
|
|
|
|
|
|
bitsleft -= 3; |
27035
|
|
|
|
|
|
|
|
27036
|
0
|
0
|
|
|
|
|
if (d->static_codes_loaded) |
27037
|
0
|
|
|
|
|
|
goto have_decode_tables; |
27038
|
|
|
|
|
|
|
|
27039
|
0
|
|
|
|
|
|
d->static_codes_loaded = true; |
27040
|
|
|
|
|
|
|
|
27041
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_LITLEN_SYMS == 288); |
27042
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_OFFSET_SYMS == 32); |
27043
|
|
|
|
|
|
|
|
27044
|
0
|
0
|
|
|
|
|
for (i = 0; i < 144; i++) |
27045
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 8; |
27046
|
0
|
0
|
|
|
|
|
for (; i < 256; i++) |
27047
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 9; |
27048
|
0
|
0
|
|
|
|
|
for (; i < 280; i++) |
27049
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 7; |
27050
|
0
|
0
|
|
|
|
|
for (; i < 288; i++) |
27051
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 8; |
27052
|
|
|
|
|
|
|
|
27053
|
0
|
0
|
|
|
|
|
for (; i < 288 + 32; i++) |
27054
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 5; |
27055
|
|
|
|
|
|
|
|
27056
|
0
|
|
|
|
|
|
num_litlen_syms = 288; |
27057
|
0
|
|
|
|
|
|
num_offset_syms = 32; |
27058
|
|
|
|
|
|
|
} |
27059
|
|
|
|
|
|
|
|
27060
|
|
|
|
|
|
|
|
27061
|
|
|
|
|
|
|
|
27062
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(build_offset_decode_table(d, num_litlen_syms, num_offset_syms)); |
27063
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(build_litlen_decode_table(d, num_litlen_syms, num_offset_syms)); |
27064
|
|
|
|
|
|
|
have_decode_tables: |
27065
|
0
|
|
|
|
|
|
litlen_tablemask = BITMASK(d->litlen_tablebits); |
27066
|
|
|
|
|
|
|
|
27067
|
|
|
|
|
|
|
|
27068
|
0
|
0
|
|
|
|
|
if (in_next >= in_fastloop_end || out_next >= out_fastloop_end) |
|
|
0
|
|
|
|
|
|
27069
|
|
|
|
|
|
|
goto generic_loop; |
27070
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27071
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
27072
|
|
|
|
|
|
|
do { |
27073
|
|
|
|
|
|
|
u32 length, offset, lit; |
27074
|
|
|
|
|
|
|
const u8 *src; |
27075
|
|
|
|
|
|
|
u8 *dst; |
27076
|
|
|
|
|
|
|
|
27077
|
|
|
|
|
|
|
|
27078
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
27079
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
27080
|
0
|
|
|
|
|
|
bitsleft -= entry; |
27081
|
|
|
|
|
|
|
|
27082
|
|
|
|
|
|
|
|
27083
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
27084
|
|
|
|
|
|
|
|
27085
|
|
|
|
|
|
|
if ( |
27086
|
|
|
|
|
|
|
CAN_CONSUME_AND_THEN_PRELOAD(2 * LITLEN_TABLEBITS + |
27087
|
|
|
|
|
|
|
LENGTH_MAXBITS, |
27088
|
|
|
|
|
|
|
OFFSET_TABLEBITS) && |
27089
|
|
|
|
|
|
|
|
27090
|
|
|
|
|
|
|
CAN_CONSUME_AND_THEN_PRELOAD(2 * LITLEN_TABLEBITS + |
27091
|
|
|
|
|
|
|
DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
27092
|
|
|
|
|
|
|
LITLEN_TABLEBITS)) { |
27093
|
|
|
|
|
|
|
|
27094
|
0
|
|
|
|
|
|
lit = entry >> 16; |
27095
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
27096
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
27097
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
27098
|
0
|
|
|
|
|
|
bitsleft -= entry; |
27099
|
0
|
|
|
|
|
|
*out_next++ = lit; |
27100
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
27101
|
|
|
|
|
|
|
|
27102
|
0
|
|
|
|
|
|
lit = entry >> 16; |
27103
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
27104
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
27105
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
27106
|
0
|
|
|
|
|
|
bitsleft -= entry; |
27107
|
0
|
|
|
|
|
|
*out_next++ = lit; |
27108
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
27109
|
|
|
|
|
|
|
|
27110
|
0
|
|
|
|
|
|
lit = entry >> 16; |
27111
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
27112
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27113
|
0
|
|
|
|
|
|
*out_next++ = lit; |
27114
|
0
|
|
|
|
|
|
continue; |
27115
|
|
|
|
|
|
|
} |
27116
|
|
|
|
|
|
|
} |
27117
|
|
|
|
|
|
|
} else { |
27118
|
|
|
|
|
|
|
|
27119
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME_AND_THEN_PRELOAD( |
27120
|
|
|
|
|
|
|
LITLEN_TABLEBITS, LITLEN_TABLEBITS)); |
27121
|
|
|
|
|
|
|
lit = entry >> 16; |
27122
|
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
27123
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27124
|
|
|
|
|
|
|
*out_next++ = lit; |
27125
|
|
|
|
|
|
|
continue; |
27126
|
|
|
|
|
|
|
} |
27127
|
|
|
|
|
|
|
} |
27128
|
|
|
|
|
|
|
|
27129
|
|
|
|
|
|
|
|
27130
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
27131
|
|
|
|
|
|
|
|
27132
|
|
|
|
|
|
|
|
27133
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
27134
|
0
|
|
|
|
|
|
goto block_done; |
27135
|
|
|
|
|
|
|
|
27136
|
|
|
|
|
|
|
|
27137
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[(entry >> 16) + |
27138
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
27139
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
27140
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
27141
|
0
|
|
|
|
|
|
bitsleft -= entry; |
27142
|
|
|
|
|
|
|
|
27143
|
|
|
|
|
|
|
|
27144
|
|
|
|
|
|
|
if (!CAN_CONSUME_AND_THEN_PRELOAD(DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
27145
|
|
|
|
|
|
|
LITLEN_TABLEBITS) || |
27146
|
|
|
|
|
|
|
!CAN_CONSUME_AND_THEN_PRELOAD(LENGTH_MAXBITS, |
27147
|
|
|
|
|
|
|
OFFSET_TABLEBITS)) |
27148
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27149
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
27150
|
|
|
|
|
|
|
|
27151
|
0
|
|
|
|
|
|
lit = entry >> 16; |
27152
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
27153
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27154
|
0
|
|
|
|
|
|
*out_next++ = lit; |
27155
|
0
|
|
|
|
|
|
continue; |
27156
|
|
|
|
|
|
|
} |
27157
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
27158
|
0
|
|
|
|
|
|
goto block_done; |
27159
|
|
|
|
|
|
|
|
27160
|
|
|
|
|
|
|
} |
27161
|
|
|
|
|
|
|
|
27162
|
|
|
|
|
|
|
|
27163
|
0
|
|
|
|
|
|
length = entry >> 16; |
27164
|
0
|
|
|
|
|
|
length += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
27165
|
|
|
|
|
|
|
|
27166
|
|
|
|
|
|
|
|
27167
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME_AND_THEN_PRELOAD(LENGTH_MAXFASTBITS, |
27168
|
|
|
|
|
|
|
OFFSET_TABLEBITS)); |
27169
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[bitbuf & BITMASK(OFFSET_TABLEBITS)]; |
27170
|
|
|
|
|
|
|
if (CAN_CONSUME_AND_THEN_PRELOAD(OFFSET_MAXBITS, |
27171
|
|
|
|
|
|
|
LITLEN_TABLEBITS)) { |
27172
|
|
|
|
|
|
|
|
27173
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
27174
|
|
|
|
|
|
|
|
27175
|
0
|
0
|
|
|
|
|
if (unlikely((u8)bitsleft < OFFSET_MAXBITS + |
27176
|
|
|
|
|
|
|
LITLEN_TABLEBITS - PRELOAD_SLACK)) |
27177
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27178
|
0
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
27179
|
0
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
27180
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
27181
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
27182
|
0
|
0
|
|
|
|
|
} else if (unlikely((u8)bitsleft < OFFSET_MAXFASTBITS + |
27183
|
|
|
|
|
|
|
LITLEN_TABLEBITS - PRELOAD_SLACK)) |
27184
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27185
|
|
|
|
|
|
|
} else { |
27186
|
|
|
|
|
|
|
|
27187
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27188
|
|
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
27189
|
|
|
|
|
|
|
|
27190
|
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
27191
|
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
27192
|
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
27193
|
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
27194
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27195
|
|
|
|
|
|
|
|
27196
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME( |
27197
|
|
|
|
|
|
|
OFFSET_MAXBITS - OFFSET_TABLEBITS)); |
27198
|
|
|
|
|
|
|
} else { |
27199
|
|
|
|
|
|
|
|
27200
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME(OFFSET_MAXFASTBITS)); |
27201
|
|
|
|
|
|
|
} |
27202
|
|
|
|
|
|
|
} |
27203
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
27204
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
27205
|
0
|
|
|
|
|
|
bitsleft -= entry; |
27206
|
0
|
|
|
|
|
|
offset = entry >> 16; |
27207
|
0
|
|
|
|
|
|
offset += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
27208
|
|
|
|
|
|
|
|
27209
|
|
|
|
|
|
|
|
27210
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(offset <= out_next - (const u8 *)out); |
27211
|
0
|
|
|
|
|
|
src = out_next - offset; |
27212
|
0
|
|
|
|
|
|
dst = out_next; |
27213
|
0
|
|
|
|
|
|
out_next += length; |
27214
|
|
|
|
|
|
|
|
27215
|
|
|
|
|
|
|
|
27216
|
|
|
|
|
|
|
if (!CAN_CONSUME_AND_THEN_PRELOAD( |
27217
|
|
|
|
|
|
|
MAX(OFFSET_MAXBITS - OFFSET_TABLEBITS, |
27218
|
|
|
|
|
|
|
OFFSET_MAXFASTBITS), |
27219
|
|
|
|
|
|
|
LITLEN_TABLEBITS) && |
27220
|
|
|
|
|
|
|
unlikely((u8)bitsleft < LITLEN_TABLEBITS - PRELOAD_SLACK)) |
27221
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27222
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
27223
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
27224
|
|
|
|
|
|
|
|
27225
|
|
|
|
|
|
|
|
27226
|
0
|
0
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST && offset >= WORDBYTES) { |
27227
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27228
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27229
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27230
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27231
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27232
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27233
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27234
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27235
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27236
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27237
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27238
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27239
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27240
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27241
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27242
|
0
|
0
|
|
|
|
|
while (dst < out_next) { |
27243
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27244
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27245
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27246
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27247
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27248
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27249
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27250
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27251
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27252
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27253
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27254
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27255
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27256
|
0
|
|
|
|
|
|
src += WORDBYTES; |
27257
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27258
|
|
|
|
|
|
|
} |
27259
|
0
|
0
|
|
|
|
|
} else if (UNALIGNED_ACCESS_IS_FAST && offset == 1) { |
27260
|
|
|
|
|
|
|
machine_word_t v; |
27261
|
|
|
|
|
|
|
|
27262
|
|
|
|
|
|
|
|
27263
|
0
|
|
|
|
|
|
v = (machine_word_t)0x0101010101010101 * src[0]; |
27264
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
27265
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27266
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
27267
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27268
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
27269
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27270
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
27271
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27272
|
0
|
0
|
|
|
|
|
while (dst < out_next) { |
27273
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
27274
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27275
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
27276
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27277
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
27278
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27279
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
27280
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
27281
|
|
|
|
|
|
|
} |
27282
|
|
|
|
|
|
|
} else if (UNALIGNED_ACCESS_IS_FAST) { |
27283
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27284
|
0
|
|
|
|
|
|
src += offset; |
27285
|
0
|
|
|
|
|
|
dst += offset; |
27286
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27287
|
0
|
|
|
|
|
|
src += offset; |
27288
|
0
|
|
|
|
|
|
dst += offset; |
27289
|
|
|
|
|
|
|
do { |
27290
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27291
|
0
|
|
|
|
|
|
src += offset; |
27292
|
0
|
|
|
|
|
|
dst += offset; |
27293
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
27294
|
0
|
|
|
|
|
|
src += offset; |
27295
|
0
|
|
|
|
|
|
dst += offset; |
27296
|
0
|
0
|
|
|
|
|
} while (dst < out_next); |
27297
|
|
|
|
|
|
|
} else { |
27298
|
|
|
|
|
|
|
*dst++ = *src++; |
27299
|
|
|
|
|
|
|
*dst++ = *src++; |
27300
|
|
|
|
|
|
|
do { |
27301
|
|
|
|
|
|
|
*dst++ = *src++; |
27302
|
|
|
|
|
|
|
} while (dst < out_next); |
27303
|
|
|
|
|
|
|
} |
27304
|
0
|
0
|
|
|
|
|
} while (in_next < in_fastloop_end && out_next < out_fastloop_end); |
|
|
0
|
|
|
|
|
|
27305
|
|
|
|
|
|
|
|
27306
|
|
|
|
|
|
|
|
27307
|
|
|
|
|
|
|
generic_loop: |
27308
|
|
|
|
|
|
|
for (;;) { |
27309
|
|
|
|
|
|
|
u32 length, offset; |
27310
|
|
|
|
|
|
|
const u8 *src; |
27311
|
|
|
|
|
|
|
u8 *dst; |
27312
|
|
|
|
|
|
|
|
27313
|
0
|
0
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
27314
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
27315
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
27316
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
27317
|
0
|
|
|
|
|
|
bitsleft -= entry; |
27318
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_SUBTABLE_POINTER)) { |
27319
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[(entry >> 16) + |
27320
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
27321
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
27322
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
27323
|
0
|
|
|
|
|
|
bitsleft -= entry; |
27324
|
|
|
|
|
|
|
} |
27325
|
0
|
|
|
|
|
|
length = entry >> 16; |
27326
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
27327
|
0
|
0
|
|
|
|
|
if (unlikely(out_next == out_end)) |
27328
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
27329
|
0
|
|
|
|
|
|
*out_next++ = length; |
27330
|
0
|
|
|
|
|
|
continue; |
27331
|
|
|
|
|
|
|
} |
27332
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
27333
|
0
|
|
|
|
|
|
goto block_done; |
27334
|
0
|
|
|
|
|
|
length += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
27335
|
0
|
0
|
|
|
|
|
if (unlikely(length > out_end - out_next)) |
27336
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
27337
|
|
|
|
|
|
|
|
27338
|
|
|
|
|
|
|
if (!CAN_CONSUME(LENGTH_MAXBITS + OFFSET_MAXBITS)) |
27339
|
|
|
|
|
|
|
REFILL_BITS(); |
27340
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[bitbuf & BITMASK(OFFSET_TABLEBITS)]; |
27341
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
27342
|
0
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
27343
|
0
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
27344
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
27345
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
27346
|
|
|
|
|
|
|
if (!CAN_CONSUME(OFFSET_MAXBITS)) |
27347
|
|
|
|
|
|
|
REFILL_BITS(); |
27348
|
|
|
|
|
|
|
} |
27349
|
0
|
|
|
|
|
|
offset = entry >> 16; |
27350
|
0
|
|
|
|
|
|
offset += EXTRACT_VARBITS8(bitbuf, entry) >> (u8)(entry >> 8); |
27351
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
27352
|
0
|
|
|
|
|
|
bitsleft -= entry; |
27353
|
|
|
|
|
|
|
|
27354
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(offset <= out_next - (const u8 *)out); |
27355
|
0
|
|
|
|
|
|
src = out_next - offset; |
27356
|
0
|
|
|
|
|
|
dst = out_next; |
27357
|
0
|
|
|
|
|
|
out_next += length; |
27358
|
|
|
|
|
|
|
|
27359
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MIN_MATCH_LEN == 3); |
27360
|
0
|
|
|
|
|
|
*dst++ = *src++; |
27361
|
0
|
|
|
|
|
|
*dst++ = *src++; |
27362
|
|
|
|
|
|
|
do { |
27363
|
0
|
|
|
|
|
|
*dst++ = *src++; |
27364
|
0
|
0
|
|
|
|
|
} while (dst < out_next); |
27365
|
0
|
|
|
|
|
|
} |
27366
|
|
|
|
|
|
|
|
27367
|
|
|
|
|
|
|
block_done: |
27368
|
|
|
|
|
|
|
|
27369
|
|
|
|
|
|
|
|
27370
|
0
|
0
|
|
|
|
|
if (!is_final_block) |
27371
|
0
|
|
|
|
|
|
goto next_block; |
27372
|
|
|
|
|
|
|
|
27373
|
|
|
|
|
|
|
|
27374
|
|
|
|
|
|
|
|
27375
|
0
|
|
|
|
|
|
bitsleft = (u8)bitsleft; |
27376
|
|
|
|
|
|
|
|
27377
|
|
|
|
|
|
|
|
27378
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(overread_count <= (bitsleft >> 3)); |
27379
|
|
|
|
|
|
|
|
27380
|
|
|
|
|
|
|
|
27381
|
0
|
0
|
|
|
|
|
if (actual_in_nbytes_ret) { |
27382
|
|
|
|
|
|
|
|
27383
|
0
|
|
|
|
|
|
in_next -= (bitsleft >> 3) - overread_count; |
27384
|
|
|
|
|
|
|
|
27385
|
0
|
|
|
|
|
|
*actual_in_nbytes_ret = in_next - (u8 *)in; |
27386
|
|
|
|
|
|
|
} |
27387
|
|
|
|
|
|
|
|
27388
|
|
|
|
|
|
|
|
27389
|
0
|
0
|
|
|
|
|
if (actual_out_nbytes_ret) { |
27390
|
0
|
|
|
|
|
|
*actual_out_nbytes_ret = out_next - (u8 *)out; |
27391
|
|
|
|
|
|
|
} else { |
27392
|
0
|
0
|
|
|
|
|
if (out_next != out_end) |
27393
|
0
|
|
|
|
|
|
return LIBDEFLATE_SHORT_OUTPUT; |
27394
|
|
|
|
|
|
|
} |
27395
|
0
|
|
|
|
|
|
return LIBDEFLATE_SUCCESS; |
27396
|
|
|
|
|
|
|
} |
27397
|
|
|
|
|
|
|
|
27398
|
|
|
|
|
|
|
#undef FUNCNAME |
27399
|
|
|
|
|
|
|
#undef ATTRIBUTES |
27400
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS |
27401
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS8 |
27402
|
|
|
|
|
|
|
|
27403
|
|
|
|
|
|
|
#endif |
27404
|
|
|
|
|
|
|
|
27405
|
|
|
|
|
|
|
#if defined(deflate_decompress_bmi2) && HAVE_BMI2_NATIVE |
27406
|
|
|
|
|
|
|
#define DEFAULT_IMPL deflate_decompress_bmi2 |
27407
|
|
|
|
|
|
|
#else |
27408
|
|
|
|
|
|
|
static inline decompress_func_t |
27409
|
2
|
|
|
|
|
|
arch_select_decompress_func(void) |
27410
|
|
|
|
|
|
|
{ |
27411
|
|
|
|
|
|
|
#ifdef deflate_decompress_bmi2 |
27412
|
2
|
50
|
|
|
|
|
if (HAVE_BMI2(get_x86_cpu_features())) |
27413
|
0
|
|
|
|
|
|
return deflate_decompress_bmi2; |
27414
|
|
|
|
|
|
|
#endif |
27415
|
2
|
|
|
|
|
|
return NULL; |
27416
|
|
|
|
|
|
|
} |
27417
|
|
|
|
|
|
|
#define arch_select_decompress_func arch_select_decompress_func |
27418
|
|
|
|
|
|
|
#endif |
27419
|
|
|
|
|
|
|
|
27420
|
|
|
|
|
|
|
#endif |
27421
|
|
|
|
|
|
|
|
27422
|
|
|
|
|
|
|
#endif |
27423
|
|
|
|
|
|
|
|
27424
|
|
|
|
|
|
|
#ifndef DEFAULT_IMPL |
27425
|
|
|
|
|
|
|
# define DEFAULT_IMPL deflate_decompress_default |
27426
|
|
|
|
|
|
|
#endif |
27427
|
|
|
|
|
|
|
|
27428
|
|
|
|
|
|
|
#ifdef arch_select_decompress_func |
27429
|
|
|
|
|
|
|
static enum libdeflate_result |
27430
|
|
|
|
|
|
|
dispatch_decomp(struct libdeflate_decompressor *d, |
27431
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27432
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27433
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret); |
27434
|
|
|
|
|
|
|
|
27435
|
|
|
|
|
|
|
static volatile decompress_func_t decompress_impl = dispatch_decomp; |
27436
|
|
|
|
|
|
|
|
27437
|
|
|
|
|
|
|
|
27438
|
|
|
|
|
|
|
static enum libdeflate_result |
27439
|
2
|
|
|
|
|
|
dispatch_decomp(struct libdeflate_decompressor *d, |
27440
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27441
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27442
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret) |
27443
|
|
|
|
|
|
|
{ |
27444
|
2
|
|
|
|
|
|
decompress_func_t f = arch_select_decompress_func(); |
27445
|
|
|
|
|
|
|
|
27446
|
2
|
50
|
|
|
|
|
if (f == NULL) |
27447
|
2
|
|
|
|
|
|
f = DEFAULT_IMPL; |
27448
|
|
|
|
|
|
|
|
27449
|
2
|
|
|
|
|
|
decompress_impl = f; |
27450
|
2
|
|
|
|
|
|
return f(d, in, in_nbytes, out, out_nbytes_avail, |
27451
|
|
|
|
|
|
|
actual_in_nbytes_ret, actual_out_nbytes_ret); |
27452
|
|
|
|
|
|
|
} |
27453
|
|
|
|
|
|
|
#else |
27454
|
|
|
|
|
|
|
|
27455
|
|
|
|
|
|
|
# define decompress_impl DEFAULT_IMPL |
27456
|
|
|
|
|
|
|
#endif |
27457
|
|
|
|
|
|
|
|
27458
|
|
|
|
|
|
|
|
27459
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27460
|
40
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *d, |
27461
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27462
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27463
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
27464
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
27465
|
|
|
|
|
|
|
{ |
27466
|
40
|
|
|
|
|
|
return decompress_impl(d, in, in_nbytes, out, out_nbytes_avail, |
27467
|
|
|
|
|
|
|
actual_in_nbytes_ret, actual_out_nbytes_ret); |
27468
|
|
|
|
|
|
|
} |
27469
|
|
|
|
|
|
|
|
27470
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27471
|
0
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *d, |
27472
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27473
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27474
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
27475
|
|
|
|
|
|
|
{ |
27476
|
0
|
|
|
|
|
|
return libdeflate_deflate_decompress_ex(d, in, in_nbytes, |
27477
|
|
|
|
|
|
|
out, out_nbytes_avail, |
27478
|
|
|
|
|
|
|
NULL, actual_out_nbytes_ret); |
27479
|
|
|
|
|
|
|
} |
27480
|
|
|
|
|
|
|
|
27481
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
27482
|
38
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options) |
27483
|
|
|
|
|
|
|
{ |
27484
|
|
|
|
|
|
|
struct libdeflate_decompressor *d; |
27485
|
|
|
|
|
|
|
|
27486
|
|
|
|
|
|
|
|
27487
|
38
|
50
|
|
|
|
|
if (options->sizeof_options != sizeof(*options)) |
27488
|
0
|
|
|
|
|
|
return NULL; |
27489
|
|
|
|
|
|
|
|
27490
|
38
|
50
|
|
|
|
|
d = (options->malloc_func ? options->malloc_func : |
27491
|
|
|
|
|
|
|
libdeflate_default_malloc_func)(sizeof(*d)); |
27492
|
38
|
50
|
|
|
|
|
if (d == NULL) |
27493
|
0
|
|
|
|
|
|
return NULL; |
27494
|
|
|
|
|
|
|
|
27495
|
38
|
|
|
|
|
|
memset(d, 0, sizeof(*d)); |
27496
|
76
|
|
|
|
|
|
d->free_func = options->free_func ? |
27497
|
38
|
50
|
|
|
|
|
options->free_func : libdeflate_default_free_func; |
27498
|
38
|
|
|
|
|
|
return d; |
27499
|
|
|
|
|
|
|
} |
27500
|
|
|
|
|
|
|
|
27501
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
27502
|
38
|
|
|
|
|
|
libdeflate_alloc_decompressor(void) |
27503
|
|
|
|
|
|
|
{ |
27504
|
|
|
|
|
|
|
static const struct libdeflate_options defaults = { |
27505
|
|
|
|
|
|
|
.sizeof_options = sizeof(defaults), |
27506
|
|
|
|
|
|
|
}; |
27507
|
38
|
|
|
|
|
|
return libdeflate_alloc_decompressor_ex(&defaults); |
27508
|
|
|
|
|
|
|
} |
27509
|
|
|
|
|
|
|
|
27510
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
27511
|
38
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *d) |
27512
|
|
|
|
|
|
|
{ |
27513
|
38
|
50
|
|
|
|
|
if (d) |
27514
|
38
|
|
|
|
|
|
d->free_func(d); |
27515
|
38
|
|
|
|
|
|
} |
27516
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/gzip_compress.c */ |
27517
|
|
|
|
|
|
|
|
27518
|
|
|
|
|
|
|
|
27519
|
|
|
|
|
|
|
/* #include "deflate_compress.h" */ |
27520
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_COMPRESS_H |
27521
|
|
|
|
|
|
|
#define LIB_DEFLATE_COMPRESS_H |
27522
|
|
|
|
|
|
|
|
27523
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
27524
|
|
|
|
|
|
|
|
27525
|
|
|
|
|
|
|
|
27526
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
27527
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
27528
|
|
|
|
|
|
|
|
27529
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
27530
|
|
|
|
|
|
|
|
27531
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
27532
|
|
|
|
|
|
|
#endif |
27533
|
|
|
|
|
|
|
|
27534
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
27535
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
27536
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
27537
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
27538
|
|
|
|
|
|
|
#else |
27539
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
27540
|
|
|
|
|
|
|
#endif |
27541
|
|
|
|
|
|
|
|
27542
|
|
|
|
|
|
|
|
27543
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
27544
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
27545
|
|
|
|
|
|
|
#else |
27546
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
27547
|
|
|
|
|
|
|
#endif |
27548
|
|
|
|
|
|
|
|
27549
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
27550
|
|
|
|
|
|
|
|
27551
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
27552
|
|
|
|
|
|
|
|
27553
|
|
|
|
|
|
|
|
27554
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
27555
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
27556
|
|
|
|
|
|
|
|
27557
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
27558
|
|
|
|
|
|
|
|
27559
|
|
|
|
|
|
|
|
27560
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
27561
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
27562
|
|
|
|
|
|
|
|
27563
|
|
|
|
|
|
|
#include |
27564
|
|
|
|
|
|
|
#include |
27565
|
|
|
|
|
|
|
|
27566
|
|
|
|
|
|
|
#ifdef __cplusplus |
27567
|
|
|
|
|
|
|
extern "C" { |
27568
|
|
|
|
|
|
|
#endif |
27569
|
|
|
|
|
|
|
|
27570
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
27571
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
27572
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
27573
|
|
|
|
|
|
|
|
27574
|
|
|
|
|
|
|
|
27575
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
27576
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
27577
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
27578
|
|
|
|
|
|
|
# else |
27579
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
27580
|
|
|
|
|
|
|
# endif |
27581
|
|
|
|
|
|
|
#endif |
27582
|
|
|
|
|
|
|
|
27583
|
|
|
|
|
|
|
|
27584
|
|
|
|
|
|
|
|
27585
|
|
|
|
|
|
|
|
27586
|
|
|
|
|
|
|
|
27587
|
|
|
|
|
|
|
struct libdeflate_compressor; |
27588
|
|
|
|
|
|
|
struct libdeflate_options; |
27589
|
|
|
|
|
|
|
|
27590
|
|
|
|
|
|
|
|
27591
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
27592
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
27593
|
|
|
|
|
|
|
|
27594
|
|
|
|
|
|
|
|
27595
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
27596
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
27597
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
27598
|
|
|
|
|
|
|
|
27599
|
|
|
|
|
|
|
|
27600
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27601
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
27602
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27603
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
27604
|
|
|
|
|
|
|
|
27605
|
|
|
|
|
|
|
|
27606
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27607
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
27608
|
|
|
|
|
|
|
size_t in_nbytes); |
27609
|
|
|
|
|
|
|
|
27610
|
|
|
|
|
|
|
|
27611
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27612
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
27613
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27614
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
27615
|
|
|
|
|
|
|
|
27616
|
|
|
|
|
|
|
|
27617
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27618
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
27619
|
|
|
|
|
|
|
size_t in_nbytes); |
27620
|
|
|
|
|
|
|
|
27621
|
|
|
|
|
|
|
|
27622
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27623
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
27624
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27625
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
27626
|
|
|
|
|
|
|
|
27627
|
|
|
|
|
|
|
|
27628
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27629
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
27630
|
|
|
|
|
|
|
size_t in_nbytes); |
27631
|
|
|
|
|
|
|
|
27632
|
|
|
|
|
|
|
|
27633
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
27634
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
27635
|
|
|
|
|
|
|
|
27636
|
|
|
|
|
|
|
|
27637
|
|
|
|
|
|
|
|
27638
|
|
|
|
|
|
|
|
27639
|
|
|
|
|
|
|
|
27640
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
27641
|
|
|
|
|
|
|
struct libdeflate_options; |
27642
|
|
|
|
|
|
|
|
27643
|
|
|
|
|
|
|
|
27644
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
27645
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
27646
|
|
|
|
|
|
|
|
27647
|
|
|
|
|
|
|
|
27648
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
27649
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
27650
|
|
|
|
|
|
|
|
27651
|
|
|
|
|
|
|
|
27652
|
|
|
|
|
|
|
enum libdeflate_result { |
27653
|
|
|
|
|
|
|
|
27654
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
27655
|
|
|
|
|
|
|
|
27656
|
|
|
|
|
|
|
|
27657
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
27658
|
|
|
|
|
|
|
|
27659
|
|
|
|
|
|
|
|
27660
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
27661
|
|
|
|
|
|
|
|
27662
|
|
|
|
|
|
|
|
27663
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
27664
|
|
|
|
|
|
|
}; |
27665
|
|
|
|
|
|
|
|
27666
|
|
|
|
|
|
|
|
27667
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27668
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
27669
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27670
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27671
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27672
|
|
|
|
|
|
|
|
27673
|
|
|
|
|
|
|
|
27674
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27675
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
27676
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27677
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27678
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
27679
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27680
|
|
|
|
|
|
|
|
27681
|
|
|
|
|
|
|
|
27682
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27683
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
27684
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27685
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27686
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27687
|
|
|
|
|
|
|
|
27688
|
|
|
|
|
|
|
|
27689
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27690
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
27691
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27692
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27693
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
27694
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27695
|
|
|
|
|
|
|
|
27696
|
|
|
|
|
|
|
|
27697
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27698
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
27699
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27700
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27701
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27702
|
|
|
|
|
|
|
|
27703
|
|
|
|
|
|
|
|
27704
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27705
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
27706
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27707
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27708
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
27709
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27710
|
|
|
|
|
|
|
|
27711
|
|
|
|
|
|
|
|
27712
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
27713
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
27714
|
|
|
|
|
|
|
|
27715
|
|
|
|
|
|
|
|
27716
|
|
|
|
|
|
|
|
27717
|
|
|
|
|
|
|
|
27718
|
|
|
|
|
|
|
|
27719
|
|
|
|
|
|
|
|
27720
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
27721
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
27722
|
|
|
|
|
|
|
|
27723
|
|
|
|
|
|
|
|
27724
|
|
|
|
|
|
|
|
27725
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
27726
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
27727
|
|
|
|
|
|
|
|
27728
|
|
|
|
|
|
|
|
27729
|
|
|
|
|
|
|
|
27730
|
|
|
|
|
|
|
|
27731
|
|
|
|
|
|
|
|
27732
|
|
|
|
|
|
|
|
27733
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
27734
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
27735
|
|
|
|
|
|
|
void (*free_func)(void *)); |
27736
|
|
|
|
|
|
|
|
27737
|
|
|
|
|
|
|
|
27738
|
|
|
|
|
|
|
struct libdeflate_options { |
27739
|
|
|
|
|
|
|
|
27740
|
|
|
|
|
|
|
|
27741
|
|
|
|
|
|
|
size_t sizeof_options; |
27742
|
|
|
|
|
|
|
|
27743
|
|
|
|
|
|
|
|
27744
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
27745
|
|
|
|
|
|
|
void (*free_func)(void *); |
27746
|
|
|
|
|
|
|
}; |
27747
|
|
|
|
|
|
|
|
27748
|
|
|
|
|
|
|
#ifdef __cplusplus |
27749
|
|
|
|
|
|
|
} |
27750
|
|
|
|
|
|
|
#endif |
27751
|
|
|
|
|
|
|
|
27752
|
|
|
|
|
|
|
#endif |
27753
|
|
|
|
|
|
|
|
27754
|
|
|
|
|
|
|
|
27755
|
|
|
|
|
|
|
#include |
27756
|
|
|
|
|
|
|
#include |
27757
|
|
|
|
|
|
|
#include |
27758
|
|
|
|
|
|
|
#ifdef _MSC_VER |
27759
|
|
|
|
|
|
|
# include |
27760
|
|
|
|
|
|
|
# include |
27761
|
|
|
|
|
|
|
|
27762
|
|
|
|
|
|
|
|
27763
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
27764
|
|
|
|
|
|
|
|
27765
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
27766
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
27767
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
27768
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
27769
|
|
|
|
|
|
|
|
27770
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
27771
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
27772
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
27773
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
27774
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
27775
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
27776
|
|
|
|
|
|
|
#endif |
27777
|
|
|
|
|
|
|
#ifndef FREESTANDING |
27778
|
|
|
|
|
|
|
# include |
27779
|
|
|
|
|
|
|
#endif |
27780
|
|
|
|
|
|
|
|
27781
|
|
|
|
|
|
|
|
27782
|
|
|
|
|
|
|
|
27783
|
|
|
|
|
|
|
|
27784
|
|
|
|
|
|
|
|
27785
|
|
|
|
|
|
|
|
27786
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
27787
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
27788
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
27789
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
27790
|
|
|
|
|
|
|
#ifdef _MSC_VER |
27791
|
|
|
|
|
|
|
# if defined(_M_X64) |
27792
|
|
|
|
|
|
|
# define ARCH_X86_64 |
27793
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
27794
|
|
|
|
|
|
|
# define ARCH_X86_32 |
27795
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
27796
|
|
|
|
|
|
|
# define ARCH_ARM64 |
27797
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
27798
|
|
|
|
|
|
|
# define ARCH_ARM32 |
27799
|
|
|
|
|
|
|
# endif |
27800
|
|
|
|
|
|
|
#else |
27801
|
|
|
|
|
|
|
# if defined(__x86_64__) |
27802
|
|
|
|
|
|
|
# define ARCH_X86_64 |
27803
|
|
|
|
|
|
|
# elif defined(__i386__) |
27804
|
|
|
|
|
|
|
# define ARCH_X86_32 |
27805
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
27806
|
|
|
|
|
|
|
# define ARCH_ARM64 |
27807
|
|
|
|
|
|
|
# elif defined(__arm__) |
27808
|
|
|
|
|
|
|
# define ARCH_ARM32 |
27809
|
|
|
|
|
|
|
# endif |
27810
|
|
|
|
|
|
|
#endif |
27811
|
|
|
|
|
|
|
|
27812
|
|
|
|
|
|
|
|
27813
|
|
|
|
|
|
|
|
27814
|
|
|
|
|
|
|
|
27815
|
|
|
|
|
|
|
|
27816
|
|
|
|
|
|
|
|
27817
|
|
|
|
|
|
|
typedef uint8_t u8; |
27818
|
|
|
|
|
|
|
typedef uint16_t u16; |
27819
|
|
|
|
|
|
|
typedef uint32_t u32; |
27820
|
|
|
|
|
|
|
typedef uint64_t u64; |
27821
|
|
|
|
|
|
|
typedef int8_t s8; |
27822
|
|
|
|
|
|
|
typedef int16_t s16; |
27823
|
|
|
|
|
|
|
typedef int32_t s32; |
27824
|
|
|
|
|
|
|
typedef int64_t s64; |
27825
|
|
|
|
|
|
|
|
27826
|
|
|
|
|
|
|
|
27827
|
|
|
|
|
|
|
#ifdef _MSC_VER |
27828
|
|
|
|
|
|
|
# ifdef _WIN64 |
27829
|
|
|
|
|
|
|
typedef long long ssize_t; |
27830
|
|
|
|
|
|
|
# else |
27831
|
|
|
|
|
|
|
typedef long ssize_t; |
27832
|
|
|
|
|
|
|
# endif |
27833
|
|
|
|
|
|
|
#endif |
27834
|
|
|
|
|
|
|
|
27835
|
|
|
|
|
|
|
|
27836
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
27837
|
|
|
|
|
|
|
|
27838
|
|
|
|
|
|
|
|
27839
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
27840
|
|
|
|
|
|
|
|
27841
|
|
|
|
|
|
|
|
27842
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
27843
|
|
|
|
|
|
|
|
27844
|
|
|
|
|
|
|
|
27845
|
|
|
|
|
|
|
|
27846
|
|
|
|
|
|
|
|
27847
|
|
|
|
|
|
|
|
27848
|
|
|
|
|
|
|
|
27849
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
27850
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
27851
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
27852
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
27853
|
|
|
|
|
|
|
#else |
27854
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
27855
|
|
|
|
|
|
|
#endif |
27856
|
|
|
|
|
|
|
#ifdef __clang__ |
27857
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
27858
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
27859
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
27860
|
|
|
|
|
|
|
# else |
27861
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
27862
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
27863
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
27864
|
|
|
|
|
|
|
# endif |
27865
|
|
|
|
|
|
|
#else |
27866
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
27867
|
|
|
|
|
|
|
#endif |
27868
|
|
|
|
|
|
|
|
27869
|
|
|
|
|
|
|
|
27870
|
|
|
|
|
|
|
#ifndef __has_attribute |
27871
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
27872
|
|
|
|
|
|
|
#endif |
27873
|
|
|
|
|
|
|
#ifndef __has_builtin |
27874
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
27875
|
|
|
|
|
|
|
#endif |
27876
|
|
|
|
|
|
|
|
27877
|
|
|
|
|
|
|
|
27878
|
|
|
|
|
|
|
#ifdef _MSC_VER |
27879
|
|
|
|
|
|
|
# define inline __inline |
27880
|
|
|
|
|
|
|
#endif |
27881
|
|
|
|
|
|
|
|
27882
|
|
|
|
|
|
|
|
27883
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
27884
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
27885
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27886
|
|
|
|
|
|
|
# define forceinline __forceinline |
27887
|
|
|
|
|
|
|
#else |
27888
|
|
|
|
|
|
|
# define forceinline inline |
27889
|
|
|
|
|
|
|
#endif |
27890
|
|
|
|
|
|
|
|
27891
|
|
|
|
|
|
|
|
27892
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
27893
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
27894
|
|
|
|
|
|
|
#else |
27895
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
27896
|
|
|
|
|
|
|
#endif |
27897
|
|
|
|
|
|
|
|
27898
|
|
|
|
|
|
|
|
27899
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
27900
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
27901
|
|
|
|
|
|
|
# define restrict __restrict__ |
27902
|
|
|
|
|
|
|
# else |
27903
|
|
|
|
|
|
|
# define restrict |
27904
|
|
|
|
|
|
|
# endif |
27905
|
|
|
|
|
|
|
#endif |
27906
|
|
|
|
|
|
|
|
27907
|
|
|
|
|
|
|
|
27908
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
27909
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
27910
|
|
|
|
|
|
|
#else |
27911
|
|
|
|
|
|
|
# define likely(expr) (expr) |
27912
|
|
|
|
|
|
|
#endif |
27913
|
|
|
|
|
|
|
|
27914
|
|
|
|
|
|
|
|
27915
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
27916
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
27917
|
|
|
|
|
|
|
#else |
27918
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
27919
|
|
|
|
|
|
|
#endif |
27920
|
|
|
|
|
|
|
|
27921
|
|
|
|
|
|
|
|
27922
|
|
|
|
|
|
|
#undef prefetchr |
27923
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
27924
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
27925
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27926
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
27927
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
27928
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
27929
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
27930
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
27931
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
27932
|
|
|
|
|
|
|
# endif |
27933
|
|
|
|
|
|
|
#endif |
27934
|
|
|
|
|
|
|
#ifndef prefetchr |
27935
|
|
|
|
|
|
|
# define prefetchr(addr) |
27936
|
|
|
|
|
|
|
#endif |
27937
|
|
|
|
|
|
|
|
27938
|
|
|
|
|
|
|
|
27939
|
|
|
|
|
|
|
#undef prefetchw |
27940
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
27941
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
27942
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27943
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
27944
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
27945
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
27946
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
27947
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
27948
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
27949
|
|
|
|
|
|
|
# endif |
27950
|
|
|
|
|
|
|
#endif |
27951
|
|
|
|
|
|
|
#ifndef prefetchw |
27952
|
|
|
|
|
|
|
# define prefetchw(addr) |
27953
|
|
|
|
|
|
|
#endif |
27954
|
|
|
|
|
|
|
|
27955
|
|
|
|
|
|
|
|
27956
|
|
|
|
|
|
|
#undef _aligned_attribute |
27957
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
27958
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
27959
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27960
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
27961
|
|
|
|
|
|
|
#endif |
27962
|
|
|
|
|
|
|
|
27963
|
|
|
|
|
|
|
|
27964
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
27965
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
27966
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
27967
|
|
|
|
|
|
|
#else |
27968
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
27969
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
27970
|
|
|
|
|
|
|
#endif |
27971
|
|
|
|
|
|
|
|
27972
|
|
|
|
|
|
|
|
27973
|
|
|
|
|
|
|
|
27974
|
|
|
|
|
|
|
|
27975
|
|
|
|
|
|
|
|
27976
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
27977
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
27978
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
27979
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
27980
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
27981
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
27982
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
27983
|
|
|
|
|
|
|
|
27984
|
|
|
|
|
|
|
|
27985
|
|
|
|
|
|
|
|
27986
|
|
|
|
|
|
|
|
27987
|
|
|
|
|
|
|
|
27988
|
|
|
|
|
|
|
|
27989
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
27990
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
27991
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27992
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
27993
|
|
|
|
|
|
|
#else |
27994
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
27995
|
|
|
|
|
|
|
{ |
27996
|
|
|
|
|
|
|
union { |
27997
|
|
|
|
|
|
|
u32 w; |
27998
|
|
|
|
|
|
|
u8 b; |
27999
|
|
|
|
|
|
|
} u; |
28000
|
|
|
|
|
|
|
|
28001
|
|
|
|
|
|
|
u.w = 1; |
28002
|
|
|
|
|
|
|
return u.b; |
28003
|
|
|
|
|
|
|
} |
28004
|
|
|
|
|
|
|
#endif |
28005
|
|
|
|
|
|
|
|
28006
|
|
|
|
|
|
|
|
28007
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
28008
|
|
|
|
|
|
|
{ |
28009
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
28010
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
28011
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28012
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
28013
|
|
|
|
|
|
|
#else |
28014
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
28015
|
|
|
|
|
|
|
#endif |
28016
|
|
|
|
|
|
|
} |
28017
|
|
|
|
|
|
|
|
28018
|
|
|
|
|
|
|
|
28019
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
28020
|
|
|
|
|
|
|
{ |
28021
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
28022
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
28023
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28024
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
28025
|
|
|
|
|
|
|
#else |
28026
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
28027
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
28028
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
28029
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
28030
|
|
|
|
|
|
|
#endif |
28031
|
|
|
|
|
|
|
} |
28032
|
|
|
|
|
|
|
|
28033
|
|
|
|
|
|
|
|
28034
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
28035
|
|
|
|
|
|
|
{ |
28036
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
28037
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
28038
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28039
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
28040
|
|
|
|
|
|
|
#else |
28041
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
28042
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
28043
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
28044
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
28045
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
28046
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
28047
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
28048
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
28049
|
|
|
|
|
|
|
#endif |
28050
|
|
|
|
|
|
|
} |
28051
|
|
|
|
|
|
|
|
28052
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
28053
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
28054
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
28055
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
28056
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
28057
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
28058
|
|
|
|
|
|
|
|
28059
|
|
|
|
|
|
|
|
28060
|
|
|
|
|
|
|
|
28061
|
|
|
|
|
|
|
|
28062
|
|
|
|
|
|
|
|
28063
|
|
|
|
|
|
|
|
28064
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
28065
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
28066
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
28067
|
|
|
|
|
|
|
defined(__wasm__)) |
28068
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
28069
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28070
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
28071
|
|
|
|
|
|
|
#else |
28072
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
28073
|
|
|
|
|
|
|
#endif |
28074
|
|
|
|
|
|
|
|
28075
|
|
|
|
|
|
|
|
28076
|
|
|
|
|
|
|
|
28077
|
|
|
|
|
|
|
#ifdef FREESTANDING |
28078
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
28079
|
|
|
|
|
|
|
#else |
28080
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
28081
|
|
|
|
|
|
|
#endif |
28082
|
|
|
|
|
|
|
|
28083
|
|
|
|
|
|
|
|
28084
|
|
|
|
|
|
|
|
28085
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
28086
|
|
|
|
|
|
|
static forceinline type \ |
28087
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
28088
|
|
|
|
|
|
|
{ \ |
28089
|
|
|
|
|
|
|
type v; \ |
28090
|
|
|
|
|
|
|
\ |
28091
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
28092
|
|
|
|
|
|
|
return v; \ |
28093
|
|
|
|
|
|
|
} \ |
28094
|
|
|
|
|
|
|
\ |
28095
|
|
|
|
|
|
|
static forceinline void \ |
28096
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
28097
|
|
|
|
|
|
|
{ \ |
28098
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
28099
|
|
|
|
|
|
|
} |
28100
|
|
|
|
|
|
|
|
28101
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
28102
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
28103
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
28104
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
28105
|
|
|
|
|
|
|
|
28106
|
|
|
|
|
|
|
#undef MEMCOPY |
28107
|
|
|
|
|
|
|
|
28108
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
28109
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
28110
|
|
|
|
|
|
|
|
28111
|
|
|
|
|
|
|
|
28112
|
|
|
|
|
|
|
|
28113
|
|
|
|
|
|
|
static forceinline u16 |
28114
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
28115
|
|
|
|
|
|
|
{ |
28116
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28117
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
28118
|
|
|
|
|
|
|
else |
28119
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
28120
|
|
|
|
|
|
|
} |
28121
|
|
|
|
|
|
|
|
28122
|
|
|
|
|
|
|
static forceinline u16 |
28123
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
28124
|
|
|
|
|
|
|
{ |
28125
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28126
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
28127
|
|
|
|
|
|
|
else |
28128
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
28129
|
|
|
|
|
|
|
} |
28130
|
|
|
|
|
|
|
|
28131
|
|
|
|
|
|
|
static forceinline u32 |
28132
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
28133
|
|
|
|
|
|
|
{ |
28134
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28135
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
28136
|
|
|
|
|
|
|
else |
28137
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
28138
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
28139
|
|
|
|
|
|
|
} |
28140
|
|
|
|
|
|
|
|
28141
|
|
|
|
|
|
|
static forceinline u32 |
28142
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
28143
|
|
|
|
|
|
|
{ |
28144
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28145
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
28146
|
|
|
|
|
|
|
else |
28147
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
28148
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
28149
|
|
|
|
|
|
|
} |
28150
|
|
|
|
|
|
|
|
28151
|
|
|
|
|
|
|
static forceinline u64 |
28152
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
28153
|
|
|
|
|
|
|
{ |
28154
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28155
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
28156
|
|
|
|
|
|
|
else |
28157
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
28158
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
28159
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
28160
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
28161
|
|
|
|
|
|
|
} |
28162
|
|
|
|
|
|
|
|
28163
|
|
|
|
|
|
|
static forceinline machine_word_t |
28164
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
28165
|
|
|
|
|
|
|
{ |
28166
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
28167
|
|
|
|
|
|
|
if (WORDBITS == 32) |
28168
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
28169
|
|
|
|
|
|
|
else |
28170
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
28171
|
|
|
|
|
|
|
} |
28172
|
|
|
|
|
|
|
|
28173
|
|
|
|
|
|
|
|
28174
|
|
|
|
|
|
|
|
28175
|
|
|
|
|
|
|
static forceinline void |
28176
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
28177
|
|
|
|
|
|
|
{ |
28178
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28179
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
28180
|
|
|
|
|
|
|
} else { |
28181
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
28182
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
28183
|
|
|
|
|
|
|
} |
28184
|
|
|
|
|
|
|
} |
28185
|
|
|
|
|
|
|
|
28186
|
|
|
|
|
|
|
static forceinline void |
28187
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
28188
|
|
|
|
|
|
|
{ |
28189
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28190
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
28191
|
|
|
|
|
|
|
} else { |
28192
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
28193
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
28194
|
|
|
|
|
|
|
} |
28195
|
|
|
|
|
|
|
} |
28196
|
|
|
|
|
|
|
|
28197
|
|
|
|
|
|
|
static forceinline void |
28198
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
28199
|
|
|
|
|
|
|
{ |
28200
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28201
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
28202
|
|
|
|
|
|
|
} else { |
28203
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
28204
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
28205
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
28206
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
28207
|
|
|
|
|
|
|
} |
28208
|
|
|
|
|
|
|
} |
28209
|
|
|
|
|
|
|
|
28210
|
|
|
|
|
|
|
static forceinline void |
28211
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
28212
|
|
|
|
|
|
|
{ |
28213
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28214
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
28215
|
|
|
|
|
|
|
} else { |
28216
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
28217
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
28218
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
28219
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
28220
|
|
|
|
|
|
|
} |
28221
|
|
|
|
|
|
|
} |
28222
|
|
|
|
|
|
|
|
28223
|
|
|
|
|
|
|
static forceinline void |
28224
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
28225
|
|
|
|
|
|
|
{ |
28226
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28227
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
28228
|
|
|
|
|
|
|
} else { |
28229
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
28230
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
28231
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
28232
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
28233
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
28234
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
28235
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
28236
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
28237
|
|
|
|
|
|
|
} |
28238
|
|
|
|
|
|
|
} |
28239
|
|
|
|
|
|
|
|
28240
|
|
|
|
|
|
|
static forceinline void |
28241
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
28242
|
|
|
|
|
|
|
{ |
28243
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
28244
|
|
|
|
|
|
|
if (WORDBITS == 32) |
28245
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
28246
|
|
|
|
|
|
|
else |
28247
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
28248
|
|
|
|
|
|
|
} |
28249
|
|
|
|
|
|
|
|
28250
|
|
|
|
|
|
|
|
28251
|
|
|
|
|
|
|
|
28252
|
|
|
|
|
|
|
|
28253
|
|
|
|
|
|
|
|
28254
|
|
|
|
|
|
|
|
28255
|
|
|
|
|
|
|
|
28256
|
|
|
|
|
|
|
static forceinline unsigned |
28257
|
|
|
|
|
|
|
bsr32(u32 v) |
28258
|
|
|
|
|
|
|
{ |
28259
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
28260
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
28261
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28262
|
|
|
|
|
|
|
unsigned long i; |
28263
|
|
|
|
|
|
|
|
28264
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
28265
|
|
|
|
|
|
|
return i; |
28266
|
|
|
|
|
|
|
#else |
28267
|
|
|
|
|
|
|
unsigned i = 0; |
28268
|
|
|
|
|
|
|
|
28269
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
28270
|
|
|
|
|
|
|
i++; |
28271
|
|
|
|
|
|
|
return i; |
28272
|
|
|
|
|
|
|
#endif |
28273
|
|
|
|
|
|
|
} |
28274
|
|
|
|
|
|
|
|
28275
|
|
|
|
|
|
|
static forceinline unsigned |
28276
|
|
|
|
|
|
|
bsr64(u64 v) |
28277
|
|
|
|
|
|
|
{ |
28278
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
28279
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
28280
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
28281
|
|
|
|
|
|
|
unsigned long i; |
28282
|
|
|
|
|
|
|
|
28283
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
28284
|
|
|
|
|
|
|
return i; |
28285
|
|
|
|
|
|
|
#else |
28286
|
|
|
|
|
|
|
unsigned i = 0; |
28287
|
|
|
|
|
|
|
|
28288
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
28289
|
|
|
|
|
|
|
i++; |
28290
|
|
|
|
|
|
|
return i; |
28291
|
|
|
|
|
|
|
#endif |
28292
|
|
|
|
|
|
|
} |
28293
|
|
|
|
|
|
|
|
28294
|
|
|
|
|
|
|
static forceinline unsigned |
28295
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
28296
|
|
|
|
|
|
|
{ |
28297
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
28298
|
|
|
|
|
|
|
if (WORDBITS == 32) |
28299
|
|
|
|
|
|
|
return bsr32(v); |
28300
|
|
|
|
|
|
|
else |
28301
|
|
|
|
|
|
|
return bsr64(v); |
28302
|
|
|
|
|
|
|
} |
28303
|
|
|
|
|
|
|
|
28304
|
|
|
|
|
|
|
|
28305
|
|
|
|
|
|
|
|
28306
|
|
|
|
|
|
|
static forceinline unsigned |
28307
|
|
|
|
|
|
|
bsf32(u32 v) |
28308
|
|
|
|
|
|
|
{ |
28309
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
28310
|
|
|
|
|
|
|
return __builtin_ctz(v); |
28311
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28312
|
|
|
|
|
|
|
unsigned long i; |
28313
|
|
|
|
|
|
|
|
28314
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
28315
|
|
|
|
|
|
|
return i; |
28316
|
|
|
|
|
|
|
#else |
28317
|
|
|
|
|
|
|
unsigned i = 0; |
28318
|
|
|
|
|
|
|
|
28319
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
28320
|
|
|
|
|
|
|
i++; |
28321
|
|
|
|
|
|
|
return i; |
28322
|
|
|
|
|
|
|
#endif |
28323
|
|
|
|
|
|
|
} |
28324
|
|
|
|
|
|
|
|
28325
|
|
|
|
|
|
|
static forceinline unsigned |
28326
|
|
|
|
|
|
|
bsf64(u64 v) |
28327
|
|
|
|
|
|
|
{ |
28328
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
28329
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
28330
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
28331
|
|
|
|
|
|
|
unsigned long i; |
28332
|
|
|
|
|
|
|
|
28333
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
28334
|
|
|
|
|
|
|
return i; |
28335
|
|
|
|
|
|
|
#else |
28336
|
|
|
|
|
|
|
unsigned i = 0; |
28337
|
|
|
|
|
|
|
|
28338
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
28339
|
|
|
|
|
|
|
i++; |
28340
|
|
|
|
|
|
|
return i; |
28341
|
|
|
|
|
|
|
#endif |
28342
|
|
|
|
|
|
|
} |
28343
|
|
|
|
|
|
|
|
28344
|
|
|
|
|
|
|
static forceinline unsigned |
28345
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
28346
|
|
|
|
|
|
|
{ |
28347
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
28348
|
|
|
|
|
|
|
if (WORDBITS == 32) |
28349
|
|
|
|
|
|
|
return bsf32(v); |
28350
|
|
|
|
|
|
|
else |
28351
|
|
|
|
|
|
|
return bsf64(v); |
28352
|
|
|
|
|
|
|
} |
28353
|
|
|
|
|
|
|
|
28354
|
|
|
|
|
|
|
|
28355
|
|
|
|
|
|
|
#undef rbit32 |
28356
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
28357
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
28358
|
|
|
|
|
|
|
static forceinline u32 |
28359
|
|
|
|
|
|
|
rbit32(u32 v) |
28360
|
|
|
|
|
|
|
{ |
28361
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
28362
|
|
|
|
|
|
|
return v; |
28363
|
|
|
|
|
|
|
} |
28364
|
|
|
|
|
|
|
#define rbit32 rbit32 |
28365
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
28366
|
|
|
|
|
|
|
static forceinline u32 |
28367
|
|
|
|
|
|
|
rbit32(u32 v) |
28368
|
|
|
|
|
|
|
{ |
28369
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
28370
|
|
|
|
|
|
|
return v; |
28371
|
|
|
|
|
|
|
} |
28372
|
|
|
|
|
|
|
#define rbit32 rbit32 |
28373
|
|
|
|
|
|
|
#endif |
28374
|
|
|
|
|
|
|
|
28375
|
|
|
|
|
|
|
#endif |
28376
|
|
|
|
|
|
|
|
28377
|
|
|
|
|
|
|
|
28378
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
28379
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
28380
|
|
|
|
|
|
|
|
28381
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
28382
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
28383
|
|
|
|
|
|
|
|
28384
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
28385
|
|
|
|
|
|
|
size_t alignment, size_t size); |
28386
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
28387
|
|
|
|
|
|
|
|
28388
|
|
|
|
|
|
|
#ifdef FREESTANDING |
28389
|
|
|
|
|
|
|
|
28390
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
28391
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
28392
|
|
|
|
|
|
|
|
28393
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
28394
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
28395
|
|
|
|
|
|
|
|
28396
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
28397
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
28398
|
|
|
|
|
|
|
|
28399
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
28400
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
28401
|
|
|
|
|
|
|
|
28402
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
28403
|
|
|
|
|
|
|
#else |
28404
|
|
|
|
|
|
|
#include |
28405
|
|
|
|
|
|
|
#endif |
28406
|
|
|
|
|
|
|
|
28407
|
|
|
|
|
|
|
|
28408
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
28409
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
28410
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
28411
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
28412
|
|
|
|
|
|
|
#else |
28413
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
28414
|
|
|
|
|
|
|
#endif |
28415
|
|
|
|
|
|
|
|
28416
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
28417
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
28418
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
28419
|
|
|
|
|
|
|
|
28420
|
|
|
|
|
|
|
#endif |
28421
|
|
|
|
|
|
|
|
28422
|
|
|
|
|
|
|
|
28423
|
|
|
|
|
|
|
|
28424
|
|
|
|
|
|
|
|
28425
|
|
|
|
|
|
|
struct libdeflate_compressor; |
28426
|
|
|
|
|
|
|
|
28427
|
|
|
|
|
|
|
unsigned int libdeflate_get_compression_level(struct libdeflate_compressor *c); |
28428
|
|
|
|
|
|
|
|
28429
|
|
|
|
|
|
|
#endif |
28430
|
|
|
|
|
|
|
|
28431
|
|
|
|
|
|
|
/* #include "gzip_constants.h" */ |
28432
|
|
|
|
|
|
|
|
28433
|
|
|
|
|
|
|
|
28434
|
|
|
|
|
|
|
#ifndef LIB_GZIP_CONSTANTS_H |
28435
|
|
|
|
|
|
|
#define LIB_GZIP_CONSTANTS_H |
28436
|
|
|
|
|
|
|
|
28437
|
|
|
|
|
|
|
#define GZIP_MIN_HEADER_SIZE 10 |
28438
|
|
|
|
|
|
|
#define GZIP_FOOTER_SIZE 8 |
28439
|
|
|
|
|
|
|
#define GZIP_MIN_OVERHEAD (GZIP_MIN_HEADER_SIZE + GZIP_FOOTER_SIZE) |
28440
|
|
|
|
|
|
|
|
28441
|
|
|
|
|
|
|
#define GZIP_ID1 0x1F |
28442
|
|
|
|
|
|
|
#define GZIP_ID2 0x8B |
28443
|
|
|
|
|
|
|
|
28444
|
|
|
|
|
|
|
#define GZIP_CM_DEFLATE 8 |
28445
|
|
|
|
|
|
|
|
28446
|
|
|
|
|
|
|
#define GZIP_FTEXT 0x01 |
28447
|
|
|
|
|
|
|
#define GZIP_FHCRC 0x02 |
28448
|
|
|
|
|
|
|
#define GZIP_FEXTRA 0x04 |
28449
|
|
|
|
|
|
|
#define GZIP_FNAME 0x08 |
28450
|
|
|
|
|
|
|
#define GZIP_FCOMMENT 0x10 |
28451
|
|
|
|
|
|
|
#define GZIP_FRESERVED 0xE0 |
28452
|
|
|
|
|
|
|
|
28453
|
|
|
|
|
|
|
#define GZIP_MTIME_UNAVAILABLE 0 |
28454
|
|
|
|
|
|
|
|
28455
|
|
|
|
|
|
|
#define GZIP_XFL_SLOWEST_COMPRESSION 0x02 |
28456
|
|
|
|
|
|
|
#define GZIP_XFL_FASTEST_COMPRESSION 0x04 |
28457
|
|
|
|
|
|
|
|
28458
|
|
|
|
|
|
|
#define GZIP_OS_FAT 0 |
28459
|
|
|
|
|
|
|
#define GZIP_OS_AMIGA 1 |
28460
|
|
|
|
|
|
|
#define GZIP_OS_VMS 2 |
28461
|
|
|
|
|
|
|
#define GZIP_OS_UNIX 3 |
28462
|
|
|
|
|
|
|
#define GZIP_OS_VM_CMS 4 |
28463
|
|
|
|
|
|
|
#define GZIP_OS_ATARI_TOS 5 |
28464
|
|
|
|
|
|
|
#define GZIP_OS_HPFS 6 |
28465
|
|
|
|
|
|
|
#define GZIP_OS_MACINTOSH 7 |
28466
|
|
|
|
|
|
|
#define GZIP_OS_Z_SYSTEM 8 |
28467
|
|
|
|
|
|
|
#define GZIP_OS_CP_M 9 |
28468
|
|
|
|
|
|
|
#define GZIP_OS_TOPS_20 10 |
28469
|
|
|
|
|
|
|
#define GZIP_OS_NTFS 11 |
28470
|
|
|
|
|
|
|
#define GZIP_OS_QDOS 12 |
28471
|
|
|
|
|
|
|
#define GZIP_OS_RISCOS 13 |
28472
|
|
|
|
|
|
|
#define GZIP_OS_UNKNOWN 255 |
28473
|
|
|
|
|
|
|
|
28474
|
|
|
|
|
|
|
#endif |
28475
|
|
|
|
|
|
|
|
28476
|
|
|
|
|
|
|
|
28477
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28478
|
13
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *c, |
28479
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28480
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail) |
28481
|
|
|
|
|
|
|
{ |
28482
|
13
|
|
|
|
|
|
u8 *out_next = out; |
28483
|
|
|
|
|
|
|
unsigned compression_level; |
28484
|
|
|
|
|
|
|
u8 xfl; |
28485
|
|
|
|
|
|
|
size_t deflate_size; |
28486
|
|
|
|
|
|
|
|
28487
|
13
|
50
|
|
|
|
|
if (out_nbytes_avail <= GZIP_MIN_OVERHEAD) |
28488
|
0
|
|
|
|
|
|
return 0; |
28489
|
|
|
|
|
|
|
|
28490
|
|
|
|
|
|
|
|
28491
|
13
|
|
|
|
|
|
*out_next++ = GZIP_ID1; |
28492
|
|
|
|
|
|
|
|
28493
|
13
|
|
|
|
|
|
*out_next++ = GZIP_ID2; |
28494
|
|
|
|
|
|
|
|
28495
|
13
|
|
|
|
|
|
*out_next++ = GZIP_CM_DEFLATE; |
28496
|
|
|
|
|
|
|
|
28497
|
13
|
|
|
|
|
|
*out_next++ = 0; |
28498
|
|
|
|
|
|
|
|
28499
|
|
|
|
|
|
|
put_unaligned_le32(GZIP_MTIME_UNAVAILABLE, out_next); |
28500
|
13
|
|
|
|
|
|
out_next += 4; |
28501
|
|
|
|
|
|
|
|
28502
|
13
|
|
|
|
|
|
xfl = 0; |
28503
|
13
|
|
|
|
|
|
compression_level = libdeflate_get_compression_level(c); |
28504
|
13
|
100
|
|
|
|
|
if (compression_level < 2) |
28505
|
1
|
|
|
|
|
|
xfl |= GZIP_XFL_FASTEST_COMPRESSION; |
28506
|
12
|
100
|
|
|
|
|
else if (compression_level >= 8) |
28507
|
5
|
|
|
|
|
|
xfl |= GZIP_XFL_SLOWEST_COMPRESSION; |
28508
|
13
|
|
|
|
|
|
*out_next++ = xfl; |
28509
|
|
|
|
|
|
|
|
28510
|
13
|
|
|
|
|
|
*out_next++ = GZIP_OS_UNKNOWN; |
28511
|
|
|
|
|
|
|
|
28512
|
|
|
|
|
|
|
|
28513
|
13
|
|
|
|
|
|
deflate_size = libdeflate_deflate_compress(c, in, in_nbytes, out_next, |
28514
|
|
|
|
|
|
|
out_nbytes_avail - GZIP_MIN_OVERHEAD); |
28515
|
13
|
50
|
|
|
|
|
if (deflate_size == 0) |
28516
|
0
|
|
|
|
|
|
return 0; |
28517
|
13
|
|
|
|
|
|
out_next += deflate_size; |
28518
|
|
|
|
|
|
|
|
28519
|
|
|
|
|
|
|
|
28520
|
13
|
|
|
|
|
|
put_unaligned_le32(libdeflate_crc32(0, in, in_nbytes), out_next); |
28521
|
13
|
|
|
|
|
|
out_next += 4; |
28522
|
|
|
|
|
|
|
|
28523
|
|
|
|
|
|
|
|
28524
|
13
|
|
|
|
|
|
put_unaligned_le32((u32)in_nbytes, out_next); |
28525
|
13
|
|
|
|
|
|
out_next += 4; |
28526
|
|
|
|
|
|
|
|
28527
|
13
|
|
|
|
|
|
return out_next - (u8 *)out; |
28528
|
|
|
|
|
|
|
} |
28529
|
|
|
|
|
|
|
|
28530
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28531
|
13
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *c, |
28532
|
|
|
|
|
|
|
size_t in_nbytes) |
28533
|
|
|
|
|
|
|
{ |
28534
|
13
|
|
|
|
|
|
return GZIP_MIN_OVERHEAD + |
28535
|
13
|
|
|
|
|
|
libdeflate_deflate_compress_bound(c, in_nbytes); |
28536
|
|
|
|
|
|
|
} |
28537
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/gzip_decompress.c */ |
28538
|
|
|
|
|
|
|
|
28539
|
|
|
|
|
|
|
|
28540
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
28541
|
|
|
|
|
|
|
|
28542
|
|
|
|
|
|
|
|
28543
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
28544
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
28545
|
|
|
|
|
|
|
|
28546
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
28547
|
|
|
|
|
|
|
|
28548
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
28549
|
|
|
|
|
|
|
#endif |
28550
|
|
|
|
|
|
|
|
28551
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
28552
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
28553
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
28554
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
28555
|
|
|
|
|
|
|
#else |
28556
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
28557
|
|
|
|
|
|
|
#endif |
28558
|
|
|
|
|
|
|
|
28559
|
|
|
|
|
|
|
|
28560
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
28561
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
28562
|
|
|
|
|
|
|
#else |
28563
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
28564
|
|
|
|
|
|
|
#endif |
28565
|
|
|
|
|
|
|
|
28566
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
28567
|
|
|
|
|
|
|
|
28568
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
28569
|
|
|
|
|
|
|
|
28570
|
|
|
|
|
|
|
|
28571
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
28572
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
28573
|
|
|
|
|
|
|
|
28574
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
28575
|
|
|
|
|
|
|
|
28576
|
|
|
|
|
|
|
|
28577
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
28578
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
28579
|
|
|
|
|
|
|
|
28580
|
|
|
|
|
|
|
#include |
28581
|
|
|
|
|
|
|
#include |
28582
|
|
|
|
|
|
|
|
28583
|
|
|
|
|
|
|
#ifdef __cplusplus |
28584
|
|
|
|
|
|
|
extern "C" { |
28585
|
|
|
|
|
|
|
#endif |
28586
|
|
|
|
|
|
|
|
28587
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
28588
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
28589
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
28590
|
|
|
|
|
|
|
|
28591
|
|
|
|
|
|
|
|
28592
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
28593
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
28594
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
28595
|
|
|
|
|
|
|
# else |
28596
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
28597
|
|
|
|
|
|
|
# endif |
28598
|
|
|
|
|
|
|
#endif |
28599
|
|
|
|
|
|
|
|
28600
|
|
|
|
|
|
|
|
28601
|
|
|
|
|
|
|
|
28602
|
|
|
|
|
|
|
|
28603
|
|
|
|
|
|
|
|
28604
|
|
|
|
|
|
|
struct libdeflate_compressor; |
28605
|
|
|
|
|
|
|
struct libdeflate_options; |
28606
|
|
|
|
|
|
|
|
28607
|
|
|
|
|
|
|
|
28608
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
28609
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
28610
|
|
|
|
|
|
|
|
28611
|
|
|
|
|
|
|
|
28612
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
28613
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
28614
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
28615
|
|
|
|
|
|
|
|
28616
|
|
|
|
|
|
|
|
28617
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28618
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
28619
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28620
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
28621
|
|
|
|
|
|
|
|
28622
|
|
|
|
|
|
|
|
28623
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28624
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
28625
|
|
|
|
|
|
|
size_t in_nbytes); |
28626
|
|
|
|
|
|
|
|
28627
|
|
|
|
|
|
|
|
28628
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28629
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
28630
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28631
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
28632
|
|
|
|
|
|
|
|
28633
|
|
|
|
|
|
|
|
28634
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28635
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
28636
|
|
|
|
|
|
|
size_t in_nbytes); |
28637
|
|
|
|
|
|
|
|
28638
|
|
|
|
|
|
|
|
28639
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28640
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
28641
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28642
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
28643
|
|
|
|
|
|
|
|
28644
|
|
|
|
|
|
|
|
28645
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28646
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
28647
|
|
|
|
|
|
|
size_t in_nbytes); |
28648
|
|
|
|
|
|
|
|
28649
|
|
|
|
|
|
|
|
28650
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
28651
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
28652
|
|
|
|
|
|
|
|
28653
|
|
|
|
|
|
|
|
28654
|
|
|
|
|
|
|
|
28655
|
|
|
|
|
|
|
|
28656
|
|
|
|
|
|
|
|
28657
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
28658
|
|
|
|
|
|
|
struct libdeflate_options; |
28659
|
|
|
|
|
|
|
|
28660
|
|
|
|
|
|
|
|
28661
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
28662
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
28663
|
|
|
|
|
|
|
|
28664
|
|
|
|
|
|
|
|
28665
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
28666
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
28667
|
|
|
|
|
|
|
|
28668
|
|
|
|
|
|
|
|
28669
|
|
|
|
|
|
|
enum libdeflate_result { |
28670
|
|
|
|
|
|
|
|
28671
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
28672
|
|
|
|
|
|
|
|
28673
|
|
|
|
|
|
|
|
28674
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
28675
|
|
|
|
|
|
|
|
28676
|
|
|
|
|
|
|
|
28677
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
28678
|
|
|
|
|
|
|
|
28679
|
|
|
|
|
|
|
|
28680
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
28681
|
|
|
|
|
|
|
}; |
28682
|
|
|
|
|
|
|
|
28683
|
|
|
|
|
|
|
|
28684
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28685
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
28686
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28687
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28688
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28689
|
|
|
|
|
|
|
|
28690
|
|
|
|
|
|
|
|
28691
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28692
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
28693
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28694
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28695
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
28696
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28697
|
|
|
|
|
|
|
|
28698
|
|
|
|
|
|
|
|
28699
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28700
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
28701
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28702
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28703
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28704
|
|
|
|
|
|
|
|
28705
|
|
|
|
|
|
|
|
28706
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28707
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
28708
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28709
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28710
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
28711
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28712
|
|
|
|
|
|
|
|
28713
|
|
|
|
|
|
|
|
28714
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28715
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
28716
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28717
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28718
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28719
|
|
|
|
|
|
|
|
28720
|
|
|
|
|
|
|
|
28721
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28722
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
28723
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28724
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28725
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
28726
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28727
|
|
|
|
|
|
|
|
28728
|
|
|
|
|
|
|
|
28729
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
28730
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
28731
|
|
|
|
|
|
|
|
28732
|
|
|
|
|
|
|
|
28733
|
|
|
|
|
|
|
|
28734
|
|
|
|
|
|
|
|
28735
|
|
|
|
|
|
|
|
28736
|
|
|
|
|
|
|
|
28737
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
28738
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
28739
|
|
|
|
|
|
|
|
28740
|
|
|
|
|
|
|
|
28741
|
|
|
|
|
|
|
|
28742
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
28743
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
28744
|
|
|
|
|
|
|
|
28745
|
|
|
|
|
|
|
|
28746
|
|
|
|
|
|
|
|
28747
|
|
|
|
|
|
|
|
28748
|
|
|
|
|
|
|
|
28749
|
|
|
|
|
|
|
|
28750
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
28751
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
28752
|
|
|
|
|
|
|
void (*free_func)(void *)); |
28753
|
|
|
|
|
|
|
|
28754
|
|
|
|
|
|
|
|
28755
|
|
|
|
|
|
|
struct libdeflate_options { |
28756
|
|
|
|
|
|
|
|
28757
|
|
|
|
|
|
|
|
28758
|
|
|
|
|
|
|
size_t sizeof_options; |
28759
|
|
|
|
|
|
|
|
28760
|
|
|
|
|
|
|
|
28761
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
28762
|
|
|
|
|
|
|
void (*free_func)(void *); |
28763
|
|
|
|
|
|
|
}; |
28764
|
|
|
|
|
|
|
|
28765
|
|
|
|
|
|
|
#ifdef __cplusplus |
28766
|
|
|
|
|
|
|
} |
28767
|
|
|
|
|
|
|
#endif |
28768
|
|
|
|
|
|
|
|
28769
|
|
|
|
|
|
|
#endif |
28770
|
|
|
|
|
|
|
|
28771
|
|
|
|
|
|
|
|
28772
|
|
|
|
|
|
|
#include |
28773
|
|
|
|
|
|
|
#include |
28774
|
|
|
|
|
|
|
#include |
28775
|
|
|
|
|
|
|
#ifdef _MSC_VER |
28776
|
|
|
|
|
|
|
# include |
28777
|
|
|
|
|
|
|
# include |
28778
|
|
|
|
|
|
|
|
28779
|
|
|
|
|
|
|
|
28780
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
28781
|
|
|
|
|
|
|
|
28782
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
28783
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
28784
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
28785
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
28786
|
|
|
|
|
|
|
|
28787
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
28788
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
28789
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
28790
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
28791
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
28792
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
28793
|
|
|
|
|
|
|
#endif |
28794
|
|
|
|
|
|
|
#ifndef FREESTANDING |
28795
|
|
|
|
|
|
|
# include |
28796
|
|
|
|
|
|
|
#endif |
28797
|
|
|
|
|
|
|
|
28798
|
|
|
|
|
|
|
|
28799
|
|
|
|
|
|
|
|
28800
|
|
|
|
|
|
|
|
28801
|
|
|
|
|
|
|
|
28802
|
|
|
|
|
|
|
|
28803
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
28804
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
28805
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
28806
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
28807
|
|
|
|
|
|
|
#ifdef _MSC_VER |
28808
|
|
|
|
|
|
|
# if defined(_M_X64) |
28809
|
|
|
|
|
|
|
# define ARCH_X86_64 |
28810
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
28811
|
|
|
|
|
|
|
# define ARCH_X86_32 |
28812
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
28813
|
|
|
|
|
|
|
# define ARCH_ARM64 |
28814
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
28815
|
|
|
|
|
|
|
# define ARCH_ARM32 |
28816
|
|
|
|
|
|
|
# endif |
28817
|
|
|
|
|
|
|
#else |
28818
|
|
|
|
|
|
|
# if defined(__x86_64__) |
28819
|
|
|
|
|
|
|
# define ARCH_X86_64 |
28820
|
|
|
|
|
|
|
# elif defined(__i386__) |
28821
|
|
|
|
|
|
|
# define ARCH_X86_32 |
28822
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
28823
|
|
|
|
|
|
|
# define ARCH_ARM64 |
28824
|
|
|
|
|
|
|
# elif defined(__arm__) |
28825
|
|
|
|
|
|
|
# define ARCH_ARM32 |
28826
|
|
|
|
|
|
|
# endif |
28827
|
|
|
|
|
|
|
#endif |
28828
|
|
|
|
|
|
|
|
28829
|
|
|
|
|
|
|
|
28830
|
|
|
|
|
|
|
|
28831
|
|
|
|
|
|
|
|
28832
|
|
|
|
|
|
|
|
28833
|
|
|
|
|
|
|
|
28834
|
|
|
|
|
|
|
typedef uint8_t u8; |
28835
|
|
|
|
|
|
|
typedef uint16_t u16; |
28836
|
|
|
|
|
|
|
typedef uint32_t u32; |
28837
|
|
|
|
|
|
|
typedef uint64_t u64; |
28838
|
|
|
|
|
|
|
typedef int8_t s8; |
28839
|
|
|
|
|
|
|
typedef int16_t s16; |
28840
|
|
|
|
|
|
|
typedef int32_t s32; |
28841
|
|
|
|
|
|
|
typedef int64_t s64; |
28842
|
|
|
|
|
|
|
|
28843
|
|
|
|
|
|
|
|
28844
|
|
|
|
|
|
|
#ifdef _MSC_VER |
28845
|
|
|
|
|
|
|
# ifdef _WIN64 |
28846
|
|
|
|
|
|
|
typedef long long ssize_t; |
28847
|
|
|
|
|
|
|
# else |
28848
|
|
|
|
|
|
|
typedef long ssize_t; |
28849
|
|
|
|
|
|
|
# endif |
28850
|
|
|
|
|
|
|
#endif |
28851
|
|
|
|
|
|
|
|
28852
|
|
|
|
|
|
|
|
28853
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
28854
|
|
|
|
|
|
|
|
28855
|
|
|
|
|
|
|
|
28856
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
28857
|
|
|
|
|
|
|
|
28858
|
|
|
|
|
|
|
|
28859
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
28860
|
|
|
|
|
|
|
|
28861
|
|
|
|
|
|
|
|
28862
|
|
|
|
|
|
|
|
28863
|
|
|
|
|
|
|
|
28864
|
|
|
|
|
|
|
|
28865
|
|
|
|
|
|
|
|
28866
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
28867
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
28868
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
28869
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
28870
|
|
|
|
|
|
|
#else |
28871
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
28872
|
|
|
|
|
|
|
#endif |
28873
|
|
|
|
|
|
|
#ifdef __clang__ |
28874
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
28875
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
28876
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
28877
|
|
|
|
|
|
|
# else |
28878
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
28879
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
28880
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
28881
|
|
|
|
|
|
|
# endif |
28882
|
|
|
|
|
|
|
#else |
28883
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
28884
|
|
|
|
|
|
|
#endif |
28885
|
|
|
|
|
|
|
|
28886
|
|
|
|
|
|
|
|
28887
|
|
|
|
|
|
|
#ifndef __has_attribute |
28888
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
28889
|
|
|
|
|
|
|
#endif |
28890
|
|
|
|
|
|
|
#ifndef __has_builtin |
28891
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
28892
|
|
|
|
|
|
|
#endif |
28893
|
|
|
|
|
|
|
|
28894
|
|
|
|
|
|
|
|
28895
|
|
|
|
|
|
|
#ifdef _MSC_VER |
28896
|
|
|
|
|
|
|
# define inline __inline |
28897
|
|
|
|
|
|
|
#endif |
28898
|
|
|
|
|
|
|
|
28899
|
|
|
|
|
|
|
|
28900
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
28901
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
28902
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28903
|
|
|
|
|
|
|
# define forceinline __forceinline |
28904
|
|
|
|
|
|
|
#else |
28905
|
|
|
|
|
|
|
# define forceinline inline |
28906
|
|
|
|
|
|
|
#endif |
28907
|
|
|
|
|
|
|
|
28908
|
|
|
|
|
|
|
|
28909
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
28910
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
28911
|
|
|
|
|
|
|
#else |
28912
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
28913
|
|
|
|
|
|
|
#endif |
28914
|
|
|
|
|
|
|
|
28915
|
|
|
|
|
|
|
|
28916
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
28917
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
28918
|
|
|
|
|
|
|
# define restrict __restrict__ |
28919
|
|
|
|
|
|
|
# else |
28920
|
|
|
|
|
|
|
# define restrict |
28921
|
|
|
|
|
|
|
# endif |
28922
|
|
|
|
|
|
|
#endif |
28923
|
|
|
|
|
|
|
|
28924
|
|
|
|
|
|
|
|
28925
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
28926
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
28927
|
|
|
|
|
|
|
#else |
28928
|
|
|
|
|
|
|
# define likely(expr) (expr) |
28929
|
|
|
|
|
|
|
#endif |
28930
|
|
|
|
|
|
|
|
28931
|
|
|
|
|
|
|
|
28932
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
28933
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
28934
|
|
|
|
|
|
|
#else |
28935
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
28936
|
|
|
|
|
|
|
#endif |
28937
|
|
|
|
|
|
|
|
28938
|
|
|
|
|
|
|
|
28939
|
|
|
|
|
|
|
#undef prefetchr |
28940
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
28941
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
28942
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28943
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
28944
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
28945
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
28946
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
28947
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
28948
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
28949
|
|
|
|
|
|
|
# endif |
28950
|
|
|
|
|
|
|
#endif |
28951
|
|
|
|
|
|
|
#ifndef prefetchr |
28952
|
|
|
|
|
|
|
# define prefetchr(addr) |
28953
|
|
|
|
|
|
|
#endif |
28954
|
|
|
|
|
|
|
|
28955
|
|
|
|
|
|
|
|
28956
|
|
|
|
|
|
|
#undef prefetchw |
28957
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
28958
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
28959
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28960
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
28961
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
28962
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
28963
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
28964
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
28965
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
28966
|
|
|
|
|
|
|
# endif |
28967
|
|
|
|
|
|
|
#endif |
28968
|
|
|
|
|
|
|
#ifndef prefetchw |
28969
|
|
|
|
|
|
|
# define prefetchw(addr) |
28970
|
|
|
|
|
|
|
#endif |
28971
|
|
|
|
|
|
|
|
28972
|
|
|
|
|
|
|
|
28973
|
|
|
|
|
|
|
#undef _aligned_attribute |
28974
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
28975
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
28976
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28977
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
28978
|
|
|
|
|
|
|
#endif |
28979
|
|
|
|
|
|
|
|
28980
|
|
|
|
|
|
|
|
28981
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
28982
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
28983
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
28984
|
|
|
|
|
|
|
#else |
28985
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
28986
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
28987
|
|
|
|
|
|
|
#endif |
28988
|
|
|
|
|
|
|
|
28989
|
|
|
|
|
|
|
|
28990
|
|
|
|
|
|
|
|
28991
|
|
|
|
|
|
|
|
28992
|
|
|
|
|
|
|
|
28993
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
28994
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
28995
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
28996
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
28997
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
28998
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
28999
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
29000
|
|
|
|
|
|
|
|
29001
|
|
|
|
|
|
|
|
29002
|
|
|
|
|
|
|
|
29003
|
|
|
|
|
|
|
|
29004
|
|
|
|
|
|
|
|
29005
|
|
|
|
|
|
|
|
29006
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
29007
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
29008
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29009
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
29010
|
|
|
|
|
|
|
#else |
29011
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
29012
|
|
|
|
|
|
|
{ |
29013
|
|
|
|
|
|
|
union { |
29014
|
|
|
|
|
|
|
u32 w; |
29015
|
|
|
|
|
|
|
u8 b; |
29016
|
|
|
|
|
|
|
} u; |
29017
|
|
|
|
|
|
|
|
29018
|
|
|
|
|
|
|
u.w = 1; |
29019
|
|
|
|
|
|
|
return u.b; |
29020
|
|
|
|
|
|
|
} |
29021
|
|
|
|
|
|
|
#endif |
29022
|
|
|
|
|
|
|
|
29023
|
|
|
|
|
|
|
|
29024
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
29025
|
|
|
|
|
|
|
{ |
29026
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
29027
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
29028
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29029
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
29030
|
|
|
|
|
|
|
#else |
29031
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
29032
|
|
|
|
|
|
|
#endif |
29033
|
|
|
|
|
|
|
} |
29034
|
|
|
|
|
|
|
|
29035
|
|
|
|
|
|
|
|
29036
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
29037
|
|
|
|
|
|
|
{ |
29038
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
29039
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
29040
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29041
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
29042
|
|
|
|
|
|
|
#else |
29043
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
29044
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
29045
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
29046
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
29047
|
|
|
|
|
|
|
#endif |
29048
|
|
|
|
|
|
|
} |
29049
|
|
|
|
|
|
|
|
29050
|
|
|
|
|
|
|
|
29051
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
29052
|
|
|
|
|
|
|
{ |
29053
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
29054
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
29055
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29056
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
29057
|
|
|
|
|
|
|
#else |
29058
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
29059
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
29060
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
29061
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
29062
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
29063
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
29064
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
29065
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
29066
|
|
|
|
|
|
|
#endif |
29067
|
|
|
|
|
|
|
} |
29068
|
|
|
|
|
|
|
|
29069
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
29070
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
29071
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
29072
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
29073
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
29074
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
29075
|
|
|
|
|
|
|
|
29076
|
|
|
|
|
|
|
|
29077
|
|
|
|
|
|
|
|
29078
|
|
|
|
|
|
|
|
29079
|
|
|
|
|
|
|
|
29080
|
|
|
|
|
|
|
|
29081
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
29082
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
29083
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
29084
|
|
|
|
|
|
|
defined(__wasm__)) |
29085
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
29086
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29087
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
29088
|
|
|
|
|
|
|
#else |
29089
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
29090
|
|
|
|
|
|
|
#endif |
29091
|
|
|
|
|
|
|
|
29092
|
|
|
|
|
|
|
|
29093
|
|
|
|
|
|
|
|
29094
|
|
|
|
|
|
|
#ifdef FREESTANDING |
29095
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
29096
|
|
|
|
|
|
|
#else |
29097
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
29098
|
|
|
|
|
|
|
#endif |
29099
|
|
|
|
|
|
|
|
29100
|
|
|
|
|
|
|
|
29101
|
|
|
|
|
|
|
|
29102
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
29103
|
|
|
|
|
|
|
static forceinline type \ |
29104
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
29105
|
|
|
|
|
|
|
{ \ |
29106
|
|
|
|
|
|
|
type v; \ |
29107
|
|
|
|
|
|
|
\ |
29108
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
29109
|
|
|
|
|
|
|
return v; \ |
29110
|
|
|
|
|
|
|
} \ |
29111
|
|
|
|
|
|
|
\ |
29112
|
|
|
|
|
|
|
static forceinline void \ |
29113
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
29114
|
|
|
|
|
|
|
{ \ |
29115
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
29116
|
|
|
|
|
|
|
} |
29117
|
|
|
|
|
|
|
|
29118
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
29119
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
29120
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
29121
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
29122
|
|
|
|
|
|
|
|
29123
|
|
|
|
|
|
|
#undef MEMCOPY |
29124
|
|
|
|
|
|
|
|
29125
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
29126
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
29127
|
|
|
|
|
|
|
|
29128
|
|
|
|
|
|
|
|
29129
|
|
|
|
|
|
|
|
29130
|
|
|
|
|
|
|
static forceinline u16 |
29131
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
29132
|
|
|
|
|
|
|
{ |
29133
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29134
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
29135
|
|
|
|
|
|
|
else |
29136
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
29137
|
|
|
|
|
|
|
} |
29138
|
|
|
|
|
|
|
|
29139
|
|
|
|
|
|
|
static forceinline u16 |
29140
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
29141
|
|
|
|
|
|
|
{ |
29142
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29143
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
29144
|
|
|
|
|
|
|
else |
29145
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
29146
|
|
|
|
|
|
|
} |
29147
|
|
|
|
|
|
|
|
29148
|
|
|
|
|
|
|
static forceinline u32 |
29149
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
29150
|
|
|
|
|
|
|
{ |
29151
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29152
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
29153
|
|
|
|
|
|
|
else |
29154
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
29155
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
29156
|
|
|
|
|
|
|
} |
29157
|
|
|
|
|
|
|
|
29158
|
|
|
|
|
|
|
static forceinline u32 |
29159
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
29160
|
|
|
|
|
|
|
{ |
29161
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29162
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
29163
|
|
|
|
|
|
|
else |
29164
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
29165
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
29166
|
|
|
|
|
|
|
} |
29167
|
|
|
|
|
|
|
|
29168
|
|
|
|
|
|
|
static forceinline u64 |
29169
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
29170
|
|
|
|
|
|
|
{ |
29171
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29172
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
29173
|
|
|
|
|
|
|
else |
29174
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
29175
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
29176
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
29177
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
29178
|
|
|
|
|
|
|
} |
29179
|
|
|
|
|
|
|
|
29180
|
|
|
|
|
|
|
static forceinline machine_word_t |
29181
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
29182
|
|
|
|
|
|
|
{ |
29183
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
29184
|
|
|
|
|
|
|
if (WORDBITS == 32) |
29185
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
29186
|
|
|
|
|
|
|
else |
29187
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
29188
|
|
|
|
|
|
|
} |
29189
|
|
|
|
|
|
|
|
29190
|
|
|
|
|
|
|
|
29191
|
|
|
|
|
|
|
|
29192
|
|
|
|
|
|
|
static forceinline void |
29193
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
29194
|
|
|
|
|
|
|
{ |
29195
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29196
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
29197
|
|
|
|
|
|
|
} else { |
29198
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
29199
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
29200
|
|
|
|
|
|
|
} |
29201
|
|
|
|
|
|
|
} |
29202
|
|
|
|
|
|
|
|
29203
|
|
|
|
|
|
|
static forceinline void |
29204
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
29205
|
|
|
|
|
|
|
{ |
29206
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29207
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
29208
|
|
|
|
|
|
|
} else { |
29209
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
29210
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
29211
|
|
|
|
|
|
|
} |
29212
|
|
|
|
|
|
|
} |
29213
|
|
|
|
|
|
|
|
29214
|
|
|
|
|
|
|
static forceinline void |
29215
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
29216
|
|
|
|
|
|
|
{ |
29217
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29218
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
29219
|
|
|
|
|
|
|
} else { |
29220
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
29221
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
29222
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
29223
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
29224
|
|
|
|
|
|
|
} |
29225
|
|
|
|
|
|
|
} |
29226
|
|
|
|
|
|
|
|
29227
|
|
|
|
|
|
|
static forceinline void |
29228
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
29229
|
|
|
|
|
|
|
{ |
29230
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29231
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
29232
|
|
|
|
|
|
|
} else { |
29233
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
29234
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
29235
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
29236
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
29237
|
|
|
|
|
|
|
} |
29238
|
|
|
|
|
|
|
} |
29239
|
|
|
|
|
|
|
|
29240
|
|
|
|
|
|
|
static forceinline void |
29241
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
29242
|
|
|
|
|
|
|
{ |
29243
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29244
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
29245
|
|
|
|
|
|
|
} else { |
29246
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
29247
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
29248
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
29249
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
29250
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
29251
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
29252
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
29253
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
29254
|
|
|
|
|
|
|
} |
29255
|
|
|
|
|
|
|
} |
29256
|
|
|
|
|
|
|
|
29257
|
|
|
|
|
|
|
static forceinline void |
29258
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
29259
|
|
|
|
|
|
|
{ |
29260
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
29261
|
|
|
|
|
|
|
if (WORDBITS == 32) |
29262
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
29263
|
|
|
|
|
|
|
else |
29264
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
29265
|
|
|
|
|
|
|
} |
29266
|
|
|
|
|
|
|
|
29267
|
|
|
|
|
|
|
|
29268
|
|
|
|
|
|
|
|
29269
|
|
|
|
|
|
|
|
29270
|
|
|
|
|
|
|
|
29271
|
|
|
|
|
|
|
|
29272
|
|
|
|
|
|
|
|
29273
|
|
|
|
|
|
|
static forceinline unsigned |
29274
|
|
|
|
|
|
|
bsr32(u32 v) |
29275
|
|
|
|
|
|
|
{ |
29276
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
29277
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
29278
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29279
|
|
|
|
|
|
|
unsigned long i; |
29280
|
|
|
|
|
|
|
|
29281
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
29282
|
|
|
|
|
|
|
return i; |
29283
|
|
|
|
|
|
|
#else |
29284
|
|
|
|
|
|
|
unsigned i = 0; |
29285
|
|
|
|
|
|
|
|
29286
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
29287
|
|
|
|
|
|
|
i++; |
29288
|
|
|
|
|
|
|
return i; |
29289
|
|
|
|
|
|
|
#endif |
29290
|
|
|
|
|
|
|
} |
29291
|
|
|
|
|
|
|
|
29292
|
|
|
|
|
|
|
static forceinline unsigned |
29293
|
|
|
|
|
|
|
bsr64(u64 v) |
29294
|
|
|
|
|
|
|
{ |
29295
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
29296
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
29297
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
29298
|
|
|
|
|
|
|
unsigned long i; |
29299
|
|
|
|
|
|
|
|
29300
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
29301
|
|
|
|
|
|
|
return i; |
29302
|
|
|
|
|
|
|
#else |
29303
|
|
|
|
|
|
|
unsigned i = 0; |
29304
|
|
|
|
|
|
|
|
29305
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
29306
|
|
|
|
|
|
|
i++; |
29307
|
|
|
|
|
|
|
return i; |
29308
|
|
|
|
|
|
|
#endif |
29309
|
|
|
|
|
|
|
} |
29310
|
|
|
|
|
|
|
|
29311
|
|
|
|
|
|
|
static forceinline unsigned |
29312
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
29313
|
|
|
|
|
|
|
{ |
29314
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
29315
|
|
|
|
|
|
|
if (WORDBITS == 32) |
29316
|
|
|
|
|
|
|
return bsr32(v); |
29317
|
|
|
|
|
|
|
else |
29318
|
|
|
|
|
|
|
return bsr64(v); |
29319
|
|
|
|
|
|
|
} |
29320
|
|
|
|
|
|
|
|
29321
|
|
|
|
|
|
|
|
29322
|
|
|
|
|
|
|
|
29323
|
|
|
|
|
|
|
static forceinline unsigned |
29324
|
|
|
|
|
|
|
bsf32(u32 v) |
29325
|
|
|
|
|
|
|
{ |
29326
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
29327
|
|
|
|
|
|
|
return __builtin_ctz(v); |
29328
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29329
|
|
|
|
|
|
|
unsigned long i; |
29330
|
|
|
|
|
|
|
|
29331
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
29332
|
|
|
|
|
|
|
return i; |
29333
|
|
|
|
|
|
|
#else |
29334
|
|
|
|
|
|
|
unsigned i = 0; |
29335
|
|
|
|
|
|
|
|
29336
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
29337
|
|
|
|
|
|
|
i++; |
29338
|
|
|
|
|
|
|
return i; |
29339
|
|
|
|
|
|
|
#endif |
29340
|
|
|
|
|
|
|
} |
29341
|
|
|
|
|
|
|
|
29342
|
|
|
|
|
|
|
static forceinline unsigned |
29343
|
|
|
|
|
|
|
bsf64(u64 v) |
29344
|
|
|
|
|
|
|
{ |
29345
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
29346
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
29347
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
29348
|
|
|
|
|
|
|
unsigned long i; |
29349
|
|
|
|
|
|
|
|
29350
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
29351
|
|
|
|
|
|
|
return i; |
29352
|
|
|
|
|
|
|
#else |
29353
|
|
|
|
|
|
|
unsigned i = 0; |
29354
|
|
|
|
|
|
|
|
29355
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
29356
|
|
|
|
|
|
|
i++; |
29357
|
|
|
|
|
|
|
return i; |
29358
|
|
|
|
|
|
|
#endif |
29359
|
|
|
|
|
|
|
} |
29360
|
|
|
|
|
|
|
|
29361
|
|
|
|
|
|
|
static forceinline unsigned |
29362
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
29363
|
|
|
|
|
|
|
{ |
29364
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
29365
|
|
|
|
|
|
|
if (WORDBITS == 32) |
29366
|
|
|
|
|
|
|
return bsf32(v); |
29367
|
|
|
|
|
|
|
else |
29368
|
|
|
|
|
|
|
return bsf64(v); |
29369
|
|
|
|
|
|
|
} |
29370
|
|
|
|
|
|
|
|
29371
|
|
|
|
|
|
|
|
29372
|
|
|
|
|
|
|
#undef rbit32 |
29373
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
29374
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
29375
|
|
|
|
|
|
|
static forceinline u32 |
29376
|
|
|
|
|
|
|
rbit32(u32 v) |
29377
|
|
|
|
|
|
|
{ |
29378
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
29379
|
|
|
|
|
|
|
return v; |
29380
|
|
|
|
|
|
|
} |
29381
|
|
|
|
|
|
|
#define rbit32 rbit32 |
29382
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
29383
|
|
|
|
|
|
|
static forceinline u32 |
29384
|
|
|
|
|
|
|
rbit32(u32 v) |
29385
|
|
|
|
|
|
|
{ |
29386
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
29387
|
|
|
|
|
|
|
return v; |
29388
|
|
|
|
|
|
|
} |
29389
|
|
|
|
|
|
|
#define rbit32 rbit32 |
29390
|
|
|
|
|
|
|
#endif |
29391
|
|
|
|
|
|
|
|
29392
|
|
|
|
|
|
|
#endif |
29393
|
|
|
|
|
|
|
|
29394
|
|
|
|
|
|
|
|
29395
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
29396
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
29397
|
|
|
|
|
|
|
|
29398
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
29399
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
29400
|
|
|
|
|
|
|
|
29401
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
29402
|
|
|
|
|
|
|
size_t alignment, size_t size); |
29403
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
29404
|
|
|
|
|
|
|
|
29405
|
|
|
|
|
|
|
#ifdef FREESTANDING |
29406
|
|
|
|
|
|
|
|
29407
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
29408
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
29409
|
|
|
|
|
|
|
|
29410
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
29411
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
29412
|
|
|
|
|
|
|
|
29413
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
29414
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
29415
|
|
|
|
|
|
|
|
29416
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
29417
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
29418
|
|
|
|
|
|
|
|
29419
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
29420
|
|
|
|
|
|
|
#else |
29421
|
|
|
|
|
|
|
#include |
29422
|
|
|
|
|
|
|
#endif |
29423
|
|
|
|
|
|
|
|
29424
|
|
|
|
|
|
|
|
29425
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
29426
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
29427
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
29428
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
29429
|
|
|
|
|
|
|
#else |
29430
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
29431
|
|
|
|
|
|
|
#endif |
29432
|
|
|
|
|
|
|
|
29433
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
29434
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
29435
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
29436
|
|
|
|
|
|
|
|
29437
|
|
|
|
|
|
|
#endif |
29438
|
|
|
|
|
|
|
|
29439
|
|
|
|
|
|
|
/* #include "gzip_constants.h" */ |
29440
|
|
|
|
|
|
|
|
29441
|
|
|
|
|
|
|
|
29442
|
|
|
|
|
|
|
#ifndef LIB_GZIP_CONSTANTS_H |
29443
|
|
|
|
|
|
|
#define LIB_GZIP_CONSTANTS_H |
29444
|
|
|
|
|
|
|
|
29445
|
|
|
|
|
|
|
#define GZIP_MIN_HEADER_SIZE 10 |
29446
|
|
|
|
|
|
|
#define GZIP_FOOTER_SIZE 8 |
29447
|
|
|
|
|
|
|
#define GZIP_MIN_OVERHEAD (GZIP_MIN_HEADER_SIZE + GZIP_FOOTER_SIZE) |
29448
|
|
|
|
|
|
|
|
29449
|
|
|
|
|
|
|
#define GZIP_ID1 0x1F |
29450
|
|
|
|
|
|
|
#define GZIP_ID2 0x8B |
29451
|
|
|
|
|
|
|
|
29452
|
|
|
|
|
|
|
#define GZIP_CM_DEFLATE 8 |
29453
|
|
|
|
|
|
|
|
29454
|
|
|
|
|
|
|
#define GZIP_FTEXT 0x01 |
29455
|
|
|
|
|
|
|
#define GZIP_FHCRC 0x02 |
29456
|
|
|
|
|
|
|
#define GZIP_FEXTRA 0x04 |
29457
|
|
|
|
|
|
|
#define GZIP_FNAME 0x08 |
29458
|
|
|
|
|
|
|
#define GZIP_FCOMMENT 0x10 |
29459
|
|
|
|
|
|
|
#define GZIP_FRESERVED 0xE0 |
29460
|
|
|
|
|
|
|
|
29461
|
|
|
|
|
|
|
#define GZIP_MTIME_UNAVAILABLE 0 |
29462
|
|
|
|
|
|
|
|
29463
|
|
|
|
|
|
|
#define GZIP_XFL_SLOWEST_COMPRESSION 0x02 |
29464
|
|
|
|
|
|
|
#define GZIP_XFL_FASTEST_COMPRESSION 0x04 |
29465
|
|
|
|
|
|
|
|
29466
|
|
|
|
|
|
|
#define GZIP_OS_FAT 0 |
29467
|
|
|
|
|
|
|
#define GZIP_OS_AMIGA 1 |
29468
|
|
|
|
|
|
|
#define GZIP_OS_VMS 2 |
29469
|
|
|
|
|
|
|
#define GZIP_OS_UNIX 3 |
29470
|
|
|
|
|
|
|
#define GZIP_OS_VM_CMS 4 |
29471
|
|
|
|
|
|
|
#define GZIP_OS_ATARI_TOS 5 |
29472
|
|
|
|
|
|
|
#define GZIP_OS_HPFS 6 |
29473
|
|
|
|
|
|
|
#define GZIP_OS_MACINTOSH 7 |
29474
|
|
|
|
|
|
|
#define GZIP_OS_Z_SYSTEM 8 |
29475
|
|
|
|
|
|
|
#define GZIP_OS_CP_M 9 |
29476
|
|
|
|
|
|
|
#define GZIP_OS_TOPS_20 10 |
29477
|
|
|
|
|
|
|
#define GZIP_OS_NTFS 11 |
29478
|
|
|
|
|
|
|
#define GZIP_OS_QDOS 12 |
29479
|
|
|
|
|
|
|
#define GZIP_OS_RISCOS 13 |
29480
|
|
|
|
|
|
|
#define GZIP_OS_UNKNOWN 255 |
29481
|
|
|
|
|
|
|
|
29482
|
|
|
|
|
|
|
#endif |
29483
|
|
|
|
|
|
|
|
29484
|
|
|
|
|
|
|
|
29485
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29486
|
16
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *d, |
29487
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29488
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29489
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
29490
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
29491
|
|
|
|
|
|
|
{ |
29492
|
16
|
|
|
|
|
|
const u8 *in_next = in; |
29493
|
16
|
|
|
|
|
|
const u8 * const in_end = in_next + in_nbytes; |
29494
|
|
|
|
|
|
|
u8 flg; |
29495
|
|
|
|
|
|
|
size_t actual_in_nbytes; |
29496
|
|
|
|
|
|
|
size_t actual_out_nbytes; |
29497
|
|
|
|
|
|
|
enum libdeflate_result result; |
29498
|
|
|
|
|
|
|
|
29499
|
16
|
50
|
|
|
|
|
if (in_nbytes < GZIP_MIN_OVERHEAD) |
29500
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29501
|
|
|
|
|
|
|
|
29502
|
|
|
|
|
|
|
|
29503
|
16
|
50
|
|
|
|
|
if (*in_next++ != GZIP_ID1) |
29504
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29505
|
|
|
|
|
|
|
|
29506
|
16
|
50
|
|
|
|
|
if (*in_next++ != GZIP_ID2) |
29507
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29508
|
|
|
|
|
|
|
|
29509
|
16
|
50
|
|
|
|
|
if (*in_next++ != GZIP_CM_DEFLATE) |
29510
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29511
|
16
|
|
|
|
|
|
flg = *in_next++; |
29512
|
|
|
|
|
|
|
|
29513
|
16
|
|
|
|
|
|
in_next += 4; |
29514
|
|
|
|
|
|
|
|
29515
|
16
|
|
|
|
|
|
in_next += 1; |
29516
|
|
|
|
|
|
|
|
29517
|
16
|
|
|
|
|
|
in_next += 1; |
29518
|
|
|
|
|
|
|
|
29519
|
16
|
50
|
|
|
|
|
if (flg & GZIP_FRESERVED) |
29520
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29521
|
|
|
|
|
|
|
|
29522
|
|
|
|
|
|
|
|
29523
|
16
|
50
|
|
|
|
|
if (flg & GZIP_FEXTRA) { |
29524
|
0
|
|
|
|
|
|
u16 xlen = get_unaligned_le16(in_next); |
29525
|
0
|
|
|
|
|
|
in_next += 2; |
29526
|
|
|
|
|
|
|
|
29527
|
0
|
0
|
|
|
|
|
if (in_end - in_next < (u32)xlen + GZIP_FOOTER_SIZE) |
29528
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29529
|
|
|
|
|
|
|
|
29530
|
0
|
|
|
|
|
|
in_next += xlen; |
29531
|
|
|
|
|
|
|
} |
29532
|
|
|
|
|
|
|
|
29533
|
|
|
|
|
|
|
|
29534
|
16
|
100
|
|
|
|
|
if (flg & GZIP_FNAME) { |
29535
|
33
|
100
|
|
|
|
|
while (*in_next++ != 0 && in_next != in_end) |
|
|
50
|
|
|
|
|
|
29536
|
|
|
|
|
|
|
; |
29537
|
3
|
50
|
|
|
|
|
if (in_end - in_next < GZIP_FOOTER_SIZE) |
29538
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29539
|
|
|
|
|
|
|
} |
29540
|
|
|
|
|
|
|
|
29541
|
|
|
|
|
|
|
|
29542
|
16
|
50
|
|
|
|
|
if (flg & GZIP_FCOMMENT) { |
29543
|
0
|
0
|
|
|
|
|
while (*in_next++ != 0 && in_next != in_end) |
|
|
0
|
|
|
|
|
|
29544
|
|
|
|
|
|
|
; |
29545
|
0
|
0
|
|
|
|
|
if (in_end - in_next < GZIP_FOOTER_SIZE) |
29546
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29547
|
|
|
|
|
|
|
} |
29548
|
|
|
|
|
|
|
|
29549
|
|
|
|
|
|
|
|
29550
|
16
|
50
|
|
|
|
|
if (flg & GZIP_FHCRC) { |
29551
|
0
|
|
|
|
|
|
in_next += 2; |
29552
|
0
|
0
|
|
|
|
|
if (in_end - in_next < GZIP_FOOTER_SIZE) |
29553
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29554
|
|
|
|
|
|
|
} |
29555
|
|
|
|
|
|
|
|
29556
|
|
|
|
|
|
|
|
29557
|
16
|
|
|
|
|
|
result = libdeflate_deflate_decompress_ex(d, in_next, |
29558
|
16
|
|
|
|
|
|
in_end - GZIP_FOOTER_SIZE - in_next, |
29559
|
|
|
|
|
|
|
out, out_nbytes_avail, |
29560
|
|
|
|
|
|
|
&actual_in_nbytes, |
29561
|
|
|
|
|
|
|
actual_out_nbytes_ret); |
29562
|
16
|
50
|
|
|
|
|
if (result != LIBDEFLATE_SUCCESS) |
29563
|
0
|
|
|
|
|
|
return result; |
29564
|
|
|
|
|
|
|
|
29565
|
16
|
50
|
|
|
|
|
if (actual_out_nbytes_ret) |
29566
|
16
|
|
|
|
|
|
actual_out_nbytes = *actual_out_nbytes_ret; |
29567
|
|
|
|
|
|
|
else |
29568
|
0
|
|
|
|
|
|
actual_out_nbytes = out_nbytes_avail; |
29569
|
|
|
|
|
|
|
|
29570
|
16
|
|
|
|
|
|
in_next += actual_in_nbytes; |
29571
|
|
|
|
|
|
|
|
29572
|
|
|
|
|
|
|
|
29573
|
32
|
50
|
|
|
|
|
if (libdeflate_crc32(0, out, actual_out_nbytes) != |
29574
|
16
|
|
|
|
|
|
get_unaligned_le32(in_next)) |
29575
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29576
|
16
|
|
|
|
|
|
in_next += 4; |
29577
|
|
|
|
|
|
|
|
29578
|
|
|
|
|
|
|
|
29579
|
16
|
50
|
|
|
|
|
if ((u32)actual_out_nbytes != get_unaligned_le32(in_next)) |
29580
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
29581
|
16
|
|
|
|
|
|
in_next += 4; |
29582
|
|
|
|
|
|
|
|
29583
|
16
|
50
|
|
|
|
|
if (actual_in_nbytes_ret) |
29584
|
16
|
|
|
|
|
|
*actual_in_nbytes_ret = in_next - (u8 *)in; |
29585
|
|
|
|
|
|
|
|
29586
|
16
|
|
|
|
|
|
return LIBDEFLATE_SUCCESS; |
29587
|
|
|
|
|
|
|
} |
29588
|
|
|
|
|
|
|
|
29589
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29590
|
0
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *d, |
29591
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29592
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29593
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
29594
|
|
|
|
|
|
|
{ |
29595
|
0
|
|
|
|
|
|
return libdeflate_gzip_decompress_ex(d, in, in_nbytes, |
29596
|
|
|
|
|
|
|
out, out_nbytes_avail, |
29597
|
|
|
|
|
|
|
NULL, actual_out_nbytes_ret); |
29598
|
|
|
|
|
|
|
} |
29599
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/utils.c */ |
29600
|
|
|
|
|
|
|
|
29601
|
|
|
|
|
|
|
|
29602
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
29603
|
|
|
|
|
|
|
|
29604
|
|
|
|
|
|
|
|
29605
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
29606
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
29607
|
|
|
|
|
|
|
|
29608
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
29609
|
|
|
|
|
|
|
|
29610
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
29611
|
|
|
|
|
|
|
#endif |
29612
|
|
|
|
|
|
|
|
29613
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
29614
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
29615
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
29616
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
29617
|
|
|
|
|
|
|
#else |
29618
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
29619
|
|
|
|
|
|
|
#endif |
29620
|
|
|
|
|
|
|
|
29621
|
|
|
|
|
|
|
|
29622
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
29623
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
29624
|
|
|
|
|
|
|
#else |
29625
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
29626
|
|
|
|
|
|
|
#endif |
29627
|
|
|
|
|
|
|
|
29628
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
29629
|
|
|
|
|
|
|
|
29630
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
29631
|
|
|
|
|
|
|
|
29632
|
|
|
|
|
|
|
|
29633
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
29634
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
29635
|
|
|
|
|
|
|
|
29636
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
29637
|
|
|
|
|
|
|
|
29638
|
|
|
|
|
|
|
|
29639
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
29640
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
29641
|
|
|
|
|
|
|
|
29642
|
|
|
|
|
|
|
#include |
29643
|
|
|
|
|
|
|
#include |
29644
|
|
|
|
|
|
|
|
29645
|
|
|
|
|
|
|
#ifdef __cplusplus |
29646
|
|
|
|
|
|
|
extern "C" { |
29647
|
|
|
|
|
|
|
#endif |
29648
|
|
|
|
|
|
|
|
29649
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
29650
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
29651
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
29652
|
|
|
|
|
|
|
|
29653
|
|
|
|
|
|
|
|
29654
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
29655
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
29656
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
29657
|
|
|
|
|
|
|
# else |
29658
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
29659
|
|
|
|
|
|
|
# endif |
29660
|
|
|
|
|
|
|
#endif |
29661
|
|
|
|
|
|
|
|
29662
|
|
|
|
|
|
|
|
29663
|
|
|
|
|
|
|
|
29664
|
|
|
|
|
|
|
|
29665
|
|
|
|
|
|
|
|
29666
|
|
|
|
|
|
|
struct libdeflate_compressor; |
29667
|
|
|
|
|
|
|
struct libdeflate_options; |
29668
|
|
|
|
|
|
|
|
29669
|
|
|
|
|
|
|
|
29670
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
29671
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
29672
|
|
|
|
|
|
|
|
29673
|
|
|
|
|
|
|
|
29674
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
29675
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
29676
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
29677
|
|
|
|
|
|
|
|
29678
|
|
|
|
|
|
|
|
29679
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29680
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
29681
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29682
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
29683
|
|
|
|
|
|
|
|
29684
|
|
|
|
|
|
|
|
29685
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29686
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
29687
|
|
|
|
|
|
|
size_t in_nbytes); |
29688
|
|
|
|
|
|
|
|
29689
|
|
|
|
|
|
|
|
29690
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29691
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
29692
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29693
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
29694
|
|
|
|
|
|
|
|
29695
|
|
|
|
|
|
|
|
29696
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29697
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
29698
|
|
|
|
|
|
|
size_t in_nbytes); |
29699
|
|
|
|
|
|
|
|
29700
|
|
|
|
|
|
|
|
29701
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29702
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
29703
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29704
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
29705
|
|
|
|
|
|
|
|
29706
|
|
|
|
|
|
|
|
29707
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29708
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
29709
|
|
|
|
|
|
|
size_t in_nbytes); |
29710
|
|
|
|
|
|
|
|
29711
|
|
|
|
|
|
|
|
29712
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
29713
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
29714
|
|
|
|
|
|
|
|
29715
|
|
|
|
|
|
|
|
29716
|
|
|
|
|
|
|
|
29717
|
|
|
|
|
|
|
|
29718
|
|
|
|
|
|
|
|
29719
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
29720
|
|
|
|
|
|
|
struct libdeflate_options; |
29721
|
|
|
|
|
|
|
|
29722
|
|
|
|
|
|
|
|
29723
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
29724
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
29725
|
|
|
|
|
|
|
|
29726
|
|
|
|
|
|
|
|
29727
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
29728
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
29729
|
|
|
|
|
|
|
|
29730
|
|
|
|
|
|
|
|
29731
|
|
|
|
|
|
|
enum libdeflate_result { |
29732
|
|
|
|
|
|
|
|
29733
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
29734
|
|
|
|
|
|
|
|
29735
|
|
|
|
|
|
|
|
29736
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
29737
|
|
|
|
|
|
|
|
29738
|
|
|
|
|
|
|
|
29739
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
29740
|
|
|
|
|
|
|
|
29741
|
|
|
|
|
|
|
|
29742
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
29743
|
|
|
|
|
|
|
}; |
29744
|
|
|
|
|
|
|
|
29745
|
|
|
|
|
|
|
|
29746
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29747
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
29748
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29749
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29750
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29751
|
|
|
|
|
|
|
|
29752
|
|
|
|
|
|
|
|
29753
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29754
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
29755
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29756
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29757
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
29758
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29759
|
|
|
|
|
|
|
|
29760
|
|
|
|
|
|
|
|
29761
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29762
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
29763
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29764
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29765
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29766
|
|
|
|
|
|
|
|
29767
|
|
|
|
|
|
|
|
29768
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29769
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
29770
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29771
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29772
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
29773
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29774
|
|
|
|
|
|
|
|
29775
|
|
|
|
|
|
|
|
29776
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29777
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
29778
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29779
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29780
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29781
|
|
|
|
|
|
|
|
29782
|
|
|
|
|
|
|
|
29783
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29784
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
29785
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29786
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29787
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
29788
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29789
|
|
|
|
|
|
|
|
29790
|
|
|
|
|
|
|
|
29791
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
29792
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
29793
|
|
|
|
|
|
|
|
29794
|
|
|
|
|
|
|
|
29795
|
|
|
|
|
|
|
|
29796
|
|
|
|
|
|
|
|
29797
|
|
|
|
|
|
|
|
29798
|
|
|
|
|
|
|
|
29799
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
29800
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
29801
|
|
|
|
|
|
|
|
29802
|
|
|
|
|
|
|
|
29803
|
|
|
|
|
|
|
|
29804
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
29805
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
29806
|
|
|
|
|
|
|
|
29807
|
|
|
|
|
|
|
|
29808
|
|
|
|
|
|
|
|
29809
|
|
|
|
|
|
|
|
29810
|
|
|
|
|
|
|
|
29811
|
|
|
|
|
|
|
|
29812
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
29813
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
29814
|
|
|
|
|
|
|
void (*free_func)(void *)); |
29815
|
|
|
|
|
|
|
|
29816
|
|
|
|
|
|
|
|
29817
|
|
|
|
|
|
|
struct libdeflate_options { |
29818
|
|
|
|
|
|
|
|
29819
|
|
|
|
|
|
|
|
29820
|
|
|
|
|
|
|
size_t sizeof_options; |
29821
|
|
|
|
|
|
|
|
29822
|
|
|
|
|
|
|
|
29823
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
29824
|
|
|
|
|
|
|
void (*free_func)(void *); |
29825
|
|
|
|
|
|
|
}; |
29826
|
|
|
|
|
|
|
|
29827
|
|
|
|
|
|
|
#ifdef __cplusplus |
29828
|
|
|
|
|
|
|
} |
29829
|
|
|
|
|
|
|
#endif |
29830
|
|
|
|
|
|
|
|
29831
|
|
|
|
|
|
|
#endif |
29832
|
|
|
|
|
|
|
|
29833
|
|
|
|
|
|
|
|
29834
|
|
|
|
|
|
|
#include |
29835
|
|
|
|
|
|
|
#include |
29836
|
|
|
|
|
|
|
#include |
29837
|
|
|
|
|
|
|
#ifdef _MSC_VER |
29838
|
|
|
|
|
|
|
# include |
29839
|
|
|
|
|
|
|
# include |
29840
|
|
|
|
|
|
|
|
29841
|
|
|
|
|
|
|
|
29842
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
29843
|
|
|
|
|
|
|
|
29844
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
29845
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
29846
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
29847
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
29848
|
|
|
|
|
|
|
|
29849
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
29850
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
29851
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
29852
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
29853
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
29854
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
29855
|
|
|
|
|
|
|
#endif |
29856
|
|
|
|
|
|
|
#ifndef FREESTANDING |
29857
|
|
|
|
|
|
|
# include |
29858
|
|
|
|
|
|
|
#endif |
29859
|
|
|
|
|
|
|
|
29860
|
|
|
|
|
|
|
|
29861
|
|
|
|
|
|
|
|
29862
|
|
|
|
|
|
|
|
29863
|
|
|
|
|
|
|
|
29864
|
|
|
|
|
|
|
|
29865
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
29866
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
29867
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
29868
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
29869
|
|
|
|
|
|
|
#ifdef _MSC_VER |
29870
|
|
|
|
|
|
|
# if defined(_M_X64) |
29871
|
|
|
|
|
|
|
# define ARCH_X86_64 |
29872
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
29873
|
|
|
|
|
|
|
# define ARCH_X86_32 |
29874
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
29875
|
|
|
|
|
|
|
# define ARCH_ARM64 |
29876
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
29877
|
|
|
|
|
|
|
# define ARCH_ARM32 |
29878
|
|
|
|
|
|
|
# endif |
29879
|
|
|
|
|
|
|
#else |
29880
|
|
|
|
|
|
|
# if defined(__x86_64__) |
29881
|
|
|
|
|
|
|
# define ARCH_X86_64 |
29882
|
|
|
|
|
|
|
# elif defined(__i386__) |
29883
|
|
|
|
|
|
|
# define ARCH_X86_32 |
29884
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
29885
|
|
|
|
|
|
|
# define ARCH_ARM64 |
29886
|
|
|
|
|
|
|
# elif defined(__arm__) |
29887
|
|
|
|
|
|
|
# define ARCH_ARM32 |
29888
|
|
|
|
|
|
|
# endif |
29889
|
|
|
|
|
|
|
#endif |
29890
|
|
|
|
|
|
|
|
29891
|
|
|
|
|
|
|
|
29892
|
|
|
|
|
|
|
|
29893
|
|
|
|
|
|
|
|
29894
|
|
|
|
|
|
|
|
29895
|
|
|
|
|
|
|
|
29896
|
|
|
|
|
|
|
typedef uint8_t u8; |
29897
|
|
|
|
|
|
|
typedef uint16_t u16; |
29898
|
|
|
|
|
|
|
typedef uint32_t u32; |
29899
|
|
|
|
|
|
|
typedef uint64_t u64; |
29900
|
|
|
|
|
|
|
typedef int8_t s8; |
29901
|
|
|
|
|
|
|
typedef int16_t s16; |
29902
|
|
|
|
|
|
|
typedef int32_t s32; |
29903
|
|
|
|
|
|
|
typedef int64_t s64; |
29904
|
|
|
|
|
|
|
|
29905
|
|
|
|
|
|
|
|
29906
|
|
|
|
|
|
|
#ifdef _MSC_VER |
29907
|
|
|
|
|
|
|
# ifdef _WIN64 |
29908
|
|
|
|
|
|
|
typedef long long ssize_t; |
29909
|
|
|
|
|
|
|
# else |
29910
|
|
|
|
|
|
|
typedef long ssize_t; |
29911
|
|
|
|
|
|
|
# endif |
29912
|
|
|
|
|
|
|
#endif |
29913
|
|
|
|
|
|
|
|
29914
|
|
|
|
|
|
|
|
29915
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
29916
|
|
|
|
|
|
|
|
29917
|
|
|
|
|
|
|
|
29918
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
29919
|
|
|
|
|
|
|
|
29920
|
|
|
|
|
|
|
|
29921
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
29922
|
|
|
|
|
|
|
|
29923
|
|
|
|
|
|
|
|
29924
|
|
|
|
|
|
|
|
29925
|
|
|
|
|
|
|
|
29926
|
|
|
|
|
|
|
|
29927
|
|
|
|
|
|
|
|
29928
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
29929
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
29930
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
29931
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
29932
|
|
|
|
|
|
|
#else |
29933
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
29934
|
|
|
|
|
|
|
#endif |
29935
|
|
|
|
|
|
|
#ifdef __clang__ |
29936
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
29937
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
29938
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
29939
|
|
|
|
|
|
|
# else |
29940
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
29941
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
29942
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
29943
|
|
|
|
|
|
|
# endif |
29944
|
|
|
|
|
|
|
#else |
29945
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
29946
|
|
|
|
|
|
|
#endif |
29947
|
|
|
|
|
|
|
|
29948
|
|
|
|
|
|
|
|
29949
|
|
|
|
|
|
|
#ifndef __has_attribute |
29950
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
29951
|
|
|
|
|
|
|
#endif |
29952
|
|
|
|
|
|
|
#ifndef __has_builtin |
29953
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
29954
|
|
|
|
|
|
|
#endif |
29955
|
|
|
|
|
|
|
|
29956
|
|
|
|
|
|
|
|
29957
|
|
|
|
|
|
|
#ifdef _MSC_VER |
29958
|
|
|
|
|
|
|
# define inline __inline |
29959
|
|
|
|
|
|
|
#endif |
29960
|
|
|
|
|
|
|
|
29961
|
|
|
|
|
|
|
|
29962
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
29963
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
29964
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29965
|
|
|
|
|
|
|
# define forceinline __forceinline |
29966
|
|
|
|
|
|
|
#else |
29967
|
|
|
|
|
|
|
# define forceinline inline |
29968
|
|
|
|
|
|
|
#endif |
29969
|
|
|
|
|
|
|
|
29970
|
|
|
|
|
|
|
|
29971
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
29972
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
29973
|
|
|
|
|
|
|
#else |
29974
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
29975
|
|
|
|
|
|
|
#endif |
29976
|
|
|
|
|
|
|
|
29977
|
|
|
|
|
|
|
|
29978
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
29979
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
29980
|
|
|
|
|
|
|
# define restrict __restrict__ |
29981
|
|
|
|
|
|
|
# else |
29982
|
|
|
|
|
|
|
# define restrict |
29983
|
|
|
|
|
|
|
# endif |
29984
|
|
|
|
|
|
|
#endif |
29985
|
|
|
|
|
|
|
|
29986
|
|
|
|
|
|
|
|
29987
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
29988
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
29989
|
|
|
|
|
|
|
#else |
29990
|
|
|
|
|
|
|
# define likely(expr) (expr) |
29991
|
|
|
|
|
|
|
#endif |
29992
|
|
|
|
|
|
|
|
29993
|
|
|
|
|
|
|
|
29994
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
29995
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
29996
|
|
|
|
|
|
|
#else |
29997
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
29998
|
|
|
|
|
|
|
#endif |
29999
|
|
|
|
|
|
|
|
30000
|
|
|
|
|
|
|
|
30001
|
|
|
|
|
|
|
#undef prefetchr |
30002
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
30003
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
30004
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30005
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
30006
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
30007
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
30008
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
30009
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
30010
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
30011
|
|
|
|
|
|
|
# endif |
30012
|
|
|
|
|
|
|
#endif |
30013
|
|
|
|
|
|
|
#ifndef prefetchr |
30014
|
|
|
|
|
|
|
# define prefetchr(addr) |
30015
|
|
|
|
|
|
|
#endif |
30016
|
|
|
|
|
|
|
|
30017
|
|
|
|
|
|
|
|
30018
|
|
|
|
|
|
|
#undef prefetchw |
30019
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
30020
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
30021
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30022
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
30023
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
30024
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
30025
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
30026
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
30027
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
30028
|
|
|
|
|
|
|
# endif |
30029
|
|
|
|
|
|
|
#endif |
30030
|
|
|
|
|
|
|
#ifndef prefetchw |
30031
|
|
|
|
|
|
|
# define prefetchw(addr) |
30032
|
|
|
|
|
|
|
#endif |
30033
|
|
|
|
|
|
|
|
30034
|
|
|
|
|
|
|
|
30035
|
|
|
|
|
|
|
#undef _aligned_attribute |
30036
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
30037
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
30038
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30039
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
30040
|
|
|
|
|
|
|
#endif |
30041
|
|
|
|
|
|
|
|
30042
|
|
|
|
|
|
|
|
30043
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
30044
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
30045
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
30046
|
|
|
|
|
|
|
#else |
30047
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
30048
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
30049
|
|
|
|
|
|
|
#endif |
30050
|
|
|
|
|
|
|
|
30051
|
|
|
|
|
|
|
|
30052
|
|
|
|
|
|
|
|
30053
|
|
|
|
|
|
|
|
30054
|
|
|
|
|
|
|
|
30055
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
30056
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
30057
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
30058
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
30059
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
30060
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
30061
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
30062
|
|
|
|
|
|
|
|
30063
|
|
|
|
|
|
|
|
30064
|
|
|
|
|
|
|
|
30065
|
|
|
|
|
|
|
|
30066
|
|
|
|
|
|
|
|
30067
|
|
|
|
|
|
|
|
30068
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
30069
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
30070
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30071
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
30072
|
|
|
|
|
|
|
#else |
30073
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
30074
|
|
|
|
|
|
|
{ |
30075
|
|
|
|
|
|
|
union { |
30076
|
|
|
|
|
|
|
u32 w; |
30077
|
|
|
|
|
|
|
u8 b; |
30078
|
|
|
|
|
|
|
} u; |
30079
|
|
|
|
|
|
|
|
30080
|
|
|
|
|
|
|
u.w = 1; |
30081
|
|
|
|
|
|
|
return u.b; |
30082
|
|
|
|
|
|
|
} |
30083
|
|
|
|
|
|
|
#endif |
30084
|
|
|
|
|
|
|
|
30085
|
|
|
|
|
|
|
|
30086
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
30087
|
|
|
|
|
|
|
{ |
30088
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
30089
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
30090
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30091
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
30092
|
|
|
|
|
|
|
#else |
30093
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
30094
|
|
|
|
|
|
|
#endif |
30095
|
|
|
|
|
|
|
} |
30096
|
|
|
|
|
|
|
|
30097
|
|
|
|
|
|
|
|
30098
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
30099
|
|
|
|
|
|
|
{ |
30100
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
30101
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
30102
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30103
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
30104
|
|
|
|
|
|
|
#else |
30105
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
30106
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
30107
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
30108
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
30109
|
|
|
|
|
|
|
#endif |
30110
|
|
|
|
|
|
|
} |
30111
|
|
|
|
|
|
|
|
30112
|
|
|
|
|
|
|
|
30113
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
30114
|
|
|
|
|
|
|
{ |
30115
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
30116
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
30117
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30118
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
30119
|
|
|
|
|
|
|
#else |
30120
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
30121
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
30122
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
30123
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
30124
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
30125
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
30126
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
30127
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
30128
|
|
|
|
|
|
|
#endif |
30129
|
|
|
|
|
|
|
} |
30130
|
|
|
|
|
|
|
|
30131
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
30132
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
30133
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
30134
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
30135
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
30136
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
30137
|
|
|
|
|
|
|
|
30138
|
|
|
|
|
|
|
|
30139
|
|
|
|
|
|
|
|
30140
|
|
|
|
|
|
|
|
30141
|
|
|
|
|
|
|
|
30142
|
|
|
|
|
|
|
|
30143
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
30144
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
30145
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
30146
|
|
|
|
|
|
|
defined(__wasm__)) |
30147
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
30148
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30149
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
30150
|
|
|
|
|
|
|
#else |
30151
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
30152
|
|
|
|
|
|
|
#endif |
30153
|
|
|
|
|
|
|
|
30154
|
|
|
|
|
|
|
|
30155
|
|
|
|
|
|
|
|
30156
|
|
|
|
|
|
|
#ifdef FREESTANDING |
30157
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
30158
|
|
|
|
|
|
|
#else |
30159
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
30160
|
|
|
|
|
|
|
#endif |
30161
|
|
|
|
|
|
|
|
30162
|
|
|
|
|
|
|
|
30163
|
|
|
|
|
|
|
|
30164
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
30165
|
|
|
|
|
|
|
static forceinline type \ |
30166
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
30167
|
|
|
|
|
|
|
{ \ |
30168
|
|
|
|
|
|
|
type v; \ |
30169
|
|
|
|
|
|
|
\ |
30170
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
30171
|
|
|
|
|
|
|
return v; \ |
30172
|
|
|
|
|
|
|
} \ |
30173
|
|
|
|
|
|
|
\ |
30174
|
|
|
|
|
|
|
static forceinline void \ |
30175
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
30176
|
|
|
|
|
|
|
{ \ |
30177
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
30178
|
|
|
|
|
|
|
} |
30179
|
|
|
|
|
|
|
|
30180
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
30181
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
30182
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
30183
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
30184
|
|
|
|
|
|
|
|
30185
|
|
|
|
|
|
|
#undef MEMCOPY |
30186
|
|
|
|
|
|
|
|
30187
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
30188
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
30189
|
|
|
|
|
|
|
|
30190
|
|
|
|
|
|
|
|
30191
|
|
|
|
|
|
|
|
30192
|
|
|
|
|
|
|
static forceinline u16 |
30193
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
30194
|
|
|
|
|
|
|
{ |
30195
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30196
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
30197
|
|
|
|
|
|
|
else |
30198
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
30199
|
|
|
|
|
|
|
} |
30200
|
|
|
|
|
|
|
|
30201
|
|
|
|
|
|
|
static forceinline u16 |
30202
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
30203
|
|
|
|
|
|
|
{ |
30204
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30205
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
30206
|
|
|
|
|
|
|
else |
30207
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
30208
|
|
|
|
|
|
|
} |
30209
|
|
|
|
|
|
|
|
30210
|
|
|
|
|
|
|
static forceinline u32 |
30211
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
30212
|
|
|
|
|
|
|
{ |
30213
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30214
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
30215
|
|
|
|
|
|
|
else |
30216
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
30217
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
30218
|
|
|
|
|
|
|
} |
30219
|
|
|
|
|
|
|
|
30220
|
|
|
|
|
|
|
static forceinline u32 |
30221
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
30222
|
|
|
|
|
|
|
{ |
30223
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30224
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
30225
|
|
|
|
|
|
|
else |
30226
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
30227
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
30228
|
|
|
|
|
|
|
} |
30229
|
|
|
|
|
|
|
|
30230
|
|
|
|
|
|
|
static forceinline u64 |
30231
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
30232
|
|
|
|
|
|
|
{ |
30233
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30234
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
30235
|
|
|
|
|
|
|
else |
30236
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
30237
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
30238
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
30239
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
30240
|
|
|
|
|
|
|
} |
30241
|
|
|
|
|
|
|
|
30242
|
|
|
|
|
|
|
static forceinline machine_word_t |
30243
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
30244
|
|
|
|
|
|
|
{ |
30245
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
30246
|
|
|
|
|
|
|
if (WORDBITS == 32) |
30247
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
30248
|
|
|
|
|
|
|
else |
30249
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
30250
|
|
|
|
|
|
|
} |
30251
|
|
|
|
|
|
|
|
30252
|
|
|
|
|
|
|
|
30253
|
|
|
|
|
|
|
|
30254
|
|
|
|
|
|
|
static forceinline void |
30255
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
30256
|
|
|
|
|
|
|
{ |
30257
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30258
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
30259
|
|
|
|
|
|
|
} else { |
30260
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
30261
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
30262
|
|
|
|
|
|
|
} |
30263
|
|
|
|
|
|
|
} |
30264
|
|
|
|
|
|
|
|
30265
|
|
|
|
|
|
|
static forceinline void |
30266
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
30267
|
|
|
|
|
|
|
{ |
30268
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30269
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
30270
|
|
|
|
|
|
|
} else { |
30271
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
30272
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
30273
|
|
|
|
|
|
|
} |
30274
|
|
|
|
|
|
|
} |
30275
|
|
|
|
|
|
|
|
30276
|
|
|
|
|
|
|
static forceinline void |
30277
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
30278
|
|
|
|
|
|
|
{ |
30279
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30280
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
30281
|
|
|
|
|
|
|
} else { |
30282
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
30283
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
30284
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
30285
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
30286
|
|
|
|
|
|
|
} |
30287
|
|
|
|
|
|
|
} |
30288
|
|
|
|
|
|
|
|
30289
|
|
|
|
|
|
|
static forceinline void |
30290
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
30291
|
|
|
|
|
|
|
{ |
30292
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30293
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
30294
|
|
|
|
|
|
|
} else { |
30295
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
30296
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
30297
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
30298
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
30299
|
|
|
|
|
|
|
} |
30300
|
|
|
|
|
|
|
} |
30301
|
|
|
|
|
|
|
|
30302
|
|
|
|
|
|
|
static forceinline void |
30303
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
30304
|
|
|
|
|
|
|
{ |
30305
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30306
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
30307
|
|
|
|
|
|
|
} else { |
30308
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
30309
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
30310
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
30311
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
30312
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
30313
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
30314
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
30315
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
30316
|
|
|
|
|
|
|
} |
30317
|
|
|
|
|
|
|
} |
30318
|
|
|
|
|
|
|
|
30319
|
|
|
|
|
|
|
static forceinline void |
30320
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
30321
|
|
|
|
|
|
|
{ |
30322
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
30323
|
|
|
|
|
|
|
if (WORDBITS == 32) |
30324
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
30325
|
|
|
|
|
|
|
else |
30326
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
30327
|
|
|
|
|
|
|
} |
30328
|
|
|
|
|
|
|
|
30329
|
|
|
|
|
|
|
|
30330
|
|
|
|
|
|
|
|
30331
|
|
|
|
|
|
|
|
30332
|
|
|
|
|
|
|
|
30333
|
|
|
|
|
|
|
|
30334
|
|
|
|
|
|
|
|
30335
|
|
|
|
|
|
|
static forceinline unsigned |
30336
|
|
|
|
|
|
|
bsr32(u32 v) |
30337
|
|
|
|
|
|
|
{ |
30338
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
30339
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
30340
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30341
|
|
|
|
|
|
|
unsigned long i; |
30342
|
|
|
|
|
|
|
|
30343
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
30344
|
|
|
|
|
|
|
return i; |
30345
|
|
|
|
|
|
|
#else |
30346
|
|
|
|
|
|
|
unsigned i = 0; |
30347
|
|
|
|
|
|
|
|
30348
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
30349
|
|
|
|
|
|
|
i++; |
30350
|
|
|
|
|
|
|
return i; |
30351
|
|
|
|
|
|
|
#endif |
30352
|
|
|
|
|
|
|
} |
30353
|
|
|
|
|
|
|
|
30354
|
|
|
|
|
|
|
static forceinline unsigned |
30355
|
|
|
|
|
|
|
bsr64(u64 v) |
30356
|
|
|
|
|
|
|
{ |
30357
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
30358
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
30359
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
30360
|
|
|
|
|
|
|
unsigned long i; |
30361
|
|
|
|
|
|
|
|
30362
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
30363
|
|
|
|
|
|
|
return i; |
30364
|
|
|
|
|
|
|
#else |
30365
|
|
|
|
|
|
|
unsigned i = 0; |
30366
|
|
|
|
|
|
|
|
30367
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
30368
|
|
|
|
|
|
|
i++; |
30369
|
|
|
|
|
|
|
return i; |
30370
|
|
|
|
|
|
|
#endif |
30371
|
|
|
|
|
|
|
} |
30372
|
|
|
|
|
|
|
|
30373
|
|
|
|
|
|
|
static forceinline unsigned |
30374
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
30375
|
|
|
|
|
|
|
{ |
30376
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
30377
|
|
|
|
|
|
|
if (WORDBITS == 32) |
30378
|
|
|
|
|
|
|
return bsr32(v); |
30379
|
|
|
|
|
|
|
else |
30380
|
|
|
|
|
|
|
return bsr64(v); |
30381
|
|
|
|
|
|
|
} |
30382
|
|
|
|
|
|
|
|
30383
|
|
|
|
|
|
|
|
30384
|
|
|
|
|
|
|
|
30385
|
|
|
|
|
|
|
static forceinline unsigned |
30386
|
|
|
|
|
|
|
bsf32(u32 v) |
30387
|
|
|
|
|
|
|
{ |
30388
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
30389
|
|
|
|
|
|
|
return __builtin_ctz(v); |
30390
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30391
|
|
|
|
|
|
|
unsigned long i; |
30392
|
|
|
|
|
|
|
|
30393
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
30394
|
|
|
|
|
|
|
return i; |
30395
|
|
|
|
|
|
|
#else |
30396
|
|
|
|
|
|
|
unsigned i = 0; |
30397
|
|
|
|
|
|
|
|
30398
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
30399
|
|
|
|
|
|
|
i++; |
30400
|
|
|
|
|
|
|
return i; |
30401
|
|
|
|
|
|
|
#endif |
30402
|
|
|
|
|
|
|
} |
30403
|
|
|
|
|
|
|
|
30404
|
|
|
|
|
|
|
static forceinline unsigned |
30405
|
|
|
|
|
|
|
bsf64(u64 v) |
30406
|
|
|
|
|
|
|
{ |
30407
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
30408
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
30409
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
30410
|
|
|
|
|
|
|
unsigned long i; |
30411
|
|
|
|
|
|
|
|
30412
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
30413
|
|
|
|
|
|
|
return i; |
30414
|
|
|
|
|
|
|
#else |
30415
|
|
|
|
|
|
|
unsigned i = 0; |
30416
|
|
|
|
|
|
|
|
30417
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
30418
|
|
|
|
|
|
|
i++; |
30419
|
|
|
|
|
|
|
return i; |
30420
|
|
|
|
|
|
|
#endif |
30421
|
|
|
|
|
|
|
} |
30422
|
|
|
|
|
|
|
|
30423
|
|
|
|
|
|
|
static forceinline unsigned |
30424
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
30425
|
|
|
|
|
|
|
{ |
30426
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
30427
|
|
|
|
|
|
|
if (WORDBITS == 32) |
30428
|
|
|
|
|
|
|
return bsf32(v); |
30429
|
|
|
|
|
|
|
else |
30430
|
|
|
|
|
|
|
return bsf64(v); |
30431
|
|
|
|
|
|
|
} |
30432
|
|
|
|
|
|
|
|
30433
|
|
|
|
|
|
|
|
30434
|
|
|
|
|
|
|
#undef rbit32 |
30435
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
30436
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
30437
|
|
|
|
|
|
|
static forceinline u32 |
30438
|
|
|
|
|
|
|
rbit32(u32 v) |
30439
|
|
|
|
|
|
|
{ |
30440
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
30441
|
|
|
|
|
|
|
return v; |
30442
|
|
|
|
|
|
|
} |
30443
|
|
|
|
|
|
|
#define rbit32 rbit32 |
30444
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
30445
|
|
|
|
|
|
|
static forceinline u32 |
30446
|
|
|
|
|
|
|
rbit32(u32 v) |
30447
|
|
|
|
|
|
|
{ |
30448
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
30449
|
|
|
|
|
|
|
return v; |
30450
|
|
|
|
|
|
|
} |
30451
|
|
|
|
|
|
|
#define rbit32 rbit32 |
30452
|
|
|
|
|
|
|
#endif |
30453
|
|
|
|
|
|
|
|
30454
|
|
|
|
|
|
|
#endif |
30455
|
|
|
|
|
|
|
|
30456
|
|
|
|
|
|
|
|
30457
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
30458
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
30459
|
|
|
|
|
|
|
|
30460
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
30461
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
30462
|
|
|
|
|
|
|
|
30463
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
30464
|
|
|
|
|
|
|
size_t alignment, size_t size); |
30465
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
30466
|
|
|
|
|
|
|
|
30467
|
|
|
|
|
|
|
#ifdef FREESTANDING |
30468
|
|
|
|
|
|
|
|
30469
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
30470
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
30471
|
|
|
|
|
|
|
|
30472
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
30473
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
30474
|
|
|
|
|
|
|
|
30475
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
30476
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
30477
|
|
|
|
|
|
|
|
30478
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
30479
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
30480
|
|
|
|
|
|
|
|
30481
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
30482
|
|
|
|
|
|
|
#else |
30483
|
|
|
|
|
|
|
#include |
30484
|
|
|
|
|
|
|
#endif |
30485
|
|
|
|
|
|
|
|
30486
|
|
|
|
|
|
|
|
30487
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
30488
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
30489
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
30490
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
30491
|
|
|
|
|
|
|
#else |
30492
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
30493
|
|
|
|
|
|
|
#endif |
30494
|
|
|
|
|
|
|
|
30495
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
30496
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
30497
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
30498
|
|
|
|
|
|
|
|
30499
|
|
|
|
|
|
|
#endif |
30500
|
|
|
|
|
|
|
|
30501
|
|
|
|
|
|
|
|
30502
|
|
|
|
|
|
|
#ifdef FREESTANDING |
30503
|
|
|
|
|
|
|
# define malloc NULL |
30504
|
|
|
|
|
|
|
# define free NULL |
30505
|
|
|
|
|
|
|
#else |
30506
|
|
|
|
|
|
|
# include |
30507
|
|
|
|
|
|
|
#endif |
30508
|
|
|
|
|
|
|
|
30509
|
|
|
|
|
|
|
malloc_func_t libdeflate_default_malloc_func = malloc; |
30510
|
|
|
|
|
|
|
free_func_t libdeflate_default_free_func = free; |
30511
|
|
|
|
|
|
|
|
30512
|
|
|
|
|
|
|
void * |
30513
|
37
|
|
|
|
|
|
libdeflate_aligned_malloc(malloc_func_t malloc_func, |
30514
|
|
|
|
|
|
|
size_t alignment, size_t size) |
30515
|
|
|
|
|
|
|
{ |
30516
|
37
|
|
|
|
|
|
void *ptr = (*malloc_func)(sizeof(void *) + alignment - 1 + size); |
30517
|
|
|
|
|
|
|
|
30518
|
37
|
50
|
|
|
|
|
if (ptr) { |
30519
|
37
|
|
|
|
|
|
void *orig_ptr = ptr; |
30520
|
|
|
|
|
|
|
|
30521
|
37
|
|
|
|
|
|
ptr = (void *)ALIGN((uintptr_t)ptr + sizeof(void *), alignment); |
30522
|
37
|
|
|
|
|
|
((void **)ptr)[-1] = orig_ptr; |
30523
|
|
|
|
|
|
|
} |
30524
|
37
|
|
|
|
|
|
return ptr; |
30525
|
|
|
|
|
|
|
} |
30526
|
|
|
|
|
|
|
|
30527
|
|
|
|
|
|
|
void |
30528
|
37
|
|
|
|
|
|
libdeflate_aligned_free(free_func_t free_func, void *ptr) |
30529
|
|
|
|
|
|
|
{ |
30530
|
37
|
|
|
|
|
|
(*free_func)(((void **)ptr)[-1]); |
30531
|
37
|
|
|
|
|
|
} |
30532
|
|
|
|
|
|
|
|
30533
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
30534
|
0
|
|
|
|
|
|
libdeflate_set_memory_allocator(malloc_func_t malloc_func, |
30535
|
|
|
|
|
|
|
free_func_t free_func) |
30536
|
|
|
|
|
|
|
{ |
30537
|
0
|
|
|
|
|
|
libdeflate_default_malloc_func = malloc_func; |
30538
|
0
|
|
|
|
|
|
libdeflate_default_free_func = free_func; |
30539
|
0
|
|
|
|
|
|
} |
30540
|
|
|
|
|
|
|
|
30541
|
|
|
|
|
|
|
|
30542
|
|
|
|
|
|
|
#ifdef FREESTANDING |
30543
|
|
|
|
|
|
|
#undef memset |
30544
|
|
|
|
|
|
|
void * __attribute__((weak)) |
30545
|
|
|
|
|
|
|
memset(void *s, int c, size_t n) |
30546
|
|
|
|
|
|
|
{ |
30547
|
|
|
|
|
|
|
u8 *p = s; |
30548
|
|
|
|
|
|
|
size_t i; |
30549
|
|
|
|
|
|
|
|
30550
|
|
|
|
|
|
|
for (i = 0; i < n; i++) |
30551
|
|
|
|
|
|
|
p[i] = c; |
30552
|
|
|
|
|
|
|
return s; |
30553
|
|
|
|
|
|
|
} |
30554
|
|
|
|
|
|
|
|
30555
|
|
|
|
|
|
|
#undef memcpy |
30556
|
|
|
|
|
|
|
void * __attribute__((weak)) |
30557
|
|
|
|
|
|
|
memcpy(void *dest, const void *src, size_t n) |
30558
|
|
|
|
|
|
|
{ |
30559
|
|
|
|
|
|
|
u8 *d = dest; |
30560
|
|
|
|
|
|
|
const u8 *s = src; |
30561
|
|
|
|
|
|
|
size_t i; |
30562
|
|
|
|
|
|
|
|
30563
|
|
|
|
|
|
|
for (i = 0; i < n; i++) |
30564
|
|
|
|
|
|
|
d[i] = s[i]; |
30565
|
|
|
|
|
|
|
return dest; |
30566
|
|
|
|
|
|
|
} |
30567
|
|
|
|
|
|
|
|
30568
|
|
|
|
|
|
|
#undef memmove |
30569
|
|
|
|
|
|
|
void * __attribute__((weak)) |
30570
|
|
|
|
|
|
|
memmove(void *dest, const void *src, size_t n) |
30571
|
|
|
|
|
|
|
{ |
30572
|
|
|
|
|
|
|
u8 *d = dest; |
30573
|
|
|
|
|
|
|
const u8 *s = src; |
30574
|
|
|
|
|
|
|
size_t i; |
30575
|
|
|
|
|
|
|
|
30576
|
|
|
|
|
|
|
if (d <= s) |
30577
|
|
|
|
|
|
|
return memcpy(d, s, n); |
30578
|
|
|
|
|
|
|
|
30579
|
|
|
|
|
|
|
for (i = n; i > 0; i--) |
30580
|
|
|
|
|
|
|
d[i - 1] = s[i - 1]; |
30581
|
|
|
|
|
|
|
return dest; |
30582
|
|
|
|
|
|
|
} |
30583
|
|
|
|
|
|
|
|
30584
|
|
|
|
|
|
|
#undef memcmp |
30585
|
|
|
|
|
|
|
int __attribute__((weak)) |
30586
|
|
|
|
|
|
|
memcmp(const void *s1, const void *s2, size_t n) |
30587
|
|
|
|
|
|
|
{ |
30588
|
|
|
|
|
|
|
const u8 *p1 = s1; |
30589
|
|
|
|
|
|
|
const u8 *p2 = s2; |
30590
|
|
|
|
|
|
|
size_t i; |
30591
|
|
|
|
|
|
|
|
30592
|
|
|
|
|
|
|
for (i = 0; i < n; i++) { |
30593
|
|
|
|
|
|
|
if (p1[i] != p2[i]) |
30594
|
|
|
|
|
|
|
return (int)p1[i] - (int)p2[i]; |
30595
|
|
|
|
|
|
|
} |
30596
|
|
|
|
|
|
|
return 0; |
30597
|
|
|
|
|
|
|
} |
30598
|
|
|
|
|
|
|
#endif |
30599
|
|
|
|
|
|
|
|
30600
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
30601
|
|
|
|
|
|
|
#include |
30602
|
|
|
|
|
|
|
#include |
30603
|
|
|
|
|
|
|
void |
30604
|
|
|
|
|
|
|
libdeflate_assertion_failed(const char *expr, const char *file, int line) |
30605
|
|
|
|
|
|
|
{ |
30606
|
|
|
|
|
|
|
fprintf(stderr, "Assertion failed: %s at %s:%d\n", expr, file, line); |
30607
|
|
|
|
|
|
|
abort(); |
30608
|
|
|
|
|
|
|
} |
30609
|
|
|
|
|
|
|
#endif |
30610
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/zlib_compress.c */ |
30611
|
|
|
|
|
|
|
|
30612
|
|
|
|
|
|
|
|
30613
|
|
|
|
|
|
|
/* #include "deflate_compress.h" */ |
30614
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_COMPRESS_H |
30615
|
|
|
|
|
|
|
#define LIB_DEFLATE_COMPRESS_H |
30616
|
|
|
|
|
|
|
|
30617
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
30618
|
|
|
|
|
|
|
|
30619
|
|
|
|
|
|
|
|
30620
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
30621
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
30622
|
|
|
|
|
|
|
|
30623
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
30624
|
|
|
|
|
|
|
|
30625
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
30626
|
|
|
|
|
|
|
#endif |
30627
|
|
|
|
|
|
|
|
30628
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
30629
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
30630
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
30631
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
30632
|
|
|
|
|
|
|
#else |
30633
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
30634
|
|
|
|
|
|
|
#endif |
30635
|
|
|
|
|
|
|
|
30636
|
|
|
|
|
|
|
|
30637
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
30638
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
30639
|
|
|
|
|
|
|
#else |
30640
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
30641
|
|
|
|
|
|
|
#endif |
30642
|
|
|
|
|
|
|
|
30643
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
30644
|
|
|
|
|
|
|
|
30645
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
30646
|
|
|
|
|
|
|
|
30647
|
|
|
|
|
|
|
|
30648
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
30649
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
30650
|
|
|
|
|
|
|
|
30651
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
30652
|
|
|
|
|
|
|
|
30653
|
|
|
|
|
|
|
|
30654
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
30655
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
30656
|
|
|
|
|
|
|
|
30657
|
|
|
|
|
|
|
#include |
30658
|
|
|
|
|
|
|
#include |
30659
|
|
|
|
|
|
|
|
30660
|
|
|
|
|
|
|
#ifdef __cplusplus |
30661
|
|
|
|
|
|
|
extern "C" { |
30662
|
|
|
|
|
|
|
#endif |
30663
|
|
|
|
|
|
|
|
30664
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
30665
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
30666
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
30667
|
|
|
|
|
|
|
|
30668
|
|
|
|
|
|
|
|
30669
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
30670
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
30671
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
30672
|
|
|
|
|
|
|
# else |
30673
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
30674
|
|
|
|
|
|
|
# endif |
30675
|
|
|
|
|
|
|
#endif |
30676
|
|
|
|
|
|
|
|
30677
|
|
|
|
|
|
|
|
30678
|
|
|
|
|
|
|
|
30679
|
|
|
|
|
|
|
|
30680
|
|
|
|
|
|
|
|
30681
|
|
|
|
|
|
|
struct libdeflate_compressor; |
30682
|
|
|
|
|
|
|
struct libdeflate_options; |
30683
|
|
|
|
|
|
|
|
30684
|
|
|
|
|
|
|
|
30685
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
30686
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
30687
|
|
|
|
|
|
|
|
30688
|
|
|
|
|
|
|
|
30689
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
30690
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
30691
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
30692
|
|
|
|
|
|
|
|
30693
|
|
|
|
|
|
|
|
30694
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30695
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
30696
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30697
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
30698
|
|
|
|
|
|
|
|
30699
|
|
|
|
|
|
|
|
30700
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30701
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
30702
|
|
|
|
|
|
|
size_t in_nbytes); |
30703
|
|
|
|
|
|
|
|
30704
|
|
|
|
|
|
|
|
30705
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30706
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
30707
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30708
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
30709
|
|
|
|
|
|
|
|
30710
|
|
|
|
|
|
|
|
30711
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30712
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
30713
|
|
|
|
|
|
|
size_t in_nbytes); |
30714
|
|
|
|
|
|
|
|
30715
|
|
|
|
|
|
|
|
30716
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30717
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
30718
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30719
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
30720
|
|
|
|
|
|
|
|
30721
|
|
|
|
|
|
|
|
30722
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30723
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
30724
|
|
|
|
|
|
|
size_t in_nbytes); |
30725
|
|
|
|
|
|
|
|
30726
|
|
|
|
|
|
|
|
30727
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
30728
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
30729
|
|
|
|
|
|
|
|
30730
|
|
|
|
|
|
|
|
30731
|
|
|
|
|
|
|
|
30732
|
|
|
|
|
|
|
|
30733
|
|
|
|
|
|
|
|
30734
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
30735
|
|
|
|
|
|
|
struct libdeflate_options; |
30736
|
|
|
|
|
|
|
|
30737
|
|
|
|
|
|
|
|
30738
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
30739
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
30740
|
|
|
|
|
|
|
|
30741
|
|
|
|
|
|
|
|
30742
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
30743
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
30744
|
|
|
|
|
|
|
|
30745
|
|
|
|
|
|
|
|
30746
|
|
|
|
|
|
|
enum libdeflate_result { |
30747
|
|
|
|
|
|
|
|
30748
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
30749
|
|
|
|
|
|
|
|
30750
|
|
|
|
|
|
|
|
30751
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
30752
|
|
|
|
|
|
|
|
30753
|
|
|
|
|
|
|
|
30754
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
30755
|
|
|
|
|
|
|
|
30756
|
|
|
|
|
|
|
|
30757
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
30758
|
|
|
|
|
|
|
}; |
30759
|
|
|
|
|
|
|
|
30760
|
|
|
|
|
|
|
|
30761
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30762
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
30763
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30764
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30765
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30766
|
|
|
|
|
|
|
|
30767
|
|
|
|
|
|
|
|
30768
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30769
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
30770
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30771
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30772
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
30773
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30774
|
|
|
|
|
|
|
|
30775
|
|
|
|
|
|
|
|
30776
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30777
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
30778
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30779
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30780
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30781
|
|
|
|
|
|
|
|
30782
|
|
|
|
|
|
|
|
30783
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30784
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
30785
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30786
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30787
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
30788
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30789
|
|
|
|
|
|
|
|
30790
|
|
|
|
|
|
|
|
30791
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30792
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
30793
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30794
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30795
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30796
|
|
|
|
|
|
|
|
30797
|
|
|
|
|
|
|
|
30798
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30799
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
30800
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30801
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30802
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
30803
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30804
|
|
|
|
|
|
|
|
30805
|
|
|
|
|
|
|
|
30806
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
30807
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
30808
|
|
|
|
|
|
|
|
30809
|
|
|
|
|
|
|
|
30810
|
|
|
|
|
|
|
|
30811
|
|
|
|
|
|
|
|
30812
|
|
|
|
|
|
|
|
30813
|
|
|
|
|
|
|
|
30814
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
30815
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
30816
|
|
|
|
|
|
|
|
30817
|
|
|
|
|
|
|
|
30818
|
|
|
|
|
|
|
|
30819
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
30820
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
30821
|
|
|
|
|
|
|
|
30822
|
|
|
|
|
|
|
|
30823
|
|
|
|
|
|
|
|
30824
|
|
|
|
|
|
|
|
30825
|
|
|
|
|
|
|
|
30826
|
|
|
|
|
|
|
|
30827
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
30828
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
30829
|
|
|
|
|
|
|
void (*free_func)(void *)); |
30830
|
|
|
|
|
|
|
|
30831
|
|
|
|
|
|
|
|
30832
|
|
|
|
|
|
|
struct libdeflate_options { |
30833
|
|
|
|
|
|
|
|
30834
|
|
|
|
|
|
|
|
30835
|
|
|
|
|
|
|
size_t sizeof_options; |
30836
|
|
|
|
|
|
|
|
30837
|
|
|
|
|
|
|
|
30838
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
30839
|
|
|
|
|
|
|
void (*free_func)(void *); |
30840
|
|
|
|
|
|
|
}; |
30841
|
|
|
|
|
|
|
|
30842
|
|
|
|
|
|
|
#ifdef __cplusplus |
30843
|
|
|
|
|
|
|
} |
30844
|
|
|
|
|
|
|
#endif |
30845
|
|
|
|
|
|
|
|
30846
|
|
|
|
|
|
|
#endif |
30847
|
|
|
|
|
|
|
|
30848
|
|
|
|
|
|
|
|
30849
|
|
|
|
|
|
|
#include |
30850
|
|
|
|
|
|
|
#include |
30851
|
|
|
|
|
|
|
#include |
30852
|
|
|
|
|
|
|
#ifdef _MSC_VER |
30853
|
|
|
|
|
|
|
# include |
30854
|
|
|
|
|
|
|
# include |
30855
|
|
|
|
|
|
|
|
30856
|
|
|
|
|
|
|
|
30857
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
30858
|
|
|
|
|
|
|
|
30859
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
30860
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
30861
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
30862
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
30863
|
|
|
|
|
|
|
|
30864
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
30865
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
30866
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
30867
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
30868
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
30869
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
30870
|
|
|
|
|
|
|
#endif |
30871
|
|
|
|
|
|
|
#ifndef FREESTANDING |
30872
|
|
|
|
|
|
|
# include |
30873
|
|
|
|
|
|
|
#endif |
30874
|
|
|
|
|
|
|
|
30875
|
|
|
|
|
|
|
|
30876
|
|
|
|
|
|
|
|
30877
|
|
|
|
|
|
|
|
30878
|
|
|
|
|
|
|
|
30879
|
|
|
|
|
|
|
|
30880
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
30881
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
30882
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
30883
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
30884
|
|
|
|
|
|
|
#ifdef _MSC_VER |
30885
|
|
|
|
|
|
|
# if defined(_M_X64) |
30886
|
|
|
|
|
|
|
# define ARCH_X86_64 |
30887
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
30888
|
|
|
|
|
|
|
# define ARCH_X86_32 |
30889
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
30890
|
|
|
|
|
|
|
# define ARCH_ARM64 |
30891
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
30892
|
|
|
|
|
|
|
# define ARCH_ARM32 |
30893
|
|
|
|
|
|
|
# endif |
30894
|
|
|
|
|
|
|
#else |
30895
|
|
|
|
|
|
|
# if defined(__x86_64__) |
30896
|
|
|
|
|
|
|
# define ARCH_X86_64 |
30897
|
|
|
|
|
|
|
# elif defined(__i386__) |
30898
|
|
|
|
|
|
|
# define ARCH_X86_32 |
30899
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
30900
|
|
|
|
|
|
|
# define ARCH_ARM64 |
30901
|
|
|
|
|
|
|
# elif defined(__arm__) |
30902
|
|
|
|
|
|
|
# define ARCH_ARM32 |
30903
|
|
|
|
|
|
|
# endif |
30904
|
|
|
|
|
|
|
#endif |
30905
|
|
|
|
|
|
|
|
30906
|
|
|
|
|
|
|
|
30907
|
|
|
|
|
|
|
|
30908
|
|
|
|
|
|
|
|
30909
|
|
|
|
|
|
|
|
30910
|
|
|
|
|
|
|
|
30911
|
|
|
|
|
|
|
typedef uint8_t u8; |
30912
|
|
|
|
|
|
|
typedef uint16_t u16; |
30913
|
|
|
|
|
|
|
typedef uint32_t u32; |
30914
|
|
|
|
|
|
|
typedef uint64_t u64; |
30915
|
|
|
|
|
|
|
typedef int8_t s8; |
30916
|
|
|
|
|
|
|
typedef int16_t s16; |
30917
|
|
|
|
|
|
|
typedef int32_t s32; |
30918
|
|
|
|
|
|
|
typedef int64_t s64; |
30919
|
|
|
|
|
|
|
|
30920
|
|
|
|
|
|
|
|
30921
|
|
|
|
|
|
|
#ifdef _MSC_VER |
30922
|
|
|
|
|
|
|
# ifdef _WIN64 |
30923
|
|
|
|
|
|
|
typedef long long ssize_t; |
30924
|
|
|
|
|
|
|
# else |
30925
|
|
|
|
|
|
|
typedef long ssize_t; |
30926
|
|
|
|
|
|
|
# endif |
30927
|
|
|
|
|
|
|
#endif |
30928
|
|
|
|
|
|
|
|
30929
|
|
|
|
|
|
|
|
30930
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
30931
|
|
|
|
|
|
|
|
30932
|
|
|
|
|
|
|
|
30933
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
30934
|
|
|
|
|
|
|
|
30935
|
|
|
|
|
|
|
|
30936
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
30937
|
|
|
|
|
|
|
|
30938
|
|
|
|
|
|
|
|
30939
|
|
|
|
|
|
|
|
30940
|
|
|
|
|
|
|
|
30941
|
|
|
|
|
|
|
|
30942
|
|
|
|
|
|
|
|
30943
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
30944
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
30945
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
30946
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
30947
|
|
|
|
|
|
|
#else |
30948
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
30949
|
|
|
|
|
|
|
#endif |
30950
|
|
|
|
|
|
|
#ifdef __clang__ |
30951
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
30952
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
30953
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
30954
|
|
|
|
|
|
|
# else |
30955
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
30956
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
30957
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
30958
|
|
|
|
|
|
|
# endif |
30959
|
|
|
|
|
|
|
#else |
30960
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
30961
|
|
|
|
|
|
|
#endif |
30962
|
|
|
|
|
|
|
|
30963
|
|
|
|
|
|
|
|
30964
|
|
|
|
|
|
|
#ifndef __has_attribute |
30965
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
30966
|
|
|
|
|
|
|
#endif |
30967
|
|
|
|
|
|
|
#ifndef __has_builtin |
30968
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
30969
|
|
|
|
|
|
|
#endif |
30970
|
|
|
|
|
|
|
|
30971
|
|
|
|
|
|
|
|
30972
|
|
|
|
|
|
|
#ifdef _MSC_VER |
30973
|
|
|
|
|
|
|
# define inline __inline |
30974
|
|
|
|
|
|
|
#endif |
30975
|
|
|
|
|
|
|
|
30976
|
|
|
|
|
|
|
|
30977
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
30978
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
30979
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30980
|
|
|
|
|
|
|
# define forceinline __forceinline |
30981
|
|
|
|
|
|
|
#else |
30982
|
|
|
|
|
|
|
# define forceinline inline |
30983
|
|
|
|
|
|
|
#endif |
30984
|
|
|
|
|
|
|
|
30985
|
|
|
|
|
|
|
|
30986
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
30987
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
30988
|
|
|
|
|
|
|
#else |
30989
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
30990
|
|
|
|
|
|
|
#endif |
30991
|
|
|
|
|
|
|
|
30992
|
|
|
|
|
|
|
|
30993
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
30994
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
30995
|
|
|
|
|
|
|
# define restrict __restrict__ |
30996
|
|
|
|
|
|
|
# else |
30997
|
|
|
|
|
|
|
# define restrict |
30998
|
|
|
|
|
|
|
# endif |
30999
|
|
|
|
|
|
|
#endif |
31000
|
|
|
|
|
|
|
|
31001
|
|
|
|
|
|
|
|
31002
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
31003
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
31004
|
|
|
|
|
|
|
#else |
31005
|
|
|
|
|
|
|
# define likely(expr) (expr) |
31006
|
|
|
|
|
|
|
#endif |
31007
|
|
|
|
|
|
|
|
31008
|
|
|
|
|
|
|
|
31009
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
31010
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
31011
|
|
|
|
|
|
|
#else |
31012
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
31013
|
|
|
|
|
|
|
#endif |
31014
|
|
|
|
|
|
|
|
31015
|
|
|
|
|
|
|
|
31016
|
|
|
|
|
|
|
#undef prefetchr |
31017
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
31018
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
31019
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31020
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
31021
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
31022
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
31023
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
31024
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
31025
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
31026
|
|
|
|
|
|
|
# endif |
31027
|
|
|
|
|
|
|
#endif |
31028
|
|
|
|
|
|
|
#ifndef prefetchr |
31029
|
|
|
|
|
|
|
# define prefetchr(addr) |
31030
|
|
|
|
|
|
|
#endif |
31031
|
|
|
|
|
|
|
|
31032
|
|
|
|
|
|
|
|
31033
|
|
|
|
|
|
|
#undef prefetchw |
31034
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
31035
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
31036
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31037
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
31038
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
31039
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
31040
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
31041
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
31042
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
31043
|
|
|
|
|
|
|
# endif |
31044
|
|
|
|
|
|
|
#endif |
31045
|
|
|
|
|
|
|
#ifndef prefetchw |
31046
|
|
|
|
|
|
|
# define prefetchw(addr) |
31047
|
|
|
|
|
|
|
#endif |
31048
|
|
|
|
|
|
|
|
31049
|
|
|
|
|
|
|
|
31050
|
|
|
|
|
|
|
#undef _aligned_attribute |
31051
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
31052
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
31053
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31054
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
31055
|
|
|
|
|
|
|
#endif |
31056
|
|
|
|
|
|
|
|
31057
|
|
|
|
|
|
|
|
31058
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
31059
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
31060
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
31061
|
|
|
|
|
|
|
#else |
31062
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
31063
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
31064
|
|
|
|
|
|
|
#endif |
31065
|
|
|
|
|
|
|
|
31066
|
|
|
|
|
|
|
|
31067
|
|
|
|
|
|
|
|
31068
|
|
|
|
|
|
|
|
31069
|
|
|
|
|
|
|
|
31070
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
31071
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
31072
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
31073
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
31074
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
31075
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
31076
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
31077
|
|
|
|
|
|
|
|
31078
|
|
|
|
|
|
|
|
31079
|
|
|
|
|
|
|
|
31080
|
|
|
|
|
|
|
|
31081
|
|
|
|
|
|
|
|
31082
|
|
|
|
|
|
|
|
31083
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
31084
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
31085
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31086
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
31087
|
|
|
|
|
|
|
#else |
31088
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
31089
|
|
|
|
|
|
|
{ |
31090
|
|
|
|
|
|
|
union { |
31091
|
|
|
|
|
|
|
u32 w; |
31092
|
|
|
|
|
|
|
u8 b; |
31093
|
|
|
|
|
|
|
} u; |
31094
|
|
|
|
|
|
|
|
31095
|
|
|
|
|
|
|
u.w = 1; |
31096
|
|
|
|
|
|
|
return u.b; |
31097
|
|
|
|
|
|
|
} |
31098
|
|
|
|
|
|
|
#endif |
31099
|
|
|
|
|
|
|
|
31100
|
|
|
|
|
|
|
|
31101
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
31102
|
|
|
|
|
|
|
{ |
31103
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
31104
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
31105
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31106
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
31107
|
|
|
|
|
|
|
#else |
31108
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
31109
|
|
|
|
|
|
|
#endif |
31110
|
|
|
|
|
|
|
} |
31111
|
|
|
|
|
|
|
|
31112
|
|
|
|
|
|
|
|
31113
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
31114
|
|
|
|
|
|
|
{ |
31115
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
31116
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
31117
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31118
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
31119
|
|
|
|
|
|
|
#else |
31120
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
31121
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
31122
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
31123
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
31124
|
|
|
|
|
|
|
#endif |
31125
|
|
|
|
|
|
|
} |
31126
|
|
|
|
|
|
|
|
31127
|
|
|
|
|
|
|
|
31128
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
31129
|
|
|
|
|
|
|
{ |
31130
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
31131
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
31132
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31133
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
31134
|
|
|
|
|
|
|
#else |
31135
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
31136
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
31137
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
31138
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
31139
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
31140
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
31141
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
31142
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
31143
|
|
|
|
|
|
|
#endif |
31144
|
|
|
|
|
|
|
} |
31145
|
|
|
|
|
|
|
|
31146
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
31147
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
31148
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
31149
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
31150
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
31151
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
31152
|
|
|
|
|
|
|
|
31153
|
|
|
|
|
|
|
|
31154
|
|
|
|
|
|
|
|
31155
|
|
|
|
|
|
|
|
31156
|
|
|
|
|
|
|
|
31157
|
|
|
|
|
|
|
|
31158
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
31159
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
31160
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
31161
|
|
|
|
|
|
|
defined(__wasm__)) |
31162
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
31163
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31164
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
31165
|
|
|
|
|
|
|
#else |
31166
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
31167
|
|
|
|
|
|
|
#endif |
31168
|
|
|
|
|
|
|
|
31169
|
|
|
|
|
|
|
|
31170
|
|
|
|
|
|
|
|
31171
|
|
|
|
|
|
|
#ifdef FREESTANDING |
31172
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
31173
|
|
|
|
|
|
|
#else |
31174
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
31175
|
|
|
|
|
|
|
#endif |
31176
|
|
|
|
|
|
|
|
31177
|
|
|
|
|
|
|
|
31178
|
|
|
|
|
|
|
|
31179
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
31180
|
|
|
|
|
|
|
static forceinline type \ |
31181
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
31182
|
|
|
|
|
|
|
{ \ |
31183
|
|
|
|
|
|
|
type v; \ |
31184
|
|
|
|
|
|
|
\ |
31185
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
31186
|
|
|
|
|
|
|
return v; \ |
31187
|
|
|
|
|
|
|
} \ |
31188
|
|
|
|
|
|
|
\ |
31189
|
|
|
|
|
|
|
static forceinline void \ |
31190
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
31191
|
|
|
|
|
|
|
{ \ |
31192
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
31193
|
|
|
|
|
|
|
} |
31194
|
|
|
|
|
|
|
|
31195
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
31196
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
31197
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
31198
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
31199
|
|
|
|
|
|
|
|
31200
|
|
|
|
|
|
|
#undef MEMCOPY |
31201
|
|
|
|
|
|
|
|
31202
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
31203
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
31204
|
|
|
|
|
|
|
|
31205
|
|
|
|
|
|
|
|
31206
|
|
|
|
|
|
|
|
31207
|
|
|
|
|
|
|
static forceinline u16 |
31208
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
31209
|
|
|
|
|
|
|
{ |
31210
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31211
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
31212
|
|
|
|
|
|
|
else |
31213
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
31214
|
|
|
|
|
|
|
} |
31215
|
|
|
|
|
|
|
|
31216
|
|
|
|
|
|
|
static forceinline u16 |
31217
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
31218
|
|
|
|
|
|
|
{ |
31219
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31220
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
31221
|
|
|
|
|
|
|
else |
31222
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
31223
|
|
|
|
|
|
|
} |
31224
|
|
|
|
|
|
|
|
31225
|
|
|
|
|
|
|
static forceinline u32 |
31226
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
31227
|
|
|
|
|
|
|
{ |
31228
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31229
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
31230
|
|
|
|
|
|
|
else |
31231
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
31232
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
31233
|
|
|
|
|
|
|
} |
31234
|
|
|
|
|
|
|
|
31235
|
|
|
|
|
|
|
static forceinline u32 |
31236
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
31237
|
|
|
|
|
|
|
{ |
31238
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31239
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
31240
|
|
|
|
|
|
|
else |
31241
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
31242
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
31243
|
|
|
|
|
|
|
} |
31244
|
|
|
|
|
|
|
|
31245
|
|
|
|
|
|
|
static forceinline u64 |
31246
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
31247
|
|
|
|
|
|
|
{ |
31248
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31249
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
31250
|
|
|
|
|
|
|
else |
31251
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
31252
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
31253
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
31254
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
31255
|
|
|
|
|
|
|
} |
31256
|
|
|
|
|
|
|
|
31257
|
|
|
|
|
|
|
static forceinline machine_word_t |
31258
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
31259
|
|
|
|
|
|
|
{ |
31260
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
31261
|
|
|
|
|
|
|
if (WORDBITS == 32) |
31262
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
31263
|
|
|
|
|
|
|
else |
31264
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
31265
|
|
|
|
|
|
|
} |
31266
|
|
|
|
|
|
|
|
31267
|
|
|
|
|
|
|
|
31268
|
|
|
|
|
|
|
|
31269
|
|
|
|
|
|
|
static forceinline void |
31270
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
31271
|
|
|
|
|
|
|
{ |
31272
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31273
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
31274
|
|
|
|
|
|
|
} else { |
31275
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
31276
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
31277
|
|
|
|
|
|
|
} |
31278
|
|
|
|
|
|
|
} |
31279
|
|
|
|
|
|
|
|
31280
|
|
|
|
|
|
|
static forceinline void |
31281
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
31282
|
|
|
|
|
|
|
{ |
31283
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31284
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
31285
|
|
|
|
|
|
|
} else { |
31286
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
31287
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
31288
|
|
|
|
|
|
|
} |
31289
|
|
|
|
|
|
|
} |
31290
|
|
|
|
|
|
|
|
31291
|
|
|
|
|
|
|
static forceinline void |
31292
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
31293
|
|
|
|
|
|
|
{ |
31294
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31295
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
31296
|
|
|
|
|
|
|
} else { |
31297
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
31298
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
31299
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
31300
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
31301
|
|
|
|
|
|
|
} |
31302
|
|
|
|
|
|
|
} |
31303
|
|
|
|
|
|
|
|
31304
|
|
|
|
|
|
|
static forceinline void |
31305
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
31306
|
|
|
|
|
|
|
{ |
31307
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31308
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
31309
|
|
|
|
|
|
|
} else { |
31310
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
31311
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
31312
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
31313
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
31314
|
|
|
|
|
|
|
} |
31315
|
|
|
|
|
|
|
} |
31316
|
|
|
|
|
|
|
|
31317
|
|
|
|
|
|
|
static forceinline void |
31318
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
31319
|
|
|
|
|
|
|
{ |
31320
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31321
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
31322
|
|
|
|
|
|
|
} else { |
31323
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
31324
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
31325
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
31326
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
31327
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
31328
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
31329
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
31330
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
31331
|
|
|
|
|
|
|
} |
31332
|
|
|
|
|
|
|
} |
31333
|
|
|
|
|
|
|
|
31334
|
|
|
|
|
|
|
static forceinline void |
31335
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
31336
|
|
|
|
|
|
|
{ |
31337
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
31338
|
|
|
|
|
|
|
if (WORDBITS == 32) |
31339
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
31340
|
|
|
|
|
|
|
else |
31341
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
31342
|
|
|
|
|
|
|
} |
31343
|
|
|
|
|
|
|
|
31344
|
|
|
|
|
|
|
|
31345
|
|
|
|
|
|
|
|
31346
|
|
|
|
|
|
|
|
31347
|
|
|
|
|
|
|
|
31348
|
|
|
|
|
|
|
|
31349
|
|
|
|
|
|
|
|
31350
|
|
|
|
|
|
|
static forceinline unsigned |
31351
|
|
|
|
|
|
|
bsr32(u32 v) |
31352
|
|
|
|
|
|
|
{ |
31353
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
31354
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
31355
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31356
|
|
|
|
|
|
|
unsigned long i; |
31357
|
|
|
|
|
|
|
|
31358
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
31359
|
|
|
|
|
|
|
return i; |
31360
|
|
|
|
|
|
|
#else |
31361
|
|
|
|
|
|
|
unsigned i = 0; |
31362
|
|
|
|
|
|
|
|
31363
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
31364
|
|
|
|
|
|
|
i++; |
31365
|
|
|
|
|
|
|
return i; |
31366
|
|
|
|
|
|
|
#endif |
31367
|
|
|
|
|
|
|
} |
31368
|
|
|
|
|
|
|
|
31369
|
|
|
|
|
|
|
static forceinline unsigned |
31370
|
|
|
|
|
|
|
bsr64(u64 v) |
31371
|
|
|
|
|
|
|
{ |
31372
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
31373
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
31374
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
31375
|
|
|
|
|
|
|
unsigned long i; |
31376
|
|
|
|
|
|
|
|
31377
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
31378
|
|
|
|
|
|
|
return i; |
31379
|
|
|
|
|
|
|
#else |
31380
|
|
|
|
|
|
|
unsigned i = 0; |
31381
|
|
|
|
|
|
|
|
31382
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
31383
|
|
|
|
|
|
|
i++; |
31384
|
|
|
|
|
|
|
return i; |
31385
|
|
|
|
|
|
|
#endif |
31386
|
|
|
|
|
|
|
} |
31387
|
|
|
|
|
|
|
|
31388
|
|
|
|
|
|
|
static forceinline unsigned |
31389
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
31390
|
|
|
|
|
|
|
{ |
31391
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
31392
|
|
|
|
|
|
|
if (WORDBITS == 32) |
31393
|
|
|
|
|
|
|
return bsr32(v); |
31394
|
|
|
|
|
|
|
else |
31395
|
|
|
|
|
|
|
return bsr64(v); |
31396
|
|
|
|
|
|
|
} |
31397
|
|
|
|
|
|
|
|
31398
|
|
|
|
|
|
|
|
31399
|
|
|
|
|
|
|
|
31400
|
|
|
|
|
|
|
static forceinline unsigned |
31401
|
|
|
|
|
|
|
bsf32(u32 v) |
31402
|
|
|
|
|
|
|
{ |
31403
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
31404
|
|
|
|
|
|
|
return __builtin_ctz(v); |
31405
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31406
|
|
|
|
|
|
|
unsigned long i; |
31407
|
|
|
|
|
|
|
|
31408
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
31409
|
|
|
|
|
|
|
return i; |
31410
|
|
|
|
|
|
|
#else |
31411
|
|
|
|
|
|
|
unsigned i = 0; |
31412
|
|
|
|
|
|
|
|
31413
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
31414
|
|
|
|
|
|
|
i++; |
31415
|
|
|
|
|
|
|
return i; |
31416
|
|
|
|
|
|
|
#endif |
31417
|
|
|
|
|
|
|
} |
31418
|
|
|
|
|
|
|
|
31419
|
|
|
|
|
|
|
static forceinline unsigned |
31420
|
|
|
|
|
|
|
bsf64(u64 v) |
31421
|
|
|
|
|
|
|
{ |
31422
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
31423
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
31424
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
31425
|
|
|
|
|
|
|
unsigned long i; |
31426
|
|
|
|
|
|
|
|
31427
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
31428
|
|
|
|
|
|
|
return i; |
31429
|
|
|
|
|
|
|
#else |
31430
|
|
|
|
|
|
|
unsigned i = 0; |
31431
|
|
|
|
|
|
|
|
31432
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
31433
|
|
|
|
|
|
|
i++; |
31434
|
|
|
|
|
|
|
return i; |
31435
|
|
|
|
|
|
|
#endif |
31436
|
|
|
|
|
|
|
} |
31437
|
|
|
|
|
|
|
|
31438
|
|
|
|
|
|
|
static forceinline unsigned |
31439
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
31440
|
|
|
|
|
|
|
{ |
31441
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
31442
|
|
|
|
|
|
|
if (WORDBITS == 32) |
31443
|
|
|
|
|
|
|
return bsf32(v); |
31444
|
|
|
|
|
|
|
else |
31445
|
|
|
|
|
|
|
return bsf64(v); |
31446
|
|
|
|
|
|
|
} |
31447
|
|
|
|
|
|
|
|
31448
|
|
|
|
|
|
|
|
31449
|
|
|
|
|
|
|
#undef rbit32 |
31450
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
31451
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
31452
|
|
|
|
|
|
|
static forceinline u32 |
31453
|
|
|
|
|
|
|
rbit32(u32 v) |
31454
|
|
|
|
|
|
|
{ |
31455
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
31456
|
|
|
|
|
|
|
return v; |
31457
|
|
|
|
|
|
|
} |
31458
|
|
|
|
|
|
|
#define rbit32 rbit32 |
31459
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
31460
|
|
|
|
|
|
|
static forceinline u32 |
31461
|
|
|
|
|
|
|
rbit32(u32 v) |
31462
|
|
|
|
|
|
|
{ |
31463
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
31464
|
|
|
|
|
|
|
return v; |
31465
|
|
|
|
|
|
|
} |
31466
|
|
|
|
|
|
|
#define rbit32 rbit32 |
31467
|
|
|
|
|
|
|
#endif |
31468
|
|
|
|
|
|
|
|
31469
|
|
|
|
|
|
|
#endif |
31470
|
|
|
|
|
|
|
|
31471
|
|
|
|
|
|
|
|
31472
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
31473
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
31474
|
|
|
|
|
|
|
|
31475
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
31476
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
31477
|
|
|
|
|
|
|
|
31478
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
31479
|
|
|
|
|
|
|
size_t alignment, size_t size); |
31480
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
31481
|
|
|
|
|
|
|
|
31482
|
|
|
|
|
|
|
#ifdef FREESTANDING |
31483
|
|
|
|
|
|
|
|
31484
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
31485
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
31486
|
|
|
|
|
|
|
|
31487
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
31488
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
31489
|
|
|
|
|
|
|
|
31490
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
31491
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
31492
|
|
|
|
|
|
|
|
31493
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
31494
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
31495
|
|
|
|
|
|
|
|
31496
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
31497
|
|
|
|
|
|
|
#else |
31498
|
|
|
|
|
|
|
#include |
31499
|
|
|
|
|
|
|
#endif |
31500
|
|
|
|
|
|
|
|
31501
|
|
|
|
|
|
|
|
31502
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
31503
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
31504
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
31505
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
31506
|
|
|
|
|
|
|
#else |
31507
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
31508
|
|
|
|
|
|
|
#endif |
31509
|
|
|
|
|
|
|
|
31510
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
31511
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
31512
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
31513
|
|
|
|
|
|
|
|
31514
|
|
|
|
|
|
|
#endif |
31515
|
|
|
|
|
|
|
|
31516
|
|
|
|
|
|
|
|
31517
|
|
|
|
|
|
|
|
31518
|
|
|
|
|
|
|
|
31519
|
|
|
|
|
|
|
struct libdeflate_compressor; |
31520
|
|
|
|
|
|
|
|
31521
|
|
|
|
|
|
|
unsigned int libdeflate_get_compression_level(struct libdeflate_compressor *c); |
31522
|
|
|
|
|
|
|
|
31523
|
|
|
|
|
|
|
#endif |
31524
|
|
|
|
|
|
|
|
31525
|
|
|
|
|
|
|
/* #include "zlib_constants.h" */ |
31526
|
|
|
|
|
|
|
|
31527
|
|
|
|
|
|
|
|
31528
|
|
|
|
|
|
|
#ifndef LIB_ZLIB_CONSTANTS_H |
31529
|
|
|
|
|
|
|
#define LIB_ZLIB_CONSTANTS_H |
31530
|
|
|
|
|
|
|
|
31531
|
|
|
|
|
|
|
#define ZLIB_MIN_HEADER_SIZE 2 |
31532
|
|
|
|
|
|
|
#define ZLIB_FOOTER_SIZE 4 |
31533
|
|
|
|
|
|
|
#define ZLIB_MIN_OVERHEAD (ZLIB_MIN_HEADER_SIZE + ZLIB_FOOTER_SIZE) |
31534
|
|
|
|
|
|
|
|
31535
|
|
|
|
|
|
|
#define ZLIB_CM_DEFLATE 8 |
31536
|
|
|
|
|
|
|
|
31537
|
|
|
|
|
|
|
#define ZLIB_CINFO_32K_WINDOW 7 |
31538
|
|
|
|
|
|
|
|
31539
|
|
|
|
|
|
|
#define ZLIB_FASTEST_COMPRESSION 0 |
31540
|
|
|
|
|
|
|
#define ZLIB_FAST_COMPRESSION 1 |
31541
|
|
|
|
|
|
|
#define ZLIB_DEFAULT_COMPRESSION 2 |
31542
|
|
|
|
|
|
|
#define ZLIB_SLOWEST_COMPRESSION 3 |
31543
|
|
|
|
|
|
|
|
31544
|
|
|
|
|
|
|
#endif |
31545
|
|
|
|
|
|
|
|
31546
|
|
|
|
|
|
|
|
31547
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31548
|
12
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *c, |
31549
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31550
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail) |
31551
|
|
|
|
|
|
|
{ |
31552
|
12
|
|
|
|
|
|
u8 *out_next = out; |
31553
|
|
|
|
|
|
|
u16 hdr; |
31554
|
|
|
|
|
|
|
unsigned compression_level; |
31555
|
|
|
|
|
|
|
unsigned level_hint; |
31556
|
|
|
|
|
|
|
size_t deflate_size; |
31557
|
|
|
|
|
|
|
|
31558
|
12
|
50
|
|
|
|
|
if (out_nbytes_avail <= ZLIB_MIN_OVERHEAD) |
31559
|
0
|
|
|
|
|
|
return 0; |
31560
|
|
|
|
|
|
|
|
31561
|
|
|
|
|
|
|
|
31562
|
12
|
|
|
|
|
|
hdr = (ZLIB_CM_DEFLATE << 8) | (ZLIB_CINFO_32K_WINDOW << 12); |
31563
|
12
|
|
|
|
|
|
compression_level = libdeflate_get_compression_level(c); |
31564
|
12
|
100
|
|
|
|
|
if (compression_level < 2) |
31565
|
1
|
|
|
|
|
|
level_hint = ZLIB_FASTEST_COMPRESSION; |
31566
|
11
|
100
|
|
|
|
|
else if (compression_level < 6) |
31567
|
4
|
|
|
|
|
|
level_hint = ZLIB_FAST_COMPRESSION; |
31568
|
7
|
100
|
|
|
|
|
else if (compression_level < 8) |
31569
|
2
|
|
|
|
|
|
level_hint = ZLIB_DEFAULT_COMPRESSION; |
31570
|
|
|
|
|
|
|
else |
31571
|
5
|
|
|
|
|
|
level_hint = ZLIB_SLOWEST_COMPRESSION; |
31572
|
12
|
|
|
|
|
|
hdr |= level_hint << 6; |
31573
|
12
|
|
|
|
|
|
hdr |= 31 - (hdr % 31); |
31574
|
|
|
|
|
|
|
|
31575
|
12
|
|
|
|
|
|
put_unaligned_be16(hdr, out_next); |
31576
|
12
|
|
|
|
|
|
out_next += 2; |
31577
|
|
|
|
|
|
|
|
31578
|
|
|
|
|
|
|
|
31579
|
12
|
|
|
|
|
|
deflate_size = libdeflate_deflate_compress(c, in, in_nbytes, out_next, |
31580
|
|
|
|
|
|
|
out_nbytes_avail - ZLIB_MIN_OVERHEAD); |
31581
|
12
|
50
|
|
|
|
|
if (deflate_size == 0) |
31582
|
0
|
|
|
|
|
|
return 0; |
31583
|
12
|
|
|
|
|
|
out_next += deflate_size; |
31584
|
|
|
|
|
|
|
|
31585
|
|
|
|
|
|
|
|
31586
|
12
|
|
|
|
|
|
put_unaligned_be32(libdeflate_adler32(1, in, in_nbytes), out_next); |
31587
|
12
|
|
|
|
|
|
out_next += 4; |
31588
|
|
|
|
|
|
|
|
31589
|
12
|
|
|
|
|
|
return out_next - (u8 *)out; |
31590
|
|
|
|
|
|
|
} |
31591
|
|
|
|
|
|
|
|
31592
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31593
|
12
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *c, |
31594
|
|
|
|
|
|
|
size_t in_nbytes) |
31595
|
|
|
|
|
|
|
{ |
31596
|
12
|
|
|
|
|
|
return ZLIB_MIN_OVERHEAD + |
31597
|
12
|
|
|
|
|
|
libdeflate_deflate_compress_bound(c, in_nbytes); |
31598
|
|
|
|
|
|
|
} |
31599
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/zlib_decompress.c */ |
31600
|
|
|
|
|
|
|
|
31601
|
|
|
|
|
|
|
|
31602
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
31603
|
|
|
|
|
|
|
|
31604
|
|
|
|
|
|
|
|
31605
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
31606
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
31607
|
|
|
|
|
|
|
|
31608
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
31609
|
|
|
|
|
|
|
|
31610
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
31611
|
|
|
|
|
|
|
#endif |
31612
|
|
|
|
|
|
|
|
31613
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
31614
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
31615
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
31616
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
31617
|
|
|
|
|
|
|
#else |
31618
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
31619
|
|
|
|
|
|
|
#endif |
31620
|
|
|
|
|
|
|
|
31621
|
|
|
|
|
|
|
|
31622
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
31623
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
31624
|
|
|
|
|
|
|
#else |
31625
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
31626
|
|
|
|
|
|
|
#endif |
31627
|
|
|
|
|
|
|
|
31628
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
31629
|
|
|
|
|
|
|
|
31630
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
31631
|
|
|
|
|
|
|
|
31632
|
|
|
|
|
|
|
|
31633
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
31634
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
31635
|
|
|
|
|
|
|
|
31636
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
31637
|
|
|
|
|
|
|
|
31638
|
|
|
|
|
|
|
|
31639
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
31640
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
31641
|
|
|
|
|
|
|
|
31642
|
|
|
|
|
|
|
#include |
31643
|
|
|
|
|
|
|
#include |
31644
|
|
|
|
|
|
|
|
31645
|
|
|
|
|
|
|
#ifdef __cplusplus |
31646
|
|
|
|
|
|
|
extern "C" { |
31647
|
|
|
|
|
|
|
#endif |
31648
|
|
|
|
|
|
|
|
31649
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
31650
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
31651
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
31652
|
|
|
|
|
|
|
|
31653
|
|
|
|
|
|
|
|
31654
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
31655
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
31656
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
31657
|
|
|
|
|
|
|
# else |
31658
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
31659
|
|
|
|
|
|
|
# endif |
31660
|
|
|
|
|
|
|
#endif |
31661
|
|
|
|
|
|
|
|
31662
|
|
|
|
|
|
|
|
31663
|
|
|
|
|
|
|
|
31664
|
|
|
|
|
|
|
|
31665
|
|
|
|
|
|
|
|
31666
|
|
|
|
|
|
|
struct libdeflate_compressor; |
31667
|
|
|
|
|
|
|
struct libdeflate_options; |
31668
|
|
|
|
|
|
|
|
31669
|
|
|
|
|
|
|
|
31670
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
31671
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
31672
|
|
|
|
|
|
|
|
31673
|
|
|
|
|
|
|
|
31674
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
31675
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
31676
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
31677
|
|
|
|
|
|
|
|
31678
|
|
|
|
|
|
|
|
31679
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31680
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
31681
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31682
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
31683
|
|
|
|
|
|
|
|
31684
|
|
|
|
|
|
|
|
31685
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31686
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
31687
|
|
|
|
|
|
|
size_t in_nbytes); |
31688
|
|
|
|
|
|
|
|
31689
|
|
|
|
|
|
|
|
31690
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31691
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
31692
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31693
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
31694
|
|
|
|
|
|
|
|
31695
|
|
|
|
|
|
|
|
31696
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31697
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
31698
|
|
|
|
|
|
|
size_t in_nbytes); |
31699
|
|
|
|
|
|
|
|
31700
|
|
|
|
|
|
|
|
31701
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31702
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
31703
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31704
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
31705
|
|
|
|
|
|
|
|
31706
|
|
|
|
|
|
|
|
31707
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31708
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
31709
|
|
|
|
|
|
|
size_t in_nbytes); |
31710
|
|
|
|
|
|
|
|
31711
|
|
|
|
|
|
|
|
31712
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
31713
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
31714
|
|
|
|
|
|
|
|
31715
|
|
|
|
|
|
|
|
31716
|
|
|
|
|
|
|
|
31717
|
|
|
|
|
|
|
|
31718
|
|
|
|
|
|
|
|
31719
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
31720
|
|
|
|
|
|
|
struct libdeflate_options; |
31721
|
|
|
|
|
|
|
|
31722
|
|
|
|
|
|
|
|
31723
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
31724
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
31725
|
|
|
|
|
|
|
|
31726
|
|
|
|
|
|
|
|
31727
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
31728
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
31729
|
|
|
|
|
|
|
|
31730
|
|
|
|
|
|
|
|
31731
|
|
|
|
|
|
|
enum libdeflate_result { |
31732
|
|
|
|
|
|
|
|
31733
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
31734
|
|
|
|
|
|
|
|
31735
|
|
|
|
|
|
|
|
31736
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
31737
|
|
|
|
|
|
|
|
31738
|
|
|
|
|
|
|
|
31739
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
31740
|
|
|
|
|
|
|
|
31741
|
|
|
|
|
|
|
|
31742
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
31743
|
|
|
|
|
|
|
}; |
31744
|
|
|
|
|
|
|
|
31745
|
|
|
|
|
|
|
|
31746
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31747
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
31748
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31749
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31750
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31751
|
|
|
|
|
|
|
|
31752
|
|
|
|
|
|
|
|
31753
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31754
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
31755
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31756
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31757
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
31758
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31759
|
|
|
|
|
|
|
|
31760
|
|
|
|
|
|
|
|
31761
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31762
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
31763
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31764
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31765
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31766
|
|
|
|
|
|
|
|
31767
|
|
|
|
|
|
|
|
31768
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31769
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
31770
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31771
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31772
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
31773
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31774
|
|
|
|
|
|
|
|
31775
|
|
|
|
|
|
|
|
31776
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31777
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
31778
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31779
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31780
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31781
|
|
|
|
|
|
|
|
31782
|
|
|
|
|
|
|
|
31783
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31784
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
31785
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31786
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31787
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
31788
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31789
|
|
|
|
|
|
|
|
31790
|
|
|
|
|
|
|
|
31791
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
31792
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
31793
|
|
|
|
|
|
|
|
31794
|
|
|
|
|
|
|
|
31795
|
|
|
|
|
|
|
|
31796
|
|
|
|
|
|
|
|
31797
|
|
|
|
|
|
|
|
31798
|
|
|
|
|
|
|
|
31799
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
31800
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
31801
|
|
|
|
|
|
|
|
31802
|
|
|
|
|
|
|
|
31803
|
|
|
|
|
|
|
|
31804
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
31805
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
31806
|
|
|
|
|
|
|
|
31807
|
|
|
|
|
|
|
|
31808
|
|
|
|
|
|
|
|
31809
|
|
|
|
|
|
|
|
31810
|
|
|
|
|
|
|
|
31811
|
|
|
|
|
|
|
|
31812
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
31813
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
31814
|
|
|
|
|
|
|
void (*free_func)(void *)); |
31815
|
|
|
|
|
|
|
|
31816
|
|
|
|
|
|
|
|
31817
|
|
|
|
|
|
|
struct libdeflate_options { |
31818
|
|
|
|
|
|
|
|
31819
|
|
|
|
|
|
|
|
31820
|
|
|
|
|
|
|
size_t sizeof_options; |
31821
|
|
|
|
|
|
|
|
31822
|
|
|
|
|
|
|
|
31823
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
31824
|
|
|
|
|
|
|
void (*free_func)(void *); |
31825
|
|
|
|
|
|
|
}; |
31826
|
|
|
|
|
|
|
|
31827
|
|
|
|
|
|
|
#ifdef __cplusplus |
31828
|
|
|
|
|
|
|
} |
31829
|
|
|
|
|
|
|
#endif |
31830
|
|
|
|
|
|
|
|
31831
|
|
|
|
|
|
|
#endif |
31832
|
|
|
|
|
|
|
|
31833
|
|
|
|
|
|
|
|
31834
|
|
|
|
|
|
|
#include |
31835
|
|
|
|
|
|
|
#include |
31836
|
|
|
|
|
|
|
#include |
31837
|
|
|
|
|
|
|
#ifdef _MSC_VER |
31838
|
|
|
|
|
|
|
# include |
31839
|
|
|
|
|
|
|
# include |
31840
|
|
|
|
|
|
|
|
31841
|
|
|
|
|
|
|
|
31842
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
31843
|
|
|
|
|
|
|
|
31844
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
31845
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
31846
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
31847
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
31848
|
|
|
|
|
|
|
|
31849
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
31850
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
31851
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
31852
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
31853
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
31854
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
31855
|
|
|
|
|
|
|
#endif |
31856
|
|
|
|
|
|
|
#ifndef FREESTANDING |
31857
|
|
|
|
|
|
|
# include |
31858
|
|
|
|
|
|
|
#endif |
31859
|
|
|
|
|
|
|
|
31860
|
|
|
|
|
|
|
|
31861
|
|
|
|
|
|
|
|
31862
|
|
|
|
|
|
|
|
31863
|
|
|
|
|
|
|
|
31864
|
|
|
|
|
|
|
|
31865
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
31866
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
31867
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
31868
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
31869
|
|
|
|
|
|
|
#ifdef _MSC_VER |
31870
|
|
|
|
|
|
|
# if defined(_M_X64) |
31871
|
|
|
|
|
|
|
# define ARCH_X86_64 |
31872
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
31873
|
|
|
|
|
|
|
# define ARCH_X86_32 |
31874
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
31875
|
|
|
|
|
|
|
# define ARCH_ARM64 |
31876
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
31877
|
|
|
|
|
|
|
# define ARCH_ARM32 |
31878
|
|
|
|
|
|
|
# endif |
31879
|
|
|
|
|
|
|
#else |
31880
|
|
|
|
|
|
|
# if defined(__x86_64__) |
31881
|
|
|
|
|
|
|
# define ARCH_X86_64 |
31882
|
|
|
|
|
|
|
# elif defined(__i386__) |
31883
|
|
|
|
|
|
|
# define ARCH_X86_32 |
31884
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
31885
|
|
|
|
|
|
|
# define ARCH_ARM64 |
31886
|
|
|
|
|
|
|
# elif defined(__arm__) |
31887
|
|
|
|
|
|
|
# define ARCH_ARM32 |
31888
|
|
|
|
|
|
|
# endif |
31889
|
|
|
|
|
|
|
#endif |
31890
|
|
|
|
|
|
|
|
31891
|
|
|
|
|
|
|
|
31892
|
|
|
|
|
|
|
|
31893
|
|
|
|
|
|
|
|
31894
|
|
|
|
|
|
|
|
31895
|
|
|
|
|
|
|
|
31896
|
|
|
|
|
|
|
typedef uint8_t u8; |
31897
|
|
|
|
|
|
|
typedef uint16_t u16; |
31898
|
|
|
|
|
|
|
typedef uint32_t u32; |
31899
|
|
|
|
|
|
|
typedef uint64_t u64; |
31900
|
|
|
|
|
|
|
typedef int8_t s8; |
31901
|
|
|
|
|
|
|
typedef int16_t s16; |
31902
|
|
|
|
|
|
|
typedef int32_t s32; |
31903
|
|
|
|
|
|
|
typedef int64_t s64; |
31904
|
|
|
|
|
|
|
|
31905
|
|
|
|
|
|
|
|
31906
|
|
|
|
|
|
|
#ifdef _MSC_VER |
31907
|
|
|
|
|
|
|
# ifdef _WIN64 |
31908
|
|
|
|
|
|
|
typedef long long ssize_t; |
31909
|
|
|
|
|
|
|
# else |
31910
|
|
|
|
|
|
|
typedef long ssize_t; |
31911
|
|
|
|
|
|
|
# endif |
31912
|
|
|
|
|
|
|
#endif |
31913
|
|
|
|
|
|
|
|
31914
|
|
|
|
|
|
|
|
31915
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
31916
|
|
|
|
|
|
|
|
31917
|
|
|
|
|
|
|
|
31918
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
31919
|
|
|
|
|
|
|
|
31920
|
|
|
|
|
|
|
|
31921
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
31922
|
|
|
|
|
|
|
|
31923
|
|
|
|
|
|
|
|
31924
|
|
|
|
|
|
|
|
31925
|
|
|
|
|
|
|
|
31926
|
|
|
|
|
|
|
|
31927
|
|
|
|
|
|
|
|
31928
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
31929
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
31930
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
31931
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
31932
|
|
|
|
|
|
|
#else |
31933
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
31934
|
|
|
|
|
|
|
#endif |
31935
|
|
|
|
|
|
|
#ifdef __clang__ |
31936
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
31937
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
31938
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
31939
|
|
|
|
|
|
|
# else |
31940
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
31941
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
31942
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
31943
|
|
|
|
|
|
|
# endif |
31944
|
|
|
|
|
|
|
#else |
31945
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
31946
|
|
|
|
|
|
|
#endif |
31947
|
|
|
|
|
|
|
|
31948
|
|
|
|
|
|
|
|
31949
|
|
|
|
|
|
|
#ifndef __has_attribute |
31950
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
31951
|
|
|
|
|
|
|
#endif |
31952
|
|
|
|
|
|
|
#ifndef __has_builtin |
31953
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
31954
|
|
|
|
|
|
|
#endif |
31955
|
|
|
|
|
|
|
|
31956
|
|
|
|
|
|
|
|
31957
|
|
|
|
|
|
|
#ifdef _MSC_VER |
31958
|
|
|
|
|
|
|
# define inline __inline |
31959
|
|
|
|
|
|
|
#endif |
31960
|
|
|
|
|
|
|
|
31961
|
|
|
|
|
|
|
|
31962
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
31963
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
31964
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31965
|
|
|
|
|
|
|
# define forceinline __forceinline |
31966
|
|
|
|
|
|
|
#else |
31967
|
|
|
|
|
|
|
# define forceinline inline |
31968
|
|
|
|
|
|
|
#endif |
31969
|
|
|
|
|
|
|
|
31970
|
|
|
|
|
|
|
|
31971
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
31972
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
31973
|
|
|
|
|
|
|
#else |
31974
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
31975
|
|
|
|
|
|
|
#endif |
31976
|
|
|
|
|
|
|
|
31977
|
|
|
|
|
|
|
|
31978
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
31979
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
31980
|
|
|
|
|
|
|
# define restrict __restrict__ |
31981
|
|
|
|
|
|
|
# else |
31982
|
|
|
|
|
|
|
# define restrict |
31983
|
|
|
|
|
|
|
# endif |
31984
|
|
|
|
|
|
|
#endif |
31985
|
|
|
|
|
|
|
|
31986
|
|
|
|
|
|
|
|
31987
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
31988
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
31989
|
|
|
|
|
|
|
#else |
31990
|
|
|
|
|
|
|
# define likely(expr) (expr) |
31991
|
|
|
|
|
|
|
#endif |
31992
|
|
|
|
|
|
|
|
31993
|
|
|
|
|
|
|
|
31994
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
31995
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
31996
|
|
|
|
|
|
|
#else |
31997
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
31998
|
|
|
|
|
|
|
#endif |
31999
|
|
|
|
|
|
|
|
32000
|
|
|
|
|
|
|
|
32001
|
|
|
|
|
|
|
#undef prefetchr |
32002
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
32003
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
32004
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32005
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
32006
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
32007
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
32008
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
32009
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
32010
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
32011
|
|
|
|
|
|
|
# endif |
32012
|
|
|
|
|
|
|
#endif |
32013
|
|
|
|
|
|
|
#ifndef prefetchr |
32014
|
|
|
|
|
|
|
# define prefetchr(addr) |
32015
|
|
|
|
|
|
|
#endif |
32016
|
|
|
|
|
|
|
|
32017
|
|
|
|
|
|
|
|
32018
|
|
|
|
|
|
|
#undef prefetchw |
32019
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
32020
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
32021
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32022
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
32023
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
32024
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
32025
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
32026
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
32027
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
32028
|
|
|
|
|
|
|
# endif |
32029
|
|
|
|
|
|
|
#endif |
32030
|
|
|
|
|
|
|
#ifndef prefetchw |
32031
|
|
|
|
|
|
|
# define prefetchw(addr) |
32032
|
|
|
|
|
|
|
#endif |
32033
|
|
|
|
|
|
|
|
32034
|
|
|
|
|
|
|
|
32035
|
|
|
|
|
|
|
#undef _aligned_attribute |
32036
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
32037
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
32038
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32039
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
32040
|
|
|
|
|
|
|
#endif |
32041
|
|
|
|
|
|
|
|
32042
|
|
|
|
|
|
|
|
32043
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
32044
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
32045
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
32046
|
|
|
|
|
|
|
#else |
32047
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
32048
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
32049
|
|
|
|
|
|
|
#endif |
32050
|
|
|
|
|
|
|
|
32051
|
|
|
|
|
|
|
|
32052
|
|
|
|
|
|
|
|
32053
|
|
|
|
|
|
|
|
32054
|
|
|
|
|
|
|
|
32055
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
32056
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
32057
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
32058
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
32059
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
32060
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
32061
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
32062
|
|
|
|
|
|
|
|
32063
|
|
|
|
|
|
|
|
32064
|
|
|
|
|
|
|
|
32065
|
|
|
|
|
|
|
|
32066
|
|
|
|
|
|
|
|
32067
|
|
|
|
|
|
|
|
32068
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
32069
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
32070
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32071
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
32072
|
|
|
|
|
|
|
#else |
32073
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
32074
|
|
|
|
|
|
|
{ |
32075
|
|
|
|
|
|
|
union { |
32076
|
|
|
|
|
|
|
u32 w; |
32077
|
|
|
|
|
|
|
u8 b; |
32078
|
|
|
|
|
|
|
} u; |
32079
|
|
|
|
|
|
|
|
32080
|
|
|
|
|
|
|
u.w = 1; |
32081
|
|
|
|
|
|
|
return u.b; |
32082
|
|
|
|
|
|
|
} |
32083
|
|
|
|
|
|
|
#endif |
32084
|
|
|
|
|
|
|
|
32085
|
|
|
|
|
|
|
|
32086
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
32087
|
|
|
|
|
|
|
{ |
32088
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
32089
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
32090
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32091
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
32092
|
|
|
|
|
|
|
#else |
32093
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
32094
|
|
|
|
|
|
|
#endif |
32095
|
|
|
|
|
|
|
} |
32096
|
|
|
|
|
|
|
|
32097
|
|
|
|
|
|
|
|
32098
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
32099
|
|
|
|
|
|
|
{ |
32100
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
32101
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
32102
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32103
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
32104
|
|
|
|
|
|
|
#else |
32105
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
32106
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
32107
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
32108
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
32109
|
|
|
|
|
|
|
#endif |
32110
|
|
|
|
|
|
|
} |
32111
|
|
|
|
|
|
|
|
32112
|
|
|
|
|
|
|
|
32113
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
32114
|
|
|
|
|
|
|
{ |
32115
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
32116
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
32117
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32118
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
32119
|
|
|
|
|
|
|
#else |
32120
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
32121
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
32122
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
32123
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
32124
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
32125
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
32126
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
32127
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
32128
|
|
|
|
|
|
|
#endif |
32129
|
|
|
|
|
|
|
} |
32130
|
|
|
|
|
|
|
|
32131
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
32132
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
32133
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
32134
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
32135
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
32136
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
32137
|
|
|
|
|
|
|
|
32138
|
|
|
|
|
|
|
|
32139
|
|
|
|
|
|
|
|
32140
|
|
|
|
|
|
|
|
32141
|
|
|
|
|
|
|
|
32142
|
|
|
|
|
|
|
|
32143
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
32144
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
32145
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
32146
|
|
|
|
|
|
|
defined(__wasm__)) |
32147
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
32148
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32149
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
32150
|
|
|
|
|
|
|
#else |
32151
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
32152
|
|
|
|
|
|
|
#endif |
32153
|
|
|
|
|
|
|
|
32154
|
|
|
|
|
|
|
|
32155
|
|
|
|
|
|
|
|
32156
|
|
|
|
|
|
|
#ifdef FREESTANDING |
32157
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
32158
|
|
|
|
|
|
|
#else |
32159
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
32160
|
|
|
|
|
|
|
#endif |
32161
|
|
|
|
|
|
|
|
32162
|
|
|
|
|
|
|
|
32163
|
|
|
|
|
|
|
|
32164
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
32165
|
|
|
|
|
|
|
static forceinline type \ |
32166
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
32167
|
|
|
|
|
|
|
{ \ |
32168
|
|
|
|
|
|
|
type v; \ |
32169
|
|
|
|
|
|
|
\ |
32170
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
32171
|
|
|
|
|
|
|
return v; \ |
32172
|
|
|
|
|
|
|
} \ |
32173
|
|
|
|
|
|
|
\ |
32174
|
|
|
|
|
|
|
static forceinline void \ |
32175
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
32176
|
|
|
|
|
|
|
{ \ |
32177
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
32178
|
|
|
|
|
|
|
} |
32179
|
|
|
|
|
|
|
|
32180
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
32181
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
32182
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
32183
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
32184
|
|
|
|
|
|
|
|
32185
|
|
|
|
|
|
|
#undef MEMCOPY |
32186
|
|
|
|
|
|
|
|
32187
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
32188
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
32189
|
|
|
|
|
|
|
|
32190
|
|
|
|
|
|
|
|
32191
|
|
|
|
|
|
|
|
32192
|
|
|
|
|
|
|
static forceinline u16 |
32193
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
32194
|
|
|
|
|
|
|
{ |
32195
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32196
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
32197
|
|
|
|
|
|
|
else |
32198
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
32199
|
|
|
|
|
|
|
} |
32200
|
|
|
|
|
|
|
|
32201
|
|
|
|
|
|
|
static forceinline u16 |
32202
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
32203
|
|
|
|
|
|
|
{ |
32204
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32205
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
32206
|
|
|
|
|
|
|
else |
32207
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
32208
|
|
|
|
|
|
|
} |
32209
|
|
|
|
|
|
|
|
32210
|
|
|
|
|
|
|
static forceinline u32 |
32211
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
32212
|
|
|
|
|
|
|
{ |
32213
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32214
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
32215
|
|
|
|
|
|
|
else |
32216
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
32217
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
32218
|
|
|
|
|
|
|
} |
32219
|
|
|
|
|
|
|
|
32220
|
|
|
|
|
|
|
static forceinline u32 |
32221
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
32222
|
|
|
|
|
|
|
{ |
32223
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32224
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
32225
|
|
|
|
|
|
|
else |
32226
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
32227
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
32228
|
|
|
|
|
|
|
} |
32229
|
|
|
|
|
|
|
|
32230
|
|
|
|
|
|
|
static forceinline u64 |
32231
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
32232
|
|
|
|
|
|
|
{ |
32233
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32234
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
32235
|
|
|
|
|
|
|
else |
32236
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
32237
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
32238
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
32239
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
32240
|
|
|
|
|
|
|
} |
32241
|
|
|
|
|
|
|
|
32242
|
|
|
|
|
|
|
static forceinline machine_word_t |
32243
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
32244
|
|
|
|
|
|
|
{ |
32245
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
32246
|
|
|
|
|
|
|
if (WORDBITS == 32) |
32247
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
32248
|
|
|
|
|
|
|
else |
32249
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
32250
|
|
|
|
|
|
|
} |
32251
|
|
|
|
|
|
|
|
32252
|
|
|
|
|
|
|
|
32253
|
|
|
|
|
|
|
|
32254
|
|
|
|
|
|
|
static forceinline void |
32255
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
32256
|
|
|
|
|
|
|
{ |
32257
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32258
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
32259
|
|
|
|
|
|
|
} else { |
32260
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
32261
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
32262
|
|
|
|
|
|
|
} |
32263
|
|
|
|
|
|
|
} |
32264
|
|
|
|
|
|
|
|
32265
|
|
|
|
|
|
|
static forceinline void |
32266
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
32267
|
|
|
|
|
|
|
{ |
32268
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32269
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
32270
|
|
|
|
|
|
|
} else { |
32271
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
32272
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
32273
|
|
|
|
|
|
|
} |
32274
|
|
|
|
|
|
|
} |
32275
|
|
|
|
|
|
|
|
32276
|
|
|
|
|
|
|
static forceinline void |
32277
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
32278
|
|
|
|
|
|
|
{ |
32279
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32280
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
32281
|
|
|
|
|
|
|
} else { |
32282
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
32283
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
32284
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
32285
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
32286
|
|
|
|
|
|
|
} |
32287
|
|
|
|
|
|
|
} |
32288
|
|
|
|
|
|
|
|
32289
|
|
|
|
|
|
|
static forceinline void |
32290
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
32291
|
|
|
|
|
|
|
{ |
32292
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32293
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
32294
|
|
|
|
|
|
|
} else { |
32295
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
32296
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
32297
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
32298
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
32299
|
|
|
|
|
|
|
} |
32300
|
|
|
|
|
|
|
} |
32301
|
|
|
|
|
|
|
|
32302
|
|
|
|
|
|
|
static forceinline void |
32303
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
32304
|
|
|
|
|
|
|
{ |
32305
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32306
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
32307
|
|
|
|
|
|
|
} else { |
32308
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
32309
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
32310
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
32311
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
32312
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
32313
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
32314
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
32315
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
32316
|
|
|
|
|
|
|
} |
32317
|
|
|
|
|
|
|
} |
32318
|
|
|
|
|
|
|
|
32319
|
|
|
|
|
|
|
static forceinline void |
32320
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
32321
|
|
|
|
|
|
|
{ |
32322
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
32323
|
|
|
|
|
|
|
if (WORDBITS == 32) |
32324
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
32325
|
|
|
|
|
|
|
else |
32326
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
32327
|
|
|
|
|
|
|
} |
32328
|
|
|
|
|
|
|
|
32329
|
|
|
|
|
|
|
|
32330
|
|
|
|
|
|
|
|
32331
|
|
|
|
|
|
|
|
32332
|
|
|
|
|
|
|
|
32333
|
|
|
|
|
|
|
|
32334
|
|
|
|
|
|
|
|
32335
|
|
|
|
|
|
|
static forceinline unsigned |
32336
|
|
|
|
|
|
|
bsr32(u32 v) |
32337
|
|
|
|
|
|
|
{ |
32338
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
32339
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
32340
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32341
|
|
|
|
|
|
|
unsigned long i; |
32342
|
|
|
|
|
|
|
|
32343
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
32344
|
|
|
|
|
|
|
return i; |
32345
|
|
|
|
|
|
|
#else |
32346
|
|
|
|
|
|
|
unsigned i = 0; |
32347
|
|
|
|
|
|
|
|
32348
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
32349
|
|
|
|
|
|
|
i++; |
32350
|
|
|
|
|
|
|
return i; |
32351
|
|
|
|
|
|
|
#endif |
32352
|
|
|
|
|
|
|
} |
32353
|
|
|
|
|
|
|
|
32354
|
|
|
|
|
|
|
static forceinline unsigned |
32355
|
|
|
|
|
|
|
bsr64(u64 v) |
32356
|
|
|
|
|
|
|
{ |
32357
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
32358
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
32359
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
32360
|
|
|
|
|
|
|
unsigned long i; |
32361
|
|
|
|
|
|
|
|
32362
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
32363
|
|
|
|
|
|
|
return i; |
32364
|
|
|
|
|
|
|
#else |
32365
|
|
|
|
|
|
|
unsigned i = 0; |
32366
|
|
|
|
|
|
|
|
32367
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
32368
|
|
|
|
|
|
|
i++; |
32369
|
|
|
|
|
|
|
return i; |
32370
|
|
|
|
|
|
|
#endif |
32371
|
|
|
|
|
|
|
} |
32372
|
|
|
|
|
|
|
|
32373
|
|
|
|
|
|
|
static forceinline unsigned |
32374
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
32375
|
|
|
|
|
|
|
{ |
32376
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
32377
|
|
|
|
|
|
|
if (WORDBITS == 32) |
32378
|
|
|
|
|
|
|
return bsr32(v); |
32379
|
|
|
|
|
|
|
else |
32380
|
|
|
|
|
|
|
return bsr64(v); |
32381
|
|
|
|
|
|
|
} |
32382
|
|
|
|
|
|
|
|
32383
|
|
|
|
|
|
|
|
32384
|
|
|
|
|
|
|
|
32385
|
|
|
|
|
|
|
static forceinline unsigned |
32386
|
|
|
|
|
|
|
bsf32(u32 v) |
32387
|
|
|
|
|
|
|
{ |
32388
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
32389
|
|
|
|
|
|
|
return __builtin_ctz(v); |
32390
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32391
|
|
|
|
|
|
|
unsigned long i; |
32392
|
|
|
|
|
|
|
|
32393
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
32394
|
|
|
|
|
|
|
return i; |
32395
|
|
|
|
|
|
|
#else |
32396
|
|
|
|
|
|
|
unsigned i = 0; |
32397
|
|
|
|
|
|
|
|
32398
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
32399
|
|
|
|
|
|
|
i++; |
32400
|
|
|
|
|
|
|
return i; |
32401
|
|
|
|
|
|
|
#endif |
32402
|
|
|
|
|
|
|
} |
32403
|
|
|
|
|
|
|
|
32404
|
|
|
|
|
|
|
static forceinline unsigned |
32405
|
|
|
|
|
|
|
bsf64(u64 v) |
32406
|
|
|
|
|
|
|
{ |
32407
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
32408
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
32409
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
32410
|
|
|
|
|
|
|
unsigned long i; |
32411
|
|
|
|
|
|
|
|
32412
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
32413
|
|
|
|
|
|
|
return i; |
32414
|
|
|
|
|
|
|
#else |
32415
|
|
|
|
|
|
|
unsigned i = 0; |
32416
|
|
|
|
|
|
|
|
32417
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
32418
|
|
|
|
|
|
|
i++; |
32419
|
|
|
|
|
|
|
return i; |
32420
|
|
|
|
|
|
|
#endif |
32421
|
|
|
|
|
|
|
} |
32422
|
|
|
|
|
|
|
|
32423
|
|
|
|
|
|
|
static forceinline unsigned |
32424
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
32425
|
|
|
|
|
|
|
{ |
32426
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
32427
|
|
|
|
|
|
|
if (WORDBITS == 32) |
32428
|
|
|
|
|
|
|
return bsf32(v); |
32429
|
|
|
|
|
|
|
else |
32430
|
|
|
|
|
|
|
return bsf64(v); |
32431
|
|
|
|
|
|
|
} |
32432
|
|
|
|
|
|
|
|
32433
|
|
|
|
|
|
|
|
32434
|
|
|
|
|
|
|
#undef rbit32 |
32435
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
32436
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
32437
|
|
|
|
|
|
|
static forceinline u32 |
32438
|
|
|
|
|
|
|
rbit32(u32 v) |
32439
|
|
|
|
|
|
|
{ |
32440
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
32441
|
|
|
|
|
|
|
return v; |
32442
|
|
|
|
|
|
|
} |
32443
|
|
|
|
|
|
|
#define rbit32 rbit32 |
32444
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
32445
|
|
|
|
|
|
|
static forceinline u32 |
32446
|
|
|
|
|
|
|
rbit32(u32 v) |
32447
|
|
|
|
|
|
|
{ |
32448
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
32449
|
|
|
|
|
|
|
return v; |
32450
|
|
|
|
|
|
|
} |
32451
|
|
|
|
|
|
|
#define rbit32 rbit32 |
32452
|
|
|
|
|
|
|
#endif |
32453
|
|
|
|
|
|
|
|
32454
|
|
|
|
|
|
|
#endif |
32455
|
|
|
|
|
|
|
|
32456
|
|
|
|
|
|
|
|
32457
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
32458
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
32459
|
|
|
|
|
|
|
|
32460
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
32461
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
32462
|
|
|
|
|
|
|
|
32463
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
32464
|
|
|
|
|
|
|
size_t alignment, size_t size); |
32465
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
32466
|
|
|
|
|
|
|
|
32467
|
|
|
|
|
|
|
#ifdef FREESTANDING |
32468
|
|
|
|
|
|
|
|
32469
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
32470
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
32471
|
|
|
|
|
|
|
|
32472
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
32473
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
32474
|
|
|
|
|
|
|
|
32475
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
32476
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
32477
|
|
|
|
|
|
|
|
32478
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
32479
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
32480
|
|
|
|
|
|
|
|
32481
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
32482
|
|
|
|
|
|
|
#else |
32483
|
|
|
|
|
|
|
#include |
32484
|
|
|
|
|
|
|
#endif |
32485
|
|
|
|
|
|
|
|
32486
|
|
|
|
|
|
|
|
32487
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
32488
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
32489
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
32490
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
32491
|
|
|
|
|
|
|
#else |
32492
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
32493
|
|
|
|
|
|
|
#endif |
32494
|
|
|
|
|
|
|
|
32495
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
32496
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
32497
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
32498
|
|
|
|
|
|
|
|
32499
|
|
|
|
|
|
|
#endif |
32500
|
|
|
|
|
|
|
|
32501
|
|
|
|
|
|
|
/* #include "zlib_constants.h" */ |
32502
|
|
|
|
|
|
|
|
32503
|
|
|
|
|
|
|
|
32504
|
|
|
|
|
|
|
#ifndef LIB_ZLIB_CONSTANTS_H |
32505
|
|
|
|
|
|
|
#define LIB_ZLIB_CONSTANTS_H |
32506
|
|
|
|
|
|
|
|
32507
|
|
|
|
|
|
|
#define ZLIB_MIN_HEADER_SIZE 2 |
32508
|
|
|
|
|
|
|
#define ZLIB_FOOTER_SIZE 4 |
32509
|
|
|
|
|
|
|
#define ZLIB_MIN_OVERHEAD (ZLIB_MIN_HEADER_SIZE + ZLIB_FOOTER_SIZE) |
32510
|
|
|
|
|
|
|
|
32511
|
|
|
|
|
|
|
#define ZLIB_CM_DEFLATE 8 |
32512
|
|
|
|
|
|
|
|
32513
|
|
|
|
|
|
|
#define ZLIB_CINFO_32K_WINDOW 7 |
32514
|
|
|
|
|
|
|
|
32515
|
|
|
|
|
|
|
#define ZLIB_FASTEST_COMPRESSION 0 |
32516
|
|
|
|
|
|
|
#define ZLIB_FAST_COMPRESSION 1 |
32517
|
|
|
|
|
|
|
#define ZLIB_DEFAULT_COMPRESSION 2 |
32518
|
|
|
|
|
|
|
#define ZLIB_SLOWEST_COMPRESSION 3 |
32519
|
|
|
|
|
|
|
|
32520
|
|
|
|
|
|
|
#endif |
32521
|
|
|
|
|
|
|
|
32522
|
|
|
|
|
|
|
|
32523
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32524
|
12
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *d, |
32525
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32526
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32527
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
32528
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
32529
|
|
|
|
|
|
|
{ |
32530
|
12
|
|
|
|
|
|
const u8 *in_next = in; |
32531
|
12
|
|
|
|
|
|
const u8 * const in_end = in_next + in_nbytes; |
32532
|
|
|
|
|
|
|
u16 hdr; |
32533
|
|
|
|
|
|
|
size_t actual_in_nbytes; |
32534
|
|
|
|
|
|
|
size_t actual_out_nbytes; |
32535
|
|
|
|
|
|
|
enum libdeflate_result result; |
32536
|
|
|
|
|
|
|
|
32537
|
12
|
50
|
|
|
|
|
if (in_nbytes < ZLIB_MIN_OVERHEAD) |
32538
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
32539
|
|
|
|
|
|
|
|
32540
|
|
|
|
|
|
|
|
32541
|
12
|
|
|
|
|
|
hdr = get_unaligned_be16(in_next); |
32542
|
12
|
|
|
|
|
|
in_next += 2; |
32543
|
|
|
|
|
|
|
|
32544
|
|
|
|
|
|
|
|
32545
|
12
|
50
|
|
|
|
|
if ((hdr % 31) != 0) |
32546
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
32547
|
|
|
|
|
|
|
|
32548
|
|
|
|
|
|
|
|
32549
|
12
|
50
|
|
|
|
|
if (((hdr >> 8) & 0xF) != ZLIB_CM_DEFLATE) |
32550
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
32551
|
|
|
|
|
|
|
|
32552
|
|
|
|
|
|
|
|
32553
|
12
|
50
|
|
|
|
|
if ((hdr >> 12) > ZLIB_CINFO_32K_WINDOW) |
32554
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
32555
|
|
|
|
|
|
|
|
32556
|
|
|
|
|
|
|
|
32557
|
12
|
50
|
|
|
|
|
if ((hdr >> 5) & 1) |
32558
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
32559
|
|
|
|
|
|
|
|
32560
|
|
|
|
|
|
|
|
32561
|
12
|
|
|
|
|
|
result = libdeflate_deflate_decompress_ex(d, in_next, |
32562
|
12
|
|
|
|
|
|
in_end - ZLIB_FOOTER_SIZE - in_next, |
32563
|
|
|
|
|
|
|
out, out_nbytes_avail, |
32564
|
|
|
|
|
|
|
&actual_in_nbytes, actual_out_nbytes_ret); |
32565
|
12
|
50
|
|
|
|
|
if (result != LIBDEFLATE_SUCCESS) |
32566
|
0
|
|
|
|
|
|
return result; |
32567
|
|
|
|
|
|
|
|
32568
|
12
|
50
|
|
|
|
|
if (actual_out_nbytes_ret) |
32569
|
12
|
|
|
|
|
|
actual_out_nbytes = *actual_out_nbytes_ret; |
32570
|
|
|
|
|
|
|
else |
32571
|
0
|
|
|
|
|
|
actual_out_nbytes = out_nbytes_avail; |
32572
|
|
|
|
|
|
|
|
32573
|
12
|
|
|
|
|
|
in_next += actual_in_nbytes; |
32574
|
|
|
|
|
|
|
|
32575
|
|
|
|
|
|
|
|
32576
|
24
|
50
|
|
|
|
|
if (libdeflate_adler32(1, out, actual_out_nbytes) != |
32577
|
12
|
|
|
|
|
|
get_unaligned_be32(in_next)) |
32578
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
32579
|
12
|
|
|
|
|
|
in_next += 4; |
32580
|
|
|
|
|
|
|
|
32581
|
12
|
50
|
|
|
|
|
if (actual_in_nbytes_ret) |
32582
|
12
|
|
|
|
|
|
*actual_in_nbytes_ret = in_next - (u8 *)in; |
32583
|
|
|
|
|
|
|
|
32584
|
12
|
|
|
|
|
|
return LIBDEFLATE_SUCCESS; |
32585
|
|
|
|
|
|
|
} |
32586
|
|
|
|
|
|
|
|
32587
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32588
|
0
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *d, |
32589
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32590
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32591
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
32592
|
|
|
|
|
|
|
{ |
32593
|
0
|
|
|
|
|
|
return libdeflate_zlib_decompress_ex(d, in, in_nbytes, |
32594
|
|
|
|
|
|
|
out, out_nbytes_avail, |
32595
|
|
|
|
|
|
|
NULL, actual_out_nbytes_ret); |
32596
|
|
|
|
|
|
|
} |
32597
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/arm/cpu_features.c */ |
32598
|
|
|
|
|
|
|
|
32599
|
|
|
|
|
|
|
|
32600
|
|
|
|
|
|
|
|
32601
|
|
|
|
|
|
|
|
32602
|
|
|
|
|
|
|
#ifdef __APPLE__ |
32603
|
|
|
|
|
|
|
# undef _ANSI_SOURCE |
32604
|
|
|
|
|
|
|
# undef _DARWIN_C_SOURCE |
32605
|
|
|
|
|
|
|
# define _DARWIN_C_SOURCE |
32606
|
|
|
|
|
|
|
#endif |
32607
|
|
|
|
|
|
|
|
32608
|
|
|
|
|
|
|
/* #include "cpu_features_common.h" */ |
32609
|
|
|
|
|
|
|
|
32610
|
|
|
|
|
|
|
|
32611
|
|
|
|
|
|
|
#ifndef LIB_CPU_FEATURES_COMMON_H |
32612
|
|
|
|
|
|
|
#define LIB_CPU_FEATURES_COMMON_H |
32613
|
|
|
|
|
|
|
|
32614
|
|
|
|
|
|
|
#if defined(TEST_SUPPORT__DO_NOT_USE) && !defined(FREESTANDING) |
32615
|
|
|
|
|
|
|
|
32616
|
|
|
|
|
|
|
# undef _ANSI_SOURCE |
32617
|
|
|
|
|
|
|
# ifndef __APPLE__ |
32618
|
|
|
|
|
|
|
# undef _GNU_SOURCE |
32619
|
|
|
|
|
|
|
# define _GNU_SOURCE |
32620
|
|
|
|
|
|
|
# endif |
32621
|
|
|
|
|
|
|
# include |
32622
|
|
|
|
|
|
|
# include |
32623
|
|
|
|
|
|
|
# include |
32624
|
|
|
|
|
|
|
#endif |
32625
|
|
|
|
|
|
|
|
32626
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
32627
|
|
|
|
|
|
|
|
32628
|
|
|
|
|
|
|
|
32629
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
32630
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
32631
|
|
|
|
|
|
|
|
32632
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
32633
|
|
|
|
|
|
|
|
32634
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
32635
|
|
|
|
|
|
|
#endif |
32636
|
|
|
|
|
|
|
|
32637
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
32638
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
32639
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
32640
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
32641
|
|
|
|
|
|
|
#else |
32642
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
32643
|
|
|
|
|
|
|
#endif |
32644
|
|
|
|
|
|
|
|
32645
|
|
|
|
|
|
|
|
32646
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
32647
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
32648
|
|
|
|
|
|
|
#else |
32649
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
32650
|
|
|
|
|
|
|
#endif |
32651
|
|
|
|
|
|
|
|
32652
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
32653
|
|
|
|
|
|
|
|
32654
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
32655
|
|
|
|
|
|
|
|
32656
|
|
|
|
|
|
|
|
32657
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
32658
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
32659
|
|
|
|
|
|
|
|
32660
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
32661
|
|
|
|
|
|
|
|
32662
|
|
|
|
|
|
|
|
32663
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
32664
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
32665
|
|
|
|
|
|
|
|
32666
|
|
|
|
|
|
|
#include |
32667
|
|
|
|
|
|
|
#include |
32668
|
|
|
|
|
|
|
|
32669
|
|
|
|
|
|
|
#ifdef __cplusplus |
32670
|
|
|
|
|
|
|
extern "C" { |
32671
|
|
|
|
|
|
|
#endif |
32672
|
|
|
|
|
|
|
|
32673
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
32674
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
32675
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
32676
|
|
|
|
|
|
|
|
32677
|
|
|
|
|
|
|
|
32678
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
32679
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
32680
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
32681
|
|
|
|
|
|
|
# else |
32682
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
32683
|
|
|
|
|
|
|
# endif |
32684
|
|
|
|
|
|
|
#endif |
32685
|
|
|
|
|
|
|
|
32686
|
|
|
|
|
|
|
|
32687
|
|
|
|
|
|
|
|
32688
|
|
|
|
|
|
|
|
32689
|
|
|
|
|
|
|
|
32690
|
|
|
|
|
|
|
struct libdeflate_compressor; |
32691
|
|
|
|
|
|
|
struct libdeflate_options; |
32692
|
|
|
|
|
|
|
|
32693
|
|
|
|
|
|
|
|
32694
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
32695
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
32696
|
|
|
|
|
|
|
|
32697
|
|
|
|
|
|
|
|
32698
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
32699
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
32700
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
32701
|
|
|
|
|
|
|
|
32702
|
|
|
|
|
|
|
|
32703
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32704
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
32705
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32706
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32707
|
|
|
|
|
|
|
|
32708
|
|
|
|
|
|
|
|
32709
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32710
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
32711
|
|
|
|
|
|
|
size_t in_nbytes); |
32712
|
|
|
|
|
|
|
|
32713
|
|
|
|
|
|
|
|
32714
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32715
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
32716
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32717
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32718
|
|
|
|
|
|
|
|
32719
|
|
|
|
|
|
|
|
32720
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32721
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
32722
|
|
|
|
|
|
|
size_t in_nbytes); |
32723
|
|
|
|
|
|
|
|
32724
|
|
|
|
|
|
|
|
32725
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32726
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
32727
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32728
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32729
|
|
|
|
|
|
|
|
32730
|
|
|
|
|
|
|
|
32731
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32732
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
32733
|
|
|
|
|
|
|
size_t in_nbytes); |
32734
|
|
|
|
|
|
|
|
32735
|
|
|
|
|
|
|
|
32736
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
32737
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
32738
|
|
|
|
|
|
|
|
32739
|
|
|
|
|
|
|
|
32740
|
|
|
|
|
|
|
|
32741
|
|
|
|
|
|
|
|
32742
|
|
|
|
|
|
|
|
32743
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
32744
|
|
|
|
|
|
|
struct libdeflate_options; |
32745
|
|
|
|
|
|
|
|
32746
|
|
|
|
|
|
|
|
32747
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
32748
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
32749
|
|
|
|
|
|
|
|
32750
|
|
|
|
|
|
|
|
32751
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
32752
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
32753
|
|
|
|
|
|
|
|
32754
|
|
|
|
|
|
|
|
32755
|
|
|
|
|
|
|
enum libdeflate_result { |
32756
|
|
|
|
|
|
|
|
32757
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
32758
|
|
|
|
|
|
|
|
32759
|
|
|
|
|
|
|
|
32760
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
32761
|
|
|
|
|
|
|
|
32762
|
|
|
|
|
|
|
|
32763
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
32764
|
|
|
|
|
|
|
|
32765
|
|
|
|
|
|
|
|
32766
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
32767
|
|
|
|
|
|
|
}; |
32768
|
|
|
|
|
|
|
|
32769
|
|
|
|
|
|
|
|
32770
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32771
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
32772
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32773
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32774
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32775
|
|
|
|
|
|
|
|
32776
|
|
|
|
|
|
|
|
32777
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32778
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
32779
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32780
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32781
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
32782
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32783
|
|
|
|
|
|
|
|
32784
|
|
|
|
|
|
|
|
32785
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32786
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
32787
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32788
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32789
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32790
|
|
|
|
|
|
|
|
32791
|
|
|
|
|
|
|
|
32792
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32793
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
32794
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32795
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32796
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
32797
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32798
|
|
|
|
|
|
|
|
32799
|
|
|
|
|
|
|
|
32800
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32801
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
32802
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32803
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32804
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32805
|
|
|
|
|
|
|
|
32806
|
|
|
|
|
|
|
|
32807
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32808
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
32809
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32810
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32811
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
32812
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32813
|
|
|
|
|
|
|
|
32814
|
|
|
|
|
|
|
|
32815
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
32816
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
32817
|
|
|
|
|
|
|
|
32818
|
|
|
|
|
|
|
|
32819
|
|
|
|
|
|
|
|
32820
|
|
|
|
|
|
|
|
32821
|
|
|
|
|
|
|
|
32822
|
|
|
|
|
|
|
|
32823
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
32824
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
32825
|
|
|
|
|
|
|
|
32826
|
|
|
|
|
|
|
|
32827
|
|
|
|
|
|
|
|
32828
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
32829
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
32830
|
|
|
|
|
|
|
|
32831
|
|
|
|
|
|
|
|
32832
|
|
|
|
|
|
|
|
32833
|
|
|
|
|
|
|
|
32834
|
|
|
|
|
|
|
|
32835
|
|
|
|
|
|
|
|
32836
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
32837
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
32838
|
|
|
|
|
|
|
void (*free_func)(void *)); |
32839
|
|
|
|
|
|
|
|
32840
|
|
|
|
|
|
|
|
32841
|
|
|
|
|
|
|
struct libdeflate_options { |
32842
|
|
|
|
|
|
|
|
32843
|
|
|
|
|
|
|
|
32844
|
|
|
|
|
|
|
size_t sizeof_options; |
32845
|
|
|
|
|
|
|
|
32846
|
|
|
|
|
|
|
|
32847
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
32848
|
|
|
|
|
|
|
void (*free_func)(void *); |
32849
|
|
|
|
|
|
|
}; |
32850
|
|
|
|
|
|
|
|
32851
|
|
|
|
|
|
|
#ifdef __cplusplus |
32852
|
|
|
|
|
|
|
} |
32853
|
|
|
|
|
|
|
#endif |
32854
|
|
|
|
|
|
|
|
32855
|
|
|
|
|
|
|
#endif |
32856
|
|
|
|
|
|
|
|
32857
|
|
|
|
|
|
|
|
32858
|
|
|
|
|
|
|
#include |
32859
|
|
|
|
|
|
|
#include |
32860
|
|
|
|
|
|
|
#include |
32861
|
|
|
|
|
|
|
#ifdef _MSC_VER |
32862
|
|
|
|
|
|
|
# include |
32863
|
|
|
|
|
|
|
# include |
32864
|
|
|
|
|
|
|
|
32865
|
|
|
|
|
|
|
|
32866
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
32867
|
|
|
|
|
|
|
|
32868
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
32869
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
32870
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
32871
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
32872
|
|
|
|
|
|
|
|
32873
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
32874
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
32875
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
32876
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
32877
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
32878
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
32879
|
|
|
|
|
|
|
#endif |
32880
|
|
|
|
|
|
|
#ifndef FREESTANDING |
32881
|
|
|
|
|
|
|
# include |
32882
|
|
|
|
|
|
|
#endif |
32883
|
|
|
|
|
|
|
|
32884
|
|
|
|
|
|
|
|
32885
|
|
|
|
|
|
|
|
32886
|
|
|
|
|
|
|
|
32887
|
|
|
|
|
|
|
|
32888
|
|
|
|
|
|
|
|
32889
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
32890
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
32891
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
32892
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
32893
|
|
|
|
|
|
|
#ifdef _MSC_VER |
32894
|
|
|
|
|
|
|
# if defined(_M_X64) |
32895
|
|
|
|
|
|
|
# define ARCH_X86_64 |
32896
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
32897
|
|
|
|
|
|
|
# define ARCH_X86_32 |
32898
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
32899
|
|
|
|
|
|
|
# define ARCH_ARM64 |
32900
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
32901
|
|
|
|
|
|
|
# define ARCH_ARM32 |
32902
|
|
|
|
|
|
|
# endif |
32903
|
|
|
|
|
|
|
#else |
32904
|
|
|
|
|
|
|
# if defined(__x86_64__) |
32905
|
|
|
|
|
|
|
# define ARCH_X86_64 |
32906
|
|
|
|
|
|
|
# elif defined(__i386__) |
32907
|
|
|
|
|
|
|
# define ARCH_X86_32 |
32908
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
32909
|
|
|
|
|
|
|
# define ARCH_ARM64 |
32910
|
|
|
|
|
|
|
# elif defined(__arm__) |
32911
|
|
|
|
|
|
|
# define ARCH_ARM32 |
32912
|
|
|
|
|
|
|
# endif |
32913
|
|
|
|
|
|
|
#endif |
32914
|
|
|
|
|
|
|
|
32915
|
|
|
|
|
|
|
|
32916
|
|
|
|
|
|
|
|
32917
|
|
|
|
|
|
|
|
32918
|
|
|
|
|
|
|
|
32919
|
|
|
|
|
|
|
|
32920
|
|
|
|
|
|
|
typedef uint8_t u8; |
32921
|
|
|
|
|
|
|
typedef uint16_t u16; |
32922
|
|
|
|
|
|
|
typedef uint32_t u32; |
32923
|
|
|
|
|
|
|
typedef uint64_t u64; |
32924
|
|
|
|
|
|
|
typedef int8_t s8; |
32925
|
|
|
|
|
|
|
typedef int16_t s16; |
32926
|
|
|
|
|
|
|
typedef int32_t s32; |
32927
|
|
|
|
|
|
|
typedef int64_t s64; |
32928
|
|
|
|
|
|
|
|
32929
|
|
|
|
|
|
|
|
32930
|
|
|
|
|
|
|
#ifdef _MSC_VER |
32931
|
|
|
|
|
|
|
# ifdef _WIN64 |
32932
|
|
|
|
|
|
|
typedef long long ssize_t; |
32933
|
|
|
|
|
|
|
# else |
32934
|
|
|
|
|
|
|
typedef long ssize_t; |
32935
|
|
|
|
|
|
|
# endif |
32936
|
|
|
|
|
|
|
#endif |
32937
|
|
|
|
|
|
|
|
32938
|
|
|
|
|
|
|
|
32939
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
32940
|
|
|
|
|
|
|
|
32941
|
|
|
|
|
|
|
|
32942
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
32943
|
|
|
|
|
|
|
|
32944
|
|
|
|
|
|
|
|
32945
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
32946
|
|
|
|
|
|
|
|
32947
|
|
|
|
|
|
|
|
32948
|
|
|
|
|
|
|
|
32949
|
|
|
|
|
|
|
|
32950
|
|
|
|
|
|
|
|
32951
|
|
|
|
|
|
|
|
32952
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
32953
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
32954
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
32955
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
32956
|
|
|
|
|
|
|
#else |
32957
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
32958
|
|
|
|
|
|
|
#endif |
32959
|
|
|
|
|
|
|
#ifdef __clang__ |
32960
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
32961
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
32962
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
32963
|
|
|
|
|
|
|
# else |
32964
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
32965
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
32966
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
32967
|
|
|
|
|
|
|
# endif |
32968
|
|
|
|
|
|
|
#else |
32969
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
32970
|
|
|
|
|
|
|
#endif |
32971
|
|
|
|
|
|
|
|
32972
|
|
|
|
|
|
|
|
32973
|
|
|
|
|
|
|
#ifndef __has_attribute |
32974
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
32975
|
|
|
|
|
|
|
#endif |
32976
|
|
|
|
|
|
|
#ifndef __has_builtin |
32977
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
32978
|
|
|
|
|
|
|
#endif |
32979
|
|
|
|
|
|
|
|
32980
|
|
|
|
|
|
|
|
32981
|
|
|
|
|
|
|
#ifdef _MSC_VER |
32982
|
|
|
|
|
|
|
# define inline __inline |
32983
|
|
|
|
|
|
|
#endif |
32984
|
|
|
|
|
|
|
|
32985
|
|
|
|
|
|
|
|
32986
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
32987
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
32988
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32989
|
|
|
|
|
|
|
# define forceinline __forceinline |
32990
|
|
|
|
|
|
|
#else |
32991
|
|
|
|
|
|
|
# define forceinline inline |
32992
|
|
|
|
|
|
|
#endif |
32993
|
|
|
|
|
|
|
|
32994
|
|
|
|
|
|
|
|
32995
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
32996
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
32997
|
|
|
|
|
|
|
#else |
32998
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
32999
|
|
|
|
|
|
|
#endif |
33000
|
|
|
|
|
|
|
|
33001
|
|
|
|
|
|
|
|
33002
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
33003
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
33004
|
|
|
|
|
|
|
# define restrict __restrict__ |
33005
|
|
|
|
|
|
|
# else |
33006
|
|
|
|
|
|
|
# define restrict |
33007
|
|
|
|
|
|
|
# endif |
33008
|
|
|
|
|
|
|
#endif |
33009
|
|
|
|
|
|
|
|
33010
|
|
|
|
|
|
|
|
33011
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
33012
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
33013
|
|
|
|
|
|
|
#else |
33014
|
|
|
|
|
|
|
# define likely(expr) (expr) |
33015
|
|
|
|
|
|
|
#endif |
33016
|
|
|
|
|
|
|
|
33017
|
|
|
|
|
|
|
|
33018
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
33019
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
33020
|
|
|
|
|
|
|
#else |
33021
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
33022
|
|
|
|
|
|
|
#endif |
33023
|
|
|
|
|
|
|
|
33024
|
|
|
|
|
|
|
|
33025
|
|
|
|
|
|
|
#undef prefetchr |
33026
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
33027
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
33028
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33029
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
33030
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
33031
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
33032
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
33033
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
33034
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
33035
|
|
|
|
|
|
|
# endif |
33036
|
|
|
|
|
|
|
#endif |
33037
|
|
|
|
|
|
|
#ifndef prefetchr |
33038
|
|
|
|
|
|
|
# define prefetchr(addr) |
33039
|
|
|
|
|
|
|
#endif |
33040
|
|
|
|
|
|
|
|
33041
|
|
|
|
|
|
|
|
33042
|
|
|
|
|
|
|
#undef prefetchw |
33043
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
33044
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
33045
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33046
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
33047
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
33048
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
33049
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
33050
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
33051
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
33052
|
|
|
|
|
|
|
# endif |
33053
|
|
|
|
|
|
|
#endif |
33054
|
|
|
|
|
|
|
#ifndef prefetchw |
33055
|
|
|
|
|
|
|
# define prefetchw(addr) |
33056
|
|
|
|
|
|
|
#endif |
33057
|
|
|
|
|
|
|
|
33058
|
|
|
|
|
|
|
|
33059
|
|
|
|
|
|
|
#undef _aligned_attribute |
33060
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
33061
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
33062
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33063
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
33064
|
|
|
|
|
|
|
#endif |
33065
|
|
|
|
|
|
|
|
33066
|
|
|
|
|
|
|
|
33067
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
33068
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
33069
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
33070
|
|
|
|
|
|
|
#else |
33071
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
33072
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
33073
|
|
|
|
|
|
|
#endif |
33074
|
|
|
|
|
|
|
|
33075
|
|
|
|
|
|
|
|
33076
|
|
|
|
|
|
|
|
33077
|
|
|
|
|
|
|
|
33078
|
|
|
|
|
|
|
|
33079
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
33080
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
33081
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
33082
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
33083
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
33084
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
33085
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
33086
|
|
|
|
|
|
|
|
33087
|
|
|
|
|
|
|
|
33088
|
|
|
|
|
|
|
|
33089
|
|
|
|
|
|
|
|
33090
|
|
|
|
|
|
|
|
33091
|
|
|
|
|
|
|
|
33092
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
33093
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
33094
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33095
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
33096
|
|
|
|
|
|
|
#else |
33097
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
33098
|
|
|
|
|
|
|
{ |
33099
|
|
|
|
|
|
|
union { |
33100
|
|
|
|
|
|
|
u32 w; |
33101
|
|
|
|
|
|
|
u8 b; |
33102
|
|
|
|
|
|
|
} u; |
33103
|
|
|
|
|
|
|
|
33104
|
|
|
|
|
|
|
u.w = 1; |
33105
|
|
|
|
|
|
|
return u.b; |
33106
|
|
|
|
|
|
|
} |
33107
|
|
|
|
|
|
|
#endif |
33108
|
|
|
|
|
|
|
|
33109
|
|
|
|
|
|
|
|
33110
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
33111
|
|
|
|
|
|
|
{ |
33112
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
33113
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
33114
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33115
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
33116
|
|
|
|
|
|
|
#else |
33117
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
33118
|
|
|
|
|
|
|
#endif |
33119
|
|
|
|
|
|
|
} |
33120
|
|
|
|
|
|
|
|
33121
|
|
|
|
|
|
|
|
33122
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
33123
|
|
|
|
|
|
|
{ |
33124
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
33125
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
33126
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33127
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
33128
|
|
|
|
|
|
|
#else |
33129
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
33130
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
33131
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
33132
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
33133
|
|
|
|
|
|
|
#endif |
33134
|
|
|
|
|
|
|
} |
33135
|
|
|
|
|
|
|
|
33136
|
|
|
|
|
|
|
|
33137
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
33138
|
|
|
|
|
|
|
{ |
33139
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
33140
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
33141
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33142
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
33143
|
|
|
|
|
|
|
#else |
33144
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
33145
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
33146
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
33147
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
33148
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
33149
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
33150
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
33151
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
33152
|
|
|
|
|
|
|
#endif |
33153
|
|
|
|
|
|
|
} |
33154
|
|
|
|
|
|
|
|
33155
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
33156
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
33157
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
33158
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
33159
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
33160
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
33161
|
|
|
|
|
|
|
|
33162
|
|
|
|
|
|
|
|
33163
|
|
|
|
|
|
|
|
33164
|
|
|
|
|
|
|
|
33165
|
|
|
|
|
|
|
|
33166
|
|
|
|
|
|
|
|
33167
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
33168
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
33169
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
33170
|
|
|
|
|
|
|
defined(__wasm__)) |
33171
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
33172
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33173
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
33174
|
|
|
|
|
|
|
#else |
33175
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
33176
|
|
|
|
|
|
|
#endif |
33177
|
|
|
|
|
|
|
|
33178
|
|
|
|
|
|
|
|
33179
|
|
|
|
|
|
|
|
33180
|
|
|
|
|
|
|
#ifdef FREESTANDING |
33181
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
33182
|
|
|
|
|
|
|
#else |
33183
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
33184
|
|
|
|
|
|
|
#endif |
33185
|
|
|
|
|
|
|
|
33186
|
|
|
|
|
|
|
|
33187
|
|
|
|
|
|
|
|
33188
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
33189
|
|
|
|
|
|
|
static forceinline type \ |
33190
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
33191
|
|
|
|
|
|
|
{ \ |
33192
|
|
|
|
|
|
|
type v; \ |
33193
|
|
|
|
|
|
|
\ |
33194
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
33195
|
|
|
|
|
|
|
return v; \ |
33196
|
|
|
|
|
|
|
} \ |
33197
|
|
|
|
|
|
|
\ |
33198
|
|
|
|
|
|
|
static forceinline void \ |
33199
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
33200
|
|
|
|
|
|
|
{ \ |
33201
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
33202
|
|
|
|
|
|
|
} |
33203
|
|
|
|
|
|
|
|
33204
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
33205
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
33206
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
33207
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
33208
|
|
|
|
|
|
|
|
33209
|
|
|
|
|
|
|
#undef MEMCOPY |
33210
|
|
|
|
|
|
|
|
33211
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
33212
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
33213
|
|
|
|
|
|
|
|
33214
|
|
|
|
|
|
|
|
33215
|
|
|
|
|
|
|
|
33216
|
|
|
|
|
|
|
static forceinline u16 |
33217
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
33218
|
|
|
|
|
|
|
{ |
33219
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33220
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
33221
|
|
|
|
|
|
|
else |
33222
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
33223
|
|
|
|
|
|
|
} |
33224
|
|
|
|
|
|
|
|
33225
|
|
|
|
|
|
|
static forceinline u16 |
33226
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
33227
|
|
|
|
|
|
|
{ |
33228
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33229
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
33230
|
|
|
|
|
|
|
else |
33231
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
33232
|
|
|
|
|
|
|
} |
33233
|
|
|
|
|
|
|
|
33234
|
|
|
|
|
|
|
static forceinline u32 |
33235
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
33236
|
|
|
|
|
|
|
{ |
33237
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33238
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
33239
|
|
|
|
|
|
|
else |
33240
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
33241
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
33242
|
|
|
|
|
|
|
} |
33243
|
|
|
|
|
|
|
|
33244
|
|
|
|
|
|
|
static forceinline u32 |
33245
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
33246
|
|
|
|
|
|
|
{ |
33247
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33248
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
33249
|
|
|
|
|
|
|
else |
33250
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
33251
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
33252
|
|
|
|
|
|
|
} |
33253
|
|
|
|
|
|
|
|
33254
|
|
|
|
|
|
|
static forceinline u64 |
33255
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
33256
|
|
|
|
|
|
|
{ |
33257
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33258
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
33259
|
|
|
|
|
|
|
else |
33260
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
33261
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
33262
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
33263
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
33264
|
|
|
|
|
|
|
} |
33265
|
|
|
|
|
|
|
|
33266
|
|
|
|
|
|
|
static forceinline machine_word_t |
33267
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
33268
|
|
|
|
|
|
|
{ |
33269
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
33270
|
|
|
|
|
|
|
if (WORDBITS == 32) |
33271
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
33272
|
|
|
|
|
|
|
else |
33273
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
33274
|
|
|
|
|
|
|
} |
33275
|
|
|
|
|
|
|
|
33276
|
|
|
|
|
|
|
|
33277
|
|
|
|
|
|
|
|
33278
|
|
|
|
|
|
|
static forceinline void |
33279
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
33280
|
|
|
|
|
|
|
{ |
33281
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33282
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
33283
|
|
|
|
|
|
|
} else { |
33284
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
33285
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
33286
|
|
|
|
|
|
|
} |
33287
|
|
|
|
|
|
|
} |
33288
|
|
|
|
|
|
|
|
33289
|
|
|
|
|
|
|
static forceinline void |
33290
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
33291
|
|
|
|
|
|
|
{ |
33292
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33293
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
33294
|
|
|
|
|
|
|
} else { |
33295
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
33296
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
33297
|
|
|
|
|
|
|
} |
33298
|
|
|
|
|
|
|
} |
33299
|
|
|
|
|
|
|
|
33300
|
|
|
|
|
|
|
static forceinline void |
33301
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
33302
|
|
|
|
|
|
|
{ |
33303
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33304
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
33305
|
|
|
|
|
|
|
} else { |
33306
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
33307
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
33308
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
33309
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
33310
|
|
|
|
|
|
|
} |
33311
|
|
|
|
|
|
|
} |
33312
|
|
|
|
|
|
|
|
33313
|
|
|
|
|
|
|
static forceinline void |
33314
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
33315
|
|
|
|
|
|
|
{ |
33316
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33317
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
33318
|
|
|
|
|
|
|
} else { |
33319
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
33320
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
33321
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
33322
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
33323
|
|
|
|
|
|
|
} |
33324
|
|
|
|
|
|
|
} |
33325
|
|
|
|
|
|
|
|
33326
|
|
|
|
|
|
|
static forceinline void |
33327
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
33328
|
|
|
|
|
|
|
{ |
33329
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33330
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
33331
|
|
|
|
|
|
|
} else { |
33332
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
33333
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
33334
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
33335
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
33336
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
33337
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
33338
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
33339
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
33340
|
|
|
|
|
|
|
} |
33341
|
|
|
|
|
|
|
} |
33342
|
|
|
|
|
|
|
|
33343
|
|
|
|
|
|
|
static forceinline void |
33344
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
33345
|
|
|
|
|
|
|
{ |
33346
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
33347
|
|
|
|
|
|
|
if (WORDBITS == 32) |
33348
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
33349
|
|
|
|
|
|
|
else |
33350
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
33351
|
|
|
|
|
|
|
} |
33352
|
|
|
|
|
|
|
|
33353
|
|
|
|
|
|
|
|
33354
|
|
|
|
|
|
|
|
33355
|
|
|
|
|
|
|
|
33356
|
|
|
|
|
|
|
|
33357
|
|
|
|
|
|
|
|
33358
|
|
|
|
|
|
|
|
33359
|
|
|
|
|
|
|
static forceinline unsigned |
33360
|
|
|
|
|
|
|
bsr32(u32 v) |
33361
|
|
|
|
|
|
|
{ |
33362
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
33363
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
33364
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33365
|
|
|
|
|
|
|
unsigned long i; |
33366
|
|
|
|
|
|
|
|
33367
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
33368
|
|
|
|
|
|
|
return i; |
33369
|
|
|
|
|
|
|
#else |
33370
|
|
|
|
|
|
|
unsigned i = 0; |
33371
|
|
|
|
|
|
|
|
33372
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
33373
|
|
|
|
|
|
|
i++; |
33374
|
|
|
|
|
|
|
return i; |
33375
|
|
|
|
|
|
|
#endif |
33376
|
|
|
|
|
|
|
} |
33377
|
|
|
|
|
|
|
|
33378
|
|
|
|
|
|
|
static forceinline unsigned |
33379
|
|
|
|
|
|
|
bsr64(u64 v) |
33380
|
|
|
|
|
|
|
{ |
33381
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
33382
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
33383
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
33384
|
|
|
|
|
|
|
unsigned long i; |
33385
|
|
|
|
|
|
|
|
33386
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
33387
|
|
|
|
|
|
|
return i; |
33388
|
|
|
|
|
|
|
#else |
33389
|
|
|
|
|
|
|
unsigned i = 0; |
33390
|
|
|
|
|
|
|
|
33391
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
33392
|
|
|
|
|
|
|
i++; |
33393
|
|
|
|
|
|
|
return i; |
33394
|
|
|
|
|
|
|
#endif |
33395
|
|
|
|
|
|
|
} |
33396
|
|
|
|
|
|
|
|
33397
|
|
|
|
|
|
|
static forceinline unsigned |
33398
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
33399
|
|
|
|
|
|
|
{ |
33400
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
33401
|
|
|
|
|
|
|
if (WORDBITS == 32) |
33402
|
|
|
|
|
|
|
return bsr32(v); |
33403
|
|
|
|
|
|
|
else |
33404
|
|
|
|
|
|
|
return bsr64(v); |
33405
|
|
|
|
|
|
|
} |
33406
|
|
|
|
|
|
|
|
33407
|
|
|
|
|
|
|
|
33408
|
|
|
|
|
|
|
|
33409
|
|
|
|
|
|
|
static forceinline unsigned |
33410
|
|
|
|
|
|
|
bsf32(u32 v) |
33411
|
|
|
|
|
|
|
{ |
33412
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
33413
|
|
|
|
|
|
|
return __builtin_ctz(v); |
33414
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33415
|
|
|
|
|
|
|
unsigned long i; |
33416
|
|
|
|
|
|
|
|
33417
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
33418
|
|
|
|
|
|
|
return i; |
33419
|
|
|
|
|
|
|
#else |
33420
|
|
|
|
|
|
|
unsigned i = 0; |
33421
|
|
|
|
|
|
|
|
33422
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
33423
|
|
|
|
|
|
|
i++; |
33424
|
|
|
|
|
|
|
return i; |
33425
|
|
|
|
|
|
|
#endif |
33426
|
|
|
|
|
|
|
} |
33427
|
|
|
|
|
|
|
|
33428
|
|
|
|
|
|
|
static forceinline unsigned |
33429
|
|
|
|
|
|
|
bsf64(u64 v) |
33430
|
|
|
|
|
|
|
{ |
33431
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
33432
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
33433
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
33434
|
|
|
|
|
|
|
unsigned long i; |
33435
|
|
|
|
|
|
|
|
33436
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
33437
|
|
|
|
|
|
|
return i; |
33438
|
|
|
|
|
|
|
#else |
33439
|
|
|
|
|
|
|
unsigned i = 0; |
33440
|
|
|
|
|
|
|
|
33441
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
33442
|
|
|
|
|
|
|
i++; |
33443
|
|
|
|
|
|
|
return i; |
33444
|
|
|
|
|
|
|
#endif |
33445
|
|
|
|
|
|
|
} |
33446
|
|
|
|
|
|
|
|
33447
|
|
|
|
|
|
|
static forceinline unsigned |
33448
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
33449
|
|
|
|
|
|
|
{ |
33450
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
33451
|
|
|
|
|
|
|
if (WORDBITS == 32) |
33452
|
|
|
|
|
|
|
return bsf32(v); |
33453
|
|
|
|
|
|
|
else |
33454
|
|
|
|
|
|
|
return bsf64(v); |
33455
|
|
|
|
|
|
|
} |
33456
|
|
|
|
|
|
|
|
33457
|
|
|
|
|
|
|
|
33458
|
|
|
|
|
|
|
#undef rbit32 |
33459
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
33460
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
33461
|
|
|
|
|
|
|
static forceinline u32 |
33462
|
|
|
|
|
|
|
rbit32(u32 v) |
33463
|
|
|
|
|
|
|
{ |
33464
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
33465
|
|
|
|
|
|
|
return v; |
33466
|
|
|
|
|
|
|
} |
33467
|
|
|
|
|
|
|
#define rbit32 rbit32 |
33468
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
33469
|
|
|
|
|
|
|
static forceinline u32 |
33470
|
|
|
|
|
|
|
rbit32(u32 v) |
33471
|
|
|
|
|
|
|
{ |
33472
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
33473
|
|
|
|
|
|
|
return v; |
33474
|
|
|
|
|
|
|
} |
33475
|
|
|
|
|
|
|
#define rbit32 rbit32 |
33476
|
|
|
|
|
|
|
#endif |
33477
|
|
|
|
|
|
|
|
33478
|
|
|
|
|
|
|
#endif |
33479
|
|
|
|
|
|
|
|
33480
|
|
|
|
|
|
|
|
33481
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
33482
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
33483
|
|
|
|
|
|
|
|
33484
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
33485
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
33486
|
|
|
|
|
|
|
|
33487
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
33488
|
|
|
|
|
|
|
size_t alignment, size_t size); |
33489
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
33490
|
|
|
|
|
|
|
|
33491
|
|
|
|
|
|
|
#ifdef FREESTANDING |
33492
|
|
|
|
|
|
|
|
33493
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
33494
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
33495
|
|
|
|
|
|
|
|
33496
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
33497
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
33498
|
|
|
|
|
|
|
|
33499
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
33500
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
33501
|
|
|
|
|
|
|
|
33502
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
33503
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
33504
|
|
|
|
|
|
|
|
33505
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
33506
|
|
|
|
|
|
|
#else |
33507
|
|
|
|
|
|
|
#include |
33508
|
|
|
|
|
|
|
#endif |
33509
|
|
|
|
|
|
|
|
33510
|
|
|
|
|
|
|
|
33511
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
33512
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
33513
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
33514
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
33515
|
|
|
|
|
|
|
#else |
33516
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
33517
|
|
|
|
|
|
|
#endif |
33518
|
|
|
|
|
|
|
|
33519
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
33520
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
33521
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
33522
|
|
|
|
|
|
|
|
33523
|
|
|
|
|
|
|
#endif |
33524
|
|
|
|
|
|
|
|
33525
|
|
|
|
|
|
|
|
33526
|
|
|
|
|
|
|
struct cpu_feature { |
33527
|
|
|
|
|
|
|
u32 bit; |
33528
|
|
|
|
|
|
|
const char *name; |
33529
|
|
|
|
|
|
|
}; |
33530
|
|
|
|
|
|
|
|
33531
|
|
|
|
|
|
|
#if defined(TEST_SUPPORT__DO_NOT_USE) && !defined(FREESTANDING) |
33532
|
|
|
|
|
|
|
|
33533
|
|
|
|
|
|
|
static inline void |
33534
|
|
|
|
|
|
|
disable_cpu_features_for_testing(u32 *features, |
33535
|
|
|
|
|
|
|
const struct cpu_feature *feature_table, |
33536
|
|
|
|
|
|
|
size_t feature_table_length) |
33537
|
|
|
|
|
|
|
{ |
33538
|
|
|
|
|
|
|
char *env_value, *strbuf, *p, *saveptr = NULL; |
33539
|
|
|
|
|
|
|
size_t i; |
33540
|
|
|
|
|
|
|
|
33541
|
|
|
|
|
|
|
env_value = getenv("LIBDEFLATE_DISABLE_CPU_FEATURES"); |
33542
|
|
|
|
|
|
|
if (!env_value) |
33543
|
|
|
|
|
|
|
return; |
33544
|
|
|
|
|
|
|
strbuf = strdup(env_value); |
33545
|
|
|
|
|
|
|
if (!strbuf) |
33546
|
|
|
|
|
|
|
abort(); |
33547
|
|
|
|
|
|
|
p = strtok_r(strbuf, ",", &saveptr); |
33548
|
|
|
|
|
|
|
while (p) { |
33549
|
|
|
|
|
|
|
for (i = 0; i < feature_table_length; i++) { |
33550
|
|
|
|
|
|
|
if (strcmp(p, feature_table[i].name) == 0) { |
33551
|
|
|
|
|
|
|
*features &= ~feature_table[i].bit; |
33552
|
|
|
|
|
|
|
break; |
33553
|
|
|
|
|
|
|
} |
33554
|
|
|
|
|
|
|
} |
33555
|
|
|
|
|
|
|
if (i == feature_table_length) { |
33556
|
|
|
|
|
|
|
fprintf(stderr, |
33557
|
|
|
|
|
|
|
"unrecognized feature in LIBDEFLATE_DISABLE_CPU_FEATURES: \"%s\"\n", |
33558
|
|
|
|
|
|
|
p); |
33559
|
|
|
|
|
|
|
abort(); |
33560
|
|
|
|
|
|
|
} |
33561
|
|
|
|
|
|
|
p = strtok_r(NULL, ",", &saveptr); |
33562
|
|
|
|
|
|
|
} |
33563
|
|
|
|
|
|
|
free(strbuf); |
33564
|
|
|
|
|
|
|
} |
33565
|
|
|
|
|
|
|
#else |
33566
|
|
|
|
|
|
|
static inline void |
33567
|
2
|
|
|
|
|
|
disable_cpu_features_for_testing(u32 *features, |
33568
|
|
|
|
|
|
|
const struct cpu_feature *feature_table, |
33569
|
|
|
|
|
|
|
size_t feature_table_length) |
33570
|
|
|
|
|
|
|
{ |
33571
|
2
|
|
|
|
|
|
} |
33572
|
|
|
|
|
|
|
#endif |
33573
|
|
|
|
|
|
|
|
33574
|
|
|
|
|
|
|
#endif |
33575
|
|
|
|
|
|
|
|
33576
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
33577
|
|
|
|
|
|
|
|
33578
|
|
|
|
|
|
|
|
33579
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
33580
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
33581
|
|
|
|
|
|
|
|
33582
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
33583
|
|
|
|
|
|
|
|
33584
|
|
|
|
|
|
|
|
33585
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
33586
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
33587
|
|
|
|
|
|
|
|
33588
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
33589
|
|
|
|
|
|
|
|
33590
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
33591
|
|
|
|
|
|
|
#endif |
33592
|
|
|
|
|
|
|
|
33593
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
33594
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
33595
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
33596
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
33597
|
|
|
|
|
|
|
#else |
33598
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
33599
|
|
|
|
|
|
|
#endif |
33600
|
|
|
|
|
|
|
|
33601
|
|
|
|
|
|
|
|
33602
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
33603
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
33604
|
|
|
|
|
|
|
#else |
33605
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
33606
|
|
|
|
|
|
|
#endif |
33607
|
|
|
|
|
|
|
|
33608
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
33609
|
|
|
|
|
|
|
|
33610
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
33611
|
|
|
|
|
|
|
|
33612
|
|
|
|
|
|
|
|
33613
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
33614
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
33615
|
|
|
|
|
|
|
|
33616
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
33617
|
|
|
|
|
|
|
|
33618
|
|
|
|
|
|
|
|
33619
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
33620
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
33621
|
|
|
|
|
|
|
|
33622
|
|
|
|
|
|
|
#include |
33623
|
|
|
|
|
|
|
#include |
33624
|
|
|
|
|
|
|
|
33625
|
|
|
|
|
|
|
#ifdef __cplusplus |
33626
|
|
|
|
|
|
|
extern "C" { |
33627
|
|
|
|
|
|
|
#endif |
33628
|
|
|
|
|
|
|
|
33629
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
33630
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
33631
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
33632
|
|
|
|
|
|
|
|
33633
|
|
|
|
|
|
|
|
33634
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
33635
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
33636
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
33637
|
|
|
|
|
|
|
# else |
33638
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
33639
|
|
|
|
|
|
|
# endif |
33640
|
|
|
|
|
|
|
#endif |
33641
|
|
|
|
|
|
|
|
33642
|
|
|
|
|
|
|
|
33643
|
|
|
|
|
|
|
|
33644
|
|
|
|
|
|
|
|
33645
|
|
|
|
|
|
|
|
33646
|
|
|
|
|
|
|
struct libdeflate_compressor; |
33647
|
|
|
|
|
|
|
struct libdeflate_options; |
33648
|
|
|
|
|
|
|
|
33649
|
|
|
|
|
|
|
|
33650
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
33651
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
33652
|
|
|
|
|
|
|
|
33653
|
|
|
|
|
|
|
|
33654
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
33655
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
33656
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
33657
|
|
|
|
|
|
|
|
33658
|
|
|
|
|
|
|
|
33659
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
33660
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
33661
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33662
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
33663
|
|
|
|
|
|
|
|
33664
|
|
|
|
|
|
|
|
33665
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
33666
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
33667
|
|
|
|
|
|
|
size_t in_nbytes); |
33668
|
|
|
|
|
|
|
|
33669
|
|
|
|
|
|
|
|
33670
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
33671
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
33672
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33673
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
33674
|
|
|
|
|
|
|
|
33675
|
|
|
|
|
|
|
|
33676
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
33677
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
33678
|
|
|
|
|
|
|
size_t in_nbytes); |
33679
|
|
|
|
|
|
|
|
33680
|
|
|
|
|
|
|
|
33681
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
33682
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
33683
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33684
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
33685
|
|
|
|
|
|
|
|
33686
|
|
|
|
|
|
|
|
33687
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
33688
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
33689
|
|
|
|
|
|
|
size_t in_nbytes); |
33690
|
|
|
|
|
|
|
|
33691
|
|
|
|
|
|
|
|
33692
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
33693
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
33694
|
|
|
|
|
|
|
|
33695
|
|
|
|
|
|
|
|
33696
|
|
|
|
|
|
|
|
33697
|
|
|
|
|
|
|
|
33698
|
|
|
|
|
|
|
|
33699
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
33700
|
|
|
|
|
|
|
struct libdeflate_options; |
33701
|
|
|
|
|
|
|
|
33702
|
|
|
|
|
|
|
|
33703
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
33704
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
33705
|
|
|
|
|
|
|
|
33706
|
|
|
|
|
|
|
|
33707
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
33708
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
33709
|
|
|
|
|
|
|
|
33710
|
|
|
|
|
|
|
|
33711
|
|
|
|
|
|
|
enum libdeflate_result { |
33712
|
|
|
|
|
|
|
|
33713
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
33714
|
|
|
|
|
|
|
|
33715
|
|
|
|
|
|
|
|
33716
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
33717
|
|
|
|
|
|
|
|
33718
|
|
|
|
|
|
|
|
33719
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
33720
|
|
|
|
|
|
|
|
33721
|
|
|
|
|
|
|
|
33722
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
33723
|
|
|
|
|
|
|
}; |
33724
|
|
|
|
|
|
|
|
33725
|
|
|
|
|
|
|
|
33726
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33727
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
33728
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33729
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33730
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33731
|
|
|
|
|
|
|
|
33732
|
|
|
|
|
|
|
|
33733
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33734
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
33735
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33736
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33737
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
33738
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33739
|
|
|
|
|
|
|
|
33740
|
|
|
|
|
|
|
|
33741
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33742
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
33743
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33744
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33745
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33746
|
|
|
|
|
|
|
|
33747
|
|
|
|
|
|
|
|
33748
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33749
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
33750
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33751
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33752
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
33753
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33754
|
|
|
|
|
|
|
|
33755
|
|
|
|
|
|
|
|
33756
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33757
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
33758
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33759
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33760
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33761
|
|
|
|
|
|
|
|
33762
|
|
|
|
|
|
|
|
33763
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33764
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
33765
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33766
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33767
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
33768
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33769
|
|
|
|
|
|
|
|
33770
|
|
|
|
|
|
|
|
33771
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
33772
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
33773
|
|
|
|
|
|
|
|
33774
|
|
|
|
|
|
|
|
33775
|
|
|
|
|
|
|
|
33776
|
|
|
|
|
|
|
|
33777
|
|
|
|
|
|
|
|
33778
|
|
|
|
|
|
|
|
33779
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
33780
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
33781
|
|
|
|
|
|
|
|
33782
|
|
|
|
|
|
|
|
33783
|
|
|
|
|
|
|
|
33784
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
33785
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
33786
|
|
|
|
|
|
|
|
33787
|
|
|
|
|
|
|
|
33788
|
|
|
|
|
|
|
|
33789
|
|
|
|
|
|
|
|
33790
|
|
|
|
|
|
|
|
33791
|
|
|
|
|
|
|
|
33792
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
33793
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
33794
|
|
|
|
|
|
|
void (*free_func)(void *)); |
33795
|
|
|
|
|
|
|
|
33796
|
|
|
|
|
|
|
|
33797
|
|
|
|
|
|
|
struct libdeflate_options { |
33798
|
|
|
|
|
|
|
|
33799
|
|
|
|
|
|
|
|
33800
|
|
|
|
|
|
|
size_t sizeof_options; |
33801
|
|
|
|
|
|
|
|
33802
|
|
|
|
|
|
|
|
33803
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
33804
|
|
|
|
|
|
|
void (*free_func)(void *); |
33805
|
|
|
|
|
|
|
}; |
33806
|
|
|
|
|
|
|
|
33807
|
|
|
|
|
|
|
#ifdef __cplusplus |
33808
|
|
|
|
|
|
|
} |
33809
|
|
|
|
|
|
|
#endif |
33810
|
|
|
|
|
|
|
|
33811
|
|
|
|
|
|
|
#endif |
33812
|
|
|
|
|
|
|
|
33813
|
|
|
|
|
|
|
|
33814
|
|
|
|
|
|
|
#include |
33815
|
|
|
|
|
|
|
#include |
33816
|
|
|
|
|
|
|
#include |
33817
|
|
|
|
|
|
|
#ifdef _MSC_VER |
33818
|
|
|
|
|
|
|
# include |
33819
|
|
|
|
|
|
|
# include |
33820
|
|
|
|
|
|
|
|
33821
|
|
|
|
|
|
|
|
33822
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
33823
|
|
|
|
|
|
|
|
33824
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
33825
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
33826
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
33827
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
33828
|
|
|
|
|
|
|
|
33829
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
33830
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
33831
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
33832
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
33833
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
33834
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
33835
|
|
|
|
|
|
|
#endif |
33836
|
|
|
|
|
|
|
#ifndef FREESTANDING |
33837
|
|
|
|
|
|
|
# include |
33838
|
|
|
|
|
|
|
#endif |
33839
|
|
|
|
|
|
|
|
33840
|
|
|
|
|
|
|
|
33841
|
|
|
|
|
|
|
|
33842
|
|
|
|
|
|
|
|
33843
|
|
|
|
|
|
|
|
33844
|
|
|
|
|
|
|
|
33845
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
33846
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
33847
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
33848
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
33849
|
|
|
|
|
|
|
#ifdef _MSC_VER |
33850
|
|
|
|
|
|
|
# if defined(_M_X64) |
33851
|
|
|
|
|
|
|
# define ARCH_X86_64 |
33852
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
33853
|
|
|
|
|
|
|
# define ARCH_X86_32 |
33854
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
33855
|
|
|
|
|
|
|
# define ARCH_ARM64 |
33856
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
33857
|
|
|
|
|
|
|
# define ARCH_ARM32 |
33858
|
|
|
|
|
|
|
# endif |
33859
|
|
|
|
|
|
|
#else |
33860
|
|
|
|
|
|
|
# if defined(__x86_64__) |
33861
|
|
|
|
|
|
|
# define ARCH_X86_64 |
33862
|
|
|
|
|
|
|
# elif defined(__i386__) |
33863
|
|
|
|
|
|
|
# define ARCH_X86_32 |
33864
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
33865
|
|
|
|
|
|
|
# define ARCH_ARM64 |
33866
|
|
|
|
|
|
|
# elif defined(__arm__) |
33867
|
|
|
|
|
|
|
# define ARCH_ARM32 |
33868
|
|
|
|
|
|
|
# endif |
33869
|
|
|
|
|
|
|
#endif |
33870
|
|
|
|
|
|
|
|
33871
|
|
|
|
|
|
|
|
33872
|
|
|
|
|
|
|
|
33873
|
|
|
|
|
|
|
|
33874
|
|
|
|
|
|
|
|
33875
|
|
|
|
|
|
|
|
33876
|
|
|
|
|
|
|
typedef uint8_t u8; |
33877
|
|
|
|
|
|
|
typedef uint16_t u16; |
33878
|
|
|
|
|
|
|
typedef uint32_t u32; |
33879
|
|
|
|
|
|
|
typedef uint64_t u64; |
33880
|
|
|
|
|
|
|
typedef int8_t s8; |
33881
|
|
|
|
|
|
|
typedef int16_t s16; |
33882
|
|
|
|
|
|
|
typedef int32_t s32; |
33883
|
|
|
|
|
|
|
typedef int64_t s64; |
33884
|
|
|
|
|
|
|
|
33885
|
|
|
|
|
|
|
|
33886
|
|
|
|
|
|
|
#ifdef _MSC_VER |
33887
|
|
|
|
|
|
|
# ifdef _WIN64 |
33888
|
|
|
|
|
|
|
typedef long long ssize_t; |
33889
|
|
|
|
|
|
|
# else |
33890
|
|
|
|
|
|
|
typedef long ssize_t; |
33891
|
|
|
|
|
|
|
# endif |
33892
|
|
|
|
|
|
|
#endif |
33893
|
|
|
|
|
|
|
|
33894
|
|
|
|
|
|
|
|
33895
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
33896
|
|
|
|
|
|
|
|
33897
|
|
|
|
|
|
|
|
33898
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
33899
|
|
|
|
|
|
|
|
33900
|
|
|
|
|
|
|
|
33901
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
33902
|
|
|
|
|
|
|
|
33903
|
|
|
|
|
|
|
|
33904
|
|
|
|
|
|
|
|
33905
|
|
|
|
|
|
|
|
33906
|
|
|
|
|
|
|
|
33907
|
|
|
|
|
|
|
|
33908
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
33909
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
33910
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
33911
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
33912
|
|
|
|
|
|
|
#else |
33913
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
33914
|
|
|
|
|
|
|
#endif |
33915
|
|
|
|
|
|
|
#ifdef __clang__ |
33916
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
33917
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
33918
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
33919
|
|
|
|
|
|
|
# else |
33920
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
33921
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
33922
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
33923
|
|
|
|
|
|
|
# endif |
33924
|
|
|
|
|
|
|
#else |
33925
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
33926
|
|
|
|
|
|
|
#endif |
33927
|
|
|
|
|
|
|
|
33928
|
|
|
|
|
|
|
|
33929
|
|
|
|
|
|
|
#ifndef __has_attribute |
33930
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
33931
|
|
|
|
|
|
|
#endif |
33932
|
|
|
|
|
|
|
#ifndef __has_builtin |
33933
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
33934
|
|
|
|
|
|
|
#endif |
33935
|
|
|
|
|
|
|
|
33936
|
|
|
|
|
|
|
|
33937
|
|
|
|
|
|
|
#ifdef _MSC_VER |
33938
|
|
|
|
|
|
|
# define inline __inline |
33939
|
|
|
|
|
|
|
#endif |
33940
|
|
|
|
|
|
|
|
33941
|
|
|
|
|
|
|
|
33942
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
33943
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
33944
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33945
|
|
|
|
|
|
|
# define forceinline __forceinline |
33946
|
|
|
|
|
|
|
#else |
33947
|
|
|
|
|
|
|
# define forceinline inline |
33948
|
|
|
|
|
|
|
#endif |
33949
|
|
|
|
|
|
|
|
33950
|
|
|
|
|
|
|
|
33951
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
33952
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
33953
|
|
|
|
|
|
|
#else |
33954
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
33955
|
|
|
|
|
|
|
#endif |
33956
|
|
|
|
|
|
|
|
33957
|
|
|
|
|
|
|
|
33958
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
33959
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
33960
|
|
|
|
|
|
|
# define restrict __restrict__ |
33961
|
|
|
|
|
|
|
# else |
33962
|
|
|
|
|
|
|
# define restrict |
33963
|
|
|
|
|
|
|
# endif |
33964
|
|
|
|
|
|
|
#endif |
33965
|
|
|
|
|
|
|
|
33966
|
|
|
|
|
|
|
|
33967
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
33968
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
33969
|
|
|
|
|
|
|
#else |
33970
|
|
|
|
|
|
|
# define likely(expr) (expr) |
33971
|
|
|
|
|
|
|
#endif |
33972
|
|
|
|
|
|
|
|
33973
|
|
|
|
|
|
|
|
33974
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
33975
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
33976
|
|
|
|
|
|
|
#else |
33977
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
33978
|
|
|
|
|
|
|
#endif |
33979
|
|
|
|
|
|
|
|
33980
|
|
|
|
|
|
|
|
33981
|
|
|
|
|
|
|
#undef prefetchr |
33982
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
33983
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
33984
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33985
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
33986
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
33987
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
33988
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
33989
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
33990
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
33991
|
|
|
|
|
|
|
# endif |
33992
|
|
|
|
|
|
|
#endif |
33993
|
|
|
|
|
|
|
#ifndef prefetchr |
33994
|
|
|
|
|
|
|
# define prefetchr(addr) |
33995
|
|
|
|
|
|
|
#endif |
33996
|
|
|
|
|
|
|
|
33997
|
|
|
|
|
|
|
|
33998
|
|
|
|
|
|
|
#undef prefetchw |
33999
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
34000
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
34001
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34002
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
34003
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
34004
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
34005
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
34006
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
34007
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
34008
|
|
|
|
|
|
|
# endif |
34009
|
|
|
|
|
|
|
#endif |
34010
|
|
|
|
|
|
|
#ifndef prefetchw |
34011
|
|
|
|
|
|
|
# define prefetchw(addr) |
34012
|
|
|
|
|
|
|
#endif |
34013
|
|
|
|
|
|
|
|
34014
|
|
|
|
|
|
|
|
34015
|
|
|
|
|
|
|
#undef _aligned_attribute |
34016
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
34017
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
34018
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34019
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
34020
|
|
|
|
|
|
|
#endif |
34021
|
|
|
|
|
|
|
|
34022
|
|
|
|
|
|
|
|
34023
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
34024
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
34025
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
34026
|
|
|
|
|
|
|
#else |
34027
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
34028
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
34029
|
|
|
|
|
|
|
#endif |
34030
|
|
|
|
|
|
|
|
34031
|
|
|
|
|
|
|
|
34032
|
|
|
|
|
|
|
|
34033
|
|
|
|
|
|
|
|
34034
|
|
|
|
|
|
|
|
34035
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
34036
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
34037
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
34038
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
34039
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
34040
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
34041
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
34042
|
|
|
|
|
|
|
|
34043
|
|
|
|
|
|
|
|
34044
|
|
|
|
|
|
|
|
34045
|
|
|
|
|
|
|
|
34046
|
|
|
|
|
|
|
|
34047
|
|
|
|
|
|
|
|
34048
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
34049
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
34050
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34051
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
34052
|
|
|
|
|
|
|
#else |
34053
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
34054
|
|
|
|
|
|
|
{ |
34055
|
|
|
|
|
|
|
union { |
34056
|
|
|
|
|
|
|
u32 w; |
34057
|
|
|
|
|
|
|
u8 b; |
34058
|
|
|
|
|
|
|
} u; |
34059
|
|
|
|
|
|
|
|
34060
|
|
|
|
|
|
|
u.w = 1; |
34061
|
|
|
|
|
|
|
return u.b; |
34062
|
|
|
|
|
|
|
} |
34063
|
|
|
|
|
|
|
#endif |
34064
|
|
|
|
|
|
|
|
34065
|
|
|
|
|
|
|
|
34066
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
34067
|
|
|
|
|
|
|
{ |
34068
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
34069
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
34070
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34071
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
34072
|
|
|
|
|
|
|
#else |
34073
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
34074
|
|
|
|
|
|
|
#endif |
34075
|
|
|
|
|
|
|
} |
34076
|
|
|
|
|
|
|
|
34077
|
|
|
|
|
|
|
|
34078
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
34079
|
|
|
|
|
|
|
{ |
34080
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
34081
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
34082
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34083
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
34084
|
|
|
|
|
|
|
#else |
34085
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
34086
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
34087
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
34088
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
34089
|
|
|
|
|
|
|
#endif |
34090
|
|
|
|
|
|
|
} |
34091
|
|
|
|
|
|
|
|
34092
|
|
|
|
|
|
|
|
34093
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
34094
|
|
|
|
|
|
|
{ |
34095
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
34096
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
34097
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34098
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
34099
|
|
|
|
|
|
|
#else |
34100
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
34101
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
34102
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
34103
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
34104
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
34105
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
34106
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
34107
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
34108
|
|
|
|
|
|
|
#endif |
34109
|
|
|
|
|
|
|
} |
34110
|
|
|
|
|
|
|
|
34111
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
34112
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
34113
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
34114
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
34115
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
34116
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
34117
|
|
|
|
|
|
|
|
34118
|
|
|
|
|
|
|
|
34119
|
|
|
|
|
|
|
|
34120
|
|
|
|
|
|
|
|
34121
|
|
|
|
|
|
|
|
34122
|
|
|
|
|
|
|
|
34123
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
34124
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
34125
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
34126
|
|
|
|
|
|
|
defined(__wasm__)) |
34127
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
34128
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34129
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
34130
|
|
|
|
|
|
|
#else |
34131
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
34132
|
|
|
|
|
|
|
#endif |
34133
|
|
|
|
|
|
|
|
34134
|
|
|
|
|
|
|
|
34135
|
|
|
|
|
|
|
|
34136
|
|
|
|
|
|
|
#ifdef FREESTANDING |
34137
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
34138
|
|
|
|
|
|
|
#else |
34139
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
34140
|
|
|
|
|
|
|
#endif |
34141
|
|
|
|
|
|
|
|
34142
|
|
|
|
|
|
|
|
34143
|
|
|
|
|
|
|
|
34144
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
34145
|
|
|
|
|
|
|
static forceinline type \ |
34146
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
34147
|
|
|
|
|
|
|
{ \ |
34148
|
|
|
|
|
|
|
type v; \ |
34149
|
|
|
|
|
|
|
\ |
34150
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
34151
|
|
|
|
|
|
|
return v; \ |
34152
|
|
|
|
|
|
|
} \ |
34153
|
|
|
|
|
|
|
\ |
34154
|
|
|
|
|
|
|
static forceinline void \ |
34155
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
34156
|
|
|
|
|
|
|
{ \ |
34157
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
34158
|
|
|
|
|
|
|
} |
34159
|
|
|
|
|
|
|
|
34160
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
34161
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
34162
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
34163
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
34164
|
|
|
|
|
|
|
|
34165
|
|
|
|
|
|
|
#undef MEMCOPY |
34166
|
|
|
|
|
|
|
|
34167
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
34168
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
34169
|
|
|
|
|
|
|
|
34170
|
|
|
|
|
|
|
|
34171
|
|
|
|
|
|
|
|
34172
|
|
|
|
|
|
|
static forceinline u16 |
34173
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
34174
|
|
|
|
|
|
|
{ |
34175
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34176
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
34177
|
|
|
|
|
|
|
else |
34178
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
34179
|
|
|
|
|
|
|
} |
34180
|
|
|
|
|
|
|
|
34181
|
|
|
|
|
|
|
static forceinline u16 |
34182
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
34183
|
|
|
|
|
|
|
{ |
34184
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34185
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
34186
|
|
|
|
|
|
|
else |
34187
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
34188
|
|
|
|
|
|
|
} |
34189
|
|
|
|
|
|
|
|
34190
|
|
|
|
|
|
|
static forceinline u32 |
34191
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
34192
|
|
|
|
|
|
|
{ |
34193
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34194
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
34195
|
|
|
|
|
|
|
else |
34196
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
34197
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
34198
|
|
|
|
|
|
|
} |
34199
|
|
|
|
|
|
|
|
34200
|
|
|
|
|
|
|
static forceinline u32 |
34201
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
34202
|
|
|
|
|
|
|
{ |
34203
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34204
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
34205
|
|
|
|
|
|
|
else |
34206
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
34207
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
34208
|
|
|
|
|
|
|
} |
34209
|
|
|
|
|
|
|
|
34210
|
|
|
|
|
|
|
static forceinline u64 |
34211
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
34212
|
|
|
|
|
|
|
{ |
34213
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34214
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
34215
|
|
|
|
|
|
|
else |
34216
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
34217
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
34218
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
34219
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
34220
|
|
|
|
|
|
|
} |
34221
|
|
|
|
|
|
|
|
34222
|
|
|
|
|
|
|
static forceinline machine_word_t |
34223
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
34224
|
|
|
|
|
|
|
{ |
34225
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
34226
|
|
|
|
|
|
|
if (WORDBITS == 32) |
34227
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
34228
|
|
|
|
|
|
|
else |
34229
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
34230
|
|
|
|
|
|
|
} |
34231
|
|
|
|
|
|
|
|
34232
|
|
|
|
|
|
|
|
34233
|
|
|
|
|
|
|
|
34234
|
|
|
|
|
|
|
static forceinline void |
34235
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
34236
|
|
|
|
|
|
|
{ |
34237
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34238
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
34239
|
|
|
|
|
|
|
} else { |
34240
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
34241
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
34242
|
|
|
|
|
|
|
} |
34243
|
|
|
|
|
|
|
} |
34244
|
|
|
|
|
|
|
|
34245
|
|
|
|
|
|
|
static forceinline void |
34246
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
34247
|
|
|
|
|
|
|
{ |
34248
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34249
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
34250
|
|
|
|
|
|
|
} else { |
34251
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
34252
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
34253
|
|
|
|
|
|
|
} |
34254
|
|
|
|
|
|
|
} |
34255
|
|
|
|
|
|
|
|
34256
|
|
|
|
|
|
|
static forceinline void |
34257
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
34258
|
|
|
|
|
|
|
{ |
34259
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34260
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
34261
|
|
|
|
|
|
|
} else { |
34262
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
34263
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
34264
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
34265
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
34266
|
|
|
|
|
|
|
} |
34267
|
|
|
|
|
|
|
} |
34268
|
|
|
|
|
|
|
|
34269
|
|
|
|
|
|
|
static forceinline void |
34270
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
34271
|
|
|
|
|
|
|
{ |
34272
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34273
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
34274
|
|
|
|
|
|
|
} else { |
34275
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
34276
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
34277
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
34278
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
34279
|
|
|
|
|
|
|
} |
34280
|
|
|
|
|
|
|
} |
34281
|
|
|
|
|
|
|
|
34282
|
|
|
|
|
|
|
static forceinline void |
34283
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
34284
|
|
|
|
|
|
|
{ |
34285
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34286
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
34287
|
|
|
|
|
|
|
} else { |
34288
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
34289
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
34290
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
34291
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
34292
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
34293
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
34294
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
34295
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
34296
|
|
|
|
|
|
|
} |
34297
|
|
|
|
|
|
|
} |
34298
|
|
|
|
|
|
|
|
34299
|
|
|
|
|
|
|
static forceinline void |
34300
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
34301
|
|
|
|
|
|
|
{ |
34302
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
34303
|
|
|
|
|
|
|
if (WORDBITS == 32) |
34304
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
34305
|
|
|
|
|
|
|
else |
34306
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
34307
|
|
|
|
|
|
|
} |
34308
|
|
|
|
|
|
|
|
34309
|
|
|
|
|
|
|
|
34310
|
|
|
|
|
|
|
|
34311
|
|
|
|
|
|
|
|
34312
|
|
|
|
|
|
|
|
34313
|
|
|
|
|
|
|
|
34314
|
|
|
|
|
|
|
|
34315
|
|
|
|
|
|
|
static forceinline unsigned |
34316
|
|
|
|
|
|
|
bsr32(u32 v) |
34317
|
|
|
|
|
|
|
{ |
34318
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
34319
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
34320
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34321
|
|
|
|
|
|
|
unsigned long i; |
34322
|
|
|
|
|
|
|
|
34323
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
34324
|
|
|
|
|
|
|
return i; |
34325
|
|
|
|
|
|
|
#else |
34326
|
|
|
|
|
|
|
unsigned i = 0; |
34327
|
|
|
|
|
|
|
|
34328
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
34329
|
|
|
|
|
|
|
i++; |
34330
|
|
|
|
|
|
|
return i; |
34331
|
|
|
|
|
|
|
#endif |
34332
|
|
|
|
|
|
|
} |
34333
|
|
|
|
|
|
|
|
34334
|
|
|
|
|
|
|
static forceinline unsigned |
34335
|
|
|
|
|
|
|
bsr64(u64 v) |
34336
|
|
|
|
|
|
|
{ |
34337
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
34338
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
34339
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
34340
|
|
|
|
|
|
|
unsigned long i; |
34341
|
|
|
|
|
|
|
|
34342
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
34343
|
|
|
|
|
|
|
return i; |
34344
|
|
|
|
|
|
|
#else |
34345
|
|
|
|
|
|
|
unsigned i = 0; |
34346
|
|
|
|
|
|
|
|
34347
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
34348
|
|
|
|
|
|
|
i++; |
34349
|
|
|
|
|
|
|
return i; |
34350
|
|
|
|
|
|
|
#endif |
34351
|
|
|
|
|
|
|
} |
34352
|
|
|
|
|
|
|
|
34353
|
|
|
|
|
|
|
static forceinline unsigned |
34354
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
34355
|
|
|
|
|
|
|
{ |
34356
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
34357
|
|
|
|
|
|
|
if (WORDBITS == 32) |
34358
|
|
|
|
|
|
|
return bsr32(v); |
34359
|
|
|
|
|
|
|
else |
34360
|
|
|
|
|
|
|
return bsr64(v); |
34361
|
|
|
|
|
|
|
} |
34362
|
|
|
|
|
|
|
|
34363
|
|
|
|
|
|
|
|
34364
|
|
|
|
|
|
|
|
34365
|
|
|
|
|
|
|
static forceinline unsigned |
34366
|
|
|
|
|
|
|
bsf32(u32 v) |
34367
|
|
|
|
|
|
|
{ |
34368
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
34369
|
|
|
|
|
|
|
return __builtin_ctz(v); |
34370
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34371
|
|
|
|
|
|
|
unsigned long i; |
34372
|
|
|
|
|
|
|
|
34373
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
34374
|
|
|
|
|
|
|
return i; |
34375
|
|
|
|
|
|
|
#else |
34376
|
|
|
|
|
|
|
unsigned i = 0; |
34377
|
|
|
|
|
|
|
|
34378
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
34379
|
|
|
|
|
|
|
i++; |
34380
|
|
|
|
|
|
|
return i; |
34381
|
|
|
|
|
|
|
#endif |
34382
|
|
|
|
|
|
|
} |
34383
|
|
|
|
|
|
|
|
34384
|
|
|
|
|
|
|
static forceinline unsigned |
34385
|
|
|
|
|
|
|
bsf64(u64 v) |
34386
|
|
|
|
|
|
|
{ |
34387
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
34388
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
34389
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
34390
|
|
|
|
|
|
|
unsigned long i; |
34391
|
|
|
|
|
|
|
|
34392
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
34393
|
|
|
|
|
|
|
return i; |
34394
|
|
|
|
|
|
|
#else |
34395
|
|
|
|
|
|
|
unsigned i = 0; |
34396
|
|
|
|
|
|
|
|
34397
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
34398
|
|
|
|
|
|
|
i++; |
34399
|
|
|
|
|
|
|
return i; |
34400
|
|
|
|
|
|
|
#endif |
34401
|
|
|
|
|
|
|
} |
34402
|
|
|
|
|
|
|
|
34403
|
|
|
|
|
|
|
static forceinline unsigned |
34404
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
34405
|
|
|
|
|
|
|
{ |
34406
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
34407
|
|
|
|
|
|
|
if (WORDBITS == 32) |
34408
|
|
|
|
|
|
|
return bsf32(v); |
34409
|
|
|
|
|
|
|
else |
34410
|
|
|
|
|
|
|
return bsf64(v); |
34411
|
|
|
|
|
|
|
} |
34412
|
|
|
|
|
|
|
|
34413
|
|
|
|
|
|
|
|
34414
|
|
|
|
|
|
|
#undef rbit32 |
34415
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
34416
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
34417
|
|
|
|
|
|
|
static forceinline u32 |
34418
|
|
|
|
|
|
|
rbit32(u32 v) |
34419
|
|
|
|
|
|
|
{ |
34420
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
34421
|
|
|
|
|
|
|
return v; |
34422
|
|
|
|
|
|
|
} |
34423
|
|
|
|
|
|
|
#define rbit32 rbit32 |
34424
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
34425
|
|
|
|
|
|
|
static forceinline u32 |
34426
|
|
|
|
|
|
|
rbit32(u32 v) |
34427
|
|
|
|
|
|
|
{ |
34428
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
34429
|
|
|
|
|
|
|
return v; |
34430
|
|
|
|
|
|
|
} |
34431
|
|
|
|
|
|
|
#define rbit32 rbit32 |
34432
|
|
|
|
|
|
|
#endif |
34433
|
|
|
|
|
|
|
|
34434
|
|
|
|
|
|
|
#endif |
34435
|
|
|
|
|
|
|
|
34436
|
|
|
|
|
|
|
|
34437
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
34438
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
34439
|
|
|
|
|
|
|
|
34440
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
34441
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
34442
|
|
|
|
|
|
|
|
34443
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
34444
|
|
|
|
|
|
|
size_t alignment, size_t size); |
34445
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
34446
|
|
|
|
|
|
|
|
34447
|
|
|
|
|
|
|
#ifdef FREESTANDING |
34448
|
|
|
|
|
|
|
|
34449
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
34450
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
34451
|
|
|
|
|
|
|
|
34452
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
34453
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
34454
|
|
|
|
|
|
|
|
34455
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
34456
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
34457
|
|
|
|
|
|
|
|
34458
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
34459
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
34460
|
|
|
|
|
|
|
|
34461
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
34462
|
|
|
|
|
|
|
#else |
34463
|
|
|
|
|
|
|
#include |
34464
|
|
|
|
|
|
|
#endif |
34465
|
|
|
|
|
|
|
|
34466
|
|
|
|
|
|
|
|
34467
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
34468
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
34469
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
34470
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
34471
|
|
|
|
|
|
|
#else |
34472
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
34473
|
|
|
|
|
|
|
#endif |
34474
|
|
|
|
|
|
|
|
34475
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
34476
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
34477
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
34478
|
|
|
|
|
|
|
|
34479
|
|
|
|
|
|
|
#endif |
34480
|
|
|
|
|
|
|
|
34481
|
|
|
|
|
|
|
|
34482
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
34483
|
|
|
|
|
|
|
|
34484
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
34485
|
|
|
|
|
|
|
|
34486
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
34487
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
34488
|
|
|
|
|
|
|
(defined(__linux__) || \ |
34489
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
34490
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
34491
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
34492
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
34493
|
|
|
|
|
|
|
#endif |
34494
|
|
|
|
|
|
|
|
34495
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
34496
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
34497
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
34498
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
34499
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
34500
|
|
|
|
|
|
|
|
34501
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
34502
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
34503
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
34504
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
34505
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
34506
|
|
|
|
|
|
|
|
34507
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
34508
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
34509
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
34510
|
|
|
|
|
|
|
|
34511
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
34512
|
|
|
|
|
|
|
|
34513
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
34514
|
|
|
|
|
|
|
{ |
34515
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
34516
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
34517
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
34518
|
|
|
|
|
|
|
} |
34519
|
|
|
|
|
|
|
#else |
34520
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
34521
|
|
|
|
|
|
|
#endif |
34522
|
|
|
|
|
|
|
|
34523
|
|
|
|
|
|
|
|
34524
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
34525
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
34526
|
|
|
|
|
|
|
#else |
34527
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
34528
|
|
|
|
|
|
|
#endif |
34529
|
|
|
|
|
|
|
|
34530
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
34531
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
34532
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
34533
|
|
|
|
|
|
|
#else |
34534
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
34535
|
|
|
|
|
|
|
#endif |
34536
|
|
|
|
|
|
|
|
34537
|
|
|
|
|
|
|
|
34538
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
34539
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
34540
|
|
|
|
|
|
|
#else |
34541
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
34542
|
|
|
|
|
|
|
#endif |
34543
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
34544
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
34545
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
34546
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
34547
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
34548
|
|
|
|
|
|
|
\ |
34549
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
34550
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
34551
|
|
|
|
|
|
|
|
34552
|
|
|
|
|
|
|
# ifdef _MSC_VER |
34553
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
34554
|
|
|
|
|
|
|
# else |
34555
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
34556
|
|
|
|
|
|
|
# endif |
34557
|
|
|
|
|
|
|
#else |
34558
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
34559
|
|
|
|
|
|
|
#endif |
34560
|
|
|
|
|
|
|
|
34561
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
34562
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
34563
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
34564
|
|
|
|
|
|
|
#else |
34565
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
34566
|
|
|
|
|
|
|
#endif |
34567
|
|
|
|
|
|
|
|
34568
|
|
|
|
|
|
|
|
34569
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
34570
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
34571
|
|
|
|
|
|
|
#else |
34572
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
34573
|
|
|
|
|
|
|
#endif |
34574
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
34575
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
34576
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
34577
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
34578
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
34579
|
|
|
|
|
|
|
|
34580
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
34581
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
34582
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
34583
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
34584
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
34585
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
34586
|
|
|
|
|
|
|
# endif |
34587
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
34588
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
34589
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
34590
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
34591
|
|
|
|
|
|
|
# endif |
34592
|
|
|
|
|
|
|
#endif |
34593
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
34594
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
34595
|
|
|
|
|
|
|
#endif |
34596
|
|
|
|
|
|
|
|
34597
|
|
|
|
|
|
|
|
34598
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
34599
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
34600
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
34601
|
|
|
|
|
|
|
# else |
34602
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
34603
|
|
|
|
|
|
|
# endif |
34604
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
34605
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
34606
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
34607
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
34608
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
34609
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
34610
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
34611
|
|
|
|
|
|
|
#else |
34612
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
34613
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
34614
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
34615
|
|
|
|
|
|
|
#endif |
34616
|
|
|
|
|
|
|
|
34617
|
|
|
|
|
|
|
|
34618
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
34619
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
34620
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
34621
|
|
|
|
|
|
|
# else |
34622
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
34623
|
|
|
|
|
|
|
# endif |
34624
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
34625
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
34626
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
34627
|
|
|
|
|
|
|
defined(_MSC_VER))) |
34628
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
34629
|
|
|
|
|
|
|
# else |
34630
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
34631
|
|
|
|
|
|
|
# endif |
34632
|
|
|
|
|
|
|
#else |
34633
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
34634
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
34635
|
|
|
|
|
|
|
#endif |
34636
|
|
|
|
|
|
|
|
34637
|
|
|
|
|
|
|
|
34638
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
34639
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
34640
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
34641
|
|
|
|
|
|
|
#endif |
34642
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
34643
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
34644
|
|
|
|
|
|
|
#endif |
34645
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
34646
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
34647
|
|
|
|
|
|
|
#endif |
34648
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
34649
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
34650
|
|
|
|
|
|
|
# include |
34651
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
34652
|
|
|
|
|
|
|
#endif |
34653
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
34654
|
|
|
|
|
|
|
# include |
34655
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
34656
|
|
|
|
|
|
|
#endif |
34657
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
34658
|
|
|
|
|
|
|
# include |
34659
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
34660
|
|
|
|
|
|
|
#endif |
34661
|
|
|
|
|
|
|
|
34662
|
|
|
|
|
|
|
#endif |
34663
|
|
|
|
|
|
|
|
34664
|
|
|
|
|
|
|
#endif |
34665
|
|
|
|
|
|
|
|
34666
|
|
|
|
|
|
|
|
34667
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
34668
|
|
|
|
|
|
|
|
34669
|
|
|
|
|
|
|
#ifdef __linux__ |
34670
|
|
|
|
|
|
|
|
34671
|
|
|
|
|
|
|
|
34672
|
|
|
|
|
|
|
#include |
34673
|
|
|
|
|
|
|
#include |
34674
|
|
|
|
|
|
|
#include |
34675
|
|
|
|
|
|
|
#include |
34676
|
|
|
|
|
|
|
|
34677
|
|
|
|
|
|
|
#define AT_HWCAP 16 |
34678
|
|
|
|
|
|
|
#define AT_HWCAP2 26 |
34679
|
|
|
|
|
|
|
|
34680
|
|
|
|
|
|
|
static void scan_auxv(unsigned long *hwcap, unsigned long *hwcap2) |
34681
|
|
|
|
|
|
|
{ |
34682
|
|
|
|
|
|
|
int fd; |
34683
|
|
|
|
|
|
|
unsigned long auxbuf[32]; |
34684
|
|
|
|
|
|
|
int filled = 0; |
34685
|
|
|
|
|
|
|
int i; |
34686
|
|
|
|
|
|
|
|
34687
|
|
|
|
|
|
|
fd = open("/proc/self/auxv", O_RDONLY); |
34688
|
|
|
|
|
|
|
if (fd < 0) |
34689
|
|
|
|
|
|
|
return; |
34690
|
|
|
|
|
|
|
|
34691
|
|
|
|
|
|
|
for (;;) { |
34692
|
|
|
|
|
|
|
do { |
34693
|
|
|
|
|
|
|
int ret = read(fd, &((char *)auxbuf)[filled], |
34694
|
|
|
|
|
|
|
sizeof(auxbuf) - filled); |
34695
|
|
|
|
|
|
|
if (ret <= 0) { |
34696
|
|
|
|
|
|
|
if (ret < 0 && errno == EINTR) |
34697
|
|
|
|
|
|
|
continue; |
34698
|
|
|
|
|
|
|
goto out; |
34699
|
|
|
|
|
|
|
} |
34700
|
|
|
|
|
|
|
filled += ret; |
34701
|
|
|
|
|
|
|
} while (filled < 2 * sizeof(long)); |
34702
|
|
|
|
|
|
|
|
34703
|
|
|
|
|
|
|
i = 0; |
34704
|
|
|
|
|
|
|
do { |
34705
|
|
|
|
|
|
|
unsigned long type = auxbuf[i]; |
34706
|
|
|
|
|
|
|
unsigned long value = auxbuf[i + 1]; |
34707
|
|
|
|
|
|
|
|
34708
|
|
|
|
|
|
|
if (type == AT_HWCAP) |
34709
|
|
|
|
|
|
|
*hwcap = value; |
34710
|
|
|
|
|
|
|
else if (type == AT_HWCAP2) |
34711
|
|
|
|
|
|
|
*hwcap2 = value; |
34712
|
|
|
|
|
|
|
i += 2; |
34713
|
|
|
|
|
|
|
filled -= 2 * sizeof(long); |
34714
|
|
|
|
|
|
|
} while (filled >= 2 * sizeof(long)); |
34715
|
|
|
|
|
|
|
|
34716
|
|
|
|
|
|
|
memmove(auxbuf, &auxbuf[i], filled); |
34717
|
|
|
|
|
|
|
} |
34718
|
|
|
|
|
|
|
out: |
34719
|
|
|
|
|
|
|
close(fd); |
34720
|
|
|
|
|
|
|
} |
34721
|
|
|
|
|
|
|
|
34722
|
|
|
|
|
|
|
static u32 query_arm_cpu_features(void) |
34723
|
|
|
|
|
|
|
{ |
34724
|
|
|
|
|
|
|
u32 features = 0; |
34725
|
|
|
|
|
|
|
unsigned long hwcap = 0; |
34726
|
|
|
|
|
|
|
unsigned long hwcap2 = 0; |
34727
|
|
|
|
|
|
|
|
34728
|
|
|
|
|
|
|
scan_auxv(&hwcap, &hwcap2); |
34729
|
|
|
|
|
|
|
|
34730
|
|
|
|
|
|
|
#ifdef ARCH_ARM32 |
34731
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(long) == 4); |
34732
|
|
|
|
|
|
|
if (hwcap & (1 << 12)) |
34733
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_NEON; |
34734
|
|
|
|
|
|
|
if (hwcap2 & (1 << 1)) |
34735
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_PMULL; |
34736
|
|
|
|
|
|
|
if (hwcap2 & (1 << 4)) |
34737
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_CRC32; |
34738
|
|
|
|
|
|
|
#else |
34739
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(long) == 8); |
34740
|
|
|
|
|
|
|
if (hwcap & (1 << 1)) |
34741
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_NEON; |
34742
|
|
|
|
|
|
|
if (hwcap & (1 << 4)) |
34743
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_PMULL; |
34744
|
|
|
|
|
|
|
if (hwcap & (1 << 7)) |
34745
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_CRC32; |
34746
|
|
|
|
|
|
|
if (hwcap & (1 << 17)) |
34747
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_SHA3; |
34748
|
|
|
|
|
|
|
if (hwcap & (1 << 20)) |
34749
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_DOTPROD; |
34750
|
|
|
|
|
|
|
#endif |
34751
|
|
|
|
|
|
|
return features; |
34752
|
|
|
|
|
|
|
} |
34753
|
|
|
|
|
|
|
|
34754
|
|
|
|
|
|
|
#elif defined(__APPLE__) |
34755
|
|
|
|
|
|
|
|
34756
|
|
|
|
|
|
|
|
34757
|
|
|
|
|
|
|
#include |
34758
|
|
|
|
|
|
|
#include |
34759
|
|
|
|
|
|
|
|
34760
|
|
|
|
|
|
|
static const struct { |
34761
|
|
|
|
|
|
|
const char *name; |
34762
|
|
|
|
|
|
|
u32 feature; |
34763
|
|
|
|
|
|
|
} feature_sysctls[] = { |
34764
|
|
|
|
|
|
|
{ "hw.optional.neon", ARM_CPU_FEATURE_NEON }, |
34765
|
|
|
|
|
|
|
{ "hw.optional.AdvSIMD", ARM_CPU_FEATURE_NEON }, |
34766
|
|
|
|
|
|
|
{ "hw.optional.arm.FEAT_PMULL", ARM_CPU_FEATURE_PMULL }, |
34767
|
|
|
|
|
|
|
{ "hw.optional.armv8_crc32", ARM_CPU_FEATURE_CRC32 }, |
34768
|
|
|
|
|
|
|
{ "hw.optional.armv8_2_sha3", ARM_CPU_FEATURE_SHA3 }, |
34769
|
|
|
|
|
|
|
{ "hw.optional.arm.FEAT_SHA3", ARM_CPU_FEATURE_SHA3 }, |
34770
|
|
|
|
|
|
|
{ "hw.optional.arm.FEAT_DotProd", ARM_CPU_FEATURE_DOTPROD }, |
34771
|
|
|
|
|
|
|
}; |
34772
|
|
|
|
|
|
|
|
34773
|
|
|
|
|
|
|
static u32 query_arm_cpu_features(void) |
34774
|
|
|
|
|
|
|
{ |
34775
|
|
|
|
|
|
|
u32 features = 0; |
34776
|
|
|
|
|
|
|
size_t i; |
34777
|
|
|
|
|
|
|
|
34778
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(feature_sysctls); i++) { |
34779
|
|
|
|
|
|
|
const char *name = feature_sysctls[i].name; |
34780
|
|
|
|
|
|
|
u32 val = 0; |
34781
|
|
|
|
|
|
|
size_t valsize = sizeof(val); |
34782
|
|
|
|
|
|
|
|
34783
|
|
|
|
|
|
|
if (sysctlbyname(name, &val, &valsize, NULL, 0) == 0 && |
34784
|
|
|
|
|
|
|
valsize == sizeof(val) && val == 1) |
34785
|
|
|
|
|
|
|
features |= feature_sysctls[i].feature; |
34786
|
|
|
|
|
|
|
} |
34787
|
|
|
|
|
|
|
return features; |
34788
|
|
|
|
|
|
|
} |
34789
|
|
|
|
|
|
|
#elif defined(_WIN32) |
34790
|
|
|
|
|
|
|
|
34791
|
|
|
|
|
|
|
#include |
34792
|
|
|
|
|
|
|
|
34793
|
|
|
|
|
|
|
static u32 query_arm_cpu_features(void) |
34794
|
|
|
|
|
|
|
{ |
34795
|
|
|
|
|
|
|
u32 features = ARM_CPU_FEATURE_NEON; |
34796
|
|
|
|
|
|
|
|
34797
|
|
|
|
|
|
|
if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) |
34798
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_PMULL; |
34799
|
|
|
|
|
|
|
if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)) |
34800
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_CRC32; |
34801
|
|
|
|
|
|
|
|
34802
|
|
|
|
|
|
|
|
34803
|
|
|
|
|
|
|
|
34804
|
|
|
|
|
|
|
return features; |
34805
|
|
|
|
|
|
|
} |
34806
|
|
|
|
|
|
|
#else |
34807
|
|
|
|
|
|
|
#error "unhandled case" |
34808
|
|
|
|
|
|
|
#endif |
34809
|
|
|
|
|
|
|
|
34810
|
|
|
|
|
|
|
static const struct cpu_feature arm_cpu_feature_table[] = { |
34811
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_NEON, "neon"}, |
34812
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_PMULL, "pmull"}, |
34813
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_CRC32, "crc32"}, |
34814
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_SHA3, "sha3"}, |
34815
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_DOTPROD, "dotprod"}, |
34816
|
|
|
|
|
|
|
}; |
34817
|
|
|
|
|
|
|
|
34818
|
|
|
|
|
|
|
volatile u32 libdeflate_arm_cpu_features = 0; |
34819
|
|
|
|
|
|
|
|
34820
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void) |
34821
|
|
|
|
|
|
|
{ |
34822
|
|
|
|
|
|
|
u32 features = query_arm_cpu_features(); |
34823
|
|
|
|
|
|
|
|
34824
|
|
|
|
|
|
|
disable_cpu_features_for_testing(&features, arm_cpu_feature_table, |
34825
|
|
|
|
|
|
|
ARRAY_LEN(arm_cpu_feature_table)); |
34826
|
|
|
|
|
|
|
|
34827
|
|
|
|
|
|
|
libdeflate_arm_cpu_features = features | ARM_CPU_FEATURES_KNOWN; |
34828
|
|
|
|
|
|
|
} |
34829
|
|
|
|
|
|
|
|
34830
|
|
|
|
|
|
|
#endif |
34831
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.19/lib/x86/cpu_features.c */ |
34832
|
|
|
|
|
|
|
|
34833
|
|
|
|
|
|
|
|
34834
|
|
|
|
|
|
|
/* #include "cpu_features_common.h" - no include guard */ |
34835
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
34836
|
|
|
|
|
|
|
|
34837
|
|
|
|
|
|
|
|
34838
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
34839
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
34840
|
|
|
|
|
|
|
|
34841
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
34842
|
|
|
|
|
|
|
|
34843
|
|
|
|
|
|
|
|
34844
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
34845
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
34846
|
|
|
|
|
|
|
|
34847
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
34848
|
|
|
|
|
|
|
|
34849
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
34850
|
|
|
|
|
|
|
#endif |
34851
|
|
|
|
|
|
|
|
34852
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
34853
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
34854
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
34855
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
34856
|
|
|
|
|
|
|
#else |
34857
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
34858
|
|
|
|
|
|
|
#endif |
34859
|
|
|
|
|
|
|
|
34860
|
|
|
|
|
|
|
|
34861
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
34862
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
34863
|
|
|
|
|
|
|
#else |
34864
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
34865
|
|
|
|
|
|
|
#endif |
34866
|
|
|
|
|
|
|
|
34867
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
34868
|
|
|
|
|
|
|
|
34869
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
34870
|
|
|
|
|
|
|
|
34871
|
|
|
|
|
|
|
|
34872
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
34873
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
34874
|
|
|
|
|
|
|
|
34875
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
34876
|
|
|
|
|
|
|
|
34877
|
|
|
|
|
|
|
|
34878
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
34879
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
34880
|
|
|
|
|
|
|
|
34881
|
|
|
|
|
|
|
#include |
34882
|
|
|
|
|
|
|
#include |
34883
|
|
|
|
|
|
|
|
34884
|
|
|
|
|
|
|
#ifdef __cplusplus |
34885
|
|
|
|
|
|
|
extern "C" { |
34886
|
|
|
|
|
|
|
#endif |
34887
|
|
|
|
|
|
|
|
34888
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
34889
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 19 |
34890
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.19" |
34891
|
|
|
|
|
|
|
|
34892
|
|
|
|
|
|
|
|
34893
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
34894
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
34895
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
34896
|
|
|
|
|
|
|
# else |
34897
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
34898
|
|
|
|
|
|
|
# endif |
34899
|
|
|
|
|
|
|
#endif |
34900
|
|
|
|
|
|
|
|
34901
|
|
|
|
|
|
|
|
34902
|
|
|
|
|
|
|
|
34903
|
|
|
|
|
|
|
|
34904
|
|
|
|
|
|
|
|
34905
|
|
|
|
|
|
|
struct libdeflate_compressor; |
34906
|
|
|
|
|
|
|
struct libdeflate_options; |
34907
|
|
|
|
|
|
|
|
34908
|
|
|
|
|
|
|
|
34909
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
34910
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
34911
|
|
|
|
|
|
|
|
34912
|
|
|
|
|
|
|
|
34913
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
34914
|
|
|
|
|
|
|
libdeflate_alloc_compressor_ex(int compression_level, |
34915
|
|
|
|
|
|
|
const struct libdeflate_options *options); |
34916
|
|
|
|
|
|
|
|
34917
|
|
|
|
|
|
|
|
34918
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34919
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
34920
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34921
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
34922
|
|
|
|
|
|
|
|
34923
|
|
|
|
|
|
|
|
34924
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34925
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
34926
|
|
|
|
|
|
|
size_t in_nbytes); |
34927
|
|
|
|
|
|
|
|
34928
|
|
|
|
|
|
|
|
34929
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34930
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
34931
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34932
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
34933
|
|
|
|
|
|
|
|
34934
|
|
|
|
|
|
|
|
34935
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34936
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
34937
|
|
|
|
|
|
|
size_t in_nbytes); |
34938
|
|
|
|
|
|
|
|
34939
|
|
|
|
|
|
|
|
34940
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34941
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
34942
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34943
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
34944
|
|
|
|
|
|
|
|
34945
|
|
|
|
|
|
|
|
34946
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34947
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
34948
|
|
|
|
|
|
|
size_t in_nbytes); |
34949
|
|
|
|
|
|
|
|
34950
|
|
|
|
|
|
|
|
34951
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
34952
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
34953
|
|
|
|
|
|
|
|
34954
|
|
|
|
|
|
|
|
34955
|
|
|
|
|
|
|
|
34956
|
|
|
|
|
|
|
|
34957
|
|
|
|
|
|
|
|
34958
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
34959
|
|
|
|
|
|
|
struct libdeflate_options; |
34960
|
|
|
|
|
|
|
|
34961
|
|
|
|
|
|
|
|
34962
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
34963
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
34964
|
|
|
|
|
|
|
|
34965
|
|
|
|
|
|
|
|
34966
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
34967
|
|
|
|
|
|
|
libdeflate_alloc_decompressor_ex(const struct libdeflate_options *options); |
34968
|
|
|
|
|
|
|
|
34969
|
|
|
|
|
|
|
|
34970
|
|
|
|
|
|
|
enum libdeflate_result { |
34971
|
|
|
|
|
|
|
|
34972
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
34973
|
|
|
|
|
|
|
|
34974
|
|
|
|
|
|
|
|
34975
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
34976
|
|
|
|
|
|
|
|
34977
|
|
|
|
|
|
|
|
34978
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
34979
|
|
|
|
|
|
|
|
34980
|
|
|
|
|
|
|
|
34981
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
34982
|
|
|
|
|
|
|
}; |
34983
|
|
|
|
|
|
|
|
34984
|
|
|
|
|
|
|
|
34985
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
34986
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
34987
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34988
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
34989
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
34990
|
|
|
|
|
|
|
|
34991
|
|
|
|
|
|
|
|
34992
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
34993
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
34994
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34995
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
34996
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
34997
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
34998
|
|
|
|
|
|
|
|
34999
|
|
|
|
|
|
|
|
35000
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
35001
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
35002
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
35003
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
35004
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
35005
|
|
|
|
|
|
|
|
35006
|
|
|
|
|
|
|
|
35007
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
35008
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
35009
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
35010
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
35011
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
35012
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
35013
|
|
|
|
|
|
|
|
35014
|
|
|
|
|
|
|
|
35015
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
35016
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
35017
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
35018
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
35019
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
35020
|
|
|
|
|
|
|
|
35021
|
|
|
|
|
|
|
|
35022
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
35023
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
35024
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
35025
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
35026
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
35027
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
35028
|
|
|
|
|
|
|
|
35029
|
|
|
|
|
|
|
|
35030
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
35031
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
35032
|
|
|
|
|
|
|
|
35033
|
|
|
|
|
|
|
|
35034
|
|
|
|
|
|
|
|
35035
|
|
|
|
|
|
|
|
35036
|
|
|
|
|
|
|
|
35037
|
|
|
|
|
|
|
|
35038
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
35039
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
35040
|
|
|
|
|
|
|
|
35041
|
|
|
|
|
|
|
|
35042
|
|
|
|
|
|
|
|
35043
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
35044
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
35045
|
|
|
|
|
|
|
|
35046
|
|
|
|
|
|
|
|
35047
|
|
|
|
|
|
|
|
35048
|
|
|
|
|
|
|
|
35049
|
|
|
|
|
|
|
|
35050
|
|
|
|
|
|
|
|
35051
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
35052
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
35053
|
|
|
|
|
|
|
void (*free_func)(void *)); |
35054
|
|
|
|
|
|
|
|
35055
|
|
|
|
|
|
|
|
35056
|
|
|
|
|
|
|
struct libdeflate_options { |
35057
|
|
|
|
|
|
|
|
35058
|
|
|
|
|
|
|
|
35059
|
|
|
|
|
|
|
size_t sizeof_options; |
35060
|
|
|
|
|
|
|
|
35061
|
|
|
|
|
|
|
|
35062
|
|
|
|
|
|
|
void *(*malloc_func)(size_t); |
35063
|
|
|
|
|
|
|
void (*free_func)(void *); |
35064
|
|
|
|
|
|
|
}; |
35065
|
|
|
|
|
|
|
|
35066
|
|
|
|
|
|
|
#ifdef __cplusplus |
35067
|
|
|
|
|
|
|
} |
35068
|
|
|
|
|
|
|
#endif |
35069
|
|
|
|
|
|
|
|
35070
|
|
|
|
|
|
|
#endif |
35071
|
|
|
|
|
|
|
|
35072
|
|
|
|
|
|
|
|
35073
|
|
|
|
|
|
|
#include |
35074
|
|
|
|
|
|
|
#include |
35075
|
|
|
|
|
|
|
#include |
35076
|
|
|
|
|
|
|
#ifdef _MSC_VER |
35077
|
|
|
|
|
|
|
# include |
35078
|
|
|
|
|
|
|
# include |
35079
|
|
|
|
|
|
|
|
35080
|
|
|
|
|
|
|
|
35081
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
35082
|
|
|
|
|
|
|
|
35083
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
35084
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
35085
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
35086
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
35087
|
|
|
|
|
|
|
|
35088
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
35089
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
35090
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
35091
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
35092
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
35093
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
35094
|
|
|
|
|
|
|
#endif |
35095
|
|
|
|
|
|
|
#ifndef FREESTANDING |
35096
|
|
|
|
|
|
|
# include |
35097
|
|
|
|
|
|
|
#endif |
35098
|
|
|
|
|
|
|
|
35099
|
|
|
|
|
|
|
|
35100
|
|
|
|
|
|
|
|
35101
|
|
|
|
|
|
|
|
35102
|
|
|
|
|
|
|
|
35103
|
|
|
|
|
|
|
|
35104
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
35105
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
35106
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
35107
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
35108
|
|
|
|
|
|
|
#ifdef _MSC_VER |
35109
|
|
|
|
|
|
|
# if defined(_M_X64) |
35110
|
|
|
|
|
|
|
# define ARCH_X86_64 |
35111
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
35112
|
|
|
|
|
|
|
# define ARCH_X86_32 |
35113
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
35114
|
|
|
|
|
|
|
# define ARCH_ARM64 |
35115
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
35116
|
|
|
|
|
|
|
# define ARCH_ARM32 |
35117
|
|
|
|
|
|
|
# endif |
35118
|
|
|
|
|
|
|
#else |
35119
|
|
|
|
|
|
|
# if defined(__x86_64__) |
35120
|
|
|
|
|
|
|
# define ARCH_X86_64 |
35121
|
|
|
|
|
|
|
# elif defined(__i386__) |
35122
|
|
|
|
|
|
|
# define ARCH_X86_32 |
35123
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
35124
|
|
|
|
|
|
|
# define ARCH_ARM64 |
35125
|
|
|
|
|
|
|
# elif defined(__arm__) |
35126
|
|
|
|
|
|
|
# define ARCH_ARM32 |
35127
|
|
|
|
|
|
|
# endif |
35128
|
|
|
|
|
|
|
#endif |
35129
|
|
|
|
|
|
|
|
35130
|
|
|
|
|
|
|
|
35131
|
|
|
|
|
|
|
|
35132
|
|
|
|
|
|
|
|
35133
|
|
|
|
|
|
|
|
35134
|
|
|
|
|
|
|
|
35135
|
|
|
|
|
|
|
typedef uint8_t u8; |
35136
|
|
|
|
|
|
|
typedef uint16_t u16; |
35137
|
|
|
|
|
|
|
typedef uint32_t u32; |
35138
|
|
|
|
|
|
|
typedef uint64_t u64; |
35139
|
|
|
|
|
|
|
typedef int8_t s8; |
35140
|
|
|
|
|
|
|
typedef int16_t s16; |
35141
|
|
|
|
|
|
|
typedef int32_t s32; |
35142
|
|
|
|
|
|
|
typedef int64_t s64; |
35143
|
|
|
|
|
|
|
|
35144
|
|
|
|
|
|
|
|
35145
|
|
|
|
|
|
|
#ifdef _MSC_VER |
35146
|
|
|
|
|
|
|
# ifdef _WIN64 |
35147
|
|
|
|
|
|
|
typedef long long ssize_t; |
35148
|
|
|
|
|
|
|
# else |
35149
|
|
|
|
|
|
|
typedef long ssize_t; |
35150
|
|
|
|
|
|
|
# endif |
35151
|
|
|
|
|
|
|
#endif |
35152
|
|
|
|
|
|
|
|
35153
|
|
|
|
|
|
|
|
35154
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
35155
|
|
|
|
|
|
|
|
35156
|
|
|
|
|
|
|
|
35157
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
35158
|
|
|
|
|
|
|
|
35159
|
|
|
|
|
|
|
|
35160
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
35161
|
|
|
|
|
|
|
|
35162
|
|
|
|
|
|
|
|
35163
|
|
|
|
|
|
|
|
35164
|
|
|
|
|
|
|
|
35165
|
|
|
|
|
|
|
|
35166
|
|
|
|
|
|
|
|
35167
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
35168
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
35169
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
35170
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
35171
|
|
|
|
|
|
|
#else |
35172
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
35173
|
|
|
|
|
|
|
#endif |
35174
|
|
|
|
|
|
|
#ifdef __clang__ |
35175
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
35176
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
35177
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
35178
|
|
|
|
|
|
|
# else |
35179
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
35180
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
35181
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
35182
|
|
|
|
|
|
|
# endif |
35183
|
|
|
|
|
|
|
#else |
35184
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
35185
|
|
|
|
|
|
|
#endif |
35186
|
|
|
|
|
|
|
|
35187
|
|
|
|
|
|
|
|
35188
|
|
|
|
|
|
|
#ifndef __has_attribute |
35189
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
35190
|
|
|
|
|
|
|
#endif |
35191
|
|
|
|
|
|
|
#ifndef __has_builtin |
35192
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
35193
|
|
|
|
|
|
|
#endif |
35194
|
|
|
|
|
|
|
|
35195
|
|
|
|
|
|
|
|
35196
|
|
|
|
|
|
|
#ifdef _MSC_VER |
35197
|
|
|
|
|
|
|
# define inline __inline |
35198
|
|
|
|
|
|
|
#endif |
35199
|
|
|
|
|
|
|
|
35200
|
|
|
|
|
|
|
|
35201
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
35202
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
35203
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35204
|
|
|
|
|
|
|
# define forceinline __forceinline |
35205
|
|
|
|
|
|
|
#else |
35206
|
|
|
|
|
|
|
# define forceinline inline |
35207
|
|
|
|
|
|
|
#endif |
35208
|
|
|
|
|
|
|
|
35209
|
|
|
|
|
|
|
|
35210
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
35211
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
35212
|
|
|
|
|
|
|
#else |
35213
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
35214
|
|
|
|
|
|
|
#endif |
35215
|
|
|
|
|
|
|
|
35216
|
|
|
|
|
|
|
|
35217
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
35218
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
35219
|
|
|
|
|
|
|
# define restrict __restrict__ |
35220
|
|
|
|
|
|
|
# else |
35221
|
|
|
|
|
|
|
# define restrict |
35222
|
|
|
|
|
|
|
# endif |
35223
|
|
|
|
|
|
|
#endif |
35224
|
|
|
|
|
|
|
|
35225
|
|
|
|
|
|
|
|
35226
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
35227
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
35228
|
|
|
|
|
|
|
#else |
35229
|
|
|
|
|
|
|
# define likely(expr) (expr) |
35230
|
|
|
|
|
|
|
#endif |
35231
|
|
|
|
|
|
|
|
35232
|
|
|
|
|
|
|
|
35233
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
35234
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
35235
|
|
|
|
|
|
|
#else |
35236
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
35237
|
|
|
|
|
|
|
#endif |
35238
|
|
|
|
|
|
|
|
35239
|
|
|
|
|
|
|
|
35240
|
|
|
|
|
|
|
#undef prefetchr |
35241
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
35242
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
35243
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35244
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
35245
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
35246
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
35247
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
35248
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
35249
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
35250
|
|
|
|
|
|
|
# endif |
35251
|
|
|
|
|
|
|
#endif |
35252
|
|
|
|
|
|
|
#ifndef prefetchr |
35253
|
|
|
|
|
|
|
# define prefetchr(addr) |
35254
|
|
|
|
|
|
|
#endif |
35255
|
|
|
|
|
|
|
|
35256
|
|
|
|
|
|
|
|
35257
|
|
|
|
|
|
|
#undef prefetchw |
35258
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
35259
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
35260
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35261
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
35262
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
35263
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
35264
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
35265
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
35266
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
35267
|
|
|
|
|
|
|
# endif |
35268
|
|
|
|
|
|
|
#endif |
35269
|
|
|
|
|
|
|
#ifndef prefetchw |
35270
|
|
|
|
|
|
|
# define prefetchw(addr) |
35271
|
|
|
|
|
|
|
#endif |
35272
|
|
|
|
|
|
|
|
35273
|
|
|
|
|
|
|
|
35274
|
|
|
|
|
|
|
#undef _aligned_attribute |
35275
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
35276
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
35277
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35278
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
35279
|
|
|
|
|
|
|
#endif |
35280
|
|
|
|
|
|
|
|
35281
|
|
|
|
|
|
|
|
35282
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
35283
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
35284
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
35285
|
|
|
|
|
|
|
#else |
35286
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
35287
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
35288
|
|
|
|
|
|
|
#endif |
35289
|
|
|
|
|
|
|
|
35290
|
|
|
|
|
|
|
|
35291
|
|
|
|
|
|
|
|
35292
|
|
|
|
|
|
|
|
35293
|
|
|
|
|
|
|
|
35294
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
35295
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
35296
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
35297
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
35298
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
35299
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
35300
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
35301
|
|
|
|
|
|
|
|
35302
|
|
|
|
|
|
|
|
35303
|
|
|
|
|
|
|
|
35304
|
|
|
|
|
|
|
|
35305
|
|
|
|
|
|
|
|
35306
|
|
|
|
|
|
|
|
35307
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
35308
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
35309
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35310
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
35311
|
|
|
|
|
|
|
#else |
35312
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
35313
|
|
|
|
|
|
|
{ |
35314
|
|
|
|
|
|
|
union { |
35315
|
|
|
|
|
|
|
u32 w; |
35316
|
|
|
|
|
|
|
u8 b; |
35317
|
|
|
|
|
|
|
} u; |
35318
|
|
|
|
|
|
|
|
35319
|
|
|
|
|
|
|
u.w = 1; |
35320
|
|
|
|
|
|
|
return u.b; |
35321
|
|
|
|
|
|
|
} |
35322
|
|
|
|
|
|
|
#endif |
35323
|
|
|
|
|
|
|
|
35324
|
|
|
|
|
|
|
|
35325
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
35326
|
|
|
|
|
|
|
{ |
35327
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
35328
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
35329
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35330
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
35331
|
|
|
|
|
|
|
#else |
35332
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
35333
|
|
|
|
|
|
|
#endif |
35334
|
|
|
|
|
|
|
} |
35335
|
|
|
|
|
|
|
|
35336
|
|
|
|
|
|
|
|
35337
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
35338
|
|
|
|
|
|
|
{ |
35339
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
35340
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
35341
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35342
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
35343
|
|
|
|
|
|
|
#else |
35344
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
35345
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
35346
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
35347
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
35348
|
|
|
|
|
|
|
#endif |
35349
|
|
|
|
|
|
|
} |
35350
|
|
|
|
|
|
|
|
35351
|
|
|
|
|
|
|
|
35352
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
35353
|
|
|
|
|
|
|
{ |
35354
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
35355
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
35356
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35357
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
35358
|
|
|
|
|
|
|
#else |
35359
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
35360
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
35361
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
35362
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
35363
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
35364
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
35365
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
35366
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
35367
|
|
|
|
|
|
|
#endif |
35368
|
|
|
|
|
|
|
} |
35369
|
|
|
|
|
|
|
|
35370
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
35371
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
35372
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
35373
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
35374
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
35375
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
35376
|
|
|
|
|
|
|
|
35377
|
|
|
|
|
|
|
|
35378
|
|
|
|
|
|
|
|
35379
|
|
|
|
|
|
|
|
35380
|
|
|
|
|
|
|
|
35381
|
|
|
|
|
|
|
|
35382
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
35383
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
35384
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
35385
|
|
|
|
|
|
|
defined(__wasm__)) |
35386
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
35387
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35388
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
35389
|
|
|
|
|
|
|
#else |
35390
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
35391
|
|
|
|
|
|
|
#endif |
35392
|
|
|
|
|
|
|
|
35393
|
|
|
|
|
|
|
|
35394
|
|
|
|
|
|
|
|
35395
|
|
|
|
|
|
|
#ifdef FREESTANDING |
35396
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
35397
|
|
|
|
|
|
|
#else |
35398
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
35399
|
|
|
|
|
|
|
#endif |
35400
|
|
|
|
|
|
|
|
35401
|
|
|
|
|
|
|
|
35402
|
|
|
|
|
|
|
|
35403
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
35404
|
|
|
|
|
|
|
static forceinline type \ |
35405
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
35406
|
|
|
|
|
|
|
{ \ |
35407
|
|
|
|
|
|
|
type v; \ |
35408
|
|
|
|
|
|
|
\ |
35409
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
35410
|
|
|
|
|
|
|
return v; \ |
35411
|
|
|
|
|
|
|
} \ |
35412
|
|
|
|
|
|
|
\ |
35413
|
|
|
|
|
|
|
static forceinline void \ |
35414
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
35415
|
|
|
|
|
|
|
{ \ |
35416
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
35417
|
|
|
|
|
|
|
} |
35418
|
|
|
|
|
|
|
|
35419
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
35420
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
35421
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
35422
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
35423
|
|
|
|
|
|
|
|
35424
|
|
|
|
|
|
|
#undef MEMCOPY |
35425
|
|
|
|
|
|
|
|
35426
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
35427
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
35428
|
|
|
|
|
|
|
|
35429
|
|
|
|
|
|
|
|
35430
|
|
|
|
|
|
|
|
35431
|
|
|
|
|
|
|
static forceinline u16 |
35432
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
35433
|
|
|
|
|
|
|
{ |
35434
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
35435
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
35436
|
|
|
|
|
|
|
else |
35437
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
35438
|
|
|
|
|
|
|
} |
35439
|
|
|
|
|
|
|
|
35440
|
|
|
|
|
|
|
static forceinline u16 |
35441
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
35442
|
|
|
|
|
|
|
{ |
35443
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
35444
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
35445
|
|
|
|
|
|
|
else |
35446
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
35447
|
|
|
|
|
|
|
} |
35448
|
|
|
|
|
|
|
|
35449
|
|
|
|
|
|
|
static forceinline u32 |
35450
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
35451
|
|
|
|
|
|
|
{ |
35452
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
35453
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
35454
|
|
|
|
|
|
|
else |
35455
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
35456
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
35457
|
|
|
|
|
|
|
} |
35458
|
|
|
|
|
|
|
|
35459
|
|
|
|
|
|
|
static forceinline u32 |
35460
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
35461
|
|
|
|
|
|
|
{ |
35462
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
35463
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
35464
|
|
|
|
|
|
|
else |
35465
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
35466
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
35467
|
|
|
|
|
|
|
} |
35468
|
|
|
|
|
|
|
|
35469
|
|
|
|
|
|
|
static forceinline u64 |
35470
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
35471
|
|
|
|
|
|
|
{ |
35472
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
35473
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
35474
|
|
|
|
|
|
|
else |
35475
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
35476
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
35477
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
35478
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
35479
|
|
|
|
|
|
|
} |
35480
|
|
|
|
|
|
|
|
35481
|
|
|
|
|
|
|
static forceinline machine_word_t |
35482
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
35483
|
|
|
|
|
|
|
{ |
35484
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
35485
|
|
|
|
|
|
|
if (WORDBITS == 32) |
35486
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
35487
|
|
|
|
|
|
|
else |
35488
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
35489
|
|
|
|
|
|
|
} |
35490
|
|
|
|
|
|
|
|
35491
|
|
|
|
|
|
|
|
35492
|
|
|
|
|
|
|
|
35493
|
|
|
|
|
|
|
static forceinline void |
35494
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
35495
|
|
|
|
|
|
|
{ |
35496
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
35497
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
35498
|
|
|
|
|
|
|
} else { |
35499
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
35500
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
35501
|
|
|
|
|
|
|
} |
35502
|
|
|
|
|
|
|
} |
35503
|
|
|
|
|
|
|
|
35504
|
|
|
|
|
|
|
static forceinline void |
35505
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
35506
|
|
|
|
|
|
|
{ |
35507
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
35508
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
35509
|
|
|
|
|
|
|
} else { |
35510
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
35511
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
35512
|
|
|
|
|
|
|
} |
35513
|
|
|
|
|
|
|
} |
35514
|
|
|
|
|
|
|
|
35515
|
|
|
|
|
|
|
static forceinline void |
35516
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
35517
|
|
|
|
|
|
|
{ |
35518
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
35519
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
35520
|
|
|
|
|
|
|
} else { |
35521
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
35522
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
35523
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
35524
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
35525
|
|
|
|
|
|
|
} |
35526
|
|
|
|
|
|
|
} |
35527
|
|
|
|
|
|
|
|
35528
|
|
|
|
|
|
|
static forceinline void |
35529
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
35530
|
|
|
|
|
|
|
{ |
35531
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
35532
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
35533
|
|
|
|
|
|
|
} else { |
35534
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
35535
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
35536
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
35537
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
35538
|
|
|
|
|
|
|
} |
35539
|
|
|
|
|
|
|
} |
35540
|
|
|
|
|
|
|
|
35541
|
|
|
|
|
|
|
static forceinline void |
35542
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
35543
|
|
|
|
|
|
|
{ |
35544
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
35545
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
35546
|
|
|
|
|
|
|
} else { |
35547
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
35548
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
35549
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
35550
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
35551
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
35552
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
35553
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
35554
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
35555
|
|
|
|
|
|
|
} |
35556
|
|
|
|
|
|
|
} |
35557
|
|
|
|
|
|
|
|
35558
|
|
|
|
|
|
|
static forceinline void |
35559
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
35560
|
|
|
|
|
|
|
{ |
35561
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
35562
|
|
|
|
|
|
|
if (WORDBITS == 32) |
35563
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
35564
|
|
|
|
|
|
|
else |
35565
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
35566
|
|
|
|
|
|
|
} |
35567
|
|
|
|
|
|
|
|
35568
|
|
|
|
|
|
|
|
35569
|
|
|
|
|
|
|
|
35570
|
|
|
|
|
|
|
|
35571
|
|
|
|
|
|
|
|
35572
|
|
|
|
|
|
|
|
35573
|
|
|
|
|
|
|
|
35574
|
|
|
|
|
|
|
static forceinline unsigned |
35575
|
|
|
|
|
|
|
bsr32(u32 v) |
35576
|
|
|
|
|
|
|
{ |
35577
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
35578
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
35579
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35580
|
|
|
|
|
|
|
unsigned long i; |
35581
|
|
|
|
|
|
|
|
35582
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
35583
|
|
|
|
|
|
|
return i; |
35584
|
|
|
|
|
|
|
#else |
35585
|
|
|
|
|
|
|
unsigned i = 0; |
35586
|
|
|
|
|
|
|
|
35587
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
35588
|
|
|
|
|
|
|
i++; |
35589
|
|
|
|
|
|
|
return i; |
35590
|
|
|
|
|
|
|
#endif |
35591
|
|
|
|
|
|
|
} |
35592
|
|
|
|
|
|
|
|
35593
|
|
|
|
|
|
|
static forceinline unsigned |
35594
|
|
|
|
|
|
|
bsr64(u64 v) |
35595
|
|
|
|
|
|
|
{ |
35596
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
35597
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
35598
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
35599
|
|
|
|
|
|
|
unsigned long i; |
35600
|
|
|
|
|
|
|
|
35601
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
35602
|
|
|
|
|
|
|
return i; |
35603
|
|
|
|
|
|
|
#else |
35604
|
|
|
|
|
|
|
unsigned i = 0; |
35605
|
|
|
|
|
|
|
|
35606
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
35607
|
|
|
|
|
|
|
i++; |
35608
|
|
|
|
|
|
|
return i; |
35609
|
|
|
|
|
|
|
#endif |
35610
|
|
|
|
|
|
|
} |
35611
|
|
|
|
|
|
|
|
35612
|
|
|
|
|
|
|
static forceinline unsigned |
35613
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
35614
|
|
|
|
|
|
|
{ |
35615
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
35616
|
|
|
|
|
|
|
if (WORDBITS == 32) |
35617
|
|
|
|
|
|
|
return bsr32(v); |
35618
|
|
|
|
|
|
|
else |
35619
|
|
|
|
|
|
|
return bsr64(v); |
35620
|
|
|
|
|
|
|
} |
35621
|
|
|
|
|
|
|
|
35622
|
|
|
|
|
|
|
|
35623
|
|
|
|
|
|
|
|
35624
|
|
|
|
|
|
|
static forceinline unsigned |
35625
|
|
|
|
|
|
|
bsf32(u32 v) |
35626
|
|
|
|
|
|
|
{ |
35627
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
35628
|
|
|
|
|
|
|
return __builtin_ctz(v); |
35629
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
35630
|
|
|
|
|
|
|
unsigned long i; |
35631
|
|
|
|
|
|
|
|
35632
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
35633
|
|
|
|
|
|
|
return i; |
35634
|
|
|
|
|
|
|
#else |
35635
|
|
|
|
|
|
|
unsigned i = 0; |
35636
|
|
|
|
|
|
|
|
35637
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
35638
|
|
|
|
|
|
|
i++; |
35639
|
|
|
|
|
|
|
return i; |
35640
|
|
|
|
|
|
|
#endif |
35641
|
|
|
|
|
|
|
} |
35642
|
|
|
|
|
|
|
|
35643
|
|
|
|
|
|
|
static forceinline unsigned |
35644
|
|
|
|
|
|
|
bsf64(u64 v) |
35645
|
|
|
|
|
|
|
{ |
35646
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
35647
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
35648
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
35649
|
|
|
|
|
|
|
unsigned long i; |
35650
|
|
|
|
|
|
|
|
35651
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
35652
|
|
|
|
|
|
|
return i; |
35653
|
|
|
|
|
|
|
#else |
35654
|
|
|
|
|
|
|
unsigned i = 0; |
35655
|
|
|
|
|
|
|
|
35656
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
35657
|
|
|
|
|
|
|
i++; |
35658
|
|
|
|
|
|
|
return i; |
35659
|
|
|
|
|
|
|
#endif |
35660
|
|
|
|
|
|
|
} |
35661
|
|
|
|
|
|
|
|
35662
|
|
|
|
|
|
|
static forceinline unsigned |
35663
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
35664
|
|
|
|
|
|
|
{ |
35665
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
35666
|
|
|
|
|
|
|
if (WORDBITS == 32) |
35667
|
|
|
|
|
|
|
return bsf32(v); |
35668
|
|
|
|
|
|
|
else |
35669
|
|
|
|
|
|
|
return bsf64(v); |
35670
|
|
|
|
|
|
|
} |
35671
|
|
|
|
|
|
|
|
35672
|
|
|
|
|
|
|
|
35673
|
|
|
|
|
|
|
#undef rbit32 |
35674
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
35675
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
35676
|
|
|
|
|
|
|
static forceinline u32 |
35677
|
|
|
|
|
|
|
rbit32(u32 v) |
35678
|
|
|
|
|
|
|
{ |
35679
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
35680
|
|
|
|
|
|
|
return v; |
35681
|
|
|
|
|
|
|
} |
35682
|
|
|
|
|
|
|
#define rbit32 rbit32 |
35683
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
35684
|
|
|
|
|
|
|
static forceinline u32 |
35685
|
|
|
|
|
|
|
rbit32(u32 v) |
35686
|
|
|
|
|
|
|
{ |
35687
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
35688
|
|
|
|
|
|
|
return v; |
35689
|
|
|
|
|
|
|
} |
35690
|
|
|
|
|
|
|
#define rbit32 rbit32 |
35691
|
|
|
|
|
|
|
#endif |
35692
|
|
|
|
|
|
|
|
35693
|
|
|
|
|
|
|
#endif |
35694
|
|
|
|
|
|
|
|
35695
|
|
|
|
|
|
|
|
35696
|
|
|
|
|
|
|
typedef void *(*malloc_func_t)(size_t); |
35697
|
|
|
|
|
|
|
typedef void (*free_func_t)(void *); |
35698
|
|
|
|
|
|
|
|
35699
|
|
|
|
|
|
|
extern malloc_func_t libdeflate_default_malloc_func; |
35700
|
|
|
|
|
|
|
extern free_func_t libdeflate_default_free_func; |
35701
|
|
|
|
|
|
|
|
35702
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(malloc_func_t malloc_func, |
35703
|
|
|
|
|
|
|
size_t alignment, size_t size); |
35704
|
|
|
|
|
|
|
void libdeflate_aligned_free(free_func_t free_func, void *ptr); |
35705
|
|
|
|
|
|
|
|
35706
|
|
|
|
|
|
|
#ifdef FREESTANDING |
35707
|
|
|
|
|
|
|
|
35708
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
35709
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
35710
|
|
|
|
|
|
|
|
35711
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
35712
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
35713
|
|
|
|
|
|
|
|
35714
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
35715
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
35716
|
|
|
|
|
|
|
|
35717
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
35718
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
35719
|
|
|
|
|
|
|
|
35720
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
35721
|
|
|
|
|
|
|
#else |
35722
|
|
|
|
|
|
|
#include |
35723
|
|
|
|
|
|
|
#endif |
35724
|
|
|
|
|
|
|
|
35725
|
|
|
|
|
|
|
|
35726
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
35727
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
35728
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
35729
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
35730
|
|
|
|
|
|
|
#else |
35731
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
35732
|
|
|
|
|
|
|
#endif |
35733
|
|
|
|
|
|
|
|
35734
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
35735
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
35736
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
35737
|
|
|
|
|
|
|
|
35738
|
|
|
|
|
|
|
#endif |
35739
|
|
|
|
|
|
|
|
35740
|
|
|
|
|
|
|
|
35741
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
35742
|
|
|
|
|
|
|
|
35743
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
35744
|
|
|
|
|
|
|
|
35745
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
35746
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
35747
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
35748
|
|
|
|
|
|
|
#endif |
35749
|
|
|
|
|
|
|
|
35750
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
35751
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
35752
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
35753
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
35754
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
35755
|
|
|
|
|
|
|
|
35756
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
35757
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
35758
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
35759
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
35760
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
35761
|
|
|
|
|
|
|
|
35762
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
35763
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
35764
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
35765
|
|
|
|
|
|
|
|
35766
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
35767
|
|
|
|
|
|
|
|
35768
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
35769
|
|
|
|
|
|
|
{ |
35770
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
35771
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
35772
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
35773
|
|
|
|
|
|
|
} |
35774
|
|
|
|
|
|
|
#else |
35775
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
35776
|
|
|
|
|
|
|
#endif |
35777
|
|
|
|
|
|
|
|
35778
|
|
|
|
|
|
|
|
35779
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
35780
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
35781
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
35782
|
|
|
|
|
|
|
#else |
35783
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
35784
|
|
|
|
|
|
|
#endif |
35785
|
|
|
|
|
|
|
|
35786
|
|
|
|
|
|
|
|
35787
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
35788
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
35789
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
35790
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
35791
|
|
|
|
|
|
|
#else |
35792
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
35793
|
|
|
|
|
|
|
#endif |
35794
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
35795
|
|
|
|
|
|
|
|
35796
|
|
|
|
|
|
|
|
35797
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
35798
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
35799
|
|
|
|
|
|
|
#else |
35800
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
35801
|
|
|
|
|
|
|
#endif |
35802
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
35803
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
35804
|
|
|
|
|
|
|
defined(_MSC_VER))) |
35805
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
35806
|
|
|
|
|
|
|
#else |
35807
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
35808
|
|
|
|
|
|
|
#endif |
35809
|
|
|
|
|
|
|
|
35810
|
|
|
|
|
|
|
|
35811
|
|
|
|
|
|
|
#ifdef __AVX__ |
35812
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
35813
|
|
|
|
|
|
|
#else |
35814
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
35815
|
|
|
|
|
|
|
#endif |
35816
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
35817
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
35818
|
|
|
|
|
|
|
defined(_MSC_VER))) |
35819
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
35820
|
|
|
|
|
|
|
#else |
35821
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
35822
|
|
|
|
|
|
|
#endif |
35823
|
|
|
|
|
|
|
|
35824
|
|
|
|
|
|
|
|
35825
|
|
|
|
|
|
|
#ifdef __AVX2__ |
35826
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
35827
|
|
|
|
|
|
|
#else |
35828
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
35829
|
|
|
|
|
|
|
#endif |
35830
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
35831
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
35832
|
|
|
|
|
|
|
defined(_MSC_VER))) |
35833
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
35834
|
|
|
|
|
|
|
#else |
35835
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
35836
|
|
|
|
|
|
|
#endif |
35837
|
|
|
|
|
|
|
|
35838
|
|
|
|
|
|
|
|
35839
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
35840
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
35841
|
|
|
|
|
|
|
#else |
35842
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
35843
|
|
|
|
|
|
|
#endif |
35844
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
35845
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
35846
|
|
|
|
|
|
|
defined(_MSC_VER))) |
35847
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
35848
|
|
|
|
|
|
|
#else |
35849
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
35850
|
|
|
|
|
|
|
#endif |
35851
|
|
|
|
|
|
|
|
35852
|
|
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1930 |
35853
|
|
|
|
|
|
|
# undef HAVE_BMI2_NATIVE |
35854
|
|
|
|
|
|
|
# undef HAVE_BMI2_INTRIN |
35855
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
35856
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
35857
|
|
|
|
|
|
|
#endif |
35858
|
|
|
|
|
|
|
|
35859
|
|
|
|
|
|
|
#endif |
35860
|
|
|
|
|
|
|
|
35861
|
|
|
|
|
|
|
#endif |
35862
|
|
|
|
|
|
|
|
35863
|
|
|
|
|
|
|
|
35864
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
35865
|
|
|
|
|
|
|
|
35866
|
|
|
|
|
|
|
|
35867
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) && defined(__PIC__) |
35868
|
|
|
|
|
|
|
# define EBX_CONSTRAINT "=&r" |
35869
|
|
|
|
|
|
|
#else |
35870
|
|
|
|
|
|
|
# define EBX_CONSTRAINT "=b" |
35871
|
|
|
|
|
|
|
#endif |
35872
|
|
|
|
|
|
|
|
35873
|
|
|
|
|
|
|
|
35874
|
|
|
|
|
|
|
static inline void |
35875
|
4
|
|
|
|
|
|
cpuid(u32 leaf, u32 subleaf, u32 *a, u32 *b, u32 *c, u32 *d) |
35876
|
|
|
|
|
|
|
{ |
35877
|
|
|
|
|
|
|
#ifdef _MSC_VER |
35878
|
|
|
|
|
|
|
int result[4]; |
35879
|
|
|
|
|
|
|
|
35880
|
|
|
|
|
|
|
__cpuidex(result, leaf, subleaf); |
35881
|
|
|
|
|
|
|
*a = result[0]; |
35882
|
|
|
|
|
|
|
*b = result[1]; |
35883
|
|
|
|
|
|
|
*c = result[2]; |
35884
|
|
|
|
|
|
|
*d = result[3]; |
35885
|
|
|
|
|
|
|
#else |
35886
|
4
|
|
|
|
|
|
__asm__ volatile(".ifnc %%ebx, %1; mov %%ebx, %1; .endif\n" |
35887
|
|
|
|
|
|
|
"cpuid \n" |
35888
|
|
|
|
|
|
|
".ifnc %%ebx, %1; xchg %%ebx, %1; .endif\n" |
35889
|
|
|
|
|
|
|
: "=a" (*a), EBX_CONSTRAINT (*b), "=c" (*c), "=d" (*d) |
35890
|
|
|
|
|
|
|
: "a" (leaf), "c" (subleaf)); |
35891
|
|
|
|
|
|
|
#endif |
35892
|
4
|
|
|
|
|
|
} |
35893
|
|
|
|
|
|
|
|
35894
|
|
|
|
|
|
|
|
35895
|
|
|
|
|
|
|
static inline u64 |
35896
|
0
|
|
|
|
|
|
read_xcr(u32 index) |
35897
|
|
|
|
|
|
|
{ |
35898
|
|
|
|
|
|
|
#ifdef _MSC_VER |
35899
|
|
|
|
|
|
|
return _xgetbv(index); |
35900
|
|
|
|
|
|
|
#else |
35901
|
|
|
|
|
|
|
u32 d, a; |
35902
|
|
|
|
|
|
|
|
35903
|
|
|
|
|
|
|
|
35904
|
0
|
|
|
|
|
|
__asm__ volatile(".byte 0x0f, 0x01, 0xd0" : |
35905
|
|
|
|
|
|
|
"=d" (d), "=a" (a) : "c" (index)); |
35906
|
|
|
|
|
|
|
|
35907
|
0
|
|
|
|
|
|
return ((u64)d << 32) | a; |
35908
|
|
|
|
|
|
|
#endif |
35909
|
|
|
|
|
|
|
} |
35910
|
|
|
|
|
|
|
|
35911
|
|
|
|
|
|
|
static const struct cpu_feature x86_cpu_feature_table[] = { |
35912
|
|
|
|
|
|
|
{X86_CPU_FEATURE_SSE2, "sse2"}, |
35913
|
|
|
|
|
|
|
{X86_CPU_FEATURE_PCLMUL, "pclmul"}, |
35914
|
|
|
|
|
|
|
{X86_CPU_FEATURE_AVX, "avx"}, |
35915
|
|
|
|
|
|
|
{X86_CPU_FEATURE_AVX2, "avx2"}, |
35916
|
|
|
|
|
|
|
{X86_CPU_FEATURE_BMI2, "bmi2"}, |
35917
|
|
|
|
|
|
|
}; |
35918
|
|
|
|
|
|
|
|
35919
|
|
|
|
|
|
|
volatile u32 libdeflate_x86_cpu_features = 0; |
35920
|
|
|
|
|
|
|
|
35921
|
|
|
|
|
|
|
|
35922
|
2
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void) |
35923
|
|
|
|
|
|
|
{ |
35924
|
|
|
|
|
|
|
u32 max_leaf, a, b, c, d; |
35925
|
2
|
|
|
|
|
|
u64 xcr0 = 0; |
35926
|
2
|
|
|
|
|
|
u32 features = 0; |
35927
|
|
|
|
|
|
|
|
35928
|
|
|
|
|
|
|
|
35929
|
2
|
|
|
|
|
|
cpuid(0, 0, &max_leaf, &b, &c, &d); |
35930
|
2
|
50
|
|
|
|
|
if (max_leaf < 1) |
35931
|
0
|
|
|
|
|
|
goto out; |
35932
|
|
|
|
|
|
|
|
35933
|
|
|
|
|
|
|
|
35934
|
2
|
|
|
|
|
|
cpuid(1, 0, &a, &b, &c, &d); |
35935
|
2
|
50
|
|
|
|
|
if (d & (1 << 26)) |
35936
|
2
|
|
|
|
|
|
features |= X86_CPU_FEATURE_SSE2; |
35937
|
2
|
50
|
|
|
|
|
if (c & (1 << 1)) |
35938
|
0
|
|
|
|
|
|
features |= X86_CPU_FEATURE_PCLMUL; |
35939
|
2
|
50
|
|
|
|
|
if (c & (1 << 27)) |
35940
|
0
|
|
|
|
|
|
xcr0 = read_xcr(0); |
35941
|
2
|
50
|
|
|
|
|
if ((c & (1 << 28)) && ((xcr0 & 0x6) == 0x6)) |
|
|
0
|
|
|
|
|
|
35942
|
0
|
|
|
|
|
|
features |= X86_CPU_FEATURE_AVX; |
35943
|
|
|
|
|
|
|
|
35944
|
2
|
50
|
|
|
|
|
if (max_leaf < 7) |
35945
|
2
|
|
|
|
|
|
goto out; |
35946
|
|
|
|
|
|
|
|
35947
|
|
|
|
|
|
|
|
35948
|
0
|
|
|
|
|
|
cpuid(7, 0, &a, &b, &c, &d); |
35949
|
0
|
0
|
|
|
|
|
if ((b & (1 << 5)) && ((xcr0 & 0x6) == 0x6)) |
|
|
0
|
|
|
|
|
|
35950
|
0
|
|
|
|
|
|
features |= X86_CPU_FEATURE_AVX2; |
35951
|
0
|
0
|
|
|
|
|
if (b & (1 << 8)) |
35952
|
0
|
|
|
|
|
|
features |= X86_CPU_FEATURE_BMI2; |
35953
|
|
|
|
|
|
|
|
35954
|
|
|
|
|
|
|
out: |
35955
|
2
|
|
|
|
|
|
disable_cpu_features_for_testing(&features, x86_cpu_feature_table, |
35956
|
|
|
|
|
|
|
ARRAY_LEN(x86_cpu_feature_table)); |
35957
|
|
|
|
|
|
|
|
35958
|
2
|
|
|
|
|
|
libdeflate_x86_cpu_features = features | X86_CPU_FEATURES_KNOWN; |
35959
|
2
|
|
|
|
|
|
} |
35960
|
|
|
|
|
|
|
|
35961
|
|
|
|
|
|
|
#endif |