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.18/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 18 |
77
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
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
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
96
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
100
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
101
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
102
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
106
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
107
|
|
|
|
|
|
|
size_t in_nbytes); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
111
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
112
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
113
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
117
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
118
|
|
|
|
|
|
|
size_t in_nbytes); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
122
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
123
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
124
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
128
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
129
|
|
|
|
|
|
|
size_t in_nbytes); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
133
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
143
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
enum libdeflate_result { |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
158
|
|
|
|
|
|
|
}; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
162
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
163
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
164
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
165
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
169
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
170
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
171
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
172
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
173
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
177
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
178
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
179
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
180
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
184
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
185
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
186
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
187
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
188
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
192
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
193
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
194
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
195
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
199
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
200
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
201
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
202
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
203
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
207
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
215
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
220
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
228
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
229
|
|
|
|
|
|
|
void (*free_func)(void *)); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
#ifdef __cplusplus |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
#endif |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
#endif |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
#include |
239
|
|
|
|
|
|
|
#include |
240
|
|
|
|
|
|
|
#include |
241
|
|
|
|
|
|
|
#ifdef _MSC_VER |
242
|
|
|
|
|
|
|
# include |
243
|
|
|
|
|
|
|
# include |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
249
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
250
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
251
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
254
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
255
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
256
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
257
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
258
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
259
|
|
|
|
|
|
|
#endif |
260
|
|
|
|
|
|
|
#ifndef FREESTANDING |
261
|
|
|
|
|
|
|
# include |
262
|
|
|
|
|
|
|
#endif |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
270
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
271
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
272
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
273
|
|
|
|
|
|
|
#ifdef _MSC_VER |
274
|
|
|
|
|
|
|
# if defined(_M_X64) |
275
|
|
|
|
|
|
|
# define ARCH_X86_64 |
276
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
277
|
|
|
|
|
|
|
# define ARCH_X86_32 |
278
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
279
|
|
|
|
|
|
|
# define ARCH_ARM64 |
280
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
281
|
|
|
|
|
|
|
# define ARCH_ARM32 |
282
|
|
|
|
|
|
|
# endif |
283
|
|
|
|
|
|
|
#else |
284
|
|
|
|
|
|
|
# if defined(__x86_64__) |
285
|
|
|
|
|
|
|
# define ARCH_X86_64 |
286
|
|
|
|
|
|
|
# elif defined(__i386__) |
287
|
|
|
|
|
|
|
# define ARCH_X86_32 |
288
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
289
|
|
|
|
|
|
|
# define ARCH_ARM64 |
290
|
|
|
|
|
|
|
# elif defined(__arm__) |
291
|
|
|
|
|
|
|
# define ARCH_ARM32 |
292
|
|
|
|
|
|
|
# endif |
293
|
|
|
|
|
|
|
#endif |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
typedef uint8_t u8; |
301
|
|
|
|
|
|
|
typedef uint16_t u16; |
302
|
|
|
|
|
|
|
typedef uint32_t u32; |
303
|
|
|
|
|
|
|
typedef uint64_t u64; |
304
|
|
|
|
|
|
|
typedef int8_t s8; |
305
|
|
|
|
|
|
|
typedef int16_t s16; |
306
|
|
|
|
|
|
|
typedef int32_t s32; |
307
|
|
|
|
|
|
|
typedef int64_t s64; |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
#ifdef _MSC_VER |
311
|
|
|
|
|
|
|
# ifdef _WIN64 |
312
|
|
|
|
|
|
|
typedef long long ssize_t; |
313
|
|
|
|
|
|
|
# else |
314
|
|
|
|
|
|
|
typedef long ssize_t; |
315
|
|
|
|
|
|
|
# endif |
316
|
|
|
|
|
|
|
#endif |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
333
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
334
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
335
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
336
|
|
|
|
|
|
|
#else |
337
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
338
|
|
|
|
|
|
|
#endif |
339
|
|
|
|
|
|
|
#ifdef __clang__ |
340
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
341
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
342
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
343
|
|
|
|
|
|
|
# else |
344
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
345
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
346
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
347
|
|
|
|
|
|
|
# endif |
348
|
|
|
|
|
|
|
#else |
349
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
350
|
|
|
|
|
|
|
#endif |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
#ifndef __has_attribute |
354
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
355
|
|
|
|
|
|
|
#endif |
356
|
|
|
|
|
|
|
#ifndef __has_builtin |
357
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
358
|
|
|
|
|
|
|
#endif |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
#ifdef _MSC_VER |
362
|
|
|
|
|
|
|
# define inline __inline |
363
|
|
|
|
|
|
|
#endif |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
367
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
368
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
369
|
|
|
|
|
|
|
# define forceinline __forceinline |
370
|
|
|
|
|
|
|
#else |
371
|
|
|
|
|
|
|
# define forceinline inline |
372
|
|
|
|
|
|
|
#endif |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
376
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
377
|
|
|
|
|
|
|
#else |
378
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
379
|
|
|
|
|
|
|
#endif |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
383
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
384
|
|
|
|
|
|
|
# define restrict __restrict__ |
385
|
|
|
|
|
|
|
# else |
386
|
|
|
|
|
|
|
# define restrict |
387
|
|
|
|
|
|
|
# endif |
388
|
|
|
|
|
|
|
#endif |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
392
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
393
|
|
|
|
|
|
|
#else |
394
|
|
|
|
|
|
|
# define likely(expr) (expr) |
395
|
|
|
|
|
|
|
#endif |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
399
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
400
|
|
|
|
|
|
|
#else |
401
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
402
|
|
|
|
|
|
|
#endif |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
#undef prefetchr |
406
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
407
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
408
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
409
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
410
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
411
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
412
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
413
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
414
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
415
|
|
|
|
|
|
|
# endif |
416
|
|
|
|
|
|
|
#endif |
417
|
|
|
|
|
|
|
#ifndef prefetchr |
418
|
|
|
|
|
|
|
# define prefetchr(addr) |
419
|
|
|
|
|
|
|
#endif |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
#undef prefetchw |
423
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
424
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
425
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
426
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
427
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
428
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
429
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
430
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
431
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
432
|
|
|
|
|
|
|
# endif |
433
|
|
|
|
|
|
|
#endif |
434
|
|
|
|
|
|
|
#ifndef prefetchw |
435
|
|
|
|
|
|
|
# define prefetchw(addr) |
436
|
|
|
|
|
|
|
#endif |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
#undef _aligned_attribute |
440
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
441
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
442
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
443
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
444
|
|
|
|
|
|
|
#endif |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
448
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
449
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
450
|
|
|
|
|
|
|
#else |
451
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
452
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
453
|
|
|
|
|
|
|
#endif |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
460
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
461
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
462
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
463
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
464
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
465
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
473
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
474
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
475
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
476
|
|
|
|
|
|
|
#else |
477
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
478
|
|
|
|
|
|
|
{ |
479
|
|
|
|
|
|
|
union { |
480
|
|
|
|
|
|
|
u32 w; |
481
|
|
|
|
|
|
|
u8 b; |
482
|
|
|
|
|
|
|
} u; |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
u.w = 1; |
485
|
|
|
|
|
|
|
return u.b; |
486
|
|
|
|
|
|
|
} |
487
|
|
|
|
|
|
|
#endif |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
491
|
|
|
|
|
|
|
{ |
492
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
493
|
24
|
|
|
|
|
|
return __builtin_bswap16(v); |
494
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
495
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
496
|
|
|
|
|
|
|
#else |
497
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
498
|
|
|
|
|
|
|
#endif |
499
|
|
|
|
|
|
|
} |
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
503
|
|
|
|
|
|
|
{ |
504
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
505
|
24
|
|
|
|
|
|
return __builtin_bswap32(v); |
506
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
507
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
508
|
|
|
|
|
|
|
#else |
509
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
510
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
511
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
512
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
513
|
|
|
|
|
|
|
#endif |
514
|
|
|
|
|
|
|
} |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
518
|
|
|
|
|
|
|
{ |
519
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
520
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
521
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
522
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
523
|
|
|
|
|
|
|
#else |
524
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
525
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
526
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
527
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
528
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
529
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
530
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
531
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
532
|
|
|
|
|
|
|
#endif |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
536
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
537
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
538
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
539
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
540
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
548
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
549
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
550
|
|
|
|
|
|
|
defined(__wasm__)) |
551
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
552
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
553
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
554
|
|
|
|
|
|
|
#else |
555
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
556
|
|
|
|
|
|
|
#endif |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
#ifdef FREESTANDING |
561
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
562
|
|
|
|
|
|
|
#else |
563
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
564
|
|
|
|
|
|
|
#endif |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
569
|
|
|
|
|
|
|
static forceinline type \ |
570
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
571
|
|
|
|
|
|
|
{ \ |
572
|
|
|
|
|
|
|
type v; \ |
573
|
|
|
|
|
|
|
\ |
574
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
575
|
|
|
|
|
|
|
return v; \ |
576
|
|
|
|
|
|
|
} \ |
577
|
|
|
|
|
|
|
\ |
578
|
|
|
|
|
|
|
static forceinline void \ |
579
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
580
|
|
|
|
|
|
|
{ \ |
581
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
582
|
|
|
|
|
|
|
} |
583
|
|
|
|
|
|
|
|
584
|
12
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
585
|
128476
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
586
|
11015
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
587
|
298975
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
#undef MEMCOPY |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
592
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
static forceinline u16 |
597
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
598
|
|
|
|
|
|
|
{ |
599
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
600
|
0
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
601
|
|
|
|
|
|
|
else |
602
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
static forceinline u16 |
606
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
607
|
|
|
|
|
|
|
{ |
608
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
609
|
12
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
610
|
|
|
|
|
|
|
else |
611
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
612
|
|
|
|
|
|
|
} |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
static forceinline u32 |
615
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
616
|
|
|
|
|
|
|
{ |
617
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
618
|
86219
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
619
|
|
|
|
|
|
|
else |
620
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
621
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
622
|
|
|
|
|
|
|
} |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
static forceinline u32 |
625
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
626
|
|
|
|
|
|
|
{ |
627
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
628
|
12
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
629
|
|
|
|
|
|
|
else |
630
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
631
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
632
|
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
static forceinline u64 |
635
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
636
|
|
|
|
|
|
|
{ |
637
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
638
|
11015
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
639
|
|
|
|
|
|
|
else |
640
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
641
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
642
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
643
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
644
|
|
|
|
|
|
|
} |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
static forceinline machine_word_t |
647
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
648
|
|
|
|
|
|
|
{ |
649
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
650
|
|
|
|
|
|
|
if (WORDBITS == 32) |
651
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
652
|
|
|
|
|
|
|
else |
653
|
11015
|
|
|
|
|
|
return get_unaligned_le64(p); |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
static forceinline void |
659
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
660
|
|
|
|
|
|
|
{ |
661
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
662
|
0
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
663
|
|
|
|
|
|
|
} else { |
664
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
665
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
static forceinline void |
670
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
671
|
|
|
|
|
|
|
{ |
672
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
673
|
24
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
674
|
|
|
|
|
|
|
} else { |
675
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
676
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
677
|
|
|
|
|
|
|
} |
678
|
|
|
|
|
|
|
} |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
static forceinline void |
681
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
682
|
|
|
|
|
|
|
{ |
683
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
684
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
685
|
|
|
|
|
|
|
} else { |
686
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
687
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
688
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
689
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
} |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
static forceinline void |
694
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
695
|
|
|
|
|
|
|
{ |
696
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
697
|
12
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
698
|
|
|
|
|
|
|
} else { |
699
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
700
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
701
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
702
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
703
|
|
|
|
|
|
|
} |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
static forceinline void |
707
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
708
|
|
|
|
|
|
|
{ |
709
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
710
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
711
|
|
|
|
|
|
|
} else { |
712
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
713
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
714
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
715
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
716
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
717
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
718
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
719
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
} |
722
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
static forceinline void |
724
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
725
|
|
|
|
|
|
|
{ |
726
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
727
|
|
|
|
|
|
|
if (WORDBITS == 32) |
728
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
729
|
|
|
|
|
|
|
else |
730
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
731
|
|
|
|
|
|
|
} |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
static forceinline unsigned |
740
|
|
|
|
|
|
|
bsr32(u32 v) |
741
|
|
|
|
|
|
|
{ |
742
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
743
|
12249
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
744
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
745
|
|
|
|
|
|
|
unsigned long i; |
746
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
748
|
|
|
|
|
|
|
return i; |
749
|
|
|
|
|
|
|
#else |
750
|
|
|
|
|
|
|
unsigned i = 0; |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
753
|
|
|
|
|
|
|
i++; |
754
|
|
|
|
|
|
|
return i; |
755
|
|
|
|
|
|
|
#endif |
756
|
|
|
|
|
|
|
} |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
static forceinline unsigned |
759
|
|
|
|
|
|
|
bsr64(u64 v) |
760
|
|
|
|
|
|
|
{ |
761
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
762
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
763
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
764
|
|
|
|
|
|
|
unsigned long i; |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
767
|
|
|
|
|
|
|
return i; |
768
|
|
|
|
|
|
|
#else |
769
|
|
|
|
|
|
|
unsigned i = 0; |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
772
|
|
|
|
|
|
|
i++; |
773
|
|
|
|
|
|
|
return i; |
774
|
|
|
|
|
|
|
#endif |
775
|
|
|
|
|
|
|
} |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
static forceinline unsigned |
778
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
779
|
|
|
|
|
|
|
{ |
780
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
781
|
|
|
|
|
|
|
if (WORDBITS == 32) |
782
|
|
|
|
|
|
|
return bsr32(v); |
783
|
|
|
|
|
|
|
else |
784
|
|
|
|
|
|
|
return bsr64(v); |
785
|
|
|
|
|
|
|
} |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
|
789
|
|
|
|
|
|
|
static forceinline unsigned |
790
|
|
|
|
|
|
|
bsf32(u32 v) |
791
|
|
|
|
|
|
|
{ |
792
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
793
|
|
|
|
|
|
|
return __builtin_ctz(v); |
794
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
795
|
|
|
|
|
|
|
unsigned long i; |
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
798
|
|
|
|
|
|
|
return i; |
799
|
|
|
|
|
|
|
#else |
800
|
|
|
|
|
|
|
unsigned i = 0; |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
803
|
|
|
|
|
|
|
i++; |
804
|
|
|
|
|
|
|
return i; |
805
|
|
|
|
|
|
|
#endif |
806
|
|
|
|
|
|
|
} |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
static forceinline unsigned |
809
|
|
|
|
|
|
|
bsf64(u64 v) |
810
|
|
|
|
|
|
|
{ |
811
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
812
|
2632
|
|
|
|
|
|
return __builtin_ctzll(v); |
813
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
814
|
|
|
|
|
|
|
unsigned long i; |
815
|
|
|
|
|
|
|
|
816
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
817
|
|
|
|
|
|
|
return i; |
818
|
|
|
|
|
|
|
#else |
819
|
|
|
|
|
|
|
unsigned i = 0; |
820
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
822
|
|
|
|
|
|
|
i++; |
823
|
|
|
|
|
|
|
return i; |
824
|
|
|
|
|
|
|
#endif |
825
|
|
|
|
|
|
|
} |
826
|
|
|
|
|
|
|
|
827
|
|
|
|
|
|
|
static forceinline unsigned |
828
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
829
|
|
|
|
|
|
|
{ |
830
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
831
|
|
|
|
|
|
|
if (WORDBITS == 32) |
832
|
|
|
|
|
|
|
return bsf32(v); |
833
|
|
|
|
|
|
|
else |
834
|
2632
|
|
|
|
|
|
return bsf64(v); |
835
|
|
|
|
|
|
|
} |
836
|
|
|
|
|
|
|
|
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
#undef rbit32 |
839
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
840
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
841
|
|
|
|
|
|
|
static forceinline u32 |
842
|
|
|
|
|
|
|
rbit32(u32 v) |
843
|
|
|
|
|
|
|
{ |
844
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
845
|
|
|
|
|
|
|
return v; |
846
|
|
|
|
|
|
|
} |
847
|
|
|
|
|
|
|
#define rbit32 rbit32 |
848
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
849
|
|
|
|
|
|
|
static forceinline u32 |
850
|
|
|
|
|
|
|
rbit32(u32 v) |
851
|
|
|
|
|
|
|
{ |
852
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
853
|
|
|
|
|
|
|
return v; |
854
|
|
|
|
|
|
|
} |
855
|
|
|
|
|
|
|
#define rbit32 rbit32 |
856
|
|
|
|
|
|
|
#endif |
857
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
#endif |
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
862
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
863
|
|
|
|
|
|
|
|
864
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
865
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
866
|
|
|
|
|
|
|
|
867
|
|
|
|
|
|
|
#ifdef FREESTANDING |
868
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
870
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
871
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
873
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
876
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
879
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
882
|
|
|
|
|
|
|
#else |
883
|
|
|
|
|
|
|
#include |
884
|
|
|
|
|
|
|
#endif |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
888
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
889
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
890
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
891
|
|
|
|
|
|
|
#else |
892
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
893
|
|
|
|
|
|
|
#endif |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
896
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
897
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
#endif |
900
|
|
|
|
|
|
|
|
901
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
|
903
|
|
|
|
|
|
|
#define DIVISOR 65521 |
904
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
#define MAX_CHUNK_LEN 5552 |
907
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
static u32 MAYBE_UNUSED |
909
|
0
|
|
|
|
|
|
adler32_generic(u32 adler, const u8 *p, size_t len) |
910
|
|
|
|
|
|
|
{ |
911
|
0
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
912
|
0
|
|
|
|
|
|
u32 s2 = adler >> 16; |
913
|
0
|
|
|
|
|
|
const u8 * const end = p + len; |
914
|
|
|
|
|
|
|
|
915
|
0
|
0
|
|
|
|
|
while (p != end) { |
916
|
0
|
|
|
|
|
|
size_t chunk_len = MIN(end - p, MAX_CHUNK_LEN); |
917
|
0
|
|
|
|
|
|
const u8 *chunk_end = p + chunk_len; |
918
|
0
|
|
|
|
|
|
size_t num_unrolled_iterations = chunk_len / 4; |
919
|
|
|
|
|
|
|
|
920
|
0
|
0
|
|
|
|
|
while (num_unrolled_iterations--) { |
921
|
0
|
|
|
|
|
|
s1 += *p++; |
922
|
0
|
|
|
|
|
|
s2 += s1; |
923
|
0
|
|
|
|
|
|
s1 += *p++; |
924
|
0
|
|
|
|
|
|
s2 += s1; |
925
|
0
|
|
|
|
|
|
s1 += *p++; |
926
|
0
|
|
|
|
|
|
s2 += s1; |
927
|
0
|
|
|
|
|
|
s1 += *p++; |
928
|
0
|
|
|
|
|
|
s2 += s1; |
929
|
|
|
|
|
|
|
} |
930
|
0
|
0
|
|
|
|
|
while (p != chunk_end) { |
931
|
0
|
|
|
|
|
|
s1 += *p++; |
932
|
0
|
|
|
|
|
|
s2 += s1; |
933
|
|
|
|
|
|
|
} |
934
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
935
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
936
|
|
|
|
|
|
|
} |
937
|
|
|
|
|
|
|
|
938
|
0
|
|
|
|
|
|
return (s2 << 16) | s1; |
939
|
|
|
|
|
|
|
} |
940
|
|
|
|
|
|
|
|
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
#undef DEFAULT_IMPL |
943
|
|
|
|
|
|
|
#undef arch_select_adler32_func |
944
|
|
|
|
|
|
|
typedef u32 (*adler32_func_t)(u32 adler, const u8 *p, size_t len); |
945
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
946
|
|
|
|
|
|
|
/* # include "arm/adler32_impl.h" */ |
947
|
|
|
|
|
|
|
|
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
#ifndef LIB_ARM_ADLER32_IMPL_H |
950
|
|
|
|
|
|
|
#define LIB_ARM_ADLER32_IMPL_H |
951
|
|
|
|
|
|
|
|
952
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
956
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
957
|
|
|
|
|
|
|
|
958
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
|
961
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
962
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
965
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
967
|
|
|
|
|
|
|
#endif |
968
|
|
|
|
|
|
|
|
969
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
970
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
971
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
972
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
973
|
|
|
|
|
|
|
#else |
974
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
975
|
|
|
|
|
|
|
#endif |
976
|
|
|
|
|
|
|
|
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
979
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
980
|
|
|
|
|
|
|
#else |
981
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
982
|
|
|
|
|
|
|
#endif |
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
987
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
|
989
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
990
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
|
995
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
996
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
997
|
|
|
|
|
|
|
|
998
|
|
|
|
|
|
|
#include |
999
|
|
|
|
|
|
|
#include |
1000
|
|
|
|
|
|
|
|
1001
|
|
|
|
|
|
|
#ifdef __cplusplus |
1002
|
|
|
|
|
|
|
extern "C" { |
1003
|
|
|
|
|
|
|
#endif |
1004
|
|
|
|
|
|
|
|
1005
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
1006
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
1007
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
|
1010
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
1011
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
1012
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
1013
|
|
|
|
|
|
|
# else |
1014
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
1015
|
|
|
|
|
|
|
# endif |
1016
|
|
|
|
|
|
|
#endif |
1017
|
|
|
|
|
|
|
|
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
|
|
1022
|
|
|
|
|
|
|
struct libdeflate_compressor; |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
|
1025
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
1026
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
1027
|
|
|
|
|
|
|
|
1028
|
|
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1030
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
1031
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1032
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
1033
|
|
|
|
|
|
|
|
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1036
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
1037
|
|
|
|
|
|
|
size_t in_nbytes); |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
|
1040
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1041
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
1042
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1043
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
1044
|
|
|
|
|
|
|
|
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1047
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
1048
|
|
|
|
|
|
|
size_t in_nbytes); |
1049
|
|
|
|
|
|
|
|
1050
|
|
|
|
|
|
|
|
1051
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1052
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
1053
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1054
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
|
1057
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
1058
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
1059
|
|
|
|
|
|
|
size_t in_nbytes); |
1060
|
|
|
|
|
|
|
|
1061
|
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
1063
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
1064
|
|
|
|
|
|
|
|
1065
|
|
|
|
|
|
|
|
1066
|
|
|
|
|
|
|
|
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
1070
|
|
|
|
|
|
|
|
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
1073
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
1074
|
|
|
|
|
|
|
|
1075
|
|
|
|
|
|
|
|
1076
|
|
|
|
|
|
|
enum libdeflate_result { |
1077
|
|
|
|
|
|
|
|
1078
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
1079
|
|
|
|
|
|
|
|
1080
|
|
|
|
|
|
|
|
1081
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
1082
|
|
|
|
|
|
|
|
1083
|
|
|
|
|
|
|
|
1084
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
1085
|
|
|
|
|
|
|
|
1086
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
1088
|
|
|
|
|
|
|
}; |
1089
|
|
|
|
|
|
|
|
1090
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1092
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
1093
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1094
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1095
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1099
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
1100
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1101
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1102
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
1103
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1104
|
|
|
|
|
|
|
|
1105
|
|
|
|
|
|
|
|
1106
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1107
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
1108
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1109
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1110
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1111
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1114
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
1115
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1116
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1117
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
1118
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1122
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
1123
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1124
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1125
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
|
1128
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
1129
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
1130
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
1131
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
1132
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
1133
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
|
1136
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
1137
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
1138
|
|
|
|
|
|
|
|
1139
|
|
|
|
|
|
|
|
1140
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
|
1142
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
|
1144
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
1145
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
1146
|
|
|
|
|
|
|
|
1147
|
|
|
|
|
|
|
|
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
1150
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
1151
|
|
|
|
|
|
|
|
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
|
1154
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
|
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
1158
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
1159
|
|
|
|
|
|
|
void (*free_func)(void *)); |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
#ifdef __cplusplus |
1162
|
|
|
|
|
|
|
} |
1163
|
|
|
|
|
|
|
#endif |
1164
|
|
|
|
|
|
|
|
1165
|
|
|
|
|
|
|
#endif |
1166
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
|
#include |
1169
|
|
|
|
|
|
|
#include |
1170
|
|
|
|
|
|
|
#include |
1171
|
|
|
|
|
|
|
#ifdef _MSC_VER |
1172
|
|
|
|
|
|
|
# include |
1173
|
|
|
|
|
|
|
# include |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
|
1176
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
1177
|
|
|
|
|
|
|
|
1178
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
1179
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
1180
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
1181
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
1182
|
|
|
|
|
|
|
|
1183
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
1184
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
1185
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
1186
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
1187
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
1188
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
1189
|
|
|
|
|
|
|
#endif |
1190
|
|
|
|
|
|
|
#ifndef FREESTANDING |
1191
|
|
|
|
|
|
|
# include |
1192
|
|
|
|
|
|
|
#endif |
1193
|
|
|
|
|
|
|
|
1194
|
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
|
|
1196
|
|
|
|
|
|
|
|
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
|
1199
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
1200
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
1201
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
1202
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
1203
|
|
|
|
|
|
|
#ifdef _MSC_VER |
1204
|
|
|
|
|
|
|
# if defined(_M_X64) |
1205
|
|
|
|
|
|
|
# define ARCH_X86_64 |
1206
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
1207
|
|
|
|
|
|
|
# define ARCH_X86_32 |
1208
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
1209
|
|
|
|
|
|
|
# define ARCH_ARM64 |
1210
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
1211
|
|
|
|
|
|
|
# define ARCH_ARM32 |
1212
|
|
|
|
|
|
|
# endif |
1213
|
|
|
|
|
|
|
#else |
1214
|
|
|
|
|
|
|
# if defined(__x86_64__) |
1215
|
|
|
|
|
|
|
# define ARCH_X86_64 |
1216
|
|
|
|
|
|
|
# elif defined(__i386__) |
1217
|
|
|
|
|
|
|
# define ARCH_X86_32 |
1218
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
1219
|
|
|
|
|
|
|
# define ARCH_ARM64 |
1220
|
|
|
|
|
|
|
# elif defined(__arm__) |
1221
|
|
|
|
|
|
|
# define ARCH_ARM32 |
1222
|
|
|
|
|
|
|
# endif |
1223
|
|
|
|
|
|
|
#endif |
1224
|
|
|
|
|
|
|
|
1225
|
|
|
|
|
|
|
|
1226
|
|
|
|
|
|
|
|
1227
|
|
|
|
|
|
|
|
1228
|
|
|
|
|
|
|
|
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
typedef uint8_t u8; |
1231
|
|
|
|
|
|
|
typedef uint16_t u16; |
1232
|
|
|
|
|
|
|
typedef uint32_t u32; |
1233
|
|
|
|
|
|
|
typedef uint64_t u64; |
1234
|
|
|
|
|
|
|
typedef int8_t s8; |
1235
|
|
|
|
|
|
|
typedef int16_t s16; |
1236
|
|
|
|
|
|
|
typedef int32_t s32; |
1237
|
|
|
|
|
|
|
typedef int64_t s64; |
1238
|
|
|
|
|
|
|
|
1239
|
|
|
|
|
|
|
|
1240
|
|
|
|
|
|
|
#ifdef _MSC_VER |
1241
|
|
|
|
|
|
|
# ifdef _WIN64 |
1242
|
|
|
|
|
|
|
typedef long long ssize_t; |
1243
|
|
|
|
|
|
|
# else |
1244
|
|
|
|
|
|
|
typedef long ssize_t; |
1245
|
|
|
|
|
|
|
# endif |
1246
|
|
|
|
|
|
|
#endif |
1247
|
|
|
|
|
|
|
|
1248
|
|
|
|
|
|
|
|
1249
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
1250
|
|
|
|
|
|
|
|
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
1253
|
|
|
|
|
|
|
|
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
1256
|
|
|
|
|
|
|
|
1257
|
|
|
|
|
|
|
|
1258
|
|
|
|
|
|
|
|
1259
|
|
|
|
|
|
|
|
1260
|
|
|
|
|
|
|
|
1261
|
|
|
|
|
|
|
|
1262
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
1263
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
1264
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
1265
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
1266
|
|
|
|
|
|
|
#else |
1267
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
1268
|
|
|
|
|
|
|
#endif |
1269
|
|
|
|
|
|
|
#ifdef __clang__ |
1270
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
1271
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
1272
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
1273
|
|
|
|
|
|
|
# else |
1274
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
1275
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
1276
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
1277
|
|
|
|
|
|
|
# endif |
1278
|
|
|
|
|
|
|
#else |
1279
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
1280
|
|
|
|
|
|
|
#endif |
1281
|
|
|
|
|
|
|
|
1282
|
|
|
|
|
|
|
|
1283
|
|
|
|
|
|
|
#ifndef __has_attribute |
1284
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
1285
|
|
|
|
|
|
|
#endif |
1286
|
|
|
|
|
|
|
#ifndef __has_builtin |
1287
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
1288
|
|
|
|
|
|
|
#endif |
1289
|
|
|
|
|
|
|
|
1290
|
|
|
|
|
|
|
|
1291
|
|
|
|
|
|
|
#ifdef _MSC_VER |
1292
|
|
|
|
|
|
|
# define inline __inline |
1293
|
|
|
|
|
|
|
#endif |
1294
|
|
|
|
|
|
|
|
1295
|
|
|
|
|
|
|
|
1296
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
1297
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
1298
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1299
|
|
|
|
|
|
|
# define forceinline __forceinline |
1300
|
|
|
|
|
|
|
#else |
1301
|
|
|
|
|
|
|
# define forceinline inline |
1302
|
|
|
|
|
|
|
#endif |
1303
|
|
|
|
|
|
|
|
1304
|
|
|
|
|
|
|
|
1305
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
1306
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
1307
|
|
|
|
|
|
|
#else |
1308
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
1309
|
|
|
|
|
|
|
#endif |
1310
|
|
|
|
|
|
|
|
1311
|
|
|
|
|
|
|
|
1312
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
1313
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
1314
|
|
|
|
|
|
|
# define restrict __restrict__ |
1315
|
|
|
|
|
|
|
# else |
1316
|
|
|
|
|
|
|
# define restrict |
1317
|
|
|
|
|
|
|
# endif |
1318
|
|
|
|
|
|
|
#endif |
1319
|
|
|
|
|
|
|
|
1320
|
|
|
|
|
|
|
|
1321
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
1322
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
1323
|
|
|
|
|
|
|
#else |
1324
|
|
|
|
|
|
|
# define likely(expr) (expr) |
1325
|
|
|
|
|
|
|
#endif |
1326
|
|
|
|
|
|
|
|
1327
|
|
|
|
|
|
|
|
1328
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
1329
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
1330
|
|
|
|
|
|
|
#else |
1331
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
1332
|
|
|
|
|
|
|
#endif |
1333
|
|
|
|
|
|
|
|
1334
|
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
|
#undef prefetchr |
1336
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
1337
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
1338
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1339
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
1340
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
1341
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
1342
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
1343
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
1344
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
1345
|
|
|
|
|
|
|
# endif |
1346
|
|
|
|
|
|
|
#endif |
1347
|
|
|
|
|
|
|
#ifndef prefetchr |
1348
|
|
|
|
|
|
|
# define prefetchr(addr) |
1349
|
|
|
|
|
|
|
#endif |
1350
|
|
|
|
|
|
|
|
1351
|
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
|
#undef prefetchw |
1353
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
1354
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
1355
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1356
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
1357
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
1358
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
1359
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
1360
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
1361
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
1362
|
|
|
|
|
|
|
# endif |
1363
|
|
|
|
|
|
|
#endif |
1364
|
|
|
|
|
|
|
#ifndef prefetchw |
1365
|
|
|
|
|
|
|
# define prefetchw(addr) |
1366
|
|
|
|
|
|
|
#endif |
1367
|
|
|
|
|
|
|
|
1368
|
|
|
|
|
|
|
|
1369
|
|
|
|
|
|
|
#undef _aligned_attribute |
1370
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
1371
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
1372
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1373
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
1374
|
|
|
|
|
|
|
#endif |
1375
|
|
|
|
|
|
|
|
1376
|
|
|
|
|
|
|
|
1377
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
1378
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
1379
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
1380
|
|
|
|
|
|
|
#else |
1381
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
1382
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
1383
|
|
|
|
|
|
|
#endif |
1384
|
|
|
|
|
|
|
|
1385
|
|
|
|
|
|
|
|
1386
|
|
|
|
|
|
|
|
1387
|
|
|
|
|
|
|
|
1388
|
|
|
|
|
|
|
|
1389
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
1390
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
1391
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
1392
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
1393
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
1394
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
1395
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
1396
|
|
|
|
|
|
|
|
1397
|
|
|
|
|
|
|
|
1398
|
|
|
|
|
|
|
|
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
|
1401
|
|
|
|
|
|
|
|
1402
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
1403
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
1404
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1405
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
1406
|
|
|
|
|
|
|
#else |
1407
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
1408
|
|
|
|
|
|
|
{ |
1409
|
|
|
|
|
|
|
union { |
1410
|
|
|
|
|
|
|
u32 w; |
1411
|
|
|
|
|
|
|
u8 b; |
1412
|
|
|
|
|
|
|
} u; |
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
u.w = 1; |
1415
|
|
|
|
|
|
|
return u.b; |
1416
|
|
|
|
|
|
|
} |
1417
|
|
|
|
|
|
|
#endif |
1418
|
|
|
|
|
|
|
|
1419
|
|
|
|
|
|
|
|
1420
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
1421
|
|
|
|
|
|
|
{ |
1422
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
1423
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
1424
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1425
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
1426
|
|
|
|
|
|
|
#else |
1427
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
1428
|
|
|
|
|
|
|
#endif |
1429
|
|
|
|
|
|
|
} |
1430
|
|
|
|
|
|
|
|
1431
|
|
|
|
|
|
|
|
1432
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
1433
|
|
|
|
|
|
|
{ |
1434
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
1435
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
1436
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1437
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
1438
|
|
|
|
|
|
|
#else |
1439
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
1440
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
1441
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
1442
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
1443
|
|
|
|
|
|
|
#endif |
1444
|
|
|
|
|
|
|
} |
1445
|
|
|
|
|
|
|
|
1446
|
|
|
|
|
|
|
|
1447
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
1448
|
|
|
|
|
|
|
{ |
1449
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
1450
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
1451
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1452
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
1453
|
|
|
|
|
|
|
#else |
1454
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
1455
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
1456
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
1457
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
1458
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
1459
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
1460
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
1461
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
1462
|
|
|
|
|
|
|
#endif |
1463
|
|
|
|
|
|
|
} |
1464
|
|
|
|
|
|
|
|
1465
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
1466
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
1467
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
1468
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
1469
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
1470
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
1471
|
|
|
|
|
|
|
|
1472
|
|
|
|
|
|
|
|
1473
|
|
|
|
|
|
|
|
1474
|
|
|
|
|
|
|
|
1475
|
|
|
|
|
|
|
|
1476
|
|
|
|
|
|
|
|
1477
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
1478
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
1479
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
1480
|
|
|
|
|
|
|
defined(__wasm__)) |
1481
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
1482
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1483
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
1484
|
|
|
|
|
|
|
#else |
1485
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
1486
|
|
|
|
|
|
|
#endif |
1487
|
|
|
|
|
|
|
|
1488
|
|
|
|
|
|
|
|
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
#ifdef FREESTANDING |
1491
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
1492
|
|
|
|
|
|
|
#else |
1493
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
1494
|
|
|
|
|
|
|
#endif |
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
|
1497
|
|
|
|
|
|
|
|
1498
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
1499
|
|
|
|
|
|
|
static forceinline type \ |
1500
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
1501
|
|
|
|
|
|
|
{ \ |
1502
|
|
|
|
|
|
|
type v; \ |
1503
|
|
|
|
|
|
|
\ |
1504
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
1505
|
|
|
|
|
|
|
return v; \ |
1506
|
|
|
|
|
|
|
} \ |
1507
|
|
|
|
|
|
|
\ |
1508
|
|
|
|
|
|
|
static forceinline void \ |
1509
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
1510
|
|
|
|
|
|
|
{ \ |
1511
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
1512
|
|
|
|
|
|
|
} |
1513
|
|
|
|
|
|
|
|
1514
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
1515
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
1516
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
1517
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
1518
|
|
|
|
|
|
|
|
1519
|
|
|
|
|
|
|
#undef MEMCOPY |
1520
|
|
|
|
|
|
|
|
1521
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
1522
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
1523
|
|
|
|
|
|
|
|
1524
|
|
|
|
|
|
|
|
1525
|
|
|
|
|
|
|
|
1526
|
|
|
|
|
|
|
static forceinline u16 |
1527
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
1528
|
|
|
|
|
|
|
{ |
1529
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1530
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
1531
|
|
|
|
|
|
|
else |
1532
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
1533
|
|
|
|
|
|
|
} |
1534
|
|
|
|
|
|
|
|
1535
|
|
|
|
|
|
|
static forceinline u16 |
1536
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
1537
|
|
|
|
|
|
|
{ |
1538
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1539
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
1540
|
|
|
|
|
|
|
else |
1541
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
1542
|
|
|
|
|
|
|
} |
1543
|
|
|
|
|
|
|
|
1544
|
|
|
|
|
|
|
static forceinline u32 |
1545
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
1546
|
|
|
|
|
|
|
{ |
1547
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1548
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
1549
|
|
|
|
|
|
|
else |
1550
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
1551
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
1552
|
|
|
|
|
|
|
} |
1553
|
|
|
|
|
|
|
|
1554
|
|
|
|
|
|
|
static forceinline u32 |
1555
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
1556
|
|
|
|
|
|
|
{ |
1557
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1558
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
1559
|
|
|
|
|
|
|
else |
1560
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
1561
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
1562
|
|
|
|
|
|
|
} |
1563
|
|
|
|
|
|
|
|
1564
|
|
|
|
|
|
|
static forceinline u64 |
1565
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
1566
|
|
|
|
|
|
|
{ |
1567
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
1568
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
1569
|
|
|
|
|
|
|
else |
1570
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
1571
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
1572
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
1573
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
1574
|
|
|
|
|
|
|
} |
1575
|
|
|
|
|
|
|
|
1576
|
|
|
|
|
|
|
static forceinline machine_word_t |
1577
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
1578
|
|
|
|
|
|
|
{ |
1579
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
1580
|
|
|
|
|
|
|
if (WORDBITS == 32) |
1581
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
1582
|
|
|
|
|
|
|
else |
1583
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
1584
|
|
|
|
|
|
|
} |
1585
|
|
|
|
|
|
|
|
1586
|
|
|
|
|
|
|
|
1587
|
|
|
|
|
|
|
|
1588
|
|
|
|
|
|
|
static forceinline void |
1589
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
1590
|
|
|
|
|
|
|
{ |
1591
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1592
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
1593
|
|
|
|
|
|
|
} else { |
1594
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
1595
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
1596
|
|
|
|
|
|
|
} |
1597
|
|
|
|
|
|
|
} |
1598
|
|
|
|
|
|
|
|
1599
|
|
|
|
|
|
|
static forceinline void |
1600
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
1601
|
|
|
|
|
|
|
{ |
1602
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1603
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
1604
|
|
|
|
|
|
|
} else { |
1605
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
1606
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
1607
|
|
|
|
|
|
|
} |
1608
|
|
|
|
|
|
|
} |
1609
|
|
|
|
|
|
|
|
1610
|
|
|
|
|
|
|
static forceinline void |
1611
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
1612
|
|
|
|
|
|
|
{ |
1613
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1614
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
1615
|
|
|
|
|
|
|
} else { |
1616
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
1617
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
1618
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
1619
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
1620
|
|
|
|
|
|
|
} |
1621
|
|
|
|
|
|
|
} |
1622
|
|
|
|
|
|
|
|
1623
|
|
|
|
|
|
|
static forceinline void |
1624
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
1625
|
|
|
|
|
|
|
{ |
1626
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1627
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
1628
|
|
|
|
|
|
|
} else { |
1629
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
1630
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
1631
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
1632
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
1633
|
|
|
|
|
|
|
} |
1634
|
|
|
|
|
|
|
} |
1635
|
|
|
|
|
|
|
|
1636
|
|
|
|
|
|
|
static forceinline void |
1637
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
1638
|
|
|
|
|
|
|
{ |
1639
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
1640
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
1641
|
|
|
|
|
|
|
} else { |
1642
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
1643
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
1644
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
1645
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
1646
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
1647
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
1648
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
1649
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
1650
|
|
|
|
|
|
|
} |
1651
|
|
|
|
|
|
|
} |
1652
|
|
|
|
|
|
|
|
1653
|
|
|
|
|
|
|
static forceinline void |
1654
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
1655
|
|
|
|
|
|
|
{ |
1656
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
1657
|
|
|
|
|
|
|
if (WORDBITS == 32) |
1658
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
1659
|
|
|
|
|
|
|
else |
1660
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
1661
|
|
|
|
|
|
|
} |
1662
|
|
|
|
|
|
|
|
1663
|
|
|
|
|
|
|
|
1664
|
|
|
|
|
|
|
|
1665
|
|
|
|
|
|
|
|
1666
|
|
|
|
|
|
|
|
1667
|
|
|
|
|
|
|
|
1668
|
|
|
|
|
|
|
|
1669
|
|
|
|
|
|
|
static forceinline unsigned |
1670
|
|
|
|
|
|
|
bsr32(u32 v) |
1671
|
|
|
|
|
|
|
{ |
1672
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
1673
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
1674
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1675
|
|
|
|
|
|
|
unsigned long i; |
1676
|
|
|
|
|
|
|
|
1677
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
1678
|
|
|
|
|
|
|
return i; |
1679
|
|
|
|
|
|
|
#else |
1680
|
|
|
|
|
|
|
unsigned i = 0; |
1681
|
|
|
|
|
|
|
|
1682
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
1683
|
|
|
|
|
|
|
i++; |
1684
|
|
|
|
|
|
|
return i; |
1685
|
|
|
|
|
|
|
#endif |
1686
|
|
|
|
|
|
|
} |
1687
|
|
|
|
|
|
|
|
1688
|
|
|
|
|
|
|
static forceinline unsigned |
1689
|
|
|
|
|
|
|
bsr64(u64 v) |
1690
|
|
|
|
|
|
|
{ |
1691
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
1692
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
1693
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
1694
|
|
|
|
|
|
|
unsigned long i; |
1695
|
|
|
|
|
|
|
|
1696
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
1697
|
|
|
|
|
|
|
return i; |
1698
|
|
|
|
|
|
|
#else |
1699
|
|
|
|
|
|
|
unsigned i = 0; |
1700
|
|
|
|
|
|
|
|
1701
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
1702
|
|
|
|
|
|
|
i++; |
1703
|
|
|
|
|
|
|
return i; |
1704
|
|
|
|
|
|
|
#endif |
1705
|
|
|
|
|
|
|
} |
1706
|
|
|
|
|
|
|
|
1707
|
|
|
|
|
|
|
static forceinline unsigned |
1708
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
1709
|
|
|
|
|
|
|
{ |
1710
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
1711
|
|
|
|
|
|
|
if (WORDBITS == 32) |
1712
|
|
|
|
|
|
|
return bsr32(v); |
1713
|
|
|
|
|
|
|
else |
1714
|
|
|
|
|
|
|
return bsr64(v); |
1715
|
|
|
|
|
|
|
} |
1716
|
|
|
|
|
|
|
|
1717
|
|
|
|
|
|
|
|
1718
|
|
|
|
|
|
|
|
1719
|
|
|
|
|
|
|
static forceinline unsigned |
1720
|
|
|
|
|
|
|
bsf32(u32 v) |
1721
|
|
|
|
|
|
|
{ |
1722
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
1723
|
|
|
|
|
|
|
return __builtin_ctz(v); |
1724
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
1725
|
|
|
|
|
|
|
unsigned long i; |
1726
|
|
|
|
|
|
|
|
1727
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
1728
|
|
|
|
|
|
|
return i; |
1729
|
|
|
|
|
|
|
#else |
1730
|
|
|
|
|
|
|
unsigned i = 0; |
1731
|
|
|
|
|
|
|
|
1732
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
1733
|
|
|
|
|
|
|
i++; |
1734
|
|
|
|
|
|
|
return i; |
1735
|
|
|
|
|
|
|
#endif |
1736
|
|
|
|
|
|
|
} |
1737
|
|
|
|
|
|
|
|
1738
|
|
|
|
|
|
|
static forceinline unsigned |
1739
|
|
|
|
|
|
|
bsf64(u64 v) |
1740
|
|
|
|
|
|
|
{ |
1741
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
1742
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
1743
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
1744
|
|
|
|
|
|
|
unsigned long i; |
1745
|
|
|
|
|
|
|
|
1746
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
1747
|
|
|
|
|
|
|
return i; |
1748
|
|
|
|
|
|
|
#else |
1749
|
|
|
|
|
|
|
unsigned i = 0; |
1750
|
|
|
|
|
|
|
|
1751
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
1752
|
|
|
|
|
|
|
i++; |
1753
|
|
|
|
|
|
|
return i; |
1754
|
|
|
|
|
|
|
#endif |
1755
|
|
|
|
|
|
|
} |
1756
|
|
|
|
|
|
|
|
1757
|
|
|
|
|
|
|
static forceinline unsigned |
1758
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
1759
|
|
|
|
|
|
|
{ |
1760
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
1761
|
|
|
|
|
|
|
if (WORDBITS == 32) |
1762
|
|
|
|
|
|
|
return bsf32(v); |
1763
|
|
|
|
|
|
|
else |
1764
|
|
|
|
|
|
|
return bsf64(v); |
1765
|
|
|
|
|
|
|
} |
1766
|
|
|
|
|
|
|
|
1767
|
|
|
|
|
|
|
|
1768
|
|
|
|
|
|
|
#undef rbit32 |
1769
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
1770
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
1771
|
|
|
|
|
|
|
static forceinline u32 |
1772
|
|
|
|
|
|
|
rbit32(u32 v) |
1773
|
|
|
|
|
|
|
{ |
1774
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
1775
|
|
|
|
|
|
|
return v; |
1776
|
|
|
|
|
|
|
} |
1777
|
|
|
|
|
|
|
#define rbit32 rbit32 |
1778
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
1779
|
|
|
|
|
|
|
static forceinline u32 |
1780
|
|
|
|
|
|
|
rbit32(u32 v) |
1781
|
|
|
|
|
|
|
{ |
1782
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
1783
|
|
|
|
|
|
|
return v; |
1784
|
|
|
|
|
|
|
} |
1785
|
|
|
|
|
|
|
#define rbit32 rbit32 |
1786
|
|
|
|
|
|
|
#endif |
1787
|
|
|
|
|
|
|
|
1788
|
|
|
|
|
|
|
#endif |
1789
|
|
|
|
|
|
|
|
1790
|
|
|
|
|
|
|
|
1791
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
1792
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
1793
|
|
|
|
|
|
|
|
1794
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
1795
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
1796
|
|
|
|
|
|
|
|
1797
|
|
|
|
|
|
|
#ifdef FREESTANDING |
1798
|
|
|
|
|
|
|
|
1799
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
1800
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
1801
|
|
|
|
|
|
|
|
1802
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
1803
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
1804
|
|
|
|
|
|
|
|
1805
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
1806
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
1807
|
|
|
|
|
|
|
|
1808
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
1809
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
1810
|
|
|
|
|
|
|
|
1811
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
1812
|
|
|
|
|
|
|
#else |
1813
|
|
|
|
|
|
|
#include |
1814
|
|
|
|
|
|
|
#endif |
1815
|
|
|
|
|
|
|
|
1816
|
|
|
|
|
|
|
|
1817
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
1818
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
1819
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
1820
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
1821
|
|
|
|
|
|
|
#else |
1822
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
1823
|
|
|
|
|
|
|
#endif |
1824
|
|
|
|
|
|
|
|
1825
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
1826
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
1827
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
1828
|
|
|
|
|
|
|
|
1829
|
|
|
|
|
|
|
#endif |
1830
|
|
|
|
|
|
|
|
1831
|
|
|
|
|
|
|
|
1832
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
1833
|
|
|
|
|
|
|
|
1834
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
1835
|
|
|
|
|
|
|
|
1836
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
1837
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
1838
|
|
|
|
|
|
|
(defined(__linux__) || \ |
1839
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
1840
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
1841
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
1842
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
1843
|
|
|
|
|
|
|
#endif |
1844
|
|
|
|
|
|
|
|
1845
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
1846
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
1847
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
1848
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
1849
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
1850
|
|
|
|
|
|
|
|
1851
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
1852
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
1853
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
1854
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
1855
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
1856
|
|
|
|
|
|
|
|
1857
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
1858
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
1859
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
1860
|
|
|
|
|
|
|
|
1861
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
1862
|
|
|
|
|
|
|
|
1863
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
1864
|
|
|
|
|
|
|
{ |
1865
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
1866
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
1867
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
1868
|
|
|
|
|
|
|
} |
1869
|
|
|
|
|
|
|
#else |
1870
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
1871
|
|
|
|
|
|
|
#endif |
1872
|
|
|
|
|
|
|
|
1873
|
|
|
|
|
|
|
|
1874
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
1875
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
1876
|
|
|
|
|
|
|
#else |
1877
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
1878
|
|
|
|
|
|
|
#endif |
1879
|
|
|
|
|
|
|
|
1880
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
1881
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
1882
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
1883
|
|
|
|
|
|
|
#else |
1884
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
1885
|
|
|
|
|
|
|
#endif |
1886
|
|
|
|
|
|
|
|
1887
|
|
|
|
|
|
|
|
1888
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
1889
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
1890
|
|
|
|
|
|
|
#else |
1891
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
1892
|
|
|
|
|
|
|
#endif |
1893
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
1894
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
1895
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
1896
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
1897
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
1898
|
|
|
|
|
|
|
\ |
1899
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
1900
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
1901
|
|
|
|
|
|
|
|
1902
|
|
|
|
|
|
|
# ifdef _MSC_VER |
1903
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
1904
|
|
|
|
|
|
|
# else |
1905
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
1906
|
|
|
|
|
|
|
# endif |
1907
|
|
|
|
|
|
|
#else |
1908
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
1909
|
|
|
|
|
|
|
#endif |
1910
|
|
|
|
|
|
|
|
1911
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
1912
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
1913
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
1914
|
|
|
|
|
|
|
#else |
1915
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
1916
|
|
|
|
|
|
|
#endif |
1917
|
|
|
|
|
|
|
|
1918
|
|
|
|
|
|
|
|
1919
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
1920
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
1921
|
|
|
|
|
|
|
#else |
1922
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
1923
|
|
|
|
|
|
|
#endif |
1924
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
1925
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
1926
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
1927
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
1928
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
1929
|
|
|
|
|
|
|
|
1930
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
1931
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
1932
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
1933
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
1934
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
1935
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
1936
|
|
|
|
|
|
|
# endif |
1937
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
1938
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
1939
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
1940
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
1941
|
|
|
|
|
|
|
# endif |
1942
|
|
|
|
|
|
|
#endif |
1943
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
1944
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
1945
|
|
|
|
|
|
|
#endif |
1946
|
|
|
|
|
|
|
|
1947
|
|
|
|
|
|
|
|
1948
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
1949
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
1950
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
1951
|
|
|
|
|
|
|
# else |
1952
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
1953
|
|
|
|
|
|
|
# endif |
1954
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
1955
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
1956
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
1957
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
1958
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
1959
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
1960
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
1961
|
|
|
|
|
|
|
#else |
1962
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
1963
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
1964
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
1965
|
|
|
|
|
|
|
#endif |
1966
|
|
|
|
|
|
|
|
1967
|
|
|
|
|
|
|
|
1968
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
1969
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
1970
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
1971
|
|
|
|
|
|
|
# else |
1972
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
1973
|
|
|
|
|
|
|
# endif |
1974
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
1975
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
1976
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
1977
|
|
|
|
|
|
|
defined(_MSC_VER))) |
1978
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
1979
|
|
|
|
|
|
|
# else |
1980
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
1981
|
|
|
|
|
|
|
# endif |
1982
|
|
|
|
|
|
|
#else |
1983
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
1984
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
1985
|
|
|
|
|
|
|
#endif |
1986
|
|
|
|
|
|
|
|
1987
|
|
|
|
|
|
|
|
1988
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
1989
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
1990
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
1991
|
|
|
|
|
|
|
#endif |
1992
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
1993
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
1994
|
|
|
|
|
|
|
#endif |
1995
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
1996
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
1997
|
|
|
|
|
|
|
#endif |
1998
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
1999
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
2000
|
|
|
|
|
|
|
# include |
2001
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
2002
|
|
|
|
|
|
|
#endif |
2003
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
2004
|
|
|
|
|
|
|
# include |
2005
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
2006
|
|
|
|
|
|
|
#endif |
2007
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
2008
|
|
|
|
|
|
|
# include |
2009
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
2010
|
|
|
|
|
|
|
#endif |
2011
|
|
|
|
|
|
|
|
2012
|
|
|
|
|
|
|
#endif |
2013
|
|
|
|
|
|
|
|
2014
|
|
|
|
|
|
|
#endif |
2015
|
|
|
|
|
|
|
|
2016
|
|
|
|
|
|
|
|
2017
|
|
|
|
|
|
|
|
2018
|
|
|
|
|
|
|
#if HAVE_NEON_INTRIN && CPU_IS_LITTLE_ENDIAN() |
2019
|
|
|
|
|
|
|
# define adler32_neon adler32_neon |
2020
|
|
|
|
|
|
|
# define FUNCNAME adler32_neon |
2021
|
|
|
|
|
|
|
# define FUNCNAME_CHUNK adler32_neon_chunk |
2022
|
|
|
|
|
|
|
# define IMPL_ALIGNMENT 16 |
2023
|
|
|
|
|
|
|
# define IMPL_SEGMENT_LEN 64 |
2024
|
|
|
|
|
|
|
|
2025
|
|
|
|
|
|
|
# define IMPL_MAX_CHUNK_LEN (64 * (0xFFFF / 0xFF)) |
2026
|
|
|
|
|
|
|
# if HAVE_NEON_NATIVE |
2027
|
|
|
|
|
|
|
# define ATTRIBUTES |
2028
|
|
|
|
|
|
|
# else |
2029
|
|
|
|
|
|
|
# ifdef ARCH_ARM32 |
2030
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("fpu=neon") |
2031
|
|
|
|
|
|
|
# else |
2032
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+simd") |
2033
|
|
|
|
|
|
|
# endif |
2034
|
|
|
|
|
|
|
# endif |
2035
|
|
|
|
|
|
|
# include |
2036
|
|
|
|
|
|
|
static forceinline ATTRIBUTES void |
2037
|
|
|
|
|
|
|
adler32_neon_chunk(const uint8x16_t *p, const uint8x16_t * const end, |
2038
|
|
|
|
|
|
|
u32 *s1, u32 *s2) |
2039
|
|
|
|
|
|
|
{ |
2040
|
|
|
|
|
|
|
static const u16 _aligned_attribute(16) mults[64] = { |
2041
|
|
|
|
|
|
|
64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, |
2042
|
|
|
|
|
|
|
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, |
2043
|
|
|
|
|
|
|
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, |
2044
|
|
|
|
|
|
|
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, |
2045
|
|
|
|
|
|
|
}; |
2046
|
|
|
|
|
|
|
const uint16x8_t mults_a = vld1q_u16(&mults[0]); |
2047
|
|
|
|
|
|
|
const uint16x8_t mults_b = vld1q_u16(&mults[8]); |
2048
|
|
|
|
|
|
|
const uint16x8_t mults_c = vld1q_u16(&mults[16]); |
2049
|
|
|
|
|
|
|
const uint16x8_t mults_d = vld1q_u16(&mults[24]); |
2050
|
|
|
|
|
|
|
const uint16x8_t mults_e = vld1q_u16(&mults[32]); |
2051
|
|
|
|
|
|
|
const uint16x8_t mults_f = vld1q_u16(&mults[40]); |
2052
|
|
|
|
|
|
|
const uint16x8_t mults_g = vld1q_u16(&mults[48]); |
2053
|
|
|
|
|
|
|
const uint16x8_t mults_h = vld1q_u16(&mults[56]); |
2054
|
|
|
|
|
|
|
|
2055
|
|
|
|
|
|
|
uint32x4_t v_s1 = vdupq_n_u32(0); |
2056
|
|
|
|
|
|
|
uint32x4_t v_s2 = vdupq_n_u32(0); |
2057
|
|
|
|
|
|
|
|
2058
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_a = vdupq_n_u16(0); |
2059
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_b = vdupq_n_u16(0); |
2060
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_c = vdupq_n_u16(0); |
2061
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_d = vdupq_n_u16(0); |
2062
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_e = vdupq_n_u16(0); |
2063
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_f = vdupq_n_u16(0); |
2064
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_g = vdupq_n_u16(0); |
2065
|
|
|
|
|
|
|
uint16x8_t v_byte_sums_h = vdupq_n_u16(0); |
2066
|
|
|
|
|
|
|
|
2067
|
|
|
|
|
|
|
do { |
2068
|
|
|
|
|
|
|
|
2069
|
|
|
|
|
|
|
const uint8x16_t bytes1 = *p++; |
2070
|
|
|
|
|
|
|
const uint8x16_t bytes2 = *p++; |
2071
|
|
|
|
|
|
|
const uint8x16_t bytes3 = *p++; |
2072
|
|
|
|
|
|
|
const uint8x16_t bytes4 = *p++; |
2073
|
|
|
|
|
|
|
uint16x8_t tmp; |
2074
|
|
|
|
|
|
|
|
2075
|
|
|
|
|
|
|
|
2076
|
|
|
|
|
|
|
v_s2 = vaddq_u32(v_s2, v_s1); |
2077
|
|
|
|
|
|
|
|
2078
|
|
|
|
|
|
|
|
2079
|
|
|
|
|
|
|
tmp = vpaddlq_u8(bytes1); |
2080
|
|
|
|
|
|
|
v_byte_sums_a = vaddw_u8(v_byte_sums_a, vget_low_u8(bytes1)); |
2081
|
|
|
|
|
|
|
v_byte_sums_b = vaddw_u8(v_byte_sums_b, vget_high_u8(bytes1)); |
2082
|
|
|
|
|
|
|
tmp = vpadalq_u8(tmp, bytes2); |
2083
|
|
|
|
|
|
|
v_byte_sums_c = vaddw_u8(v_byte_sums_c, vget_low_u8(bytes2)); |
2084
|
|
|
|
|
|
|
v_byte_sums_d = vaddw_u8(v_byte_sums_d, vget_high_u8(bytes2)); |
2085
|
|
|
|
|
|
|
tmp = vpadalq_u8(tmp, bytes3); |
2086
|
|
|
|
|
|
|
v_byte_sums_e = vaddw_u8(v_byte_sums_e, vget_low_u8(bytes3)); |
2087
|
|
|
|
|
|
|
v_byte_sums_f = vaddw_u8(v_byte_sums_f, vget_high_u8(bytes3)); |
2088
|
|
|
|
|
|
|
tmp = vpadalq_u8(tmp, bytes4); |
2089
|
|
|
|
|
|
|
v_byte_sums_g = vaddw_u8(v_byte_sums_g, vget_low_u8(bytes4)); |
2090
|
|
|
|
|
|
|
v_byte_sums_h = vaddw_u8(v_byte_sums_h, vget_high_u8(bytes4)); |
2091
|
|
|
|
|
|
|
v_s1 = vpadalq_u16(v_s1, tmp); |
2092
|
|
|
|
|
|
|
|
2093
|
|
|
|
|
|
|
} while (p != end); |
2094
|
|
|
|
|
|
|
|
2095
|
|
|
|
|
|
|
|
2096
|
|
|
|
|
|
|
#ifdef ARCH_ARM32 |
2097
|
|
|
|
|
|
|
# define umlal2(a, b, c) vmlal_u16((a), vget_high_u16(b), vget_high_u16(c)) |
2098
|
|
|
|
|
|
|
#else |
2099
|
|
|
|
|
|
|
# define umlal2 vmlal_high_u16 |
2100
|
|
|
|
|
|
|
#endif |
2101
|
|
|
|
|
|
|
v_s2 = vqshlq_n_u32(v_s2, 6); |
2102
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_a), vget_low_u16(mults_a)); |
2103
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_a, mults_a); |
2104
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_b), vget_low_u16(mults_b)); |
2105
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_b, mults_b); |
2106
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_c), vget_low_u16(mults_c)); |
2107
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_c, mults_c); |
2108
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_d), vget_low_u16(mults_d)); |
2109
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_d, mults_d); |
2110
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_e), vget_low_u16(mults_e)); |
2111
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_e, mults_e); |
2112
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_f), vget_low_u16(mults_f)); |
2113
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_f, mults_f); |
2114
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_g), vget_low_u16(mults_g)); |
2115
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_g, mults_g); |
2116
|
|
|
|
|
|
|
v_s2 = vmlal_u16(v_s2, vget_low_u16(v_byte_sums_h), vget_low_u16(mults_h)); |
2117
|
|
|
|
|
|
|
v_s2 = umlal2(v_s2, v_byte_sums_h, mults_h); |
2118
|
|
|
|
|
|
|
#undef umlal2 |
2119
|
|
|
|
|
|
|
|
2120
|
|
|
|
|
|
|
|
2121
|
|
|
|
|
|
|
#ifdef ARCH_ARM32 |
2122
|
|
|
|
|
|
|
*s1 += vgetq_lane_u32(v_s1, 0) + vgetq_lane_u32(v_s1, 1) + |
2123
|
|
|
|
|
|
|
vgetq_lane_u32(v_s1, 2) + vgetq_lane_u32(v_s1, 3); |
2124
|
|
|
|
|
|
|
*s2 += vgetq_lane_u32(v_s2, 0) + vgetq_lane_u32(v_s2, 1) + |
2125
|
|
|
|
|
|
|
vgetq_lane_u32(v_s2, 2) + vgetq_lane_u32(v_s2, 3); |
2126
|
|
|
|
|
|
|
#else |
2127
|
|
|
|
|
|
|
*s1 += vaddvq_u32(v_s1); |
2128
|
|
|
|
|
|
|
*s2 += vaddvq_u32(v_s2); |
2129
|
|
|
|
|
|
|
#endif |
2130
|
|
|
|
|
|
|
} |
2131
|
|
|
|
|
|
|
/* #include "adler32_vec_template.h" */ |
2132
|
|
|
|
|
|
|
|
2133
|
|
|
|
|
|
|
|
2134
|
|
|
|
|
|
|
|
2135
|
|
|
|
|
|
|
|
2136
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
2137
|
|
|
|
|
|
|
FUNCNAME(u32 adler, const u8 *p, size_t len) |
2138
|
|
|
|
|
|
|
{ |
2139
|
|
|
|
|
|
|
const size_t max_chunk_len = |
2140
|
|
|
|
|
|
|
MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) - |
2141
|
|
|
|
|
|
|
(MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) % IMPL_SEGMENT_LEN); |
2142
|
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
2143
|
|
|
|
|
|
|
u32 s2 = adler >> 16; |
2144
|
|
|
|
|
|
|
const u8 * const end = p + len; |
2145
|
|
|
|
|
|
|
const u8 *vend; |
2146
|
|
|
|
|
|
|
|
2147
|
|
|
|
|
|
|
|
2148
|
|
|
|
|
|
|
if (p != end && (uintptr_t)p % IMPL_ALIGNMENT) { |
2149
|
|
|
|
|
|
|
do { |
2150
|
|
|
|
|
|
|
s1 += *p++; |
2151
|
|
|
|
|
|
|
s2 += s1; |
2152
|
|
|
|
|
|
|
} while (p != end && (uintptr_t)p % IMPL_ALIGNMENT); |
2153
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2154
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2155
|
|
|
|
|
|
|
} |
2156
|
|
|
|
|
|
|
|
2157
|
|
|
|
|
|
|
|
2158
|
|
|
|
|
|
|
STATIC_ASSERT(IMPL_SEGMENT_LEN % IMPL_ALIGNMENT == 0); |
2159
|
|
|
|
|
|
|
vend = end - ((size_t)(end - p) % IMPL_SEGMENT_LEN); |
2160
|
|
|
|
|
|
|
while (p != vend) { |
2161
|
|
|
|
|
|
|
size_t chunk_len = MIN((size_t)(vend - p), max_chunk_len); |
2162
|
|
|
|
|
|
|
|
2163
|
|
|
|
|
|
|
s2 += s1 * chunk_len; |
2164
|
|
|
|
|
|
|
|
2165
|
|
|
|
|
|
|
FUNCNAME_CHUNK((const void *)p, (const void *)(p + chunk_len), |
2166
|
|
|
|
|
|
|
&s1, &s2); |
2167
|
|
|
|
|
|
|
|
2168
|
|
|
|
|
|
|
p += chunk_len; |
2169
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2170
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2171
|
|
|
|
|
|
|
} |
2172
|
|
|
|
|
|
|
|
2173
|
|
|
|
|
|
|
|
2174
|
|
|
|
|
|
|
if (p != end) { |
2175
|
|
|
|
|
|
|
do { |
2176
|
|
|
|
|
|
|
s1 += *p++; |
2177
|
|
|
|
|
|
|
s2 += s1; |
2178
|
|
|
|
|
|
|
} while (p != end); |
2179
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2180
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2181
|
|
|
|
|
|
|
} |
2182
|
|
|
|
|
|
|
|
2183
|
|
|
|
|
|
|
return (s2 << 16) | s1; |
2184
|
|
|
|
|
|
|
} |
2185
|
|
|
|
|
|
|
|
2186
|
|
|
|
|
|
|
#undef FUNCNAME |
2187
|
|
|
|
|
|
|
#undef FUNCNAME_CHUNK |
2188
|
|
|
|
|
|
|
#undef ATTRIBUTES |
2189
|
|
|
|
|
|
|
#undef IMPL_ALIGNMENT |
2190
|
|
|
|
|
|
|
#undef IMPL_SEGMENT_LEN |
2191
|
|
|
|
|
|
|
#undef IMPL_MAX_CHUNK_LEN |
2192
|
|
|
|
|
|
|
|
2193
|
|
|
|
|
|
|
#endif |
2194
|
|
|
|
|
|
|
|
2195
|
|
|
|
|
|
|
|
2196
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && CPU_IS_LITTLE_ENDIAN() |
2197
|
|
|
|
|
|
|
# define adler32_neon_dotprod adler32_neon_dotprod |
2198
|
|
|
|
|
|
|
# define FUNCNAME adler32_neon_dotprod |
2199
|
|
|
|
|
|
|
# define FUNCNAME_CHUNK adler32_neon_dotprod_chunk |
2200
|
|
|
|
|
|
|
# define IMPL_ALIGNMENT 16 |
2201
|
|
|
|
|
|
|
# define IMPL_SEGMENT_LEN 64 |
2202
|
|
|
|
|
|
|
# define IMPL_MAX_CHUNK_LEN MAX_CHUNK_LEN |
2203
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE |
2204
|
|
|
|
|
|
|
# define ATTRIBUTES |
2205
|
|
|
|
|
|
|
# else |
2206
|
|
|
|
|
|
|
# ifdef __clang__ |
2207
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("dotprod") |
2208
|
|
|
|
|
|
|
|
2209
|
|
|
|
|
|
|
# elif defined(__ARM_FEATURE_JCVT) |
2210
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+dotprod") |
2211
|
|
|
|
|
|
|
# else |
2212
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8.2-a+dotprod") |
2213
|
|
|
|
|
|
|
# endif |
2214
|
|
|
|
|
|
|
# endif |
2215
|
|
|
|
|
|
|
# include |
2216
|
|
|
|
|
|
|
static forceinline ATTRIBUTES void |
2217
|
|
|
|
|
|
|
adler32_neon_dotprod_chunk(const uint8x16_t *p, const uint8x16_t * const end, |
2218
|
|
|
|
|
|
|
u32 *s1, u32 *s2) |
2219
|
|
|
|
|
|
|
{ |
2220
|
|
|
|
|
|
|
static const u8 _aligned_attribute(16) mults[64] = { |
2221
|
|
|
|
|
|
|
64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, |
2222
|
|
|
|
|
|
|
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, |
2223
|
|
|
|
|
|
|
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, |
2224
|
|
|
|
|
|
|
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, |
2225
|
|
|
|
|
|
|
}; |
2226
|
|
|
|
|
|
|
const uint8x16_t mults_a = vld1q_u8(&mults[0]); |
2227
|
|
|
|
|
|
|
const uint8x16_t mults_b = vld1q_u8(&mults[16]); |
2228
|
|
|
|
|
|
|
const uint8x16_t mults_c = vld1q_u8(&mults[32]); |
2229
|
|
|
|
|
|
|
const uint8x16_t mults_d = vld1q_u8(&mults[48]); |
2230
|
|
|
|
|
|
|
const uint8x16_t ones = vdupq_n_u8(1); |
2231
|
|
|
|
|
|
|
uint32x4_t v_s1_a = vdupq_n_u32(0); |
2232
|
|
|
|
|
|
|
uint32x4_t v_s1_b = vdupq_n_u32(0); |
2233
|
|
|
|
|
|
|
uint32x4_t v_s1_c = vdupq_n_u32(0); |
2234
|
|
|
|
|
|
|
uint32x4_t v_s1_d = vdupq_n_u32(0); |
2235
|
|
|
|
|
|
|
uint32x4_t v_s2_a = vdupq_n_u32(0); |
2236
|
|
|
|
|
|
|
uint32x4_t v_s2_b = vdupq_n_u32(0); |
2237
|
|
|
|
|
|
|
uint32x4_t v_s2_c = vdupq_n_u32(0); |
2238
|
|
|
|
|
|
|
uint32x4_t v_s2_d = vdupq_n_u32(0); |
2239
|
|
|
|
|
|
|
uint32x4_t v_s1_sums_a = vdupq_n_u32(0); |
2240
|
|
|
|
|
|
|
uint32x4_t v_s1_sums_b = vdupq_n_u32(0); |
2241
|
|
|
|
|
|
|
uint32x4_t v_s1_sums_c = vdupq_n_u32(0); |
2242
|
|
|
|
|
|
|
uint32x4_t v_s1_sums_d = vdupq_n_u32(0); |
2243
|
|
|
|
|
|
|
uint32x4_t v_s1; |
2244
|
|
|
|
|
|
|
uint32x4_t v_s2; |
2245
|
|
|
|
|
|
|
uint32x4_t v_s1_sums; |
2246
|
|
|
|
|
|
|
|
2247
|
|
|
|
|
|
|
do { |
2248
|
|
|
|
|
|
|
uint8x16_t bytes_a = *p++; |
2249
|
|
|
|
|
|
|
uint8x16_t bytes_b = *p++; |
2250
|
|
|
|
|
|
|
uint8x16_t bytes_c = *p++; |
2251
|
|
|
|
|
|
|
uint8x16_t bytes_d = *p++; |
2252
|
|
|
|
|
|
|
|
2253
|
|
|
|
|
|
|
v_s1_sums_a = vaddq_u32(v_s1_sums_a, v_s1_a); |
2254
|
|
|
|
|
|
|
v_s1_a = vdotq_u32(v_s1_a, bytes_a, ones); |
2255
|
|
|
|
|
|
|
v_s2_a = vdotq_u32(v_s2_a, bytes_a, mults_a); |
2256
|
|
|
|
|
|
|
|
2257
|
|
|
|
|
|
|
v_s1_sums_b = vaddq_u32(v_s1_sums_b, v_s1_b); |
2258
|
|
|
|
|
|
|
v_s1_b = vdotq_u32(v_s1_b, bytes_b, ones); |
2259
|
|
|
|
|
|
|
v_s2_b = vdotq_u32(v_s2_b, bytes_b, mults_b); |
2260
|
|
|
|
|
|
|
|
2261
|
|
|
|
|
|
|
v_s1_sums_c = vaddq_u32(v_s1_sums_c, v_s1_c); |
2262
|
|
|
|
|
|
|
v_s1_c = vdotq_u32(v_s1_c, bytes_c, ones); |
2263
|
|
|
|
|
|
|
v_s2_c = vdotq_u32(v_s2_c, bytes_c, mults_c); |
2264
|
|
|
|
|
|
|
|
2265
|
|
|
|
|
|
|
v_s1_sums_d = vaddq_u32(v_s1_sums_d, v_s1_d); |
2266
|
|
|
|
|
|
|
v_s1_d = vdotq_u32(v_s1_d, bytes_d, ones); |
2267
|
|
|
|
|
|
|
v_s2_d = vdotq_u32(v_s2_d, bytes_d, mults_d); |
2268
|
|
|
|
|
|
|
} while (p != end); |
2269
|
|
|
|
|
|
|
|
2270
|
|
|
|
|
|
|
v_s1 = vaddq_u32(vaddq_u32(v_s1_a, v_s1_b), vaddq_u32(v_s1_c, v_s1_d)); |
2271
|
|
|
|
|
|
|
v_s2 = vaddq_u32(vaddq_u32(v_s2_a, v_s2_b), vaddq_u32(v_s2_c, v_s2_d)); |
2272
|
|
|
|
|
|
|
v_s1_sums = vaddq_u32(vaddq_u32(v_s1_sums_a, v_s1_sums_b), |
2273
|
|
|
|
|
|
|
vaddq_u32(v_s1_sums_c, v_s1_sums_d)); |
2274
|
|
|
|
|
|
|
v_s2 = vaddq_u32(v_s2, vqshlq_n_u32(v_s1_sums, 6)); |
2275
|
|
|
|
|
|
|
|
2276
|
|
|
|
|
|
|
*s1 += vaddvq_u32(v_s1); |
2277
|
|
|
|
|
|
|
*s2 += vaddvq_u32(v_s2); |
2278
|
|
|
|
|
|
|
} |
2279
|
|
|
|
|
|
|
/* #include "arm-../adler32_vec_template.h" */ |
2280
|
|
|
|
|
|
|
|
2281
|
|
|
|
|
|
|
|
2282
|
|
|
|
|
|
|
|
2283
|
|
|
|
|
|
|
|
2284
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
2285
|
|
|
|
|
|
|
FUNCNAME(u32 adler, const u8 *p, size_t len) |
2286
|
|
|
|
|
|
|
{ |
2287
|
|
|
|
|
|
|
const size_t max_chunk_len = |
2288
|
|
|
|
|
|
|
MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) - |
2289
|
|
|
|
|
|
|
(MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) % IMPL_SEGMENT_LEN); |
2290
|
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
2291
|
|
|
|
|
|
|
u32 s2 = adler >> 16; |
2292
|
|
|
|
|
|
|
const u8 * const end = p + len; |
2293
|
|
|
|
|
|
|
const u8 *vend; |
2294
|
|
|
|
|
|
|
|
2295
|
|
|
|
|
|
|
|
2296
|
|
|
|
|
|
|
if (p != end && (uintptr_t)p % IMPL_ALIGNMENT) { |
2297
|
|
|
|
|
|
|
do { |
2298
|
|
|
|
|
|
|
s1 += *p++; |
2299
|
|
|
|
|
|
|
s2 += s1; |
2300
|
|
|
|
|
|
|
} while (p != end && (uintptr_t)p % IMPL_ALIGNMENT); |
2301
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2302
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2303
|
|
|
|
|
|
|
} |
2304
|
|
|
|
|
|
|
|
2305
|
|
|
|
|
|
|
|
2306
|
|
|
|
|
|
|
STATIC_ASSERT(IMPL_SEGMENT_LEN % IMPL_ALIGNMENT == 0); |
2307
|
|
|
|
|
|
|
vend = end - ((size_t)(end - p) % IMPL_SEGMENT_LEN); |
2308
|
|
|
|
|
|
|
while (p != vend) { |
2309
|
|
|
|
|
|
|
size_t chunk_len = MIN((size_t)(vend - p), max_chunk_len); |
2310
|
|
|
|
|
|
|
|
2311
|
|
|
|
|
|
|
s2 += s1 * chunk_len; |
2312
|
|
|
|
|
|
|
|
2313
|
|
|
|
|
|
|
FUNCNAME_CHUNK((const void *)p, (const void *)(p + chunk_len), |
2314
|
|
|
|
|
|
|
&s1, &s2); |
2315
|
|
|
|
|
|
|
|
2316
|
|
|
|
|
|
|
p += chunk_len; |
2317
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2318
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2319
|
|
|
|
|
|
|
} |
2320
|
|
|
|
|
|
|
|
2321
|
|
|
|
|
|
|
|
2322
|
|
|
|
|
|
|
if (p != end) { |
2323
|
|
|
|
|
|
|
do { |
2324
|
|
|
|
|
|
|
s1 += *p++; |
2325
|
|
|
|
|
|
|
s2 += s1; |
2326
|
|
|
|
|
|
|
} while (p != end); |
2327
|
|
|
|
|
|
|
s1 %= DIVISOR; |
2328
|
|
|
|
|
|
|
s2 %= DIVISOR; |
2329
|
|
|
|
|
|
|
} |
2330
|
|
|
|
|
|
|
|
2331
|
|
|
|
|
|
|
return (s2 << 16) | s1; |
2332
|
|
|
|
|
|
|
} |
2333
|
|
|
|
|
|
|
|
2334
|
|
|
|
|
|
|
#undef FUNCNAME |
2335
|
|
|
|
|
|
|
#undef FUNCNAME_CHUNK |
2336
|
|
|
|
|
|
|
#undef ATTRIBUTES |
2337
|
|
|
|
|
|
|
#undef IMPL_ALIGNMENT |
2338
|
|
|
|
|
|
|
#undef IMPL_SEGMENT_LEN |
2339
|
|
|
|
|
|
|
#undef IMPL_MAX_CHUNK_LEN |
2340
|
|
|
|
|
|
|
|
2341
|
|
|
|
|
|
|
#endif |
2342
|
|
|
|
|
|
|
|
2343
|
|
|
|
|
|
|
#if defined(adler32_neon_dotprod) && HAVE_DOTPROD_NATIVE |
2344
|
|
|
|
|
|
|
#define DEFAULT_IMPL adler32_neon_dotprod |
2345
|
|
|
|
|
|
|
#else |
2346
|
|
|
|
|
|
|
static inline adler32_func_t |
2347
|
|
|
|
|
|
|
arch_select_adler32_func(void) |
2348
|
|
|
|
|
|
|
{ |
2349
|
|
|
|
|
|
|
const u32 features MAYBE_UNUSED = get_arm_cpu_features(); |
2350
|
|
|
|
|
|
|
|
2351
|
|
|
|
|
|
|
#ifdef adler32_neon_dotprod |
2352
|
|
|
|
|
|
|
if (HAVE_NEON(features) && HAVE_DOTPROD(features)) |
2353
|
|
|
|
|
|
|
return adler32_neon_dotprod; |
2354
|
|
|
|
|
|
|
#endif |
2355
|
|
|
|
|
|
|
#ifdef adler32_neon |
2356
|
|
|
|
|
|
|
if (HAVE_NEON(features)) |
2357
|
|
|
|
|
|
|
return adler32_neon; |
2358
|
|
|
|
|
|
|
#endif |
2359
|
|
|
|
|
|
|
return NULL; |
2360
|
|
|
|
|
|
|
} |
2361
|
|
|
|
|
|
|
#define arch_select_adler32_func arch_select_adler32_func |
2362
|
|
|
|
|
|
|
#endif |
2363
|
|
|
|
|
|
|
|
2364
|
|
|
|
|
|
|
#endif |
2365
|
|
|
|
|
|
|
|
2366
|
|
|
|
|
|
|
#elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
2367
|
|
|
|
|
|
|
/* # include "x86/adler32_impl.h" */ |
2368
|
|
|
|
|
|
|
|
2369
|
|
|
|
|
|
|
|
2370
|
|
|
|
|
|
|
#ifndef LIB_X86_ADLER32_IMPL_H |
2371
|
|
|
|
|
|
|
#define LIB_X86_ADLER32_IMPL_H |
2372
|
|
|
|
|
|
|
|
2373
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
2374
|
|
|
|
|
|
|
|
2375
|
|
|
|
|
|
|
|
2376
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
2377
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
2378
|
|
|
|
|
|
|
|
2379
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
2380
|
|
|
|
|
|
|
|
2381
|
|
|
|
|
|
|
|
2382
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
2383
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
2384
|
|
|
|
|
|
|
|
2385
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
2386
|
|
|
|
|
|
|
|
2387
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
2388
|
|
|
|
|
|
|
#endif |
2389
|
|
|
|
|
|
|
|
2390
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
2391
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
2392
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
2393
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
2394
|
|
|
|
|
|
|
#else |
2395
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
2396
|
|
|
|
|
|
|
#endif |
2397
|
|
|
|
|
|
|
|
2398
|
|
|
|
|
|
|
|
2399
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
2400
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
2401
|
|
|
|
|
|
|
#else |
2402
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
2403
|
|
|
|
|
|
|
#endif |
2404
|
|
|
|
|
|
|
|
2405
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
2406
|
|
|
|
|
|
|
|
2407
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
2408
|
|
|
|
|
|
|
|
2409
|
|
|
|
|
|
|
|
2410
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
2411
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
2412
|
|
|
|
|
|
|
|
2413
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
2414
|
|
|
|
|
|
|
|
2415
|
|
|
|
|
|
|
|
2416
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
2417
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
2418
|
|
|
|
|
|
|
|
2419
|
|
|
|
|
|
|
#include |
2420
|
|
|
|
|
|
|
#include |
2421
|
|
|
|
|
|
|
|
2422
|
|
|
|
|
|
|
#ifdef __cplusplus |
2423
|
|
|
|
|
|
|
extern "C" { |
2424
|
|
|
|
|
|
|
#endif |
2425
|
|
|
|
|
|
|
|
2426
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
2427
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
2428
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
2429
|
|
|
|
|
|
|
|
2430
|
|
|
|
|
|
|
|
2431
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
2432
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
2433
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
2434
|
|
|
|
|
|
|
# else |
2435
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
2436
|
|
|
|
|
|
|
# endif |
2437
|
|
|
|
|
|
|
#endif |
2438
|
|
|
|
|
|
|
|
2439
|
|
|
|
|
|
|
|
2440
|
|
|
|
|
|
|
|
2441
|
|
|
|
|
|
|
|
2442
|
|
|
|
|
|
|
|
2443
|
|
|
|
|
|
|
struct libdeflate_compressor; |
2444
|
|
|
|
|
|
|
|
2445
|
|
|
|
|
|
|
|
2446
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
2447
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
2448
|
|
|
|
|
|
|
|
2449
|
|
|
|
|
|
|
|
2450
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2451
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
2452
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2453
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
2454
|
|
|
|
|
|
|
|
2455
|
|
|
|
|
|
|
|
2456
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2457
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
2458
|
|
|
|
|
|
|
size_t in_nbytes); |
2459
|
|
|
|
|
|
|
|
2460
|
|
|
|
|
|
|
|
2461
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2462
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
2463
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2464
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
2465
|
|
|
|
|
|
|
|
2466
|
|
|
|
|
|
|
|
2467
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2468
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
2469
|
|
|
|
|
|
|
size_t in_nbytes); |
2470
|
|
|
|
|
|
|
|
2471
|
|
|
|
|
|
|
|
2472
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2473
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
2474
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2475
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
2476
|
|
|
|
|
|
|
|
2477
|
|
|
|
|
|
|
|
2478
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
2479
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
2480
|
|
|
|
|
|
|
size_t in_nbytes); |
2481
|
|
|
|
|
|
|
|
2482
|
|
|
|
|
|
|
|
2483
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
2484
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
2485
|
|
|
|
|
|
|
|
2486
|
|
|
|
|
|
|
|
2487
|
|
|
|
|
|
|
|
2488
|
|
|
|
|
|
|
|
2489
|
|
|
|
|
|
|
|
2490
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
2491
|
|
|
|
|
|
|
|
2492
|
|
|
|
|
|
|
|
2493
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
2494
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
2495
|
|
|
|
|
|
|
|
2496
|
|
|
|
|
|
|
|
2497
|
|
|
|
|
|
|
enum libdeflate_result { |
2498
|
|
|
|
|
|
|
|
2499
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
2500
|
|
|
|
|
|
|
|
2501
|
|
|
|
|
|
|
|
2502
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
2503
|
|
|
|
|
|
|
|
2504
|
|
|
|
|
|
|
|
2505
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
2506
|
|
|
|
|
|
|
|
2507
|
|
|
|
|
|
|
|
2508
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
2509
|
|
|
|
|
|
|
}; |
2510
|
|
|
|
|
|
|
|
2511
|
|
|
|
|
|
|
|
2512
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2513
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
2514
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2515
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2516
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2517
|
|
|
|
|
|
|
|
2518
|
|
|
|
|
|
|
|
2519
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2520
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
2521
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2522
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2523
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
2524
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2525
|
|
|
|
|
|
|
|
2526
|
|
|
|
|
|
|
|
2527
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2528
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
2529
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2530
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2531
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2532
|
|
|
|
|
|
|
|
2533
|
|
|
|
|
|
|
|
2534
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2535
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
2536
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2537
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2538
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
2539
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2540
|
|
|
|
|
|
|
|
2541
|
|
|
|
|
|
|
|
2542
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2543
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
2544
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2545
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2546
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2547
|
|
|
|
|
|
|
|
2548
|
|
|
|
|
|
|
|
2549
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
2550
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
2551
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
2552
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
2553
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
2554
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
2555
|
|
|
|
|
|
|
|
2556
|
|
|
|
|
|
|
|
2557
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
2558
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
2559
|
|
|
|
|
|
|
|
2560
|
|
|
|
|
|
|
|
2561
|
|
|
|
|
|
|
|
2562
|
|
|
|
|
|
|
|
2563
|
|
|
|
|
|
|
|
2564
|
|
|
|
|
|
|
|
2565
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
2566
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
2567
|
|
|
|
|
|
|
|
2568
|
|
|
|
|
|
|
|
2569
|
|
|
|
|
|
|
|
2570
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
2571
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
2572
|
|
|
|
|
|
|
|
2573
|
|
|
|
|
|
|
|
2574
|
|
|
|
|
|
|
|
2575
|
|
|
|
|
|
|
|
2576
|
|
|
|
|
|
|
|
2577
|
|
|
|
|
|
|
|
2578
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
2579
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
2580
|
|
|
|
|
|
|
void (*free_func)(void *)); |
2581
|
|
|
|
|
|
|
|
2582
|
|
|
|
|
|
|
#ifdef __cplusplus |
2583
|
|
|
|
|
|
|
} |
2584
|
|
|
|
|
|
|
#endif |
2585
|
|
|
|
|
|
|
|
2586
|
|
|
|
|
|
|
#endif |
2587
|
|
|
|
|
|
|
|
2588
|
|
|
|
|
|
|
|
2589
|
|
|
|
|
|
|
#include |
2590
|
|
|
|
|
|
|
#include |
2591
|
|
|
|
|
|
|
#include |
2592
|
|
|
|
|
|
|
#ifdef _MSC_VER |
2593
|
|
|
|
|
|
|
# include |
2594
|
|
|
|
|
|
|
# include |
2595
|
|
|
|
|
|
|
|
2596
|
|
|
|
|
|
|
|
2597
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
2598
|
|
|
|
|
|
|
|
2599
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
2600
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
2601
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
2602
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
2603
|
|
|
|
|
|
|
|
2604
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
2605
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
2606
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
2607
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
2608
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
2609
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
2610
|
|
|
|
|
|
|
#endif |
2611
|
|
|
|
|
|
|
#ifndef FREESTANDING |
2612
|
|
|
|
|
|
|
# include |
2613
|
|
|
|
|
|
|
#endif |
2614
|
|
|
|
|
|
|
|
2615
|
|
|
|
|
|
|
|
2616
|
|
|
|
|
|
|
|
2617
|
|
|
|
|
|
|
|
2618
|
|
|
|
|
|
|
|
2619
|
|
|
|
|
|
|
|
2620
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
2621
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
2622
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
2623
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
2624
|
|
|
|
|
|
|
#ifdef _MSC_VER |
2625
|
|
|
|
|
|
|
# if defined(_M_X64) |
2626
|
|
|
|
|
|
|
# define ARCH_X86_64 |
2627
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
2628
|
|
|
|
|
|
|
# define ARCH_X86_32 |
2629
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
2630
|
|
|
|
|
|
|
# define ARCH_ARM64 |
2631
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
2632
|
|
|
|
|
|
|
# define ARCH_ARM32 |
2633
|
|
|
|
|
|
|
# endif |
2634
|
|
|
|
|
|
|
#else |
2635
|
|
|
|
|
|
|
# if defined(__x86_64__) |
2636
|
|
|
|
|
|
|
# define ARCH_X86_64 |
2637
|
|
|
|
|
|
|
# elif defined(__i386__) |
2638
|
|
|
|
|
|
|
# define ARCH_X86_32 |
2639
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
2640
|
|
|
|
|
|
|
# define ARCH_ARM64 |
2641
|
|
|
|
|
|
|
# elif defined(__arm__) |
2642
|
|
|
|
|
|
|
# define ARCH_ARM32 |
2643
|
|
|
|
|
|
|
# endif |
2644
|
|
|
|
|
|
|
#endif |
2645
|
|
|
|
|
|
|
|
2646
|
|
|
|
|
|
|
|
2647
|
|
|
|
|
|
|
|
2648
|
|
|
|
|
|
|
|
2649
|
|
|
|
|
|
|
|
2650
|
|
|
|
|
|
|
|
2651
|
|
|
|
|
|
|
typedef uint8_t u8; |
2652
|
|
|
|
|
|
|
typedef uint16_t u16; |
2653
|
|
|
|
|
|
|
typedef uint32_t u32; |
2654
|
|
|
|
|
|
|
typedef uint64_t u64; |
2655
|
|
|
|
|
|
|
typedef int8_t s8; |
2656
|
|
|
|
|
|
|
typedef int16_t s16; |
2657
|
|
|
|
|
|
|
typedef int32_t s32; |
2658
|
|
|
|
|
|
|
typedef int64_t s64; |
2659
|
|
|
|
|
|
|
|
2660
|
|
|
|
|
|
|
|
2661
|
|
|
|
|
|
|
#ifdef _MSC_VER |
2662
|
|
|
|
|
|
|
# ifdef _WIN64 |
2663
|
|
|
|
|
|
|
typedef long long ssize_t; |
2664
|
|
|
|
|
|
|
# else |
2665
|
|
|
|
|
|
|
typedef long ssize_t; |
2666
|
|
|
|
|
|
|
# endif |
2667
|
|
|
|
|
|
|
#endif |
2668
|
|
|
|
|
|
|
|
2669
|
|
|
|
|
|
|
|
2670
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
2671
|
|
|
|
|
|
|
|
2672
|
|
|
|
|
|
|
|
2673
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
2674
|
|
|
|
|
|
|
|
2675
|
|
|
|
|
|
|
|
2676
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
2677
|
|
|
|
|
|
|
|
2678
|
|
|
|
|
|
|
|
2679
|
|
|
|
|
|
|
|
2680
|
|
|
|
|
|
|
|
2681
|
|
|
|
|
|
|
|
2682
|
|
|
|
|
|
|
|
2683
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
2684
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
2685
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
2686
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
2687
|
|
|
|
|
|
|
#else |
2688
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
2689
|
|
|
|
|
|
|
#endif |
2690
|
|
|
|
|
|
|
#ifdef __clang__ |
2691
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
2692
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
2693
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
2694
|
|
|
|
|
|
|
# else |
2695
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
2696
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
2697
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
2698
|
|
|
|
|
|
|
# endif |
2699
|
|
|
|
|
|
|
#else |
2700
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
2701
|
|
|
|
|
|
|
#endif |
2702
|
|
|
|
|
|
|
|
2703
|
|
|
|
|
|
|
|
2704
|
|
|
|
|
|
|
#ifndef __has_attribute |
2705
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
2706
|
|
|
|
|
|
|
#endif |
2707
|
|
|
|
|
|
|
#ifndef __has_builtin |
2708
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
2709
|
|
|
|
|
|
|
#endif |
2710
|
|
|
|
|
|
|
|
2711
|
|
|
|
|
|
|
|
2712
|
|
|
|
|
|
|
#ifdef _MSC_VER |
2713
|
|
|
|
|
|
|
# define inline __inline |
2714
|
|
|
|
|
|
|
#endif |
2715
|
|
|
|
|
|
|
|
2716
|
|
|
|
|
|
|
|
2717
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
2718
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
2719
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2720
|
|
|
|
|
|
|
# define forceinline __forceinline |
2721
|
|
|
|
|
|
|
#else |
2722
|
|
|
|
|
|
|
# define forceinline inline |
2723
|
|
|
|
|
|
|
#endif |
2724
|
|
|
|
|
|
|
|
2725
|
|
|
|
|
|
|
|
2726
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
2727
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
2728
|
|
|
|
|
|
|
#else |
2729
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
2730
|
|
|
|
|
|
|
#endif |
2731
|
|
|
|
|
|
|
|
2732
|
|
|
|
|
|
|
|
2733
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
2734
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
2735
|
|
|
|
|
|
|
# define restrict __restrict__ |
2736
|
|
|
|
|
|
|
# else |
2737
|
|
|
|
|
|
|
# define restrict |
2738
|
|
|
|
|
|
|
# endif |
2739
|
|
|
|
|
|
|
#endif |
2740
|
|
|
|
|
|
|
|
2741
|
|
|
|
|
|
|
|
2742
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
2743
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
2744
|
|
|
|
|
|
|
#else |
2745
|
|
|
|
|
|
|
# define likely(expr) (expr) |
2746
|
|
|
|
|
|
|
#endif |
2747
|
|
|
|
|
|
|
|
2748
|
|
|
|
|
|
|
|
2749
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
2750
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
2751
|
|
|
|
|
|
|
#else |
2752
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
2753
|
|
|
|
|
|
|
#endif |
2754
|
|
|
|
|
|
|
|
2755
|
|
|
|
|
|
|
|
2756
|
|
|
|
|
|
|
#undef prefetchr |
2757
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
2758
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
2759
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2760
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
2761
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
2762
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
2763
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
2764
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
2765
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
2766
|
|
|
|
|
|
|
# endif |
2767
|
|
|
|
|
|
|
#endif |
2768
|
|
|
|
|
|
|
#ifndef prefetchr |
2769
|
|
|
|
|
|
|
# define prefetchr(addr) |
2770
|
|
|
|
|
|
|
#endif |
2771
|
|
|
|
|
|
|
|
2772
|
|
|
|
|
|
|
|
2773
|
|
|
|
|
|
|
#undef prefetchw |
2774
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
2775
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
2776
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2777
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
2778
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
2779
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
2780
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
2781
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
2782
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
2783
|
|
|
|
|
|
|
# endif |
2784
|
|
|
|
|
|
|
#endif |
2785
|
|
|
|
|
|
|
#ifndef prefetchw |
2786
|
|
|
|
|
|
|
# define prefetchw(addr) |
2787
|
|
|
|
|
|
|
#endif |
2788
|
|
|
|
|
|
|
|
2789
|
|
|
|
|
|
|
|
2790
|
|
|
|
|
|
|
#undef _aligned_attribute |
2791
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
2792
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
2793
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2794
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
2795
|
|
|
|
|
|
|
#endif |
2796
|
|
|
|
|
|
|
|
2797
|
|
|
|
|
|
|
|
2798
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
2799
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
2800
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
2801
|
|
|
|
|
|
|
#else |
2802
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
2803
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
2804
|
|
|
|
|
|
|
#endif |
2805
|
|
|
|
|
|
|
|
2806
|
|
|
|
|
|
|
|
2807
|
|
|
|
|
|
|
|
2808
|
|
|
|
|
|
|
|
2809
|
|
|
|
|
|
|
|
2810
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
2811
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
2812
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
2813
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
2814
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
2815
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
2816
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
2817
|
|
|
|
|
|
|
|
2818
|
|
|
|
|
|
|
|
2819
|
|
|
|
|
|
|
|
2820
|
|
|
|
|
|
|
|
2821
|
|
|
|
|
|
|
|
2822
|
|
|
|
|
|
|
|
2823
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
2824
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
2825
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2826
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
2827
|
|
|
|
|
|
|
#else |
2828
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
2829
|
|
|
|
|
|
|
{ |
2830
|
|
|
|
|
|
|
union { |
2831
|
|
|
|
|
|
|
u32 w; |
2832
|
|
|
|
|
|
|
u8 b; |
2833
|
|
|
|
|
|
|
} u; |
2834
|
|
|
|
|
|
|
|
2835
|
|
|
|
|
|
|
u.w = 1; |
2836
|
|
|
|
|
|
|
return u.b; |
2837
|
|
|
|
|
|
|
} |
2838
|
|
|
|
|
|
|
#endif |
2839
|
|
|
|
|
|
|
|
2840
|
|
|
|
|
|
|
|
2841
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
2842
|
|
|
|
|
|
|
{ |
2843
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
2844
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
2845
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2846
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
2847
|
|
|
|
|
|
|
#else |
2848
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
2849
|
|
|
|
|
|
|
#endif |
2850
|
|
|
|
|
|
|
} |
2851
|
|
|
|
|
|
|
|
2852
|
|
|
|
|
|
|
|
2853
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
2854
|
|
|
|
|
|
|
{ |
2855
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
2856
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
2857
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2858
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
2859
|
|
|
|
|
|
|
#else |
2860
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
2861
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
2862
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
2863
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
2864
|
|
|
|
|
|
|
#endif |
2865
|
|
|
|
|
|
|
} |
2866
|
|
|
|
|
|
|
|
2867
|
|
|
|
|
|
|
|
2868
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
2869
|
|
|
|
|
|
|
{ |
2870
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
2871
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
2872
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2873
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
2874
|
|
|
|
|
|
|
#else |
2875
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
2876
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
2877
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
2878
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
2879
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
2880
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
2881
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
2882
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
2883
|
|
|
|
|
|
|
#endif |
2884
|
|
|
|
|
|
|
} |
2885
|
|
|
|
|
|
|
|
2886
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
2887
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
2888
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
2889
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
2890
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
2891
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
2892
|
|
|
|
|
|
|
|
2893
|
|
|
|
|
|
|
|
2894
|
|
|
|
|
|
|
|
2895
|
|
|
|
|
|
|
|
2896
|
|
|
|
|
|
|
|
2897
|
|
|
|
|
|
|
|
2898
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
2899
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
2900
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
2901
|
|
|
|
|
|
|
defined(__wasm__)) |
2902
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
2903
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
2904
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
2905
|
|
|
|
|
|
|
#else |
2906
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
2907
|
|
|
|
|
|
|
#endif |
2908
|
|
|
|
|
|
|
|
2909
|
|
|
|
|
|
|
|
2910
|
|
|
|
|
|
|
|
2911
|
|
|
|
|
|
|
#ifdef FREESTANDING |
2912
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
2913
|
|
|
|
|
|
|
#else |
2914
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
2915
|
|
|
|
|
|
|
#endif |
2916
|
|
|
|
|
|
|
|
2917
|
|
|
|
|
|
|
|
2918
|
|
|
|
|
|
|
|
2919
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
2920
|
|
|
|
|
|
|
static forceinline type \ |
2921
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
2922
|
|
|
|
|
|
|
{ \ |
2923
|
|
|
|
|
|
|
type v; \ |
2924
|
|
|
|
|
|
|
\ |
2925
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
2926
|
|
|
|
|
|
|
return v; \ |
2927
|
|
|
|
|
|
|
} \ |
2928
|
|
|
|
|
|
|
\ |
2929
|
|
|
|
|
|
|
static forceinline void \ |
2930
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
2931
|
|
|
|
|
|
|
{ \ |
2932
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
2933
|
|
|
|
|
|
|
} |
2934
|
|
|
|
|
|
|
|
2935
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
2936
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
2937
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
2938
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
2939
|
|
|
|
|
|
|
|
2940
|
|
|
|
|
|
|
#undef MEMCOPY |
2941
|
|
|
|
|
|
|
|
2942
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
2943
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
2944
|
|
|
|
|
|
|
|
2945
|
|
|
|
|
|
|
|
2946
|
|
|
|
|
|
|
|
2947
|
|
|
|
|
|
|
static forceinline u16 |
2948
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
2949
|
|
|
|
|
|
|
{ |
2950
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
2951
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
2952
|
|
|
|
|
|
|
else |
2953
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
2954
|
|
|
|
|
|
|
} |
2955
|
|
|
|
|
|
|
|
2956
|
|
|
|
|
|
|
static forceinline u16 |
2957
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
2958
|
|
|
|
|
|
|
{ |
2959
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
2960
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
2961
|
|
|
|
|
|
|
else |
2962
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
2963
|
|
|
|
|
|
|
} |
2964
|
|
|
|
|
|
|
|
2965
|
|
|
|
|
|
|
static forceinline u32 |
2966
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
2967
|
|
|
|
|
|
|
{ |
2968
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
2969
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
2970
|
|
|
|
|
|
|
else |
2971
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
2972
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
2973
|
|
|
|
|
|
|
} |
2974
|
|
|
|
|
|
|
|
2975
|
|
|
|
|
|
|
static forceinline u32 |
2976
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
2977
|
|
|
|
|
|
|
{ |
2978
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
2979
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
2980
|
|
|
|
|
|
|
else |
2981
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
2982
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
2983
|
|
|
|
|
|
|
} |
2984
|
|
|
|
|
|
|
|
2985
|
|
|
|
|
|
|
static forceinline u64 |
2986
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
2987
|
|
|
|
|
|
|
{ |
2988
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
2989
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
2990
|
|
|
|
|
|
|
else |
2991
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
2992
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
2993
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
2994
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
2995
|
|
|
|
|
|
|
} |
2996
|
|
|
|
|
|
|
|
2997
|
|
|
|
|
|
|
static forceinline machine_word_t |
2998
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
2999
|
|
|
|
|
|
|
{ |
3000
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
3001
|
|
|
|
|
|
|
if (WORDBITS == 32) |
3002
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
3003
|
|
|
|
|
|
|
else |
3004
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
3005
|
|
|
|
|
|
|
} |
3006
|
|
|
|
|
|
|
|
3007
|
|
|
|
|
|
|
|
3008
|
|
|
|
|
|
|
|
3009
|
|
|
|
|
|
|
static forceinline void |
3010
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
3011
|
|
|
|
|
|
|
{ |
3012
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3013
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
3014
|
|
|
|
|
|
|
} else { |
3015
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
3016
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
3017
|
|
|
|
|
|
|
} |
3018
|
|
|
|
|
|
|
} |
3019
|
|
|
|
|
|
|
|
3020
|
|
|
|
|
|
|
static forceinline void |
3021
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
3022
|
|
|
|
|
|
|
{ |
3023
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3024
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
3025
|
|
|
|
|
|
|
} else { |
3026
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
3027
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
3028
|
|
|
|
|
|
|
} |
3029
|
|
|
|
|
|
|
} |
3030
|
|
|
|
|
|
|
|
3031
|
|
|
|
|
|
|
static forceinline void |
3032
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
3033
|
|
|
|
|
|
|
{ |
3034
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3035
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
3036
|
|
|
|
|
|
|
} else { |
3037
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
3038
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
3039
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
3040
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
3041
|
|
|
|
|
|
|
} |
3042
|
|
|
|
|
|
|
} |
3043
|
|
|
|
|
|
|
|
3044
|
|
|
|
|
|
|
static forceinline void |
3045
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
3046
|
|
|
|
|
|
|
{ |
3047
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3048
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
3049
|
|
|
|
|
|
|
} else { |
3050
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
3051
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
3052
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
3053
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
3054
|
|
|
|
|
|
|
} |
3055
|
|
|
|
|
|
|
} |
3056
|
|
|
|
|
|
|
|
3057
|
|
|
|
|
|
|
static forceinline void |
3058
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
3059
|
|
|
|
|
|
|
{ |
3060
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
3061
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
3062
|
|
|
|
|
|
|
} else { |
3063
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
3064
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
3065
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
3066
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
3067
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
3068
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
3069
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
3070
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
3071
|
|
|
|
|
|
|
} |
3072
|
|
|
|
|
|
|
} |
3073
|
|
|
|
|
|
|
|
3074
|
|
|
|
|
|
|
static forceinline void |
3075
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
3076
|
|
|
|
|
|
|
{ |
3077
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
3078
|
|
|
|
|
|
|
if (WORDBITS == 32) |
3079
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
3080
|
|
|
|
|
|
|
else |
3081
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
3082
|
|
|
|
|
|
|
} |
3083
|
|
|
|
|
|
|
|
3084
|
|
|
|
|
|
|
|
3085
|
|
|
|
|
|
|
|
3086
|
|
|
|
|
|
|
|
3087
|
|
|
|
|
|
|
|
3088
|
|
|
|
|
|
|
|
3089
|
|
|
|
|
|
|
|
3090
|
|
|
|
|
|
|
static forceinline unsigned |
3091
|
|
|
|
|
|
|
bsr32(u32 v) |
3092
|
|
|
|
|
|
|
{ |
3093
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
3094
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
3095
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
3096
|
|
|
|
|
|
|
unsigned long i; |
3097
|
|
|
|
|
|
|
|
3098
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
3099
|
|
|
|
|
|
|
return i; |
3100
|
|
|
|
|
|
|
#else |
3101
|
|
|
|
|
|
|
unsigned i = 0; |
3102
|
|
|
|
|
|
|
|
3103
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
3104
|
|
|
|
|
|
|
i++; |
3105
|
|
|
|
|
|
|
return i; |
3106
|
|
|
|
|
|
|
#endif |
3107
|
|
|
|
|
|
|
} |
3108
|
|
|
|
|
|
|
|
3109
|
|
|
|
|
|
|
static forceinline unsigned |
3110
|
|
|
|
|
|
|
bsr64(u64 v) |
3111
|
|
|
|
|
|
|
{ |
3112
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
3113
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
3114
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
3115
|
|
|
|
|
|
|
unsigned long i; |
3116
|
|
|
|
|
|
|
|
3117
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
3118
|
|
|
|
|
|
|
return i; |
3119
|
|
|
|
|
|
|
#else |
3120
|
|
|
|
|
|
|
unsigned i = 0; |
3121
|
|
|
|
|
|
|
|
3122
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
3123
|
|
|
|
|
|
|
i++; |
3124
|
|
|
|
|
|
|
return i; |
3125
|
|
|
|
|
|
|
#endif |
3126
|
|
|
|
|
|
|
} |
3127
|
|
|
|
|
|
|
|
3128
|
|
|
|
|
|
|
static forceinline unsigned |
3129
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
3130
|
|
|
|
|
|
|
{ |
3131
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
3132
|
|
|
|
|
|
|
if (WORDBITS == 32) |
3133
|
|
|
|
|
|
|
return bsr32(v); |
3134
|
|
|
|
|
|
|
else |
3135
|
|
|
|
|
|
|
return bsr64(v); |
3136
|
|
|
|
|
|
|
} |
3137
|
|
|
|
|
|
|
|
3138
|
|
|
|
|
|
|
|
3139
|
|
|
|
|
|
|
|
3140
|
|
|
|
|
|
|
static forceinline unsigned |
3141
|
|
|
|
|
|
|
bsf32(u32 v) |
3142
|
|
|
|
|
|
|
{ |
3143
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
3144
|
|
|
|
|
|
|
return __builtin_ctz(v); |
3145
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
3146
|
|
|
|
|
|
|
unsigned long i; |
3147
|
|
|
|
|
|
|
|
3148
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
3149
|
|
|
|
|
|
|
return i; |
3150
|
|
|
|
|
|
|
#else |
3151
|
|
|
|
|
|
|
unsigned i = 0; |
3152
|
|
|
|
|
|
|
|
3153
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
3154
|
|
|
|
|
|
|
i++; |
3155
|
|
|
|
|
|
|
return i; |
3156
|
|
|
|
|
|
|
#endif |
3157
|
|
|
|
|
|
|
} |
3158
|
|
|
|
|
|
|
|
3159
|
|
|
|
|
|
|
static forceinline unsigned |
3160
|
|
|
|
|
|
|
bsf64(u64 v) |
3161
|
|
|
|
|
|
|
{ |
3162
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
3163
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
3164
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
3165
|
|
|
|
|
|
|
unsigned long i; |
3166
|
|
|
|
|
|
|
|
3167
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
3168
|
|
|
|
|
|
|
return i; |
3169
|
|
|
|
|
|
|
#else |
3170
|
|
|
|
|
|
|
unsigned i = 0; |
3171
|
|
|
|
|
|
|
|
3172
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
3173
|
|
|
|
|
|
|
i++; |
3174
|
|
|
|
|
|
|
return i; |
3175
|
|
|
|
|
|
|
#endif |
3176
|
|
|
|
|
|
|
} |
3177
|
|
|
|
|
|
|
|
3178
|
|
|
|
|
|
|
static forceinline unsigned |
3179
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
3180
|
|
|
|
|
|
|
{ |
3181
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
3182
|
|
|
|
|
|
|
if (WORDBITS == 32) |
3183
|
|
|
|
|
|
|
return bsf32(v); |
3184
|
|
|
|
|
|
|
else |
3185
|
|
|
|
|
|
|
return bsf64(v); |
3186
|
|
|
|
|
|
|
} |
3187
|
|
|
|
|
|
|
|
3188
|
|
|
|
|
|
|
|
3189
|
|
|
|
|
|
|
#undef rbit32 |
3190
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
3191
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
3192
|
|
|
|
|
|
|
static forceinline u32 |
3193
|
|
|
|
|
|
|
rbit32(u32 v) |
3194
|
|
|
|
|
|
|
{ |
3195
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
3196
|
|
|
|
|
|
|
return v; |
3197
|
|
|
|
|
|
|
} |
3198
|
|
|
|
|
|
|
#define rbit32 rbit32 |
3199
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
3200
|
|
|
|
|
|
|
static forceinline u32 |
3201
|
|
|
|
|
|
|
rbit32(u32 v) |
3202
|
|
|
|
|
|
|
{ |
3203
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
3204
|
|
|
|
|
|
|
return v; |
3205
|
|
|
|
|
|
|
} |
3206
|
|
|
|
|
|
|
#define rbit32 rbit32 |
3207
|
|
|
|
|
|
|
#endif |
3208
|
|
|
|
|
|
|
|
3209
|
|
|
|
|
|
|
#endif |
3210
|
|
|
|
|
|
|
|
3211
|
|
|
|
|
|
|
|
3212
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
3213
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
3214
|
|
|
|
|
|
|
|
3215
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
3216
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
3217
|
|
|
|
|
|
|
|
3218
|
|
|
|
|
|
|
#ifdef FREESTANDING |
3219
|
|
|
|
|
|
|
|
3220
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
3221
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
3222
|
|
|
|
|
|
|
|
3223
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
3224
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
3225
|
|
|
|
|
|
|
|
3226
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
3227
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
3228
|
|
|
|
|
|
|
|
3229
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
3230
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
3231
|
|
|
|
|
|
|
|
3232
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
3233
|
|
|
|
|
|
|
#else |
3234
|
|
|
|
|
|
|
#include |
3235
|
|
|
|
|
|
|
#endif |
3236
|
|
|
|
|
|
|
|
3237
|
|
|
|
|
|
|
|
3238
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
3239
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
3240
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
3241
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
3242
|
|
|
|
|
|
|
#else |
3243
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
3244
|
|
|
|
|
|
|
#endif |
3245
|
|
|
|
|
|
|
|
3246
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
3247
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
3248
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
3249
|
|
|
|
|
|
|
|
3250
|
|
|
|
|
|
|
#endif |
3251
|
|
|
|
|
|
|
|
3252
|
|
|
|
|
|
|
|
3253
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
3254
|
|
|
|
|
|
|
|
3255
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
3256
|
|
|
|
|
|
|
|
3257
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
3258
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
3259
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
3260
|
|
|
|
|
|
|
#endif |
3261
|
|
|
|
|
|
|
|
3262
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
3263
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
3264
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
3265
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
3266
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
3267
|
|
|
|
|
|
|
|
3268
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
3269
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
3270
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
3271
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
3272
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
3273
|
|
|
|
|
|
|
|
3274
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
3275
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
3276
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
3277
|
|
|
|
|
|
|
|
3278
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
3279
|
|
|
|
|
|
|
|
3280
|
5
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
3281
|
|
|
|
|
|
|
{ |
3282
|
5
|
100
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
3283
|
2
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
3284
|
5
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
3285
|
|
|
|
|
|
|
} |
3286
|
|
|
|
|
|
|
#else |
3287
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
3288
|
|
|
|
|
|
|
#endif |
3289
|
|
|
|
|
|
|
|
3290
|
|
|
|
|
|
|
|
3291
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
3292
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
3293
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
3294
|
|
|
|
|
|
|
#else |
3295
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
3296
|
|
|
|
|
|
|
#endif |
3297
|
|
|
|
|
|
|
|
3298
|
|
|
|
|
|
|
|
3299
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
3300
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
3301
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
3302
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
3303
|
|
|
|
|
|
|
#else |
3304
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
3305
|
|
|
|
|
|
|
#endif |
3306
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
3307
|
|
|
|
|
|
|
|
3308
|
|
|
|
|
|
|
|
3309
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
3310
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
3311
|
|
|
|
|
|
|
#else |
3312
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
3313
|
|
|
|
|
|
|
#endif |
3314
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
3315
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
3316
|
|
|
|
|
|
|
defined(_MSC_VER))) |
3317
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
3318
|
|
|
|
|
|
|
#else |
3319
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
3320
|
|
|
|
|
|
|
#endif |
3321
|
|
|
|
|
|
|
|
3322
|
|
|
|
|
|
|
|
3323
|
|
|
|
|
|
|
#ifdef __AVX__ |
3324
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
3325
|
|
|
|
|
|
|
#else |
3326
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
3327
|
|
|
|
|
|
|
#endif |
3328
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
3329
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
3330
|
|
|
|
|
|
|
defined(_MSC_VER))) |
3331
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
3332
|
|
|
|
|
|
|
#else |
3333
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
3334
|
|
|
|
|
|
|
#endif |
3335
|
|
|
|
|
|
|
|
3336
|
|
|
|
|
|
|
|
3337
|
|
|
|
|
|
|
#ifdef __AVX2__ |
3338
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
3339
|
|
|
|
|
|
|
#else |
3340
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
3341
|
|
|
|
|
|
|
#endif |
3342
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
3343
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
3344
|
|
|
|
|
|
|
defined(_MSC_VER))) |
3345
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
3346
|
|
|
|
|
|
|
#else |
3347
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
3348
|
|
|
|
|
|
|
#endif |
3349
|
|
|
|
|
|
|
|
3350
|
|
|
|
|
|
|
|
3351
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
3352
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
3353
|
|
|
|
|
|
|
#else |
3354
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
3355
|
|
|
|
|
|
|
#endif |
3356
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
3357
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
3358
|
|
|
|
|
|
|
defined(_MSC_VER))) |
3359
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
3360
|
|
|
|
|
|
|
#else |
3361
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
3362
|
|
|
|
|
|
|
#endif |
3363
|
|
|
|
|
|
|
|
3364
|
|
|
|
|
|
|
#endif |
3365
|
|
|
|
|
|
|
|
3366
|
|
|
|
|
|
|
#endif |
3367
|
|
|
|
|
|
|
|
3368
|
|
|
|
|
|
|
|
3369
|
|
|
|
|
|
|
|
3370
|
|
|
|
|
|
|
|
3371
|
|
|
|
|
|
|
#define ADLER32_FINISH_VEC_CHUNK_128(s1, s2, v_s1, v_s2) \ |
3372
|
|
|
|
|
|
|
{ \ |
3373
|
|
|
|
|
|
|
__m128i s1_last = (v_s1), s2_last = (v_s2); \ |
3374
|
|
|
|
|
|
|
\ |
3375
|
|
|
|
|
|
|
\ |
3376
|
|
|
|
|
|
|
s2_last = _mm_add_epi32(s2_last, _mm_shuffle_epi32(s2_last, 0x31)); \ |
3377
|
|
|
|
|
|
|
s1_last = _mm_add_epi32(s1_last, _mm_shuffle_epi32(s1_last, 0x02)); \ |
3378
|
|
|
|
|
|
|
s2_last = _mm_add_epi32(s2_last, _mm_shuffle_epi32(s2_last, 0x02)); \ |
3379
|
|
|
|
|
|
|
\ |
3380
|
|
|
|
|
|
|
*(s1) += (u32)_mm_cvtsi128_si32(s1_last); \ |
3381
|
|
|
|
|
|
|
*(s2) += (u32)_mm_cvtsi128_si32(s2_last); \ |
3382
|
|
|
|
|
|
|
} |
3383
|
|
|
|
|
|
|
|
3384
|
|
|
|
|
|
|
#define ADLER32_FINISH_VEC_CHUNK_256(s1, s2, v_s1, v_s2) \ |
3385
|
|
|
|
|
|
|
{ \ |
3386
|
|
|
|
|
|
|
__m128i s1_128bit, s2_128bit; \ |
3387
|
|
|
|
|
|
|
\ |
3388
|
|
|
|
|
|
|
\ |
3389
|
|
|
|
|
|
|
s1_128bit = _mm_add_epi32(_mm256_extracti128_si256((v_s1), 0), \ |
3390
|
|
|
|
|
|
|
_mm256_extracti128_si256((v_s1), 1)); \ |
3391
|
|
|
|
|
|
|
s2_128bit = _mm_add_epi32(_mm256_extracti128_si256((v_s2), 0), \ |
3392
|
|
|
|
|
|
|
_mm256_extracti128_si256((v_s2), 1)); \ |
3393
|
|
|
|
|
|
|
\ |
3394
|
|
|
|
|
|
|
ADLER32_FINISH_VEC_CHUNK_128((s1), (s2), s1_128bit, s2_128bit); \ |
3395
|
|
|
|
|
|
|
} |
3396
|
|
|
|
|
|
|
|
3397
|
|
|
|
|
|
|
|
3398
|
|
|
|
|
|
|
#if GCC_PREREQ(1, 0) |
3399
|
|
|
|
|
|
|
# define GCC_UPDATE_VARS(a, b, c, d, e, f) \ |
3400
|
|
|
|
|
|
|
__asm__("" : "+x" (a), "+x" (b), "+x" (c), "+x" (d), "+x" (e), "+x" (f)) |
3401
|
|
|
|
|
|
|
#else |
3402
|
|
|
|
|
|
|
# define GCC_UPDATE_VARS(a, b, c, d, e, f) \ |
3403
|
|
|
|
|
|
|
(void)a, (void)b, (void)c, (void)d, (void)e, (void)f |
3404
|
|
|
|
|
|
|
#endif |
3405
|
|
|
|
|
|
|
|
3406
|
|
|
|
|
|
|
|
3407
|
|
|
|
|
|
|
#if HAVE_SSE2_INTRIN |
3408
|
|
|
|
|
|
|
# define adler32_sse2 adler32_sse2 |
3409
|
|
|
|
|
|
|
# define FUNCNAME adler32_sse2 |
3410
|
|
|
|
|
|
|
# define FUNCNAME_CHUNK adler32_sse2_chunk |
3411
|
|
|
|
|
|
|
# define IMPL_ALIGNMENT 16 |
3412
|
|
|
|
|
|
|
# define IMPL_SEGMENT_LEN 32 |
3413
|
|
|
|
|
|
|
|
3414
|
|
|
|
|
|
|
# define IMPL_MAX_CHUNK_LEN (32 * (0x7FFF / 0xFF)) |
3415
|
|
|
|
|
|
|
# if HAVE_SSE2_NATIVE |
3416
|
|
|
|
|
|
|
# define ATTRIBUTES |
3417
|
|
|
|
|
|
|
# else |
3418
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("sse2") |
3419
|
|
|
|
|
|
|
# endif |
3420
|
|
|
|
|
|
|
# include |
3421
|
|
|
|
|
|
|
static forceinline ATTRIBUTES void |
3422
|
|
|
|
|
|
|
adler32_sse2_chunk(const __m128i *p, const __m128i *const end, u32 *s1, u32 *s2) |
3423
|
|
|
|
|
|
|
{ |
3424
|
24
|
|
|
|
|
|
const __m128i zeroes = _mm_setzero_si128(); |
3425
|
24
|
|
|
|
|
|
const __m128i mults_a = |
3426
|
|
|
|
|
|
|
_mm_setr_epi16(32, 31, 30, 29, 28, 27, 26, 25); |
3427
|
24
|
|
|
|
|
|
const __m128i mults_b = |
3428
|
|
|
|
|
|
|
_mm_setr_epi16(24, 23, 22, 21, 20, 19, 18, 17); |
3429
|
24
|
|
|
|
|
|
const __m128i mults_c = |
3430
|
|
|
|
|
|
|
_mm_setr_epi16(16, 15, 14, 13, 12, 11, 10, 9); |
3431
|
24
|
|
|
|
|
|
const __m128i mults_d = |
3432
|
|
|
|
|
|
|
_mm_setr_epi16(8, 7, 6, 5, 4, 3, 2, 1); |
3433
|
|
|
|
|
|
|
|
3434
|
|
|
|
|
|
|
|
3435
|
24
|
|
|
|
|
|
__m128i v_s1 = zeroes; |
3436
|
|
|
|
|
|
|
|
3437
|
|
|
|
|
|
|
|
3438
|
24
|
|
|
|
|
|
__m128i v_s2 = zeroes; |
3439
|
|
|
|
|
|
|
|
3440
|
|
|
|
|
|
|
|
3441
|
24
|
|
|
|
|
|
__m128i v_byte_sums_a = zeroes; |
3442
|
24
|
|
|
|
|
|
__m128i v_byte_sums_b = zeroes; |
3443
|
24
|
|
|
|
|
|
__m128i v_byte_sums_c = zeroes; |
3444
|
24
|
|
|
|
|
|
__m128i v_byte_sums_d = zeroes; |
3445
|
|
|
|
|
|
|
|
3446
|
|
|
|
|
|
|
do { |
3447
|
|
|
|
|
|
|
|
3448
|
1272
|
|
|
|
|
|
const __m128i bytes1 = *p++; |
3449
|
1272
|
|
|
|
|
|
const __m128i bytes2 = *p++; |
3450
|
|
|
|
|
|
|
|
3451
|
|
|
|
|
|
|
|
3452
|
1272
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, v_s1); |
3453
|
|
|
|
|
|
|
|
3454
|
|
|
|
|
|
|
|
3455
|
2544
|
|
|
|
|
|
v_s1 = _mm_add_epi32(v_s1, _mm_sad_epu8(bytes1, zeroes)); |
3456
|
2544
|
|
|
|
|
|
v_s1 = _mm_add_epi32(v_s1, _mm_sad_epu8(bytes2, zeroes)); |
3457
|
|
|
|
|
|
|
|
3458
|
|
|
|
|
|
|
|
3459
|
2544
|
|
|
|
|
|
v_byte_sums_a = _mm_add_epi16( |
3460
|
|
|
|
|
|
|
v_byte_sums_a, _mm_unpacklo_epi8(bytes1, zeroes)); |
3461
|
2544
|
|
|
|
|
|
v_byte_sums_b = _mm_add_epi16( |
3462
|
|
|
|
|
|
|
v_byte_sums_b, _mm_unpackhi_epi8(bytes1, zeroes)); |
3463
|
2544
|
|
|
|
|
|
v_byte_sums_c = _mm_add_epi16( |
3464
|
|
|
|
|
|
|
v_byte_sums_c, _mm_unpacklo_epi8(bytes2, zeroes)); |
3465
|
2544
|
|
|
|
|
|
v_byte_sums_d = _mm_add_epi16( |
3466
|
|
|
|
|
|
|
v_byte_sums_d, _mm_unpackhi_epi8(bytes2, zeroes)); |
3467
|
|
|
|
|
|
|
|
3468
|
1272
|
|
|
|
|
|
GCC_UPDATE_VARS(v_s1, v_s2, v_byte_sums_a, v_byte_sums_b, |
3469
|
|
|
|
|
|
|
v_byte_sums_c, v_byte_sums_d); |
3470
|
1272
|
100
|
|
|
|
|
} while (p != end); |
3471
|
|
|
|
|
|
|
|
3472
|
|
|
|
|
|
|
|
3473
|
24
|
|
|
|
|
|
v_s2 = _mm_slli_epi32(v_s2, 5); |
3474
|
48
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(v_byte_sums_a, mults_a)); |
3475
|
48
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(v_byte_sums_b, mults_b)); |
3476
|
48
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(v_byte_sums_c, mults_c)); |
3477
|
48
|
|
|
|
|
|
v_s2 = _mm_add_epi32(v_s2, _mm_madd_epi16(v_byte_sums_d, mults_d)); |
3478
|
|
|
|
|
|
|
|
3479
|
|
|
|
|
|
|
|
3480
|
72
|
|
|
|
|
|
ADLER32_FINISH_VEC_CHUNK_128(s1, s2, v_s1, v_s2); |
3481
|
|
|
|
|
|
|
} |
3482
|
|
|
|
|
|
|
/* #include "adler32_vec_template.h" */ |
3483
|
|
|
|
|
|
|
|
3484
|
|
|
|
|
|
|
|
3485
|
|
|
|
|
|
|
|
3486
|
|
|
|
|
|
|
|
3487
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
3488
|
24
|
|
|
|
|
|
FUNCNAME(u32 adler, const u8 *p, size_t len) |
3489
|
|
|
|
|
|
|
{ |
3490
|
24
|
|
|
|
|
|
const size_t max_chunk_len = |
3491
|
|
|
|
|
|
|
MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) - |
3492
|
|
|
|
|
|
|
(MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) % IMPL_SEGMENT_LEN); |
3493
|
24
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
3494
|
24
|
|
|
|
|
|
u32 s2 = adler >> 16; |
3495
|
24
|
|
|
|
|
|
const u8 * const end = p + len; |
3496
|
|
|
|
|
|
|
const u8 *vend; |
3497
|
|
|
|
|
|
|
|
3498
|
|
|
|
|
|
|
|
3499
|
24
|
50
|
|
|
|
|
if (p != end && (uintptr_t)p % IMPL_ALIGNMENT) { |
|
|
50
|
|
|
|
|
|
3500
|
|
|
|
|
|
|
do { |
3501
|
0
|
|
|
|
|
|
s1 += *p++; |
3502
|
0
|
|
|
|
|
|
s2 += s1; |
3503
|
0
|
0
|
|
|
|
|
} while (p != end && (uintptr_t)p % IMPL_ALIGNMENT); |
|
|
0
|
|
|
|
|
|
3504
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
3505
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
3506
|
|
|
|
|
|
|
} |
3507
|
|
|
|
|
|
|
|
3508
|
|
|
|
|
|
|
|
3509
|
|
|
|
|
|
|
STATIC_ASSERT(IMPL_SEGMENT_LEN % IMPL_ALIGNMENT == 0); |
3510
|
24
|
|
|
|
|
|
vend = end - ((size_t)(end - p) % IMPL_SEGMENT_LEN); |
3511
|
48
|
100
|
|
|
|
|
while (p != vend) { |
3512
|
24
|
|
|
|
|
|
size_t chunk_len = MIN((size_t)(vend - p), max_chunk_len); |
3513
|
|
|
|
|
|
|
|
3514
|
24
|
|
|
|
|
|
s2 += s1 * chunk_len; |
3515
|
|
|
|
|
|
|
|
3516
|
24
|
|
|
|
|
|
FUNCNAME_CHUNK((const void *)p, (const void *)(p + chunk_len), |
3517
|
|
|
|
|
|
|
&s1, &s2); |
3518
|
|
|
|
|
|
|
|
3519
|
24
|
|
|
|
|
|
p += chunk_len; |
3520
|
24
|
|
|
|
|
|
s1 %= DIVISOR; |
3521
|
24
|
|
|
|
|
|
s2 %= DIVISOR; |
3522
|
|
|
|
|
|
|
} |
3523
|
|
|
|
|
|
|
|
3524
|
|
|
|
|
|
|
|
3525
|
24
|
50
|
|
|
|
|
if (p != end) { |
3526
|
|
|
|
|
|
|
do { |
3527
|
96
|
|
|
|
|
|
s1 += *p++; |
3528
|
96
|
|
|
|
|
|
s2 += s1; |
3529
|
96
|
100
|
|
|
|
|
} while (p != end); |
3530
|
24
|
|
|
|
|
|
s1 %= DIVISOR; |
3531
|
24
|
|
|
|
|
|
s2 %= DIVISOR; |
3532
|
|
|
|
|
|
|
} |
3533
|
|
|
|
|
|
|
|
3534
|
24
|
|
|
|
|
|
return (s2 << 16) | s1; |
3535
|
|
|
|
|
|
|
} |
3536
|
|
|
|
|
|
|
|
3537
|
|
|
|
|
|
|
#undef FUNCNAME |
3538
|
|
|
|
|
|
|
#undef FUNCNAME_CHUNK |
3539
|
|
|
|
|
|
|
#undef ATTRIBUTES |
3540
|
|
|
|
|
|
|
#undef IMPL_ALIGNMENT |
3541
|
|
|
|
|
|
|
#undef IMPL_SEGMENT_LEN |
3542
|
|
|
|
|
|
|
#undef IMPL_MAX_CHUNK_LEN |
3543
|
|
|
|
|
|
|
|
3544
|
|
|
|
|
|
|
#endif |
3545
|
|
|
|
|
|
|
|
3546
|
|
|
|
|
|
|
|
3547
|
|
|
|
|
|
|
#if HAVE_AVX2_INTRIN |
3548
|
|
|
|
|
|
|
# define adler32_avx2 adler32_avx2 |
3549
|
|
|
|
|
|
|
# define FUNCNAME adler32_avx2 |
3550
|
|
|
|
|
|
|
# define FUNCNAME_CHUNK adler32_avx2_chunk |
3551
|
|
|
|
|
|
|
# define IMPL_ALIGNMENT 32 |
3552
|
|
|
|
|
|
|
# define IMPL_SEGMENT_LEN 64 |
3553
|
|
|
|
|
|
|
# define IMPL_MAX_CHUNK_LEN (64 * (0x7FFF / 0xFF)) |
3554
|
|
|
|
|
|
|
# if HAVE_AVX2_NATIVE |
3555
|
|
|
|
|
|
|
# define ATTRIBUTES |
3556
|
|
|
|
|
|
|
# else |
3557
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("avx2") |
3558
|
|
|
|
|
|
|
# endif |
3559
|
|
|
|
|
|
|
# include |
3560
|
|
|
|
|
|
|
|
3561
|
|
|
|
|
|
|
# if defined(__clang__) && defined(_MSC_VER) |
3562
|
|
|
|
|
|
|
# include |
3563
|
|
|
|
|
|
|
# include |
3564
|
|
|
|
|
|
|
# endif |
3565
|
|
|
|
|
|
|
static forceinline ATTRIBUTES void |
3566
|
|
|
|
|
|
|
adler32_avx2_chunk(const __m256i *p, const __m256i *const end, u32 *s1, u32 *s2) |
3567
|
|
|
|
|
|
|
{ |
3568
|
0
|
|
|
|
|
|
const __m256i zeroes = _mm256_setzero_si256(); |
3569
|
|
|
|
|
|
|
|
3570
|
0
|
|
|
|
|
|
const __m256i mults_a = |
3571
|
|
|
|
|
|
|
_mm256_setr_epi16(64, 63, 62, 61, 60, 59, 58, 57, |
3572
|
|
|
|
|
|
|
48, 47, 46, 45, 44, 43, 42, 41); |
3573
|
0
|
|
|
|
|
|
const __m256i mults_b = |
3574
|
|
|
|
|
|
|
_mm256_setr_epi16(56, 55, 54, 53, 52, 51, 50, 49, |
3575
|
|
|
|
|
|
|
40, 39, 38, 37, 36, 35, 34, 33); |
3576
|
0
|
|
|
|
|
|
const __m256i mults_c = |
3577
|
|
|
|
|
|
|
_mm256_setr_epi16(32, 31, 30, 29, 28, 27, 26, 25, |
3578
|
|
|
|
|
|
|
16, 15, 14, 13, 12, 11, 10, 9); |
3579
|
0
|
|
|
|
|
|
const __m256i mults_d = |
3580
|
|
|
|
|
|
|
_mm256_setr_epi16(24, 23, 22, 21, 20, 19, 18, 17, |
3581
|
|
|
|
|
|
|
8, 7, 6, 5, 4, 3, 2, 1); |
3582
|
0
|
|
|
|
|
|
__m256i v_s1 = zeroes; |
3583
|
0
|
|
|
|
|
|
__m256i v_s2 = zeroes; |
3584
|
0
|
|
|
|
|
|
__m256i v_byte_sums_a = zeroes; |
3585
|
0
|
|
|
|
|
|
__m256i v_byte_sums_b = zeroes; |
3586
|
0
|
|
|
|
|
|
__m256i v_byte_sums_c = zeroes; |
3587
|
0
|
|
|
|
|
|
__m256i v_byte_sums_d = zeroes; |
3588
|
|
|
|
|
|
|
|
3589
|
|
|
|
|
|
|
do { |
3590
|
0
|
|
|
|
|
|
const __m256i bytes1 = *p++; |
3591
|
0
|
|
|
|
|
|
const __m256i bytes2 = *p++; |
3592
|
|
|
|
|
|
|
|
3593
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, v_s1); |
3594
|
0
|
|
|
|
|
|
v_s1 = _mm256_add_epi32(v_s1, _mm256_sad_epu8(bytes1, zeroes)); |
3595
|
0
|
|
|
|
|
|
v_s1 = _mm256_add_epi32(v_s1, _mm256_sad_epu8(bytes2, zeroes)); |
3596
|
0
|
|
|
|
|
|
v_byte_sums_a = _mm256_add_epi16( |
3597
|
|
|
|
|
|
|
v_byte_sums_a, _mm256_unpacklo_epi8(bytes1, zeroes)); |
3598
|
0
|
|
|
|
|
|
v_byte_sums_b = _mm256_add_epi16( |
3599
|
|
|
|
|
|
|
v_byte_sums_b, _mm256_unpackhi_epi8(bytes1, zeroes)); |
3600
|
0
|
|
|
|
|
|
v_byte_sums_c = _mm256_add_epi16( |
3601
|
|
|
|
|
|
|
v_byte_sums_c, _mm256_unpacklo_epi8(bytes2, zeroes)); |
3602
|
0
|
|
|
|
|
|
v_byte_sums_d = _mm256_add_epi16( |
3603
|
|
|
|
|
|
|
v_byte_sums_d, _mm256_unpackhi_epi8(bytes2, zeroes)); |
3604
|
|
|
|
|
|
|
|
3605
|
0
|
|
|
|
|
|
GCC_UPDATE_VARS(v_s1, v_s2, v_byte_sums_a, v_byte_sums_b, |
3606
|
|
|
|
|
|
|
v_byte_sums_c, v_byte_sums_d); |
3607
|
0
|
0
|
|
|
|
|
} while (p != end); |
3608
|
|
|
|
|
|
|
|
3609
|
0
|
|
|
|
|
|
v_s2 = _mm256_slli_epi32(v_s2, 6); |
3610
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, _mm256_madd_epi16(v_byte_sums_a, mults_a)); |
3611
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, _mm256_madd_epi16(v_byte_sums_b, mults_b)); |
3612
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, _mm256_madd_epi16(v_byte_sums_c, mults_c)); |
3613
|
0
|
|
|
|
|
|
v_s2 = _mm256_add_epi32(v_s2, _mm256_madd_epi16(v_byte_sums_d, mults_d)); |
3614
|
0
|
|
|
|
|
|
ADLER32_FINISH_VEC_CHUNK_256(s1, s2, v_s1, v_s2); |
3615
|
|
|
|
|
|
|
} |
3616
|
|
|
|
|
|
|
/* #include "x86-../adler32_vec_template.h" */ |
3617
|
|
|
|
|
|
|
|
3618
|
|
|
|
|
|
|
|
3619
|
|
|
|
|
|
|
|
3620
|
|
|
|
|
|
|
|
3621
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
3622
|
0
|
|
|
|
|
|
FUNCNAME(u32 adler, const u8 *p, size_t len) |
3623
|
|
|
|
|
|
|
{ |
3624
|
0
|
|
|
|
|
|
const size_t max_chunk_len = |
3625
|
|
|
|
|
|
|
MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) - |
3626
|
|
|
|
|
|
|
(MIN(MAX_CHUNK_LEN, IMPL_MAX_CHUNK_LEN) % IMPL_SEGMENT_LEN); |
3627
|
0
|
|
|
|
|
|
u32 s1 = adler & 0xFFFF; |
3628
|
0
|
|
|
|
|
|
u32 s2 = adler >> 16; |
3629
|
0
|
|
|
|
|
|
const u8 * const end = p + len; |
3630
|
|
|
|
|
|
|
const u8 *vend; |
3631
|
|
|
|
|
|
|
|
3632
|
|
|
|
|
|
|
|
3633
|
0
|
0
|
|
|
|
|
if (p != end && (uintptr_t)p % IMPL_ALIGNMENT) { |
|
|
0
|
|
|
|
|
|
3634
|
|
|
|
|
|
|
do { |
3635
|
0
|
|
|
|
|
|
s1 += *p++; |
3636
|
0
|
|
|
|
|
|
s2 += s1; |
3637
|
0
|
0
|
|
|
|
|
} while (p != end && (uintptr_t)p % IMPL_ALIGNMENT); |
|
|
0
|
|
|
|
|
|
3638
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
3639
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
3640
|
|
|
|
|
|
|
} |
3641
|
|
|
|
|
|
|
|
3642
|
|
|
|
|
|
|
|
3643
|
|
|
|
|
|
|
STATIC_ASSERT(IMPL_SEGMENT_LEN % IMPL_ALIGNMENT == 0); |
3644
|
0
|
|
|
|
|
|
vend = end - ((size_t)(end - p) % IMPL_SEGMENT_LEN); |
3645
|
0
|
0
|
|
|
|
|
while (p != vend) { |
3646
|
0
|
|
|
|
|
|
size_t chunk_len = MIN((size_t)(vend - p), max_chunk_len); |
3647
|
|
|
|
|
|
|
|
3648
|
0
|
|
|
|
|
|
s2 += s1 * chunk_len; |
3649
|
|
|
|
|
|
|
|
3650
|
0
|
|
|
|
|
|
FUNCNAME_CHUNK((const void *)p, (const void *)(p + chunk_len), |
3651
|
|
|
|
|
|
|
&s1, &s2); |
3652
|
|
|
|
|
|
|
|
3653
|
0
|
|
|
|
|
|
p += chunk_len; |
3654
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
3655
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
3656
|
|
|
|
|
|
|
} |
3657
|
|
|
|
|
|
|
|
3658
|
|
|
|
|
|
|
|
3659
|
0
|
0
|
|
|
|
|
if (p != end) { |
3660
|
|
|
|
|
|
|
do { |
3661
|
0
|
|
|
|
|
|
s1 += *p++; |
3662
|
0
|
|
|
|
|
|
s2 += s1; |
3663
|
0
|
0
|
|
|
|
|
} while (p != end); |
3664
|
0
|
|
|
|
|
|
s1 %= DIVISOR; |
3665
|
0
|
|
|
|
|
|
s2 %= DIVISOR; |
3666
|
|
|
|
|
|
|
} |
3667
|
|
|
|
|
|
|
|
3668
|
0
|
|
|
|
|
|
return (s2 << 16) | s1; |
3669
|
|
|
|
|
|
|
} |
3670
|
|
|
|
|
|
|
|
3671
|
|
|
|
|
|
|
#undef FUNCNAME |
3672
|
|
|
|
|
|
|
#undef FUNCNAME_CHUNK |
3673
|
|
|
|
|
|
|
#undef ATTRIBUTES |
3674
|
|
|
|
|
|
|
#undef IMPL_ALIGNMENT |
3675
|
|
|
|
|
|
|
#undef IMPL_SEGMENT_LEN |
3676
|
|
|
|
|
|
|
#undef IMPL_MAX_CHUNK_LEN |
3677
|
|
|
|
|
|
|
|
3678
|
|
|
|
|
|
|
#endif |
3679
|
|
|
|
|
|
|
|
3680
|
|
|
|
|
|
|
#if defined(adler32_avx2) && HAVE_AVX2_NATIVE |
3681
|
|
|
|
|
|
|
#define DEFAULT_IMPL adler32_avx2 |
3682
|
|
|
|
|
|
|
#else |
3683
|
|
|
|
|
|
|
static inline adler32_func_t |
3684
|
1
|
|
|
|
|
|
arch_select_adler32_func(void) |
3685
|
|
|
|
|
|
|
{ |
3686
|
1
|
|
|
|
|
|
const u32 features MAYBE_UNUSED = get_x86_cpu_features(); |
3687
|
|
|
|
|
|
|
|
3688
|
|
|
|
|
|
|
#ifdef adler32_avx2 |
3689
|
1
|
50
|
|
|
|
|
if (HAVE_AVX2(features)) |
3690
|
0
|
|
|
|
|
|
return adler32_avx2; |
3691
|
|
|
|
|
|
|
#endif |
3692
|
|
|
|
|
|
|
#ifdef adler32_sse2 |
3693
|
|
|
|
|
|
|
if (HAVE_SSE2(features)) |
3694
|
1
|
|
|
|
|
|
return adler32_sse2; |
3695
|
|
|
|
|
|
|
#endif |
3696
|
|
|
|
|
|
|
return NULL; |
3697
|
|
|
|
|
|
|
} |
3698
|
|
|
|
|
|
|
#define arch_select_adler32_func arch_select_adler32_func |
3699
|
|
|
|
|
|
|
#endif |
3700
|
|
|
|
|
|
|
|
3701
|
|
|
|
|
|
|
#endif |
3702
|
|
|
|
|
|
|
|
3703
|
|
|
|
|
|
|
#endif |
3704
|
|
|
|
|
|
|
|
3705
|
|
|
|
|
|
|
#ifndef DEFAULT_IMPL |
3706
|
|
|
|
|
|
|
# define DEFAULT_IMPL adler32_generic |
3707
|
|
|
|
|
|
|
#endif |
3708
|
|
|
|
|
|
|
|
3709
|
|
|
|
|
|
|
#ifdef arch_select_adler32_func |
3710
|
|
|
|
|
|
|
static u32 adler32_dispatch_adler32(u32 adler, const u8 *p, size_t len); |
3711
|
|
|
|
|
|
|
|
3712
|
|
|
|
|
|
|
static volatile adler32_func_t adler32_impl = adler32_dispatch_adler32; |
3713
|
|
|
|
|
|
|
|
3714
|
|
|
|
|
|
|
|
3715
|
1
|
|
|
|
|
|
static u32 adler32_dispatch_adler32(u32 adler, const u8 *p, size_t len) |
3716
|
|
|
|
|
|
|
{ |
3717
|
1
|
|
|
|
|
|
adler32_func_t f = arch_select_adler32_func(); |
3718
|
|
|
|
|
|
|
|
3719
|
1
|
50
|
|
|
|
|
if (f == NULL) |
3720
|
0
|
|
|
|
|
|
f = DEFAULT_IMPL; |
3721
|
|
|
|
|
|
|
|
3722
|
1
|
|
|
|
|
|
adler32_impl = f; |
3723
|
1
|
|
|
|
|
|
return f(adler, p, len); |
3724
|
|
|
|
|
|
|
} |
3725
|
|
|
|
|
|
|
#else |
3726
|
|
|
|
|
|
|
|
3727
|
|
|
|
|
|
|
#define adler32_impl DEFAULT_IMPL |
3728
|
|
|
|
|
|
|
#endif |
3729
|
|
|
|
|
|
|
|
3730
|
|
|
|
|
|
|
LIBDEFLATEAPI u32 |
3731
|
24
|
|
|
|
|
|
libdeflate_adler32(u32 adler, const void *buffer, size_t len) |
3732
|
|
|
|
|
|
|
{ |
3733
|
24
|
50
|
|
|
|
|
if (buffer == NULL) |
3734
|
0
|
|
|
|
|
|
return 1; |
3735
|
24
|
|
|
|
|
|
return adler32_impl(adler, buffer, len); |
3736
|
|
|
|
|
|
|
} |
3737
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/crc32.c */ |
3738
|
|
|
|
|
|
|
|
3739
|
|
|
|
|
|
|
|
3740
|
|
|
|
|
|
|
|
3741
|
|
|
|
|
|
|
|
3742
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
3743
|
|
|
|
|
|
|
|
3744
|
|
|
|
|
|
|
|
3745
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
3746
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
3747
|
|
|
|
|
|
|
|
3748
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
3749
|
|
|
|
|
|
|
|
3750
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
3751
|
|
|
|
|
|
|
#endif |
3752
|
|
|
|
|
|
|
|
3753
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
3754
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
3755
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
3756
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
3757
|
|
|
|
|
|
|
#else |
3758
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
3759
|
|
|
|
|
|
|
#endif |
3760
|
|
|
|
|
|
|
|
3761
|
|
|
|
|
|
|
|
3762
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
3763
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
3764
|
|
|
|
|
|
|
#else |
3765
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
3766
|
|
|
|
|
|
|
#endif |
3767
|
|
|
|
|
|
|
|
3768
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
3769
|
|
|
|
|
|
|
|
3770
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
3771
|
|
|
|
|
|
|
|
3772
|
|
|
|
|
|
|
|
3773
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
3774
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
3775
|
|
|
|
|
|
|
|
3776
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
3777
|
|
|
|
|
|
|
|
3778
|
|
|
|
|
|
|
|
3779
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
3780
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
3781
|
|
|
|
|
|
|
|
3782
|
|
|
|
|
|
|
#include |
3783
|
|
|
|
|
|
|
#include |
3784
|
|
|
|
|
|
|
|
3785
|
|
|
|
|
|
|
#ifdef __cplusplus |
3786
|
|
|
|
|
|
|
extern "C" { |
3787
|
|
|
|
|
|
|
#endif |
3788
|
|
|
|
|
|
|
|
3789
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
3790
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
3791
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
3792
|
|
|
|
|
|
|
|
3793
|
|
|
|
|
|
|
|
3794
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
3795
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
3796
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
3797
|
|
|
|
|
|
|
# else |
3798
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
3799
|
|
|
|
|
|
|
# endif |
3800
|
|
|
|
|
|
|
#endif |
3801
|
|
|
|
|
|
|
|
3802
|
|
|
|
|
|
|
|
3803
|
|
|
|
|
|
|
|
3804
|
|
|
|
|
|
|
|
3805
|
|
|
|
|
|
|
|
3806
|
|
|
|
|
|
|
struct libdeflate_compressor; |
3807
|
|
|
|
|
|
|
|
3808
|
|
|
|
|
|
|
|
3809
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
3810
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
3811
|
|
|
|
|
|
|
|
3812
|
|
|
|
|
|
|
|
3813
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3814
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
3815
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3816
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
3817
|
|
|
|
|
|
|
|
3818
|
|
|
|
|
|
|
|
3819
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3820
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
3821
|
|
|
|
|
|
|
size_t in_nbytes); |
3822
|
|
|
|
|
|
|
|
3823
|
|
|
|
|
|
|
|
3824
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3825
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
3826
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3827
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
3828
|
|
|
|
|
|
|
|
3829
|
|
|
|
|
|
|
|
3830
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3831
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
3832
|
|
|
|
|
|
|
size_t in_nbytes); |
3833
|
|
|
|
|
|
|
|
3834
|
|
|
|
|
|
|
|
3835
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3836
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
3837
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3838
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
3839
|
|
|
|
|
|
|
|
3840
|
|
|
|
|
|
|
|
3841
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
3842
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
3843
|
|
|
|
|
|
|
size_t in_nbytes); |
3844
|
|
|
|
|
|
|
|
3845
|
|
|
|
|
|
|
|
3846
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
3847
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
3848
|
|
|
|
|
|
|
|
3849
|
|
|
|
|
|
|
|
3850
|
|
|
|
|
|
|
|
3851
|
|
|
|
|
|
|
|
3852
|
|
|
|
|
|
|
|
3853
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
3854
|
|
|
|
|
|
|
|
3855
|
|
|
|
|
|
|
|
3856
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
3857
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
3858
|
|
|
|
|
|
|
|
3859
|
|
|
|
|
|
|
|
3860
|
|
|
|
|
|
|
enum libdeflate_result { |
3861
|
|
|
|
|
|
|
|
3862
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
3863
|
|
|
|
|
|
|
|
3864
|
|
|
|
|
|
|
|
3865
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
3866
|
|
|
|
|
|
|
|
3867
|
|
|
|
|
|
|
|
3868
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
3869
|
|
|
|
|
|
|
|
3870
|
|
|
|
|
|
|
|
3871
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
3872
|
|
|
|
|
|
|
}; |
3873
|
|
|
|
|
|
|
|
3874
|
|
|
|
|
|
|
|
3875
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3876
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
3877
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3878
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3879
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3880
|
|
|
|
|
|
|
|
3881
|
|
|
|
|
|
|
|
3882
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3883
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
3884
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3885
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3886
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
3887
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3888
|
|
|
|
|
|
|
|
3889
|
|
|
|
|
|
|
|
3890
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3891
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
3892
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3893
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3894
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3895
|
|
|
|
|
|
|
|
3896
|
|
|
|
|
|
|
|
3897
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3898
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
3899
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3900
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3901
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
3902
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3903
|
|
|
|
|
|
|
|
3904
|
|
|
|
|
|
|
|
3905
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3906
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
3907
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3908
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3909
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3910
|
|
|
|
|
|
|
|
3911
|
|
|
|
|
|
|
|
3912
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
3913
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
3914
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
3915
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
3916
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
3917
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
3918
|
|
|
|
|
|
|
|
3919
|
|
|
|
|
|
|
|
3920
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
3921
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
3922
|
|
|
|
|
|
|
|
3923
|
|
|
|
|
|
|
|
3924
|
|
|
|
|
|
|
|
3925
|
|
|
|
|
|
|
|
3926
|
|
|
|
|
|
|
|
3927
|
|
|
|
|
|
|
|
3928
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
3929
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
3930
|
|
|
|
|
|
|
|
3931
|
|
|
|
|
|
|
|
3932
|
|
|
|
|
|
|
|
3933
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
3934
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
3935
|
|
|
|
|
|
|
|
3936
|
|
|
|
|
|
|
|
3937
|
|
|
|
|
|
|
|
3938
|
|
|
|
|
|
|
|
3939
|
|
|
|
|
|
|
|
3940
|
|
|
|
|
|
|
|
3941
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
3942
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
3943
|
|
|
|
|
|
|
void (*free_func)(void *)); |
3944
|
|
|
|
|
|
|
|
3945
|
|
|
|
|
|
|
#ifdef __cplusplus |
3946
|
|
|
|
|
|
|
} |
3947
|
|
|
|
|
|
|
#endif |
3948
|
|
|
|
|
|
|
|
3949
|
|
|
|
|
|
|
#endif |
3950
|
|
|
|
|
|
|
|
3951
|
|
|
|
|
|
|
|
3952
|
|
|
|
|
|
|
#include |
3953
|
|
|
|
|
|
|
#include |
3954
|
|
|
|
|
|
|
#include |
3955
|
|
|
|
|
|
|
#ifdef _MSC_VER |
3956
|
|
|
|
|
|
|
# include |
3957
|
|
|
|
|
|
|
# include |
3958
|
|
|
|
|
|
|
|
3959
|
|
|
|
|
|
|
|
3960
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
3961
|
|
|
|
|
|
|
|
3962
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
3963
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
3964
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
3965
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
3966
|
|
|
|
|
|
|
|
3967
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
3968
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
3969
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
3970
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
3971
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
3972
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
3973
|
|
|
|
|
|
|
#endif |
3974
|
|
|
|
|
|
|
#ifndef FREESTANDING |
3975
|
|
|
|
|
|
|
# include |
3976
|
|
|
|
|
|
|
#endif |
3977
|
|
|
|
|
|
|
|
3978
|
|
|
|
|
|
|
|
3979
|
|
|
|
|
|
|
|
3980
|
|
|
|
|
|
|
|
3981
|
|
|
|
|
|
|
|
3982
|
|
|
|
|
|
|
|
3983
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
3984
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
3985
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
3986
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
3987
|
|
|
|
|
|
|
#ifdef _MSC_VER |
3988
|
|
|
|
|
|
|
# if defined(_M_X64) |
3989
|
|
|
|
|
|
|
# define ARCH_X86_64 |
3990
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
3991
|
|
|
|
|
|
|
# define ARCH_X86_32 |
3992
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
3993
|
|
|
|
|
|
|
# define ARCH_ARM64 |
3994
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
3995
|
|
|
|
|
|
|
# define ARCH_ARM32 |
3996
|
|
|
|
|
|
|
# endif |
3997
|
|
|
|
|
|
|
#else |
3998
|
|
|
|
|
|
|
# if defined(__x86_64__) |
3999
|
|
|
|
|
|
|
# define ARCH_X86_64 |
4000
|
|
|
|
|
|
|
# elif defined(__i386__) |
4001
|
|
|
|
|
|
|
# define ARCH_X86_32 |
4002
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
4003
|
|
|
|
|
|
|
# define ARCH_ARM64 |
4004
|
|
|
|
|
|
|
# elif defined(__arm__) |
4005
|
|
|
|
|
|
|
# define ARCH_ARM32 |
4006
|
|
|
|
|
|
|
# endif |
4007
|
|
|
|
|
|
|
#endif |
4008
|
|
|
|
|
|
|
|
4009
|
|
|
|
|
|
|
|
4010
|
|
|
|
|
|
|
|
4011
|
|
|
|
|
|
|
|
4012
|
|
|
|
|
|
|
|
4013
|
|
|
|
|
|
|
|
4014
|
|
|
|
|
|
|
typedef uint8_t u8; |
4015
|
|
|
|
|
|
|
typedef uint16_t u16; |
4016
|
|
|
|
|
|
|
typedef uint32_t u32; |
4017
|
|
|
|
|
|
|
typedef uint64_t u64; |
4018
|
|
|
|
|
|
|
typedef int8_t s8; |
4019
|
|
|
|
|
|
|
typedef int16_t s16; |
4020
|
|
|
|
|
|
|
typedef int32_t s32; |
4021
|
|
|
|
|
|
|
typedef int64_t s64; |
4022
|
|
|
|
|
|
|
|
4023
|
|
|
|
|
|
|
|
4024
|
|
|
|
|
|
|
#ifdef _MSC_VER |
4025
|
|
|
|
|
|
|
# ifdef _WIN64 |
4026
|
|
|
|
|
|
|
typedef long long ssize_t; |
4027
|
|
|
|
|
|
|
# else |
4028
|
|
|
|
|
|
|
typedef long ssize_t; |
4029
|
|
|
|
|
|
|
# endif |
4030
|
|
|
|
|
|
|
#endif |
4031
|
|
|
|
|
|
|
|
4032
|
|
|
|
|
|
|
|
4033
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
4034
|
|
|
|
|
|
|
|
4035
|
|
|
|
|
|
|
|
4036
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
4037
|
|
|
|
|
|
|
|
4038
|
|
|
|
|
|
|
|
4039
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
4040
|
|
|
|
|
|
|
|
4041
|
|
|
|
|
|
|
|
4042
|
|
|
|
|
|
|
|
4043
|
|
|
|
|
|
|
|
4044
|
|
|
|
|
|
|
|
4045
|
|
|
|
|
|
|
|
4046
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
4047
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
4048
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
4049
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
4050
|
|
|
|
|
|
|
#else |
4051
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
4052
|
|
|
|
|
|
|
#endif |
4053
|
|
|
|
|
|
|
#ifdef __clang__ |
4054
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
4055
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
4056
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
4057
|
|
|
|
|
|
|
# else |
4058
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
4059
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
4060
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
4061
|
|
|
|
|
|
|
# endif |
4062
|
|
|
|
|
|
|
#else |
4063
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
4064
|
|
|
|
|
|
|
#endif |
4065
|
|
|
|
|
|
|
|
4066
|
|
|
|
|
|
|
|
4067
|
|
|
|
|
|
|
#ifndef __has_attribute |
4068
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
4069
|
|
|
|
|
|
|
#endif |
4070
|
|
|
|
|
|
|
#ifndef __has_builtin |
4071
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
4072
|
|
|
|
|
|
|
#endif |
4073
|
|
|
|
|
|
|
|
4074
|
|
|
|
|
|
|
|
4075
|
|
|
|
|
|
|
#ifdef _MSC_VER |
4076
|
|
|
|
|
|
|
# define inline __inline |
4077
|
|
|
|
|
|
|
#endif |
4078
|
|
|
|
|
|
|
|
4079
|
|
|
|
|
|
|
|
4080
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
4081
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
4082
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4083
|
|
|
|
|
|
|
# define forceinline __forceinline |
4084
|
|
|
|
|
|
|
#else |
4085
|
|
|
|
|
|
|
# define forceinline inline |
4086
|
|
|
|
|
|
|
#endif |
4087
|
|
|
|
|
|
|
|
4088
|
|
|
|
|
|
|
|
4089
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
4090
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
4091
|
|
|
|
|
|
|
#else |
4092
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
4093
|
|
|
|
|
|
|
#endif |
4094
|
|
|
|
|
|
|
|
4095
|
|
|
|
|
|
|
|
4096
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
4097
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
4098
|
|
|
|
|
|
|
# define restrict __restrict__ |
4099
|
|
|
|
|
|
|
# else |
4100
|
|
|
|
|
|
|
# define restrict |
4101
|
|
|
|
|
|
|
# endif |
4102
|
|
|
|
|
|
|
#endif |
4103
|
|
|
|
|
|
|
|
4104
|
|
|
|
|
|
|
|
4105
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
4106
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
4107
|
|
|
|
|
|
|
#else |
4108
|
|
|
|
|
|
|
# define likely(expr) (expr) |
4109
|
|
|
|
|
|
|
#endif |
4110
|
|
|
|
|
|
|
|
4111
|
|
|
|
|
|
|
|
4112
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
4113
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
4114
|
|
|
|
|
|
|
#else |
4115
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
4116
|
|
|
|
|
|
|
#endif |
4117
|
|
|
|
|
|
|
|
4118
|
|
|
|
|
|
|
|
4119
|
|
|
|
|
|
|
#undef prefetchr |
4120
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
4121
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
4122
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4123
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
4124
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
4125
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
4126
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
4127
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
4128
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
4129
|
|
|
|
|
|
|
# endif |
4130
|
|
|
|
|
|
|
#endif |
4131
|
|
|
|
|
|
|
#ifndef prefetchr |
4132
|
|
|
|
|
|
|
# define prefetchr(addr) |
4133
|
|
|
|
|
|
|
#endif |
4134
|
|
|
|
|
|
|
|
4135
|
|
|
|
|
|
|
|
4136
|
|
|
|
|
|
|
#undef prefetchw |
4137
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
4138
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
4139
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4140
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
4141
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
4142
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
4143
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
4144
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
4145
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
4146
|
|
|
|
|
|
|
# endif |
4147
|
|
|
|
|
|
|
#endif |
4148
|
|
|
|
|
|
|
#ifndef prefetchw |
4149
|
|
|
|
|
|
|
# define prefetchw(addr) |
4150
|
|
|
|
|
|
|
#endif |
4151
|
|
|
|
|
|
|
|
4152
|
|
|
|
|
|
|
|
4153
|
|
|
|
|
|
|
#undef _aligned_attribute |
4154
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
4155
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
4156
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4157
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
4158
|
|
|
|
|
|
|
#endif |
4159
|
|
|
|
|
|
|
|
4160
|
|
|
|
|
|
|
|
4161
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
4162
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
4163
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
4164
|
|
|
|
|
|
|
#else |
4165
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
4166
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
4167
|
|
|
|
|
|
|
#endif |
4168
|
|
|
|
|
|
|
|
4169
|
|
|
|
|
|
|
|
4170
|
|
|
|
|
|
|
|
4171
|
|
|
|
|
|
|
|
4172
|
|
|
|
|
|
|
|
4173
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
4174
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
4175
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
4176
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
4177
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
4178
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
4179
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
4180
|
|
|
|
|
|
|
|
4181
|
|
|
|
|
|
|
|
4182
|
|
|
|
|
|
|
|
4183
|
|
|
|
|
|
|
|
4184
|
|
|
|
|
|
|
|
4185
|
|
|
|
|
|
|
|
4186
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
4187
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
4188
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4189
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
4190
|
|
|
|
|
|
|
#else |
4191
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
4192
|
|
|
|
|
|
|
{ |
4193
|
|
|
|
|
|
|
union { |
4194
|
|
|
|
|
|
|
u32 w; |
4195
|
|
|
|
|
|
|
u8 b; |
4196
|
|
|
|
|
|
|
} u; |
4197
|
|
|
|
|
|
|
|
4198
|
|
|
|
|
|
|
u.w = 1; |
4199
|
|
|
|
|
|
|
return u.b; |
4200
|
|
|
|
|
|
|
} |
4201
|
|
|
|
|
|
|
#endif |
4202
|
|
|
|
|
|
|
|
4203
|
|
|
|
|
|
|
|
4204
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
4205
|
|
|
|
|
|
|
{ |
4206
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
4207
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
4208
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4209
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
4210
|
|
|
|
|
|
|
#else |
4211
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
4212
|
|
|
|
|
|
|
#endif |
4213
|
|
|
|
|
|
|
} |
4214
|
|
|
|
|
|
|
|
4215
|
|
|
|
|
|
|
|
4216
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
4217
|
|
|
|
|
|
|
{ |
4218
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
4219
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
4220
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4221
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
4222
|
|
|
|
|
|
|
#else |
4223
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
4224
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
4225
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
4226
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
4227
|
|
|
|
|
|
|
#endif |
4228
|
|
|
|
|
|
|
} |
4229
|
|
|
|
|
|
|
|
4230
|
|
|
|
|
|
|
|
4231
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
4232
|
|
|
|
|
|
|
{ |
4233
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
4234
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
4235
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4236
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
4237
|
|
|
|
|
|
|
#else |
4238
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
4239
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
4240
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
4241
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
4242
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
4243
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
4244
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
4245
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
4246
|
|
|
|
|
|
|
#endif |
4247
|
|
|
|
|
|
|
} |
4248
|
|
|
|
|
|
|
|
4249
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
4250
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
4251
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
4252
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
4253
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
4254
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
4255
|
|
|
|
|
|
|
|
4256
|
|
|
|
|
|
|
|
4257
|
|
|
|
|
|
|
|
4258
|
|
|
|
|
|
|
|
4259
|
|
|
|
|
|
|
|
4260
|
|
|
|
|
|
|
|
4261
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
4262
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
4263
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
4264
|
|
|
|
|
|
|
defined(__wasm__)) |
4265
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
4266
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4267
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
4268
|
|
|
|
|
|
|
#else |
4269
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
4270
|
|
|
|
|
|
|
#endif |
4271
|
|
|
|
|
|
|
|
4272
|
|
|
|
|
|
|
|
4273
|
|
|
|
|
|
|
|
4274
|
|
|
|
|
|
|
#ifdef FREESTANDING |
4275
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
4276
|
|
|
|
|
|
|
#else |
4277
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
4278
|
|
|
|
|
|
|
#endif |
4279
|
|
|
|
|
|
|
|
4280
|
|
|
|
|
|
|
|
4281
|
|
|
|
|
|
|
|
4282
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
4283
|
|
|
|
|
|
|
static forceinline type \ |
4284
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
4285
|
|
|
|
|
|
|
{ \ |
4286
|
|
|
|
|
|
|
type v; \ |
4287
|
|
|
|
|
|
|
\ |
4288
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
4289
|
|
|
|
|
|
|
return v; \ |
4290
|
|
|
|
|
|
|
} \ |
4291
|
|
|
|
|
|
|
\ |
4292
|
|
|
|
|
|
|
static forceinline void \ |
4293
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
4294
|
|
|
|
|
|
|
{ \ |
4295
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
4296
|
|
|
|
|
|
|
} |
4297
|
|
|
|
|
|
|
|
4298
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
4299
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
4300
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
4301
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
4302
|
|
|
|
|
|
|
|
4303
|
|
|
|
|
|
|
#undef MEMCOPY |
4304
|
|
|
|
|
|
|
|
4305
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
4306
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
4307
|
|
|
|
|
|
|
|
4308
|
|
|
|
|
|
|
|
4309
|
|
|
|
|
|
|
|
4310
|
|
|
|
|
|
|
static forceinline u16 |
4311
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
4312
|
|
|
|
|
|
|
{ |
4313
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4314
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
4315
|
|
|
|
|
|
|
else |
4316
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
4317
|
|
|
|
|
|
|
} |
4318
|
|
|
|
|
|
|
|
4319
|
|
|
|
|
|
|
static forceinline u16 |
4320
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
4321
|
|
|
|
|
|
|
{ |
4322
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4323
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
4324
|
|
|
|
|
|
|
else |
4325
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
4326
|
|
|
|
|
|
|
} |
4327
|
|
|
|
|
|
|
|
4328
|
|
|
|
|
|
|
static forceinline u32 |
4329
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
4330
|
|
|
|
|
|
|
{ |
4331
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4332
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
4333
|
|
|
|
|
|
|
else |
4334
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
4335
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
4336
|
|
|
|
|
|
|
} |
4337
|
|
|
|
|
|
|
|
4338
|
|
|
|
|
|
|
static forceinline u32 |
4339
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
4340
|
|
|
|
|
|
|
{ |
4341
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4342
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
4343
|
|
|
|
|
|
|
else |
4344
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
4345
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
4346
|
|
|
|
|
|
|
} |
4347
|
|
|
|
|
|
|
|
4348
|
|
|
|
|
|
|
static forceinline u64 |
4349
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
4350
|
|
|
|
|
|
|
{ |
4351
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
4352
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
4353
|
|
|
|
|
|
|
else |
4354
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
4355
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
4356
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
4357
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
4358
|
|
|
|
|
|
|
} |
4359
|
|
|
|
|
|
|
|
4360
|
|
|
|
|
|
|
static forceinline machine_word_t |
4361
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
4362
|
|
|
|
|
|
|
{ |
4363
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
4364
|
|
|
|
|
|
|
if (WORDBITS == 32) |
4365
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
4366
|
|
|
|
|
|
|
else |
4367
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
4368
|
|
|
|
|
|
|
} |
4369
|
|
|
|
|
|
|
|
4370
|
|
|
|
|
|
|
|
4371
|
|
|
|
|
|
|
|
4372
|
|
|
|
|
|
|
static forceinline void |
4373
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
4374
|
|
|
|
|
|
|
{ |
4375
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4376
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
4377
|
|
|
|
|
|
|
} else { |
4378
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
4379
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
4380
|
|
|
|
|
|
|
} |
4381
|
|
|
|
|
|
|
} |
4382
|
|
|
|
|
|
|
|
4383
|
|
|
|
|
|
|
static forceinline void |
4384
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
4385
|
|
|
|
|
|
|
{ |
4386
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4387
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
4388
|
|
|
|
|
|
|
} else { |
4389
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
4390
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
4391
|
|
|
|
|
|
|
} |
4392
|
|
|
|
|
|
|
} |
4393
|
|
|
|
|
|
|
|
4394
|
|
|
|
|
|
|
static forceinline void |
4395
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
4396
|
|
|
|
|
|
|
{ |
4397
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4398
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
4399
|
|
|
|
|
|
|
} else { |
4400
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
4401
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
4402
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
4403
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
4404
|
|
|
|
|
|
|
} |
4405
|
|
|
|
|
|
|
} |
4406
|
|
|
|
|
|
|
|
4407
|
|
|
|
|
|
|
static forceinline void |
4408
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
4409
|
|
|
|
|
|
|
{ |
4410
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4411
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
4412
|
|
|
|
|
|
|
} else { |
4413
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
4414
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
4415
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
4416
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
4417
|
|
|
|
|
|
|
} |
4418
|
|
|
|
|
|
|
} |
4419
|
|
|
|
|
|
|
|
4420
|
|
|
|
|
|
|
static forceinline void |
4421
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
4422
|
|
|
|
|
|
|
{ |
4423
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
4424
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
4425
|
|
|
|
|
|
|
} else { |
4426
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
4427
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
4428
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
4429
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
4430
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
4431
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
4432
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
4433
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
4434
|
|
|
|
|
|
|
} |
4435
|
|
|
|
|
|
|
} |
4436
|
|
|
|
|
|
|
|
4437
|
|
|
|
|
|
|
static forceinline void |
4438
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
4439
|
|
|
|
|
|
|
{ |
4440
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
4441
|
|
|
|
|
|
|
if (WORDBITS == 32) |
4442
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
4443
|
|
|
|
|
|
|
else |
4444
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
4445
|
|
|
|
|
|
|
} |
4446
|
|
|
|
|
|
|
|
4447
|
|
|
|
|
|
|
|
4448
|
|
|
|
|
|
|
|
4449
|
|
|
|
|
|
|
|
4450
|
|
|
|
|
|
|
|
4451
|
|
|
|
|
|
|
|
4452
|
|
|
|
|
|
|
|
4453
|
|
|
|
|
|
|
static forceinline unsigned |
4454
|
|
|
|
|
|
|
bsr32(u32 v) |
4455
|
|
|
|
|
|
|
{ |
4456
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
4457
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
4458
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4459
|
|
|
|
|
|
|
unsigned long i; |
4460
|
|
|
|
|
|
|
|
4461
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
4462
|
|
|
|
|
|
|
return i; |
4463
|
|
|
|
|
|
|
#else |
4464
|
|
|
|
|
|
|
unsigned i = 0; |
4465
|
|
|
|
|
|
|
|
4466
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
4467
|
|
|
|
|
|
|
i++; |
4468
|
|
|
|
|
|
|
return i; |
4469
|
|
|
|
|
|
|
#endif |
4470
|
|
|
|
|
|
|
} |
4471
|
|
|
|
|
|
|
|
4472
|
|
|
|
|
|
|
static forceinline unsigned |
4473
|
|
|
|
|
|
|
bsr64(u64 v) |
4474
|
|
|
|
|
|
|
{ |
4475
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
4476
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
4477
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
4478
|
|
|
|
|
|
|
unsigned long i; |
4479
|
|
|
|
|
|
|
|
4480
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
4481
|
|
|
|
|
|
|
return i; |
4482
|
|
|
|
|
|
|
#else |
4483
|
|
|
|
|
|
|
unsigned i = 0; |
4484
|
|
|
|
|
|
|
|
4485
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
4486
|
|
|
|
|
|
|
i++; |
4487
|
|
|
|
|
|
|
return i; |
4488
|
|
|
|
|
|
|
#endif |
4489
|
|
|
|
|
|
|
} |
4490
|
|
|
|
|
|
|
|
4491
|
|
|
|
|
|
|
static forceinline unsigned |
4492
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
4493
|
|
|
|
|
|
|
{ |
4494
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
4495
|
|
|
|
|
|
|
if (WORDBITS == 32) |
4496
|
|
|
|
|
|
|
return bsr32(v); |
4497
|
|
|
|
|
|
|
else |
4498
|
|
|
|
|
|
|
return bsr64(v); |
4499
|
|
|
|
|
|
|
} |
4500
|
|
|
|
|
|
|
|
4501
|
|
|
|
|
|
|
|
4502
|
|
|
|
|
|
|
|
4503
|
|
|
|
|
|
|
static forceinline unsigned |
4504
|
|
|
|
|
|
|
bsf32(u32 v) |
4505
|
|
|
|
|
|
|
{ |
4506
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
4507
|
|
|
|
|
|
|
return __builtin_ctz(v); |
4508
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
4509
|
|
|
|
|
|
|
unsigned long i; |
4510
|
|
|
|
|
|
|
|
4511
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
4512
|
|
|
|
|
|
|
return i; |
4513
|
|
|
|
|
|
|
#else |
4514
|
|
|
|
|
|
|
unsigned i = 0; |
4515
|
|
|
|
|
|
|
|
4516
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
4517
|
|
|
|
|
|
|
i++; |
4518
|
|
|
|
|
|
|
return i; |
4519
|
|
|
|
|
|
|
#endif |
4520
|
|
|
|
|
|
|
} |
4521
|
|
|
|
|
|
|
|
4522
|
|
|
|
|
|
|
static forceinline unsigned |
4523
|
|
|
|
|
|
|
bsf64(u64 v) |
4524
|
|
|
|
|
|
|
{ |
4525
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
4526
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
4527
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
4528
|
|
|
|
|
|
|
unsigned long i; |
4529
|
|
|
|
|
|
|
|
4530
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
4531
|
|
|
|
|
|
|
return i; |
4532
|
|
|
|
|
|
|
#else |
4533
|
|
|
|
|
|
|
unsigned i = 0; |
4534
|
|
|
|
|
|
|
|
4535
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
4536
|
|
|
|
|
|
|
i++; |
4537
|
|
|
|
|
|
|
return i; |
4538
|
|
|
|
|
|
|
#endif |
4539
|
|
|
|
|
|
|
} |
4540
|
|
|
|
|
|
|
|
4541
|
|
|
|
|
|
|
static forceinline unsigned |
4542
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
4543
|
|
|
|
|
|
|
{ |
4544
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
4545
|
|
|
|
|
|
|
if (WORDBITS == 32) |
4546
|
|
|
|
|
|
|
return bsf32(v); |
4547
|
|
|
|
|
|
|
else |
4548
|
|
|
|
|
|
|
return bsf64(v); |
4549
|
|
|
|
|
|
|
} |
4550
|
|
|
|
|
|
|
|
4551
|
|
|
|
|
|
|
|
4552
|
|
|
|
|
|
|
#undef rbit32 |
4553
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
4554
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
4555
|
|
|
|
|
|
|
static forceinline u32 |
4556
|
|
|
|
|
|
|
rbit32(u32 v) |
4557
|
|
|
|
|
|
|
{ |
4558
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
4559
|
|
|
|
|
|
|
return v; |
4560
|
|
|
|
|
|
|
} |
4561
|
|
|
|
|
|
|
#define rbit32 rbit32 |
4562
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
4563
|
|
|
|
|
|
|
static forceinline u32 |
4564
|
|
|
|
|
|
|
rbit32(u32 v) |
4565
|
|
|
|
|
|
|
{ |
4566
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
4567
|
|
|
|
|
|
|
return v; |
4568
|
|
|
|
|
|
|
} |
4569
|
|
|
|
|
|
|
#define rbit32 rbit32 |
4570
|
|
|
|
|
|
|
#endif |
4571
|
|
|
|
|
|
|
|
4572
|
|
|
|
|
|
|
#endif |
4573
|
|
|
|
|
|
|
|
4574
|
|
|
|
|
|
|
|
4575
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
4576
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
4577
|
|
|
|
|
|
|
|
4578
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
4579
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
4580
|
|
|
|
|
|
|
|
4581
|
|
|
|
|
|
|
#ifdef FREESTANDING |
4582
|
|
|
|
|
|
|
|
4583
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
4584
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
4585
|
|
|
|
|
|
|
|
4586
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
4587
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
4588
|
|
|
|
|
|
|
|
4589
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
4590
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
4591
|
|
|
|
|
|
|
|
4592
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
4593
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
4594
|
|
|
|
|
|
|
|
4595
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
4596
|
|
|
|
|
|
|
#else |
4597
|
|
|
|
|
|
|
#include |
4598
|
|
|
|
|
|
|
#endif |
4599
|
|
|
|
|
|
|
|
4600
|
|
|
|
|
|
|
|
4601
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
4602
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
4603
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
4604
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
4605
|
|
|
|
|
|
|
#else |
4606
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
4607
|
|
|
|
|
|
|
#endif |
4608
|
|
|
|
|
|
|
|
4609
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
4610
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
4611
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
4612
|
|
|
|
|
|
|
|
4613
|
|
|
|
|
|
|
#endif |
4614
|
|
|
|
|
|
|
|
4615
|
|
|
|
|
|
|
/* #include "crc32_multipliers.h" */ |
4616
|
|
|
|
|
|
|
|
4617
|
|
|
|
|
|
|
|
4618
|
|
|
|
|
|
|
#define CRC32_1VECS_MULT_1 0xae689191 |
4619
|
|
|
|
|
|
|
#define CRC32_1VECS_MULT_2 0xccaa009e |
4620
|
|
|
|
|
|
|
#define CRC32_1VECS_MULTS { CRC32_1VECS_MULT_1, CRC32_1VECS_MULT_2 } |
4621
|
|
|
|
|
|
|
|
4622
|
|
|
|
|
|
|
#define CRC32_2VECS_MULT_1 0xf1da05aa |
4623
|
|
|
|
|
|
|
#define CRC32_2VECS_MULT_2 0x81256527 |
4624
|
|
|
|
|
|
|
#define CRC32_2VECS_MULTS { CRC32_2VECS_MULT_1, CRC32_2VECS_MULT_2 } |
4625
|
|
|
|
|
|
|
|
4626
|
|
|
|
|
|
|
#define CRC32_3VECS_MULT_1 0x3db1ecdc |
4627
|
|
|
|
|
|
|
#define CRC32_3VECS_MULT_2 0xaf449247 |
4628
|
|
|
|
|
|
|
#define CRC32_3VECS_MULTS { CRC32_3VECS_MULT_1, CRC32_3VECS_MULT_2 } |
4629
|
|
|
|
|
|
|
|
4630
|
|
|
|
|
|
|
#define CRC32_4VECS_MULT_1 0x8f352d95 |
4631
|
|
|
|
|
|
|
#define CRC32_4VECS_MULT_2 0x1d9513d7 |
4632
|
|
|
|
|
|
|
#define CRC32_4VECS_MULTS { CRC32_4VECS_MULT_1, CRC32_4VECS_MULT_2 } |
4633
|
|
|
|
|
|
|
|
4634
|
|
|
|
|
|
|
#define CRC32_5VECS_MULT_1 0x1c279815 |
4635
|
|
|
|
|
|
|
#define CRC32_5VECS_MULT_2 0xae0b5394 |
4636
|
|
|
|
|
|
|
#define CRC32_5VECS_MULTS { CRC32_5VECS_MULT_1, CRC32_5VECS_MULT_2 } |
4637
|
|
|
|
|
|
|
|
4638
|
|
|
|
|
|
|
#define CRC32_6VECS_MULT_1 0xdf068dc2 |
4639
|
|
|
|
|
|
|
#define CRC32_6VECS_MULT_2 0x57c54819 |
4640
|
|
|
|
|
|
|
#define CRC32_6VECS_MULTS { CRC32_6VECS_MULT_1, CRC32_6VECS_MULT_2 } |
4641
|
|
|
|
|
|
|
|
4642
|
|
|
|
|
|
|
#define CRC32_7VECS_MULT_1 0x31f8303f |
4643
|
|
|
|
|
|
|
#define CRC32_7VECS_MULT_2 0x0cbec0ed |
4644
|
|
|
|
|
|
|
#define CRC32_7VECS_MULTS { CRC32_7VECS_MULT_1, CRC32_7VECS_MULT_2 } |
4645
|
|
|
|
|
|
|
|
4646
|
|
|
|
|
|
|
#define CRC32_8VECS_MULT_1 0x33fff533 |
4647
|
|
|
|
|
|
|
#define CRC32_8VECS_MULT_2 0x910eeec1 |
4648
|
|
|
|
|
|
|
#define CRC32_8VECS_MULTS { CRC32_8VECS_MULT_1, CRC32_8VECS_MULT_2 } |
4649
|
|
|
|
|
|
|
|
4650
|
|
|
|
|
|
|
#define CRC32_9VECS_MULT_1 0x26b70c3d |
4651
|
|
|
|
|
|
|
#define CRC32_9VECS_MULT_2 0x3f41287a |
4652
|
|
|
|
|
|
|
#define CRC32_9VECS_MULTS { CRC32_9VECS_MULT_1, CRC32_9VECS_MULT_2 } |
4653
|
|
|
|
|
|
|
|
4654
|
|
|
|
|
|
|
#define CRC32_10VECS_MULT_1 0xe3543be0 |
4655
|
|
|
|
|
|
|
#define CRC32_10VECS_MULT_2 0x9026d5b1 |
4656
|
|
|
|
|
|
|
#define CRC32_10VECS_MULTS { CRC32_10VECS_MULT_1, CRC32_10VECS_MULT_2 } |
4657
|
|
|
|
|
|
|
|
4658
|
|
|
|
|
|
|
#define CRC32_11VECS_MULT_1 0x5a1bb05d |
4659
|
|
|
|
|
|
|
#define CRC32_11VECS_MULT_2 0xd1df2327 |
4660
|
|
|
|
|
|
|
#define CRC32_11VECS_MULTS { CRC32_11VECS_MULT_1, CRC32_11VECS_MULT_2 } |
4661
|
|
|
|
|
|
|
|
4662
|
|
|
|
|
|
|
#define CRC32_12VECS_MULT_1 0x596c8d81 |
4663
|
|
|
|
|
|
|
#define CRC32_12VECS_MULT_2 0xf5e48c85 |
4664
|
|
|
|
|
|
|
#define CRC32_12VECS_MULTS { CRC32_12VECS_MULT_1, CRC32_12VECS_MULT_2 } |
4665
|
|
|
|
|
|
|
|
4666
|
|
|
|
|
|
|
#define CRC32_FINAL_MULT 0xb8bc6765 |
4667
|
|
|
|
|
|
|
#define CRC32_BARRETT_CONSTANT_1 0x00000001f7011641ULL |
4668
|
|
|
|
|
|
|
#define CRC32_BARRETT_CONSTANT_2 0x00000001db710641ULL |
4669
|
|
|
|
|
|
|
#define CRC32_BARRETT_CONSTANTS { CRC32_BARRETT_CONSTANT_1, CRC32_BARRETT_CONSTANT_2 } |
4670
|
|
|
|
|
|
|
|
4671
|
|
|
|
|
|
|
#define CRC32_NUM_CHUNKS 4 |
4672
|
|
|
|
|
|
|
#define CRC32_MIN_VARIABLE_CHUNK_LEN 128UL |
4673
|
|
|
|
|
|
|
#define CRC32_MAX_VARIABLE_CHUNK_LEN 16384UL |
4674
|
|
|
|
|
|
|
|
4675
|
|
|
|
|
|
|
|
4676
|
|
|
|
|
|
|
static const u32 crc32_mults_for_chunklen[][CRC32_NUM_CHUNKS - 1] MAYBE_UNUSED = { |
4677
|
|
|
|
|
|
|
{ 0 }, |
4678
|
|
|
|
|
|
|
|
4679
|
|
|
|
|
|
|
{ 0xd31343ea , 0xe95c1271 , 0x910eeec1 , }, |
4680
|
|
|
|
|
|
|
|
4681
|
|
|
|
|
|
|
{ 0x1d6708a0 , 0x0c30f51d , 0xe95c1271 , }, |
4682
|
|
|
|
|
|
|
|
4683
|
|
|
|
|
|
|
{ 0xdb3839f3 , 0x1d6708a0 , 0xd31343ea , }, |
4684
|
|
|
|
|
|
|
|
4685
|
|
|
|
|
|
|
{ 0x1753ab84 , 0xbbf2f6d6 , 0x0c30f51d , }, |
4686
|
|
|
|
|
|
|
|
4687
|
|
|
|
|
|
|
{ 0x3796455c , 0xb8e0e4a8 , 0xc352f6de , }, |
4688
|
|
|
|
|
|
|
|
4689
|
|
|
|
|
|
|
{ 0x3954de39 , 0x1753ab84 , 0x1d6708a0 , }, |
4690
|
|
|
|
|
|
|
|
4691
|
|
|
|
|
|
|
{ 0x632d78c5 , 0x3fc33de4 , 0x9a1b53c8 , }, |
4692
|
|
|
|
|
|
|
|
4693
|
|
|
|
|
|
|
{ 0xa0decef3 , 0x7b4aa8b7 , 0xbbf2f6d6 , }, |
4694
|
|
|
|
|
|
|
|
4695
|
|
|
|
|
|
|
{ 0xe9c09bb0 , 0x3954de39 , 0xdb3839f3 , }, |
4696
|
|
|
|
|
|
|
|
4697
|
|
|
|
|
|
|
{ 0xd51917a4 , 0xcae68461 , 0xb8e0e4a8 , }, |
4698
|
|
|
|
|
|
|
|
4699
|
|
|
|
|
|
|
{ 0x154a8a62 , 0x41e7589c , 0x3e9a43cd , }, |
4700
|
|
|
|
|
|
|
|
4701
|
|
|
|
|
|
|
{ 0xf196555d , 0xa0decef3 , 0x1753ab84 , }, |
4702
|
|
|
|
|
|
|
|
4703
|
|
|
|
|
|
|
{ 0x8eec2999 , 0xefb0a128 , 0x6044fbb0 , }, |
4704
|
|
|
|
|
|
|
|
4705
|
|
|
|
|
|
|
{ 0x27892abf , 0x48d72bb1 , 0x3fc33de4 , }, |
4706
|
|
|
|
|
|
|
|
4707
|
|
|
|
|
|
|
{ 0x77bc2419 , 0xd51917a4 , 0x3796455c , }, |
4708
|
|
|
|
|
|
|
|
4709
|
|
|
|
|
|
|
{ 0xcea114a5 , 0x68c0a2c5 , 0x7b4aa8b7 , }, |
4710
|
|
|
|
|
|
|
|
4711
|
|
|
|
|
|
|
{ 0xa1077e85 , 0x188cc628 , 0x0c21f835 , }, |
4712
|
|
|
|
|
|
|
|
4713
|
|
|
|
|
|
|
{ 0xc5ed75e1 , 0xf196555d , 0x3954de39 , }, |
4714
|
|
|
|
|
|
|
|
4715
|
|
|
|
|
|
|
{ 0xca4fba3f , 0x0acfa26f , 0x6cb21510 , }, |
4716
|
|
|
|
|
|
|
|
4717
|
|
|
|
|
|
|
{ 0xcf5bcdc4 , 0x4fae7fc0 , 0xcae68461 , }, |
4718
|
|
|
|
|
|
|
|
4719
|
|
|
|
|
|
|
{ 0xf36b9d16 , 0x27892abf , 0x632d78c5 , }, |
4720
|
|
|
|
|
|
|
|
4721
|
|
|
|
|
|
|
{ 0xf76fd988 , 0xed5c39b1 , 0x41e7589c , }, |
4722
|
|
|
|
|
|
|
|
4723
|
|
|
|
|
|
|
{ 0x6c45d92e , 0xff809fcd , 0x0c46baec , }, |
4724
|
|
|
|
|
|
|
|
4725
|
|
|
|
|
|
|
{ 0x6116b82b , 0xcea114a5 , 0xa0decef3 , }, |
4726
|
|
|
|
|
|
|
|
4727
|
|
|
|
|
|
|
{ 0x4d9899bb , 0x9f9d8d9c , 0x53deb236 , }, |
4728
|
|
|
|
|
|
|
|
4729
|
|
|
|
|
|
|
{ 0x3e7c93b9 , 0x6666b805 , 0xefb0a128 , }, |
4730
|
|
|
|
|
|
|
|
4731
|
|
|
|
|
|
|
{ 0x388b20ac , 0xc5ed75e1 , 0xe9c09bb0 , }, |
4732
|
|
|
|
|
|
|
|
4733
|
|
|
|
|
|
|
{ 0x0956d953 , 0x97fbdb14 , 0x48d72bb1 , }, |
4734
|
|
|
|
|
|
|
|
4735
|
|
|
|
|
|
|
{ 0x55cb4dfe , 0x1b37c832 , 0xc07331b3 , }, |
4736
|
|
|
|
|
|
|
|
4737
|
|
|
|
|
|
|
{ 0x52222fea , 0xcf5bcdc4 , 0xd51917a4 , }, |
4738
|
|
|
|
|
|
|
|
4739
|
|
|
|
|
|
|
{ 0x0603989b , 0xb03c8112 , 0x5e04b9a5 , }, |
4740
|
|
|
|
|
|
|
|
4741
|
|
|
|
|
|
|
{ 0x4470c029 , 0x2339d155 , 0x68c0a2c5 , }, |
4742
|
|
|
|
|
|
|
|
4743
|
|
|
|
|
|
|
{ 0xb6f35093 , 0xf76fd988 , 0x154a8a62 , }, |
4744
|
|
|
|
|
|
|
|
4745
|
|
|
|
|
|
|
{ 0xc46805ba , 0x416f9449 , 0x188cc628 , }, |
4746
|
|
|
|
|
|
|
|
4747
|
|
|
|
|
|
|
{ 0xc3876592 , 0x4b809189 , 0xc35cf6e7 , }, |
4748
|
|
|
|
|
|
|
|
4749
|
|
|
|
|
|
|
{ 0x5b0c98b9 , 0x6116b82b , 0xf196555d , }, |
4750
|
|
|
|
|
|
|
|
4751
|
|
|
|
|
|
|
{ 0x30d13e5f , 0x4c5a315a , 0x8c224466 , }, |
4752
|
|
|
|
|
|
|
|
4753
|
|
|
|
|
|
|
{ 0x54afca53 , 0xbccfa2c1 , 0x0acfa26f , }, |
4754
|
|
|
|
|
|
|
|
4755
|
|
|
|
|
|
|
{ 0x93102436 , 0x3e7c93b9 , 0x8eec2999 , }, |
4756
|
|
|
|
|
|
|
|
4757
|
|
|
|
|
|
|
{ 0xbd2655a8 , 0x3e116c9d , 0x4fae7fc0 , }, |
4758
|
|
|
|
|
|
|
|
4759
|
|
|
|
|
|
|
{ 0x70cd7f26 , 0x408e57f2 , 0x1691be45 , }, |
4760
|
|
|
|
|
|
|
|
4761
|
|
|
|
|
|
|
{ 0x2d546c53 , 0x0956d953 , 0x27892abf , }, |
4762
|
|
|
|
|
|
|
|
4763
|
|
|
|
|
|
|
{ 0xb53410a8 , 0x42ebf0ad , 0x161f3c12 , }, |
4764
|
|
|
|
|
|
|
|
4765
|
|
|
|
|
|
|
{ 0x67a93f75 , 0xcf3233e4 , 0xed5c39b1 , }, |
4766
|
|
|
|
|
|
|
|
4767
|
|
|
|
|
|
|
{ 0x9830ac33 , 0x52222fea , 0x77bc2419 , }, |
4768
|
|
|
|
|
|
|
|
4769
|
|
|
|
|
|
|
{ 0xb0b6fc3e , 0x2fde73f8 , 0xff809fcd , }, |
4770
|
|
|
|
|
|
|
|
4771
|
|
|
|
|
|
|
{ 0x84170f16 , 0xced90d99 , 0x30de0f98 , }, |
4772
|
|
|
|
|
|
|
|
4773
|
|
|
|
|
|
|
{ 0xd7017a0c , 0x4470c029 , 0xcea114a5 , }, |
4774
|
|
|
|
|
|
|
|
4775
|
|
|
|
|
|
|
{ 0xadb25de6 , 0x84f40beb , 0x2b7e0e1b , }, |
4776
|
|
|
|
|
|
|
|
4777
|
|
|
|
|
|
|
{ 0x8282fddc , 0xec855937 , 0x9f9d8d9c , }, |
4778
|
|
|
|
|
|
|
|
4779
|
|
|
|
|
|
|
{ 0x46362bee , 0xc46805ba , 0xa1077e85 , }, |
4780
|
|
|
|
|
|
|
|
4781
|
|
|
|
|
|
|
{ 0xb9077a01 , 0xdf7a24ac , 0x6666b805 , }, |
4782
|
|
|
|
|
|
|
|
4783
|
|
|
|
|
|
|
{ 0xf51d9bc6 , 0x2b52dc39 , 0x7e774cf6 , }, |
4784
|
|
|
|
|
|
|
|
4785
|
|
|
|
|
|
|
{ 0x4ca19a29 , 0x5b0c98b9 , 0xc5ed75e1 , }, |
4786
|
|
|
|
|
|
|
|
4787
|
|
|
|
|
|
|
{ 0xdc0fc3fc , 0xb939fcdf , 0x3678fed2 , }, |
4788
|
|
|
|
|
|
|
|
4789
|
|
|
|
|
|
|
{ 0x63c3d167 , 0x70f9947d , 0x97fbdb14 , }, |
4790
|
|
|
|
|
|
|
|
4791
|
|
|
|
|
|
|
{ 0x5851d254 , 0x54afca53 , 0xca4fba3f , }, |
4792
|
|
|
|
|
|
|
|
4793
|
|
|
|
|
|
|
{ 0xfeacf2a1 , 0x7a3c0a6a , 0x1b37c832 , }, |
4794
|
|
|
|
|
|
|
|
4795
|
|
|
|
|
|
|
{ 0x93b7edc8 , 0x1fea4d2a , 0x58fa96ee , }, |
4796
|
|
|
|
|
|
|
|
4797
|
|
|
|
|
|
|
{ 0x5539e44a , 0xbd2655a8 , 0xcf5bcdc4 , }, |
4798
|
|
|
|
|
|
|
|
4799
|
|
|
|
|
|
|
{ 0xde32a3d2 , 0x4ff61aa1 , 0x6a6a3694 , }, |
4800
|
|
|
|
|
|
|
|
4801
|
|
|
|
|
|
|
{ 0xf0baeeb6 , 0x7ae2f6f4 , 0xb03c8112 , }, |
4802
|
|
|
|
|
|
|
|
4803
|
|
|
|
|
|
|
{ 0xbe15887f , 0x2d546c53 , 0xf36b9d16 , }, |
4804
|
|
|
|
|
|
|
|
4805
|
|
|
|
|
|
|
{ 0x64f34a05 , 0xe0ee5efe , 0x2339d155 , }, |
4806
|
|
|
|
|
|
|
|
4807
|
|
|
|
|
|
|
{ 0x1b6d1aea , 0xfeafb67c , 0x4fb001a8 , }, |
4808
|
|
|
|
|
|
|
|
4809
|
|
|
|
|
|
|
{ 0x82adb0b8 , 0x67a93f75 , 0xf76fd988 , }, |
4810
|
|
|
|
|
|
|
|
4811
|
|
|
|
|
|
|
{ 0x694587c7 , 0x3b34408b , 0xeccb2978 , }, |
4812
|
|
|
|
|
|
|
|
4813
|
|
|
|
|
|
|
{ 0xd2fc57c3 , 0x07fcf8c6 , 0x416f9449 , }, |
4814
|
|
|
|
|
|
|
|
4815
|
|
|
|
|
|
|
{ 0x9dd6837c , 0xb0b6fc3e , 0x6c45d92e , }, |
4816
|
|
|
|
|
|
|
|
4817
|
|
|
|
|
|
|
{ 0x3a9d1f97 , 0xefd033b2 , 0x4b809189 , }, |
4818
|
|
|
|
|
|
|
|
4819
|
|
|
|
|
|
|
{ 0x1eee1d2a , 0xf2a6e46e , 0x55b4c814 , }, |
4820
|
|
|
|
|
|
|
|
4821
|
|
|
|
|
|
|
{ 0xb57c7728 , 0xd7017a0c , 0x6116b82b , }, |
4822
|
|
|
|
|
|
|
|
4823
|
|
|
|
|
|
|
{ 0xf2fc5d61 , 0x242aac86 , 0x05245cf0 , }, |
4824
|
|
|
|
|
|
|
|
4825
|
|
|
|
|
|
|
{ 0x26387824 , 0xc15c4ca5 , 0x4c5a315a , }, |
4826
|
|
|
|
|
|
|
|
4827
|
|
|
|
|
|
|
{ 0x8c151e77 , 0x8282fddc , 0x4d9899bb , }, |
4828
|
|
|
|
|
|
|
|
4829
|
|
|
|
|
|
|
{ 0x8ea1f680 , 0xf5ff6cdd , 0xbccfa2c1 , }, |
4830
|
|
|
|
|
|
|
|
4831
|
|
|
|
|
|
|
{ 0xe8cf3d2a , 0x338b1fb1 , 0xeda61f70 , }, |
4832
|
|
|
|
|
|
|
|
4833
|
|
|
|
|
|
|
{ 0x21f15b59 , 0xb9077a01 , 0x3e7c93b9 , }, |
4834
|
|
|
|
|
|
|
|
4835
|
|
|
|
|
|
|
{ 0x6f68d64a , 0x901b0161 , 0xb9fd3537 , }, |
4836
|
|
|
|
|
|
|
|
4837
|
|
|
|
|
|
|
{ 0x71b74d95 , 0xf5ddd5ad , 0x3e116c9d , }, |
4838
|
|
|
|
|
|
|
|
4839
|
|
|
|
|
|
|
{ 0x4c2e7261 , 0x4ca19a29 , 0x388b20ac , }, |
4840
|
|
|
|
|
|
|
|
4841
|
|
|
|
|
|
|
{ 0x8a2d38e8 , 0xd27ee0a1 , 0x408e57f2 , }, |
4842
|
|
|
|
|
|
|
|
4843
|
|
|
|
|
|
|
{ 0x7e58ca17 , 0x69dfedd2 , 0x3a76805e , }, |
4844
|
|
|
|
|
|
|
|
4845
|
|
|
|
|
|
|
{ 0xf997967f , 0x63c3d167 , 0x0956d953 , }, |
4846
|
|
|
|
|
|
|
|
4847
|
|
|
|
|
|
|
{ 0x48215963 , 0x71e1dfe0 , 0x42a6d410 , }, |
4848
|
|
|
|
|
|
|
|
4849
|
|
|
|
|
|
|
{ 0xa704b94c , 0x679f198a , 0x42ebf0ad , }, |
4850
|
|
|
|
|
|
|
|
4851
|
|
|
|
|
|
|
{ 0x1d699056 , 0xfeacf2a1 , 0x55cb4dfe , }, |
4852
|
|
|
|
|
|
|
|
4853
|
|
|
|
|
|
|
{ 0x6800bcc5 , 0x16024f15 , 0xcf3233e4 , }, |
4854
|
|
|
|
|
|
|
|
4855
|
|
|
|
|
|
|
{ 0x2d48e4ca , 0xbe61582f , 0x46026283 , }, |
4856
|
|
|
|
|
|
|
|
4857
|
|
|
|
|
|
|
{ 0x4c4c2b55 , 0x5539e44a , 0x52222fea , }, |
4858
|
|
|
|
|
|
|
|
4859
|
|
|
|
|
|
|
{ 0xd8ce94cb , 0xbc613c26 , 0x33776b4b , }, |
4860
|
|
|
|
|
|
|
|
4861
|
|
|
|
|
|
|
{ 0xd0b5a02b , 0x490d3cc6 , 0x2fde73f8 , }, |
4862
|
|
|
|
|
|
|
|
4863
|
|
|
|
|
|
|
{ 0xa223f7ec , 0xf0baeeb6 , 0x0603989b , }, |
4864
|
|
|
|
|
|
|
|
4865
|
|
|
|
|
|
|
{ 0x58de337a , 0x3bf3d597 , 0xced90d99 , }, |
4866
|
|
|
|
|
|
|
|
4867
|
|
|
|
|
|
|
{ 0x37f5d8f4 , 0x4d5b699b , 0xd7262e5f , }, |
4868
|
|
|
|
|
|
|
|
4869
|
|
|
|
|
|
|
{ 0xfa8a435d , 0x64f34a05 , 0x4470c029 , }, |
4870
|
|
|
|
|
|
|
|
4871
|
|
|
|
|
|
|
{ 0x238709fe , 0x52e7458f , 0x9a174cd3 , }, |
4872
|
|
|
|
|
|
|
|
4873
|
|
|
|
|
|
|
{ 0x9e1ba6f5 , 0xef0272f7 , 0x84f40beb , }, |
4874
|
|
|
|
|
|
|
|
4875
|
|
|
|
|
|
|
{ 0xcd8b57fa , 0x82adb0b8 , 0xb6f35093 , }, |
4876
|
|
|
|
|
|
|
|
4877
|
|
|
|
|
|
|
{ 0x0aed142f , 0xb1650290 , 0xec855937 , }, |
4878
|
|
|
|
|
|
|
|
4879
|
|
|
|
|
|
|
{ 0xd1f064db , 0x6e7340d3 , 0x5c28cb52 , }, |
4880
|
|
|
|
|
|
|
|
4881
|
|
|
|
|
|
|
{ 0x464ac895 , 0xd2fc57c3 , 0xc46805ba , }, |
4882
|
|
|
|
|
|
|
|
4883
|
|
|
|
|
|
|
{ 0xa0e6beea , 0xcfeec3d0 , 0x0225d214 , }, |
4884
|
|
|
|
|
|
|
|
4885
|
|
|
|
|
|
|
{ 0x78703ce0 , 0xc60f6075 , 0xdf7a24ac , }, |
4886
|
|
|
|
|
|
|
|
4887
|
|
|
|
|
|
|
{ 0xfea48165 , 0x3a9d1f97 , 0xc3876592 , }, |
4888
|
|
|
|
|
|
|
|
4889
|
|
|
|
|
|
|
{ 0xdb89b8db , 0xa6172211 , 0x2b52dc39 , }, |
4890
|
|
|
|
|
|
|
|
4891
|
|
|
|
|
|
|
{ 0x7ca03731 , 0x1db42849 , 0xc5df246e , }, |
4892
|
|
|
|
|
|
|
|
4893
|
|
|
|
|
|
|
{ 0x8801d0aa , 0xb57c7728 , 0x5b0c98b9 , }, |
4894
|
|
|
|
|
|
|
|
4895
|
|
|
|
|
|
|
{ 0xf89cd7f0 , 0xcc396a0b , 0xdb799c51 , }, |
4896
|
|
|
|
|
|
|
|
4897
|
|
|
|
|
|
|
{ 0x1611a808 , 0xaeae6105 , 0xb939fcdf , }, |
4898
|
|
|
|
|
|
|
|
4899
|
|
|
|
|
|
|
{ 0xe3cdb888 , 0x26387824 , 0x30d13e5f , }, |
4900
|
|
|
|
|
|
|
|
4901
|
|
|
|
|
|
|
{ 0x552a4cf6 , 0xee2d04bb , 0x70f9947d , }, |
4902
|
|
|
|
|
|
|
|
4903
|
|
|
|
|
|
|
{ 0x85e248e9 , 0x0a79663f , 0x53339cf7 , }, |
4904
|
|
|
|
|
|
|
|
4905
|
|
|
|
|
|
|
{ 0x1c61c3e9 , 0x8ea1f680 , 0x54afca53 , }, |
4906
|
|
|
|
|
|
|
|
4907
|
|
|
|
|
|
|
{ 0xb14cfc2b , 0x2e073302 , 0x10897992 , }, |
4908
|
|
|
|
|
|
|
|
4909
|
|
|
|
|
|
|
{ 0x6ec444cc , 0x9e819f13 , 0x7a3c0a6a , }, |
4910
|
|
|
|
|
|
|
|
4911
|
|
|
|
|
|
|
{ 0xe2fa5f80 , 0x21f15b59 , 0x93102436 , }, |
4912
|
|
|
|
|
|
|
|
4913
|
|
|
|
|
|
|
{ 0x6d33f4c6 , 0x31a27455 , 0x1fea4d2a , }, |
4914
|
|
|
|
|
|
|
|
4915
|
|
|
|
|
|
|
{ 0xb6dec609 , 0x4d437056 , 0x42eb1e2a , }, |
4916
|
|
|
|
|
|
|
|
4917
|
|
|
|
|
|
|
{ 0x1846c518 , 0x71b74d95 , 0xbd2655a8 , }, |
4918
|
|
|
|
|
|
|
|
4919
|
|
|
|
|
|
|
{ 0x9f947f8a , 0x2b501619 , 0xa4924b0e , }, |
4920
|
|
|
|
|
|
|
|
4921
|
|
|
|
|
|
|
{ 0xb7442f4d , 0xba30a5d8 , 0x4ff61aa1 , }, |
4922
|
|
|
|
|
|
|
|
4923
|
|
|
|
|
|
|
{ 0xe2c93242 , 0x8a2d38e8 , 0x70cd7f26 , }, |
4924
|
|
|
|
|
|
|
|
4925
|
|
|
|
|
|
|
{ 0xcd6863df , 0x78fd88dc , 0x7ae2f6f4 , }, |
4926
|
|
|
|
|
|
|
|
4927
|
|
|
|
|
|
|
{ 0xd512001d , 0xe6612dff , 0x5c4d0ca9 , }, |
4928
|
|
|
|
|
|
|
|
4929
|
|
|
|
|
|
|
{ 0x4e8d6b6c , 0xf997967f , 0x2d546c53 , }, |
4930
|
|
|
|
|
|
|
|
4931
|
|
|
|
|
|
|
{ 0xfa653ba1 , 0xc99014d4 , 0xa0c9fd27 , }, |
4932
|
|
|
|
|
|
|
|
4933
|
|
|
|
|
|
|
{ 0x49893408 , 0x29c2448b , 0xe0ee5efe , }, |
4934
|
|
|
|
|
|
|
}; |
4935
|
|
|
|
|
|
|
|
4936
|
|
|
|
|
|
|
|
4937
|
|
|
|
|
|
|
#define CRC32_FIXED_CHUNK_LEN 32768UL |
4938
|
|
|
|
|
|
|
#define CRC32_FIXED_CHUNK_MULT_1 0x29c2448b |
4939
|
|
|
|
|
|
|
#define CRC32_FIXED_CHUNK_MULT_2 0x4b912f53 |
4940
|
|
|
|
|
|
|
#define CRC32_FIXED_CHUNK_MULT_3 0x454c93be |
4941
|
|
|
|
|
|
|
|
4942
|
|
|
|
|
|
|
/* #include "crc32_tables.h" */ |
4943
|
|
|
|
|
|
|
|
4944
|
|
|
|
|
|
|
|
4945
|
|
|
|
|
|
|
static const u32 crc32_slice1_table[] MAYBE_UNUSED = { |
4946
|
|
|
|
|
|
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, |
4947
|
|
|
|
|
|
|
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, |
4948
|
|
|
|
|
|
|
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, |
4949
|
|
|
|
|
|
|
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, |
4950
|
|
|
|
|
|
|
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
4951
|
|
|
|
|
|
|
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, |
4952
|
|
|
|
|
|
|
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, |
4953
|
|
|
|
|
|
|
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, |
4954
|
|
|
|
|
|
|
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, |
4955
|
|
|
|
|
|
|
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
4956
|
|
|
|
|
|
|
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, |
4957
|
|
|
|
|
|
|
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, |
4958
|
|
|
|
|
|
|
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, |
4959
|
|
|
|
|
|
|
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, |
4960
|
|
|
|
|
|
|
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
4961
|
|
|
|
|
|
|
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, |
4962
|
|
|
|
|
|
|
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, |
4963
|
|
|
|
|
|
|
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, |
4964
|
|
|
|
|
|
|
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, |
4965
|
|
|
|
|
|
|
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
4966
|
|
|
|
|
|
|
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, |
4967
|
|
|
|
|
|
|
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, |
4968
|
|
|
|
|
|
|
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, |
4969
|
|
|
|
|
|
|
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, |
4970
|
|
|
|
|
|
|
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
4971
|
|
|
|
|
|
|
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, |
4972
|
|
|
|
|
|
|
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, |
4973
|
|
|
|
|
|
|
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, |
4974
|
|
|
|
|
|
|
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, |
4975
|
|
|
|
|
|
|
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
4976
|
|
|
|
|
|
|
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, |
4977
|
|
|
|
|
|
|
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, |
4978
|
|
|
|
|
|
|
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, |
4979
|
|
|
|
|
|
|
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, |
4980
|
|
|
|
|
|
|
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
4981
|
|
|
|
|
|
|
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, |
4982
|
|
|
|
|
|
|
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, |
4983
|
|
|
|
|
|
|
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, |
4984
|
|
|
|
|
|
|
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, |
4985
|
|
|
|
|
|
|
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
4986
|
|
|
|
|
|
|
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, |
4987
|
|
|
|
|
|
|
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, |
4988
|
|
|
|
|
|
|
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, |
4989
|
|
|
|
|
|
|
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, |
4990
|
|
|
|
|
|
|
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
4991
|
|
|
|
|
|
|
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, |
4992
|
|
|
|
|
|
|
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, |
4993
|
|
|
|
|
|
|
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, |
4994
|
|
|
|
|
|
|
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, |
4995
|
|
|
|
|
|
|
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
4996
|
|
|
|
|
|
|
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, |
4997
|
|
|
|
|
|
|
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, |
4998
|
|
|
|
|
|
|
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, |
4999
|
|
|
|
|
|
|
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, |
5000
|
|
|
|
|
|
|
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
5001
|
|
|
|
|
|
|
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, |
5002
|
|
|
|
|
|
|
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, |
5003
|
|
|
|
|
|
|
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, |
5004
|
|
|
|
|
|
|
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, |
5005
|
|
|
|
|
|
|
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
5006
|
|
|
|
|
|
|
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, |
5007
|
|
|
|
|
|
|
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, |
5008
|
|
|
|
|
|
|
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, |
5009
|
|
|
|
|
|
|
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, |
5010
|
|
|
|
|
|
|
}; |
5011
|
|
|
|
|
|
|
|
5012
|
|
|
|
|
|
|
static const u32 crc32_slice8_table[] MAYBE_UNUSED = { |
5013
|
|
|
|
|
|
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, |
5014
|
|
|
|
|
|
|
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, |
5015
|
|
|
|
|
|
|
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, |
5016
|
|
|
|
|
|
|
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, |
5017
|
|
|
|
|
|
|
0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
5018
|
|
|
|
|
|
|
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, |
5019
|
|
|
|
|
|
|
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, |
5020
|
|
|
|
|
|
|
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, |
5021
|
|
|
|
|
|
|
0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, |
5022
|
|
|
|
|
|
|
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
5023
|
|
|
|
|
|
|
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, |
5024
|
|
|
|
|
|
|
0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, |
5025
|
|
|
|
|
|
|
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, |
5026
|
|
|
|
|
|
|
0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, |
5027
|
|
|
|
|
|
|
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
5028
|
|
|
|
|
|
|
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, |
5029
|
|
|
|
|
|
|
0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, |
5030
|
|
|
|
|
|
|
0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, |
5031
|
|
|
|
|
|
|
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, |
5032
|
|
|
|
|
|
|
0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
5033
|
|
|
|
|
|
|
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, |
5034
|
|
|
|
|
|
|
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, |
5035
|
|
|
|
|
|
|
0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, |
5036
|
|
|
|
|
|
|
0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, |
5037
|
|
|
|
|
|
|
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
5038
|
|
|
|
|
|
|
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, |
5039
|
|
|
|
|
|
|
0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, |
5040
|
|
|
|
|
|
|
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, |
5041
|
|
|
|
|
|
|
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, |
5042
|
|
|
|
|
|
|
0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
5043
|
|
|
|
|
|
|
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, |
5044
|
|
|
|
|
|
|
0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, |
5045
|
|
|
|
|
|
|
0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, |
5046
|
|
|
|
|
|
|
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, |
5047
|
|
|
|
|
|
|
0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
5048
|
|
|
|
|
|
|
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, |
5049
|
|
|
|
|
|
|
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, |
5050
|
|
|
|
|
|
|
0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, |
5051
|
|
|
|
|
|
|
0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, |
5052
|
|
|
|
|
|
|
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
5053
|
|
|
|
|
|
|
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, |
5054
|
|
|
|
|
|
|
0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, |
5055
|
|
|
|
|
|
|
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, |
5056
|
|
|
|
|
|
|
0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, |
5057
|
|
|
|
|
|
|
0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
5058
|
|
|
|
|
|
|
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, |
5059
|
|
|
|
|
|
|
0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, |
5060
|
|
|
|
|
|
|
0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, |
5061
|
|
|
|
|
|
|
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, |
5062
|
|
|
|
|
|
|
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
5063
|
|
|
|
|
|
|
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, |
5064
|
|
|
|
|
|
|
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, |
5065
|
|
|
|
|
|
|
0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, |
5066
|
|
|
|
|
|
|
0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, |
5067
|
|
|
|
|
|
|
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
5068
|
|
|
|
|
|
|
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, |
5069
|
|
|
|
|
|
|
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, |
5070
|
|
|
|
|
|
|
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, |
5071
|
|
|
|
|
|
|
0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, |
5072
|
|
|
|
|
|
|
0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
5073
|
|
|
|
|
|
|
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, |
5074
|
|
|
|
|
|
|
0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, |
5075
|
|
|
|
|
|
|
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, |
5076
|
|
|
|
|
|
|
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, |
5077
|
|
|
|
|
|
|
0x00000000, 0x191b3141, 0x32366282, 0x2b2d53c3, |
5078
|
|
|
|
|
|
|
0x646cc504, 0x7d77f445, 0x565aa786, 0x4f4196c7, |
5079
|
|
|
|
|
|
|
0xc8d98a08, 0xd1c2bb49, 0xfaefe88a, 0xe3f4d9cb, |
5080
|
|
|
|
|
|
|
0xacb54f0c, 0xb5ae7e4d, 0x9e832d8e, 0x87981ccf, |
5081
|
|
|
|
|
|
|
0x4ac21251, 0x53d92310, 0x78f470d3, 0x61ef4192, |
5082
|
|
|
|
|
|
|
0x2eaed755, 0x37b5e614, 0x1c98b5d7, 0x05838496, |
5083
|
|
|
|
|
|
|
0x821b9859, 0x9b00a918, 0xb02dfadb, 0xa936cb9a, |
5084
|
|
|
|
|
|
|
0xe6775d5d, 0xff6c6c1c, 0xd4413fdf, 0xcd5a0e9e, |
5085
|
|
|
|
|
|
|
0x958424a2, 0x8c9f15e3, 0xa7b24620, 0xbea97761, |
5086
|
|
|
|
|
|
|
0xf1e8e1a6, 0xe8f3d0e7, 0xc3de8324, 0xdac5b265, |
5087
|
|
|
|
|
|
|
0x5d5daeaa, 0x44469feb, 0x6f6bcc28, 0x7670fd69, |
5088
|
|
|
|
|
|
|
0x39316bae, 0x202a5aef, 0x0b07092c, 0x121c386d, |
5089
|
|
|
|
|
|
|
0xdf4636f3, 0xc65d07b2, 0xed705471, 0xf46b6530, |
5090
|
|
|
|
|
|
|
0xbb2af3f7, 0xa231c2b6, 0x891c9175, 0x9007a034, |
5091
|
|
|
|
|
|
|
0x179fbcfb, 0x0e848dba, 0x25a9de79, 0x3cb2ef38, |
5092
|
|
|
|
|
|
|
0x73f379ff, 0x6ae848be, 0x41c51b7d, 0x58de2a3c, |
5093
|
|
|
|
|
|
|
0xf0794f05, 0xe9627e44, 0xc24f2d87, 0xdb541cc6, |
5094
|
|
|
|
|
|
|
0x94158a01, 0x8d0ebb40, 0xa623e883, 0xbf38d9c2, |
5095
|
|
|
|
|
|
|
0x38a0c50d, 0x21bbf44c, 0x0a96a78f, 0x138d96ce, |
5096
|
|
|
|
|
|
|
0x5ccc0009, 0x45d73148, 0x6efa628b, 0x77e153ca, |
5097
|
|
|
|
|
|
|
0xbabb5d54, 0xa3a06c15, 0x888d3fd6, 0x91960e97, |
5098
|
|
|
|
|
|
|
0xded79850, 0xc7cca911, 0xece1fad2, 0xf5facb93, |
5099
|
|
|
|
|
|
|
0x7262d75c, 0x6b79e61d, 0x4054b5de, 0x594f849f, |
5100
|
|
|
|
|
|
|
0x160e1258, 0x0f152319, 0x243870da, 0x3d23419b, |
5101
|
|
|
|
|
|
|
0x65fd6ba7, 0x7ce65ae6, 0x57cb0925, 0x4ed03864, |
5102
|
|
|
|
|
|
|
0x0191aea3, 0x188a9fe2, 0x33a7cc21, 0x2abcfd60, |
5103
|
|
|
|
|
|
|
0xad24e1af, 0xb43fd0ee, 0x9f12832d, 0x8609b26c, |
5104
|
|
|
|
|
|
|
0xc94824ab, 0xd05315ea, 0xfb7e4629, 0xe2657768, |
5105
|
|
|
|
|
|
|
0x2f3f79f6, 0x362448b7, 0x1d091b74, 0x04122a35, |
5106
|
|
|
|
|
|
|
0x4b53bcf2, 0x52488db3, 0x7965de70, 0x607eef31, |
5107
|
|
|
|
|
|
|
0xe7e6f3fe, 0xfefdc2bf, 0xd5d0917c, 0xcccba03d, |
5108
|
|
|
|
|
|
|
0x838a36fa, 0x9a9107bb, 0xb1bc5478, 0xa8a76539, |
5109
|
|
|
|
|
|
|
0x3b83984b, 0x2298a90a, 0x09b5fac9, 0x10aecb88, |
5110
|
|
|
|
|
|
|
0x5fef5d4f, 0x46f46c0e, 0x6dd93fcd, 0x74c20e8c, |
5111
|
|
|
|
|
|
|
0xf35a1243, 0xea412302, 0xc16c70c1, 0xd8774180, |
5112
|
|
|
|
|
|
|
0x9736d747, 0x8e2de606, 0xa500b5c5, 0xbc1b8484, |
5113
|
|
|
|
|
|
|
0x71418a1a, 0x685abb5b, 0x4377e898, 0x5a6cd9d9, |
5114
|
|
|
|
|
|
|
0x152d4f1e, 0x0c367e5f, 0x271b2d9c, 0x3e001cdd, |
5115
|
|
|
|
|
|
|
0xb9980012, 0xa0833153, 0x8bae6290, 0x92b553d1, |
5116
|
|
|
|
|
|
|
0xddf4c516, 0xc4eff457, 0xefc2a794, 0xf6d996d5, |
5117
|
|
|
|
|
|
|
0xae07bce9, 0xb71c8da8, 0x9c31de6b, 0x852aef2a, |
5118
|
|
|
|
|
|
|
0xca6b79ed, 0xd37048ac, 0xf85d1b6f, 0xe1462a2e, |
5119
|
|
|
|
|
|
|
0x66de36e1, 0x7fc507a0, 0x54e85463, 0x4df36522, |
5120
|
|
|
|
|
|
|
0x02b2f3e5, 0x1ba9c2a4, 0x30849167, 0x299fa026, |
5121
|
|
|
|
|
|
|
0xe4c5aeb8, 0xfdde9ff9, 0xd6f3cc3a, 0xcfe8fd7b, |
5122
|
|
|
|
|
|
|
0x80a96bbc, 0x99b25afd, 0xb29f093e, 0xab84387f, |
5123
|
|
|
|
|
|
|
0x2c1c24b0, 0x350715f1, 0x1e2a4632, 0x07317773, |
5124
|
|
|
|
|
|
|
0x4870e1b4, 0x516bd0f5, 0x7a468336, 0x635db277, |
5125
|
|
|
|
|
|
|
0xcbfad74e, 0xd2e1e60f, 0xf9ccb5cc, 0xe0d7848d, |
5126
|
|
|
|
|
|
|
0xaf96124a, 0xb68d230b, 0x9da070c8, 0x84bb4189, |
5127
|
|
|
|
|
|
|
0x03235d46, 0x1a386c07, 0x31153fc4, 0x280e0e85, |
5128
|
|
|
|
|
|
|
0x674f9842, 0x7e54a903, 0x5579fac0, 0x4c62cb81, |
5129
|
|
|
|
|
|
|
0x8138c51f, 0x9823f45e, 0xb30ea79d, 0xaa1596dc, |
5130
|
|
|
|
|
|
|
0xe554001b, 0xfc4f315a, 0xd7626299, 0xce7953d8, |
5131
|
|
|
|
|
|
|
0x49e14f17, 0x50fa7e56, 0x7bd72d95, 0x62cc1cd4, |
5132
|
|
|
|
|
|
|
0x2d8d8a13, 0x3496bb52, 0x1fbbe891, 0x06a0d9d0, |
5133
|
|
|
|
|
|
|
0x5e7ef3ec, 0x4765c2ad, 0x6c48916e, 0x7553a02f, |
5134
|
|
|
|
|
|
|
0x3a1236e8, 0x230907a9, 0x0824546a, 0x113f652b, |
5135
|
|
|
|
|
|
|
0x96a779e4, 0x8fbc48a5, 0xa4911b66, 0xbd8a2a27, |
5136
|
|
|
|
|
|
|
0xf2cbbce0, 0xebd08da1, 0xc0fdde62, 0xd9e6ef23, |
5137
|
|
|
|
|
|
|
0x14bce1bd, 0x0da7d0fc, 0x268a833f, 0x3f91b27e, |
5138
|
|
|
|
|
|
|
0x70d024b9, 0x69cb15f8, 0x42e6463b, 0x5bfd777a, |
5139
|
|
|
|
|
|
|
0xdc656bb5, 0xc57e5af4, 0xee530937, 0xf7483876, |
5140
|
|
|
|
|
|
|
0xb809aeb1, 0xa1129ff0, 0x8a3fcc33, 0x9324fd72, |
5141
|
|
|
|
|
|
|
0x00000000, 0x01c26a37, 0x0384d46e, 0x0246be59, |
5142
|
|
|
|
|
|
|
0x0709a8dc, 0x06cbc2eb, 0x048d7cb2, 0x054f1685, |
5143
|
|
|
|
|
|
|
0x0e1351b8, 0x0fd13b8f, 0x0d9785d6, 0x0c55efe1, |
5144
|
|
|
|
|
|
|
0x091af964, 0x08d89353, 0x0a9e2d0a, 0x0b5c473d, |
5145
|
|
|
|
|
|
|
0x1c26a370, 0x1de4c947, 0x1fa2771e, 0x1e601d29, |
5146
|
|
|
|
|
|
|
0x1b2f0bac, 0x1aed619b, 0x18abdfc2, 0x1969b5f5, |
5147
|
|
|
|
|
|
|
0x1235f2c8, 0x13f798ff, 0x11b126a6, 0x10734c91, |
5148
|
|
|
|
|
|
|
0x153c5a14, 0x14fe3023, 0x16b88e7a, 0x177ae44d, |
5149
|
|
|
|
|
|
|
0x384d46e0, 0x398f2cd7, 0x3bc9928e, 0x3a0bf8b9, |
5150
|
|
|
|
|
|
|
0x3f44ee3c, 0x3e86840b, 0x3cc03a52, 0x3d025065, |
5151
|
|
|
|
|
|
|
0x365e1758, 0x379c7d6f, 0x35dac336, 0x3418a901, |
5152
|
|
|
|
|
|
|
0x3157bf84, 0x3095d5b3, 0x32d36bea, 0x331101dd, |
5153
|
|
|
|
|
|
|
0x246be590, 0x25a98fa7, 0x27ef31fe, 0x262d5bc9, |
5154
|
|
|
|
|
|
|
0x23624d4c, 0x22a0277b, 0x20e69922, 0x2124f315, |
5155
|
|
|
|
|
|
|
0x2a78b428, 0x2bbade1f, 0x29fc6046, 0x283e0a71, |
5156
|
|
|
|
|
|
|
0x2d711cf4, 0x2cb376c3, 0x2ef5c89a, 0x2f37a2ad, |
5157
|
|
|
|
|
|
|
0x709a8dc0, 0x7158e7f7, 0x731e59ae, 0x72dc3399, |
5158
|
|
|
|
|
|
|
0x7793251c, 0x76514f2b, 0x7417f172, 0x75d59b45, |
5159
|
|
|
|
|
|
|
0x7e89dc78, 0x7f4bb64f, 0x7d0d0816, 0x7ccf6221, |
5160
|
|
|
|
|
|
|
0x798074a4, 0x78421e93, 0x7a04a0ca, 0x7bc6cafd, |
5161
|
|
|
|
|
|
|
0x6cbc2eb0, 0x6d7e4487, 0x6f38fade, 0x6efa90e9, |
5162
|
|
|
|
|
|
|
0x6bb5866c, 0x6a77ec5b, 0x68315202, 0x69f33835, |
5163
|
|
|
|
|
|
|
0x62af7f08, 0x636d153f, 0x612bab66, 0x60e9c151, |
5164
|
|
|
|
|
|
|
0x65a6d7d4, 0x6464bde3, 0x662203ba, 0x67e0698d, |
5165
|
|
|
|
|
|
|
0x48d7cb20, 0x4915a117, 0x4b531f4e, 0x4a917579, |
5166
|
|
|
|
|
|
|
0x4fde63fc, 0x4e1c09cb, 0x4c5ab792, 0x4d98dda5, |
5167
|
|
|
|
|
|
|
0x46c49a98, 0x4706f0af, 0x45404ef6, 0x448224c1, |
5168
|
|
|
|
|
|
|
0x41cd3244, 0x400f5873, 0x4249e62a, 0x438b8c1d, |
5169
|
|
|
|
|
|
|
0x54f16850, 0x55330267, 0x5775bc3e, 0x56b7d609, |
5170
|
|
|
|
|
|
|
0x53f8c08c, 0x523aaabb, 0x507c14e2, 0x51be7ed5, |
5171
|
|
|
|
|
|
|
0x5ae239e8, 0x5b2053df, 0x5966ed86, 0x58a487b1, |
5172
|
|
|
|
|
|
|
0x5deb9134, 0x5c29fb03, 0x5e6f455a, 0x5fad2f6d, |
5173
|
|
|
|
|
|
|
0xe1351b80, 0xe0f771b7, 0xe2b1cfee, 0xe373a5d9, |
5174
|
|
|
|
|
|
|
0xe63cb35c, 0xe7fed96b, 0xe5b86732, 0xe47a0d05, |
5175
|
|
|
|
|
|
|
0xef264a38, 0xeee4200f, 0xeca29e56, 0xed60f461, |
5176
|
|
|
|
|
|
|
0xe82fe2e4, 0xe9ed88d3, 0xebab368a, 0xea695cbd, |
5177
|
|
|
|
|
|
|
0xfd13b8f0, 0xfcd1d2c7, 0xfe976c9e, 0xff5506a9, |
5178
|
|
|
|
|
|
|
0xfa1a102c, 0xfbd87a1b, 0xf99ec442, 0xf85cae75, |
5179
|
|
|
|
|
|
|
0xf300e948, 0xf2c2837f, 0xf0843d26, 0xf1465711, |
5180
|
|
|
|
|
|
|
0xf4094194, 0xf5cb2ba3, 0xf78d95fa, 0xf64fffcd, |
5181
|
|
|
|
|
|
|
0xd9785d60, 0xd8ba3757, 0xdafc890e, 0xdb3ee339, |
5182
|
|
|
|
|
|
|
0xde71f5bc, 0xdfb39f8b, 0xddf521d2, 0xdc374be5, |
5183
|
|
|
|
|
|
|
0xd76b0cd8, 0xd6a966ef, 0xd4efd8b6, 0xd52db281, |
5184
|
|
|
|
|
|
|
0xd062a404, 0xd1a0ce33, 0xd3e6706a, 0xd2241a5d, |
5185
|
|
|
|
|
|
|
0xc55efe10, 0xc49c9427, 0xc6da2a7e, 0xc7184049, |
5186
|
|
|
|
|
|
|
0xc25756cc, 0xc3953cfb, 0xc1d382a2, 0xc011e895, |
5187
|
|
|
|
|
|
|
0xcb4dafa8, 0xca8fc59f, 0xc8c97bc6, 0xc90b11f1, |
5188
|
|
|
|
|
|
|
0xcc440774, 0xcd866d43, 0xcfc0d31a, 0xce02b92d, |
5189
|
|
|
|
|
|
|
0x91af9640, 0x906dfc77, 0x922b422e, 0x93e92819, |
5190
|
|
|
|
|
|
|
0x96a63e9c, 0x976454ab, 0x9522eaf2, 0x94e080c5, |
5191
|
|
|
|
|
|
|
0x9fbcc7f8, 0x9e7eadcf, 0x9c381396, 0x9dfa79a1, |
5192
|
|
|
|
|
|
|
0x98b56f24, 0x99770513, 0x9b31bb4a, 0x9af3d17d, |
5193
|
|
|
|
|
|
|
0x8d893530, 0x8c4b5f07, 0x8e0de15e, 0x8fcf8b69, |
5194
|
|
|
|
|
|
|
0x8a809dec, 0x8b42f7db, 0x89044982, 0x88c623b5, |
5195
|
|
|
|
|
|
|
0x839a6488, 0x82580ebf, 0x801eb0e6, 0x81dcdad1, |
5196
|
|
|
|
|
|
|
0x8493cc54, 0x8551a663, 0x8717183a, 0x86d5720d, |
5197
|
|
|
|
|
|
|
0xa9e2d0a0, 0xa820ba97, 0xaa6604ce, 0xaba46ef9, |
5198
|
|
|
|
|
|
|
0xaeeb787c, 0xaf29124b, 0xad6fac12, 0xacadc625, |
5199
|
|
|
|
|
|
|
0xa7f18118, 0xa633eb2f, 0xa4755576, 0xa5b73f41, |
5200
|
|
|
|
|
|
|
0xa0f829c4, 0xa13a43f3, 0xa37cfdaa, 0xa2be979d, |
5201
|
|
|
|
|
|
|
0xb5c473d0, 0xb40619e7, 0xb640a7be, 0xb782cd89, |
5202
|
|
|
|
|
|
|
0xb2cddb0c, 0xb30fb13b, 0xb1490f62, 0xb08b6555, |
5203
|
|
|
|
|
|
|
0xbbd72268, 0xba15485f, 0xb853f606, 0xb9919c31, |
5204
|
|
|
|
|
|
|
0xbcde8ab4, 0xbd1ce083, 0xbf5a5eda, 0xbe9834ed, |
5205
|
|
|
|
|
|
|
0x00000000, 0xb8bc6765, 0xaa09c88b, 0x12b5afee, |
5206
|
|
|
|
|
|
|
0x8f629757, 0x37def032, 0x256b5fdc, 0x9dd738b9, |
5207
|
|
|
|
|
|
|
0xc5b428ef, 0x7d084f8a, 0x6fbde064, 0xd7018701, |
5208
|
|
|
|
|
|
|
0x4ad6bfb8, 0xf26ad8dd, 0xe0df7733, 0x58631056, |
5209
|
|
|
|
|
|
|
0x5019579f, 0xe8a530fa, 0xfa109f14, 0x42acf871, |
5210
|
|
|
|
|
|
|
0xdf7bc0c8, 0x67c7a7ad, 0x75720843, 0xcdce6f26, |
5211
|
|
|
|
|
|
|
0x95ad7f70, 0x2d111815, 0x3fa4b7fb, 0x8718d09e, |
5212
|
|
|
|
|
|
|
0x1acfe827, 0xa2738f42, 0xb0c620ac, 0x087a47c9, |
5213
|
|
|
|
|
|
|
0xa032af3e, 0x188ec85b, 0x0a3b67b5, 0xb28700d0, |
5214
|
|
|
|
|
|
|
0x2f503869, 0x97ec5f0c, 0x8559f0e2, 0x3de59787, |
5215
|
|
|
|
|
|
|
0x658687d1, 0xdd3ae0b4, 0xcf8f4f5a, 0x7733283f, |
5216
|
|
|
|
|
|
|
0xeae41086, 0x525877e3, 0x40edd80d, 0xf851bf68, |
5217
|
|
|
|
|
|
|
0xf02bf8a1, 0x48979fc4, 0x5a22302a, 0xe29e574f, |
5218
|
|
|
|
|
|
|
0x7f496ff6, 0xc7f50893, 0xd540a77d, 0x6dfcc018, |
5219
|
|
|
|
|
|
|
0x359fd04e, 0x8d23b72b, 0x9f9618c5, 0x272a7fa0, |
5220
|
|
|
|
|
|
|
0xbafd4719, 0x0241207c, 0x10f48f92, 0xa848e8f7, |
5221
|
|
|
|
|
|
|
0x9b14583d, 0x23a83f58, 0x311d90b6, 0x89a1f7d3, |
5222
|
|
|
|
|
|
|
0x1476cf6a, 0xaccaa80f, 0xbe7f07e1, 0x06c36084, |
5223
|
|
|
|
|
|
|
0x5ea070d2, 0xe61c17b7, 0xf4a9b859, 0x4c15df3c, |
5224
|
|
|
|
|
|
|
0xd1c2e785, 0x697e80e0, 0x7bcb2f0e, 0xc377486b, |
5225
|
|
|
|
|
|
|
0xcb0d0fa2, 0x73b168c7, 0x6104c729, 0xd9b8a04c, |
5226
|
|
|
|
|
|
|
0x446f98f5, 0xfcd3ff90, 0xee66507e, 0x56da371b, |
5227
|
|
|
|
|
|
|
0x0eb9274d, 0xb6054028, 0xa4b0efc6, 0x1c0c88a3, |
5228
|
|
|
|
|
|
|
0x81dbb01a, 0x3967d77f, 0x2bd27891, 0x936e1ff4, |
5229
|
|
|
|
|
|
|
0x3b26f703, 0x839a9066, 0x912f3f88, 0x299358ed, |
5230
|
|
|
|
|
|
|
0xb4446054, 0x0cf80731, 0x1e4da8df, 0xa6f1cfba, |
5231
|
|
|
|
|
|
|
0xfe92dfec, 0x462eb889, 0x549b1767, 0xec277002, |
5232
|
|
|
|
|
|
|
0x71f048bb, 0xc94c2fde, 0xdbf98030, 0x6345e755, |
5233
|
|
|
|
|
|
|
0x6b3fa09c, 0xd383c7f9, 0xc1366817, 0x798a0f72, |
5234
|
|
|
|
|
|
|
0xe45d37cb, 0x5ce150ae, 0x4e54ff40, 0xf6e89825, |
5235
|
|
|
|
|
|
|
0xae8b8873, 0x1637ef16, 0x048240f8, 0xbc3e279d, |
5236
|
|
|
|
|
|
|
0x21e91f24, 0x99557841, 0x8be0d7af, 0x335cb0ca, |
5237
|
|
|
|
|
|
|
0xed59b63b, 0x55e5d15e, 0x47507eb0, 0xffec19d5, |
5238
|
|
|
|
|
|
|
0x623b216c, 0xda874609, 0xc832e9e7, 0x708e8e82, |
5239
|
|
|
|
|
|
|
0x28ed9ed4, 0x9051f9b1, 0x82e4565f, 0x3a58313a, |
5240
|
|
|
|
|
|
|
0xa78f0983, 0x1f336ee6, 0x0d86c108, 0xb53aa66d, |
5241
|
|
|
|
|
|
|
0xbd40e1a4, 0x05fc86c1, 0x1749292f, 0xaff54e4a, |
5242
|
|
|
|
|
|
|
0x322276f3, 0x8a9e1196, 0x982bbe78, 0x2097d91d, |
5243
|
|
|
|
|
|
|
0x78f4c94b, 0xc048ae2e, 0xd2fd01c0, 0x6a4166a5, |
5244
|
|
|
|
|
|
|
0xf7965e1c, 0x4f2a3979, 0x5d9f9697, 0xe523f1f2, |
5245
|
|
|
|
|
|
|
0x4d6b1905, 0xf5d77e60, 0xe762d18e, 0x5fdeb6eb, |
5246
|
|
|
|
|
|
|
0xc2098e52, 0x7ab5e937, 0x680046d9, 0xd0bc21bc, |
5247
|
|
|
|
|
|
|
0x88df31ea, 0x3063568f, 0x22d6f961, 0x9a6a9e04, |
5248
|
|
|
|
|
|
|
0x07bda6bd, 0xbf01c1d8, 0xadb46e36, 0x15080953, |
5249
|
|
|
|
|
|
|
0x1d724e9a, 0xa5ce29ff, 0xb77b8611, 0x0fc7e174, |
5250
|
|
|
|
|
|
|
0x9210d9cd, 0x2aacbea8, 0x38191146, 0x80a57623, |
5251
|
|
|
|
|
|
|
0xd8c66675, 0x607a0110, 0x72cfaefe, 0xca73c99b, |
5252
|
|
|
|
|
|
|
0x57a4f122, 0xef189647, 0xfdad39a9, 0x45115ecc, |
5253
|
|
|
|
|
|
|
0x764dee06, 0xcef18963, 0xdc44268d, 0x64f841e8, |
5254
|
|
|
|
|
|
|
0xf92f7951, 0x41931e34, 0x5326b1da, 0xeb9ad6bf, |
5255
|
|
|
|
|
|
|
0xb3f9c6e9, 0x0b45a18c, 0x19f00e62, 0xa14c6907, |
5256
|
|
|
|
|
|
|
0x3c9b51be, 0x842736db, 0x96929935, 0x2e2efe50, |
5257
|
|
|
|
|
|
|
0x2654b999, 0x9ee8defc, 0x8c5d7112, 0x34e11677, |
5258
|
|
|
|
|
|
|
0xa9362ece, 0x118a49ab, 0x033fe645, 0xbb838120, |
5259
|
|
|
|
|
|
|
0xe3e09176, 0x5b5cf613, 0x49e959fd, 0xf1553e98, |
5260
|
|
|
|
|
|
|
0x6c820621, 0xd43e6144, 0xc68bceaa, 0x7e37a9cf, |
5261
|
|
|
|
|
|
|
0xd67f4138, 0x6ec3265d, 0x7c7689b3, 0xc4caeed6, |
5262
|
|
|
|
|
|
|
0x591dd66f, 0xe1a1b10a, 0xf3141ee4, 0x4ba87981, |
5263
|
|
|
|
|
|
|
0x13cb69d7, 0xab770eb2, 0xb9c2a15c, 0x017ec639, |
5264
|
|
|
|
|
|
|
0x9ca9fe80, 0x241599e5, 0x36a0360b, 0x8e1c516e, |
5265
|
|
|
|
|
|
|
0x866616a7, 0x3eda71c2, 0x2c6fde2c, 0x94d3b949, |
5266
|
|
|
|
|
|
|
0x090481f0, 0xb1b8e695, 0xa30d497b, 0x1bb12e1e, |
5267
|
|
|
|
|
|
|
0x43d23e48, 0xfb6e592d, 0xe9dbf6c3, 0x516791a6, |
5268
|
|
|
|
|
|
|
0xccb0a91f, 0x740cce7a, 0x66b96194, 0xde0506f1, |
5269
|
|
|
|
|
|
|
0x00000000, 0x3d6029b0, 0x7ac05360, 0x47a07ad0, |
5270
|
|
|
|
|
|
|
0xf580a6c0, 0xc8e08f70, 0x8f40f5a0, 0xb220dc10, |
5271
|
|
|
|
|
|
|
0x30704bc1, 0x0d106271, 0x4ab018a1, 0x77d03111, |
5272
|
|
|
|
|
|
|
0xc5f0ed01, 0xf890c4b1, 0xbf30be61, 0x825097d1, |
5273
|
|
|
|
|
|
|
0x60e09782, 0x5d80be32, 0x1a20c4e2, 0x2740ed52, |
5274
|
|
|
|
|
|
|
0x95603142, 0xa80018f2, 0xefa06222, 0xd2c04b92, |
5275
|
|
|
|
|
|
|
0x5090dc43, 0x6df0f5f3, 0x2a508f23, 0x1730a693, |
5276
|
|
|
|
|
|
|
0xa5107a83, 0x98705333, 0xdfd029e3, 0xe2b00053, |
5277
|
|
|
|
|
|
|
0xc1c12f04, 0xfca106b4, 0xbb017c64, 0x866155d4, |
5278
|
|
|
|
|
|
|
0x344189c4, 0x0921a074, 0x4e81daa4, 0x73e1f314, |
5279
|
|
|
|
|
|
|
0xf1b164c5, 0xccd14d75, 0x8b7137a5, 0xb6111e15, |
5280
|
|
|
|
|
|
|
0x0431c205, 0x3951ebb5, 0x7ef19165, 0x4391b8d5, |
5281
|
|
|
|
|
|
|
0xa121b886, 0x9c419136, 0xdbe1ebe6, 0xe681c256, |
5282
|
|
|
|
|
|
|
0x54a11e46, 0x69c137f6, 0x2e614d26, 0x13016496, |
5283
|
|
|
|
|
|
|
0x9151f347, 0xac31daf7, 0xeb91a027, 0xd6f18997, |
5284
|
|
|
|
|
|
|
0x64d15587, 0x59b17c37, 0x1e1106e7, 0x23712f57, |
5285
|
|
|
|
|
|
|
0x58f35849, 0x659371f9, 0x22330b29, 0x1f532299, |
5286
|
|
|
|
|
|
|
0xad73fe89, 0x9013d739, 0xd7b3ade9, 0xead38459, |
5287
|
|
|
|
|
|
|
0x68831388, 0x55e33a38, 0x124340e8, 0x2f236958, |
5288
|
|
|
|
|
|
|
0x9d03b548, 0xa0639cf8, 0xe7c3e628, 0xdaa3cf98, |
5289
|
|
|
|
|
|
|
0x3813cfcb, 0x0573e67b, 0x42d39cab, 0x7fb3b51b, |
5290
|
|
|
|
|
|
|
0xcd93690b, 0xf0f340bb, 0xb7533a6b, 0x8a3313db, |
5291
|
|
|
|
|
|
|
0x0863840a, 0x3503adba, 0x72a3d76a, 0x4fc3feda, |
5292
|
|
|
|
|
|
|
0xfde322ca, 0xc0830b7a, 0x872371aa, 0xba43581a, |
5293
|
|
|
|
|
|
|
0x9932774d, 0xa4525efd, 0xe3f2242d, 0xde920d9d, |
5294
|
|
|
|
|
|
|
0x6cb2d18d, 0x51d2f83d, 0x167282ed, 0x2b12ab5d, |
5295
|
|
|
|
|
|
|
0xa9423c8c, 0x9422153c, 0xd3826fec, 0xeee2465c, |
5296
|
|
|
|
|
|
|
0x5cc29a4c, 0x61a2b3fc, 0x2602c92c, 0x1b62e09c, |
5297
|
|
|
|
|
|
|
0xf9d2e0cf, 0xc4b2c97f, 0x8312b3af, 0xbe729a1f, |
5298
|
|
|
|
|
|
|
0x0c52460f, 0x31326fbf, 0x7692156f, 0x4bf23cdf, |
5299
|
|
|
|
|
|
|
0xc9a2ab0e, 0xf4c282be, 0xb362f86e, 0x8e02d1de, |
5300
|
|
|
|
|
|
|
0x3c220dce, 0x0142247e, 0x46e25eae, 0x7b82771e, |
5301
|
|
|
|
|
|
|
0xb1e6b092, 0x8c869922, 0xcb26e3f2, 0xf646ca42, |
5302
|
|
|
|
|
|
|
0x44661652, 0x79063fe2, 0x3ea64532, 0x03c66c82, |
5303
|
|
|
|
|
|
|
0x8196fb53, 0xbcf6d2e3, 0xfb56a833, 0xc6368183, |
5304
|
|
|
|
|
|
|
0x74165d93, 0x49767423, 0x0ed60ef3, 0x33b62743, |
5305
|
|
|
|
|
|
|
0xd1062710, 0xec660ea0, 0xabc67470, 0x96a65dc0, |
5306
|
|
|
|
|
|
|
0x248681d0, 0x19e6a860, 0x5e46d2b0, 0x6326fb00, |
5307
|
|
|
|
|
|
|
0xe1766cd1, 0xdc164561, 0x9bb63fb1, 0xa6d61601, |
5308
|
|
|
|
|
|
|
0x14f6ca11, 0x2996e3a1, 0x6e369971, 0x5356b0c1, |
5309
|
|
|
|
|
|
|
0x70279f96, 0x4d47b626, 0x0ae7ccf6, 0x3787e546, |
5310
|
|
|
|
|
|
|
0x85a73956, 0xb8c710e6, 0xff676a36, 0xc2074386, |
5311
|
|
|
|
|
|
|
0x4057d457, 0x7d37fde7, 0x3a978737, 0x07f7ae87, |
5312
|
|
|
|
|
|
|
0xb5d77297, 0x88b75b27, 0xcf1721f7, 0xf2770847, |
5313
|
|
|
|
|
|
|
0x10c70814, 0x2da721a4, 0x6a075b74, 0x576772c4, |
5314
|
|
|
|
|
|
|
0xe547aed4, 0xd8278764, 0x9f87fdb4, 0xa2e7d404, |
5315
|
|
|
|
|
|
|
0x20b743d5, 0x1dd76a65, 0x5a7710b5, 0x67173905, |
5316
|
|
|
|
|
|
|
0xd537e515, 0xe857cca5, 0xaff7b675, 0x92979fc5, |
5317
|
|
|
|
|
|
|
0xe915e8db, 0xd475c16b, 0x93d5bbbb, 0xaeb5920b, |
5318
|
|
|
|
|
|
|
0x1c954e1b, 0x21f567ab, 0x66551d7b, 0x5b3534cb, |
5319
|
|
|
|
|
|
|
0xd965a31a, 0xe4058aaa, 0xa3a5f07a, 0x9ec5d9ca, |
5320
|
|
|
|
|
|
|
0x2ce505da, 0x11852c6a, 0x562556ba, 0x6b457f0a, |
5321
|
|
|
|
|
|
|
0x89f57f59, 0xb49556e9, 0xf3352c39, 0xce550589, |
5322
|
|
|
|
|
|
|
0x7c75d999, 0x4115f029, 0x06b58af9, 0x3bd5a349, |
5323
|
|
|
|
|
|
|
0xb9853498, 0x84e51d28, 0xc34567f8, 0xfe254e48, |
5324
|
|
|
|
|
|
|
0x4c059258, 0x7165bbe8, 0x36c5c138, 0x0ba5e888, |
5325
|
|
|
|
|
|
|
0x28d4c7df, 0x15b4ee6f, 0x521494bf, 0x6f74bd0f, |
5326
|
|
|
|
|
|
|
0xdd54611f, 0xe03448af, 0xa794327f, 0x9af41bcf, |
5327
|
|
|
|
|
|
|
0x18a48c1e, 0x25c4a5ae, 0x6264df7e, 0x5f04f6ce, |
5328
|
|
|
|
|
|
|
0xed242ade, 0xd044036e, 0x97e479be, 0xaa84500e, |
5329
|
|
|
|
|
|
|
0x4834505d, 0x755479ed, 0x32f4033d, 0x0f942a8d, |
5330
|
|
|
|
|
|
|
0xbdb4f69d, 0x80d4df2d, 0xc774a5fd, 0xfa148c4d, |
5331
|
|
|
|
|
|
|
0x78441b9c, 0x4524322c, 0x028448fc, 0x3fe4614c, |
5332
|
|
|
|
|
|
|
0x8dc4bd5c, 0xb0a494ec, 0xf704ee3c, 0xca64c78c, |
5333
|
|
|
|
|
|
|
0x00000000, 0xcb5cd3a5, 0x4dc8a10b, 0x869472ae, |
5334
|
|
|
|
|
|
|
0x9b914216, 0x50cd91b3, 0xd659e31d, 0x1d0530b8, |
5335
|
|
|
|
|
|
|
0xec53826d, 0x270f51c8, 0xa19b2366, 0x6ac7f0c3, |
5336
|
|
|
|
|
|
|
0x77c2c07b, 0xbc9e13de, 0x3a0a6170, 0xf156b2d5, |
5337
|
|
|
|
|
|
|
0x03d6029b, 0xc88ad13e, 0x4e1ea390, 0x85427035, |
5338
|
|
|
|
|
|
|
0x9847408d, 0x531b9328, 0xd58fe186, 0x1ed33223, |
5339
|
|
|
|
|
|
|
0xef8580f6, 0x24d95353, 0xa24d21fd, 0x6911f258, |
5340
|
|
|
|
|
|
|
0x7414c2e0, 0xbf481145, 0x39dc63eb, 0xf280b04e, |
5341
|
|
|
|
|
|
|
0x07ac0536, 0xccf0d693, 0x4a64a43d, 0x81387798, |
5342
|
|
|
|
|
|
|
0x9c3d4720, 0x57619485, 0xd1f5e62b, 0x1aa9358e, |
5343
|
|
|
|
|
|
|
0xebff875b, 0x20a354fe, 0xa6372650, 0x6d6bf5f5, |
5344
|
|
|
|
|
|
|
0x706ec54d, 0xbb3216e8, 0x3da66446, 0xf6fab7e3, |
5345
|
|
|
|
|
|
|
0x047a07ad, 0xcf26d408, 0x49b2a6a6, 0x82ee7503, |
5346
|
|
|
|
|
|
|
0x9feb45bb, 0x54b7961e, 0xd223e4b0, 0x197f3715, |
5347
|
|
|
|
|
|
|
0xe82985c0, 0x23755665, 0xa5e124cb, 0x6ebdf76e, |
5348
|
|
|
|
|
|
|
0x73b8c7d6, 0xb8e41473, 0x3e7066dd, 0xf52cb578, |
5349
|
|
|
|
|
|
|
0x0f580a6c, 0xc404d9c9, 0x4290ab67, 0x89cc78c2, |
5350
|
|
|
|
|
|
|
0x94c9487a, 0x5f959bdf, 0xd901e971, 0x125d3ad4, |
5351
|
|
|
|
|
|
|
0xe30b8801, 0x28575ba4, 0xaec3290a, 0x659ffaaf, |
5352
|
|
|
|
|
|
|
0x789aca17, 0xb3c619b2, 0x35526b1c, 0xfe0eb8b9, |
5353
|
|
|
|
|
|
|
0x0c8e08f7, 0xc7d2db52, 0x4146a9fc, 0x8a1a7a59, |
5354
|
|
|
|
|
|
|
0x971f4ae1, 0x5c439944, 0xdad7ebea, 0x118b384f, |
5355
|
|
|
|
|
|
|
0xe0dd8a9a, 0x2b81593f, 0xad152b91, 0x6649f834, |
5356
|
|
|
|
|
|
|
0x7b4cc88c, 0xb0101b29, 0x36846987, 0xfdd8ba22, |
5357
|
|
|
|
|
|
|
0x08f40f5a, 0xc3a8dcff, 0x453cae51, 0x8e607df4, |
5358
|
|
|
|
|
|
|
0x93654d4c, 0x58399ee9, 0xdeadec47, 0x15f13fe2, |
5359
|
|
|
|
|
|
|
0xe4a78d37, 0x2ffb5e92, 0xa96f2c3c, 0x6233ff99, |
5360
|
|
|
|
|
|
|
0x7f36cf21, 0xb46a1c84, 0x32fe6e2a, 0xf9a2bd8f, |
5361
|
|
|
|
|
|
|
0x0b220dc1, 0xc07ede64, 0x46eaacca, 0x8db67f6f, |
5362
|
|
|
|
|
|
|
0x90b34fd7, 0x5bef9c72, 0xdd7beedc, 0x16273d79, |
5363
|
|
|
|
|
|
|
0xe7718fac, 0x2c2d5c09, 0xaab92ea7, 0x61e5fd02, |
5364
|
|
|
|
|
|
|
0x7ce0cdba, 0xb7bc1e1f, 0x31286cb1, 0xfa74bf14, |
5365
|
|
|
|
|
|
|
0x1eb014d8, 0xd5ecc77d, 0x5378b5d3, 0x98246676, |
5366
|
|
|
|
|
|
|
0x852156ce, 0x4e7d856b, 0xc8e9f7c5, 0x03b52460, |
5367
|
|
|
|
|
|
|
0xf2e396b5, 0x39bf4510, 0xbf2b37be, 0x7477e41b, |
5368
|
|
|
|
|
|
|
0x6972d4a3, 0xa22e0706, 0x24ba75a8, 0xefe6a60d, |
5369
|
|
|
|
|
|
|
0x1d661643, 0xd63ac5e6, 0x50aeb748, 0x9bf264ed, |
5370
|
|
|
|
|
|
|
0x86f75455, 0x4dab87f0, 0xcb3ff55e, 0x006326fb, |
5371
|
|
|
|
|
|
|
0xf135942e, 0x3a69478b, 0xbcfd3525, 0x77a1e680, |
5372
|
|
|
|
|
|
|
0x6aa4d638, 0xa1f8059d, 0x276c7733, 0xec30a496, |
5373
|
|
|
|
|
|
|
0x191c11ee, 0xd240c24b, 0x54d4b0e5, 0x9f886340, |
5374
|
|
|
|
|
|
|
0x828d53f8, 0x49d1805d, 0xcf45f2f3, 0x04192156, |
5375
|
|
|
|
|
|
|
0xf54f9383, 0x3e134026, 0xb8873288, 0x73dbe12d, |
5376
|
|
|
|
|
|
|
0x6eded195, 0xa5820230, 0x2316709e, 0xe84aa33b, |
5377
|
|
|
|
|
|
|
0x1aca1375, 0xd196c0d0, 0x5702b27e, 0x9c5e61db, |
5378
|
|
|
|
|
|
|
0x815b5163, 0x4a0782c6, 0xcc93f068, 0x07cf23cd, |
5379
|
|
|
|
|
|
|
0xf6999118, 0x3dc542bd, 0xbb513013, 0x700de3b6, |
5380
|
|
|
|
|
|
|
0x6d08d30e, 0xa65400ab, 0x20c07205, 0xeb9ca1a0, |
5381
|
|
|
|
|
|
|
0x11e81eb4, 0xdab4cd11, 0x5c20bfbf, 0x977c6c1a, |
5382
|
|
|
|
|
|
|
0x8a795ca2, 0x41258f07, 0xc7b1fda9, 0x0ced2e0c, |
5383
|
|
|
|
|
|
|
0xfdbb9cd9, 0x36e74f7c, 0xb0733dd2, 0x7b2fee77, |
5384
|
|
|
|
|
|
|
0x662adecf, 0xad760d6a, 0x2be27fc4, 0xe0beac61, |
5385
|
|
|
|
|
|
|
0x123e1c2f, 0xd962cf8a, 0x5ff6bd24, 0x94aa6e81, |
5386
|
|
|
|
|
|
|
0x89af5e39, 0x42f38d9c, 0xc467ff32, 0x0f3b2c97, |
5387
|
|
|
|
|
|
|
0xfe6d9e42, 0x35314de7, 0xb3a53f49, 0x78f9ecec, |
5388
|
|
|
|
|
|
|
0x65fcdc54, 0xaea00ff1, 0x28347d5f, 0xe368aefa, |
5389
|
|
|
|
|
|
|
0x16441b82, 0xdd18c827, 0x5b8cba89, 0x90d0692c, |
5390
|
|
|
|
|
|
|
0x8dd55994, 0x46898a31, 0xc01df89f, 0x0b412b3a, |
5391
|
|
|
|
|
|
|
0xfa1799ef, 0x314b4a4a, 0xb7df38e4, 0x7c83eb41, |
5392
|
|
|
|
|
|
|
0x6186dbf9, 0xaada085c, 0x2c4e7af2, 0xe712a957, |
5393
|
|
|
|
|
|
|
0x15921919, 0xdececabc, 0x585ab812, 0x93066bb7, |
5394
|
|
|
|
|
|
|
0x8e035b0f, 0x455f88aa, 0xc3cbfa04, 0x089729a1, |
5395
|
|
|
|
|
|
|
0xf9c19b74, 0x329d48d1, 0xb4093a7f, 0x7f55e9da, |
5396
|
|
|
|
|
|
|
0x6250d962, 0xa90c0ac7, 0x2f987869, 0xe4c4abcc, |
5397
|
|
|
|
|
|
|
0x00000000, 0xa6770bb4, 0x979f1129, 0x31e81a9d, |
5398
|
|
|
|
|
|
|
0xf44f2413, 0x52382fa7, 0x63d0353a, 0xc5a73e8e, |
5399
|
|
|
|
|
|
|
0x33ef4e67, 0x959845d3, 0xa4705f4e, 0x020754fa, |
5400
|
|
|
|
|
|
|
0xc7a06a74, 0x61d761c0, 0x503f7b5d, 0xf64870e9, |
5401
|
|
|
|
|
|
|
0x67de9cce, 0xc1a9977a, 0xf0418de7, 0x56368653, |
5402
|
|
|
|
|
|
|
0x9391b8dd, 0x35e6b369, 0x040ea9f4, 0xa279a240, |
5403
|
|
|
|
|
|
|
0x5431d2a9, 0xf246d91d, 0xc3aec380, 0x65d9c834, |
5404
|
|
|
|
|
|
|
0xa07ef6ba, 0x0609fd0e, 0x37e1e793, 0x9196ec27, |
5405
|
|
|
|
|
|
|
0xcfbd399c, 0x69ca3228, 0x582228b5, 0xfe552301, |
5406
|
|
|
|
|
|
|
0x3bf21d8f, 0x9d85163b, 0xac6d0ca6, 0x0a1a0712, |
5407
|
|
|
|
|
|
|
0xfc5277fb, 0x5a257c4f, 0x6bcd66d2, 0xcdba6d66, |
5408
|
|
|
|
|
|
|
0x081d53e8, 0xae6a585c, 0x9f8242c1, 0x39f54975, |
5409
|
|
|
|
|
|
|
0xa863a552, 0x0e14aee6, 0x3ffcb47b, 0x998bbfcf, |
5410
|
|
|
|
|
|
|
0x5c2c8141, 0xfa5b8af5, 0xcbb39068, 0x6dc49bdc, |
5411
|
|
|
|
|
|
|
0x9b8ceb35, 0x3dfbe081, 0x0c13fa1c, 0xaa64f1a8, |
5412
|
|
|
|
|
|
|
0x6fc3cf26, 0xc9b4c492, 0xf85cde0f, 0x5e2bd5bb, |
5413
|
|
|
|
|
|
|
0x440b7579, 0xe27c7ecd, 0xd3946450, 0x75e36fe4, |
5414
|
|
|
|
|
|
|
0xb044516a, 0x16335ade, 0x27db4043, 0x81ac4bf7, |
5415
|
|
|
|
|
|
|
0x77e43b1e, 0xd19330aa, 0xe07b2a37, 0x460c2183, |
5416
|
|
|
|
|
|
|
0x83ab1f0d, 0x25dc14b9, 0x14340e24, 0xb2430590, |
5417
|
|
|
|
|
|
|
0x23d5e9b7, 0x85a2e203, 0xb44af89e, 0x123df32a, |
5418
|
|
|
|
|
|
|
0xd79acda4, 0x71edc610, 0x4005dc8d, 0xe672d739, |
5419
|
|
|
|
|
|
|
0x103aa7d0, 0xb64dac64, 0x87a5b6f9, 0x21d2bd4d, |
5420
|
|
|
|
|
|
|
0xe47583c3, 0x42028877, 0x73ea92ea, 0xd59d995e, |
5421
|
|
|
|
|
|
|
0x8bb64ce5, 0x2dc14751, 0x1c295dcc, 0xba5e5678, |
5422
|
|
|
|
|
|
|
0x7ff968f6, 0xd98e6342, 0xe86679df, 0x4e11726b, |
5423
|
|
|
|
|
|
|
0xb8590282, 0x1e2e0936, 0x2fc613ab, 0x89b1181f, |
5424
|
|
|
|
|
|
|
0x4c162691, 0xea612d25, 0xdb8937b8, 0x7dfe3c0c, |
5425
|
|
|
|
|
|
|
0xec68d02b, 0x4a1fdb9f, 0x7bf7c102, 0xdd80cab6, |
5426
|
|
|
|
|
|
|
0x1827f438, 0xbe50ff8c, 0x8fb8e511, 0x29cfeea5, |
5427
|
|
|
|
|
|
|
0xdf879e4c, 0x79f095f8, 0x48188f65, 0xee6f84d1, |
5428
|
|
|
|
|
|
|
0x2bc8ba5f, 0x8dbfb1eb, 0xbc57ab76, 0x1a20a0c2, |
5429
|
|
|
|
|
|
|
0x8816eaf2, 0x2e61e146, 0x1f89fbdb, 0xb9fef06f, |
5430
|
|
|
|
|
|
|
0x7c59cee1, 0xda2ec555, 0xebc6dfc8, 0x4db1d47c, |
5431
|
|
|
|
|
|
|
0xbbf9a495, 0x1d8eaf21, 0x2c66b5bc, 0x8a11be08, |
5432
|
|
|
|
|
|
|
0x4fb68086, 0xe9c18b32, 0xd82991af, 0x7e5e9a1b, |
5433
|
|
|
|
|
|
|
0xefc8763c, 0x49bf7d88, 0x78576715, 0xde206ca1, |
5434
|
|
|
|
|
|
|
0x1b87522f, 0xbdf0599b, 0x8c184306, 0x2a6f48b2, |
5435
|
|
|
|
|
|
|
0xdc27385b, 0x7a5033ef, 0x4bb82972, 0xedcf22c6, |
5436
|
|
|
|
|
|
|
0x28681c48, 0x8e1f17fc, 0xbff70d61, 0x198006d5, |
5437
|
|
|
|
|
|
|
0x47abd36e, 0xe1dcd8da, 0xd034c247, 0x7643c9f3, |
5438
|
|
|
|
|
|
|
0xb3e4f77d, 0x1593fcc9, 0x247be654, 0x820cede0, |
5439
|
|
|
|
|
|
|
0x74449d09, 0xd23396bd, 0xe3db8c20, 0x45ac8794, |
5440
|
|
|
|
|
|
|
0x800bb91a, 0x267cb2ae, 0x1794a833, 0xb1e3a387, |
5441
|
|
|
|
|
|
|
0x20754fa0, 0x86024414, 0xb7ea5e89, 0x119d553d, |
5442
|
|
|
|
|
|
|
0xd43a6bb3, 0x724d6007, 0x43a57a9a, 0xe5d2712e, |
5443
|
|
|
|
|
|
|
0x139a01c7, 0xb5ed0a73, 0x840510ee, 0x22721b5a, |
5444
|
|
|
|
|
|
|
0xe7d525d4, 0x41a22e60, 0x704a34fd, 0xd63d3f49, |
5445
|
|
|
|
|
|
|
0xcc1d9f8b, 0x6a6a943f, 0x5b828ea2, 0xfdf58516, |
5446
|
|
|
|
|
|
|
0x3852bb98, 0x9e25b02c, 0xafcdaab1, 0x09baa105, |
5447
|
|
|
|
|
|
|
0xfff2d1ec, 0x5985da58, 0x686dc0c5, 0xce1acb71, |
5448
|
|
|
|
|
|
|
0x0bbdf5ff, 0xadcafe4b, 0x9c22e4d6, 0x3a55ef62, |
5449
|
|
|
|
|
|
|
0xabc30345, 0x0db408f1, 0x3c5c126c, 0x9a2b19d8, |
5450
|
|
|
|
|
|
|
0x5f8c2756, 0xf9fb2ce2, 0xc813367f, 0x6e643dcb, |
5451
|
|
|
|
|
|
|
0x982c4d22, 0x3e5b4696, 0x0fb35c0b, 0xa9c457bf, |
5452
|
|
|
|
|
|
|
0x6c636931, 0xca146285, 0xfbfc7818, 0x5d8b73ac, |
5453
|
|
|
|
|
|
|
0x03a0a617, 0xa5d7ada3, 0x943fb73e, 0x3248bc8a, |
5454
|
|
|
|
|
|
|
0xf7ef8204, 0x519889b0, 0x6070932d, 0xc6079899, |
5455
|
|
|
|
|
|
|
0x304fe870, 0x9638e3c4, 0xa7d0f959, 0x01a7f2ed, |
5456
|
|
|
|
|
|
|
0xc400cc63, 0x6277c7d7, 0x539fdd4a, 0xf5e8d6fe, |
5457
|
|
|
|
|
|
|
0x647e3ad9, 0xc209316d, 0xf3e12bf0, 0x55962044, |
5458
|
|
|
|
|
|
|
0x90311eca, 0x3646157e, 0x07ae0fe3, 0xa1d90457, |
5459
|
|
|
|
|
|
|
0x579174be, 0xf1e67f0a, 0xc00e6597, 0x66796e23, |
5460
|
|
|
|
|
|
|
0xa3de50ad, 0x05a95b19, 0x34414184, 0x92364a30, |
5461
|
|
|
|
|
|
|
0x00000000, 0xccaa009e, 0x4225077d, 0x8e8f07e3, |
5462
|
|
|
|
|
|
|
0x844a0efa, 0x48e00e64, 0xc66f0987, 0x0ac50919, |
5463
|
|
|
|
|
|
|
0xd3e51bb5, 0x1f4f1b2b, 0x91c01cc8, 0x5d6a1c56, |
5464
|
|
|
|
|
|
|
0x57af154f, 0x9b0515d1, 0x158a1232, 0xd92012ac, |
5465
|
|
|
|
|
|
|
0x7cbb312b, 0xb01131b5, 0x3e9e3656, 0xf23436c8, |
5466
|
|
|
|
|
|
|
0xf8f13fd1, 0x345b3f4f, 0xbad438ac, 0x767e3832, |
5467
|
|
|
|
|
|
|
0xaf5e2a9e, 0x63f42a00, 0xed7b2de3, 0x21d12d7d, |
5468
|
|
|
|
|
|
|
0x2b142464, 0xe7be24fa, 0x69312319, 0xa59b2387, |
5469
|
|
|
|
|
|
|
0xf9766256, 0x35dc62c8, 0xbb53652b, 0x77f965b5, |
5470
|
|
|
|
|
|
|
0x7d3c6cac, 0xb1966c32, 0x3f196bd1, 0xf3b36b4f, |
5471
|
|
|
|
|
|
|
0x2a9379e3, 0xe639797d, 0x68b67e9e, 0xa41c7e00, |
5472
|
|
|
|
|
|
|
0xaed97719, 0x62737787, 0xecfc7064, 0x205670fa, |
5473
|
|
|
|
|
|
|
0x85cd537d, 0x496753e3, 0xc7e85400, 0x0b42549e, |
5474
|
|
|
|
|
|
|
0x01875d87, 0xcd2d5d19, 0x43a25afa, 0x8f085a64, |
5475
|
|
|
|
|
|
|
0x562848c8, 0x9a824856, 0x140d4fb5, 0xd8a74f2b, |
5476
|
|
|
|
|
|
|
0xd2624632, 0x1ec846ac, 0x9047414f, 0x5ced41d1, |
5477
|
|
|
|
|
|
|
0x299dc2ed, 0xe537c273, 0x6bb8c590, 0xa712c50e, |
5478
|
|
|
|
|
|
|
0xadd7cc17, 0x617dcc89, 0xeff2cb6a, 0x2358cbf4, |
5479
|
|
|
|
|
|
|
0xfa78d958, 0x36d2d9c6, 0xb85dde25, 0x74f7debb, |
5480
|
|
|
|
|
|
|
0x7e32d7a2, 0xb298d73c, 0x3c17d0df, 0xf0bdd041, |
5481
|
|
|
|
|
|
|
0x5526f3c6, 0x998cf358, 0x1703f4bb, 0xdba9f425, |
5482
|
|
|
|
|
|
|
0xd16cfd3c, 0x1dc6fda2, 0x9349fa41, 0x5fe3fadf, |
5483
|
|
|
|
|
|
|
0x86c3e873, 0x4a69e8ed, 0xc4e6ef0e, 0x084cef90, |
5484
|
|
|
|
|
|
|
0x0289e689, 0xce23e617, 0x40ace1f4, 0x8c06e16a, |
5485
|
|
|
|
|
|
|
0xd0eba0bb, 0x1c41a025, 0x92cea7c6, 0x5e64a758, |
5486
|
|
|
|
|
|
|
0x54a1ae41, 0x980baedf, 0x1684a93c, 0xda2ea9a2, |
5487
|
|
|
|
|
|
|
0x030ebb0e, 0xcfa4bb90, 0x412bbc73, 0x8d81bced, |
5488
|
|
|
|
|
|
|
0x8744b5f4, 0x4beeb56a, 0xc561b289, 0x09cbb217, |
5489
|
|
|
|
|
|
|
0xac509190, 0x60fa910e, 0xee7596ed, 0x22df9673, |
5490
|
|
|
|
|
|
|
0x281a9f6a, 0xe4b09ff4, 0x6a3f9817, 0xa6959889, |
5491
|
|
|
|
|
|
|
0x7fb58a25, 0xb31f8abb, 0x3d908d58, 0xf13a8dc6, |
5492
|
|
|
|
|
|
|
0xfbff84df, 0x37558441, 0xb9da83a2, 0x7570833c, |
5493
|
|
|
|
|
|
|
0x533b85da, 0x9f918544, 0x111e82a7, 0xddb48239, |
5494
|
|
|
|
|
|
|
0xd7718b20, 0x1bdb8bbe, 0x95548c5d, 0x59fe8cc3, |
5495
|
|
|
|
|
|
|
0x80de9e6f, 0x4c749ef1, 0xc2fb9912, 0x0e51998c, |
5496
|
|
|
|
|
|
|
0x04949095, 0xc83e900b, 0x46b197e8, 0x8a1b9776, |
5497
|
|
|
|
|
|
|
0x2f80b4f1, 0xe32ab46f, 0x6da5b38c, 0xa10fb312, |
5498
|
|
|
|
|
|
|
0xabcaba0b, 0x6760ba95, 0xe9efbd76, 0x2545bde8, |
5499
|
|
|
|
|
|
|
0xfc65af44, 0x30cfafda, 0xbe40a839, 0x72eaa8a7, |
5500
|
|
|
|
|
|
|
0x782fa1be, 0xb485a120, 0x3a0aa6c3, 0xf6a0a65d, |
5501
|
|
|
|
|
|
|
0xaa4de78c, 0x66e7e712, 0xe868e0f1, 0x24c2e06f, |
5502
|
|
|
|
|
|
|
0x2e07e976, 0xe2ade9e8, 0x6c22ee0b, 0xa088ee95, |
5503
|
|
|
|
|
|
|
0x79a8fc39, 0xb502fca7, 0x3b8dfb44, 0xf727fbda, |
5504
|
|
|
|
|
|
|
0xfde2f2c3, 0x3148f25d, 0xbfc7f5be, 0x736df520, |
5505
|
|
|
|
|
|
|
0xd6f6d6a7, 0x1a5cd639, 0x94d3d1da, 0x5879d144, |
5506
|
|
|
|
|
|
|
0x52bcd85d, 0x9e16d8c3, 0x1099df20, 0xdc33dfbe, |
5507
|
|
|
|
|
|
|
0x0513cd12, 0xc9b9cd8c, 0x4736ca6f, 0x8b9ccaf1, |
5508
|
|
|
|
|
|
|
0x8159c3e8, 0x4df3c376, 0xc37cc495, 0x0fd6c40b, |
5509
|
|
|
|
|
|
|
0x7aa64737, 0xb60c47a9, 0x3883404a, 0xf42940d4, |
5510
|
|
|
|
|
|
|
0xfeec49cd, 0x32464953, 0xbcc94eb0, 0x70634e2e, |
5511
|
|
|
|
|
|
|
0xa9435c82, 0x65e95c1c, 0xeb665bff, 0x27cc5b61, |
5512
|
|
|
|
|
|
|
0x2d095278, 0xe1a352e6, 0x6f2c5505, 0xa386559b, |
5513
|
|
|
|
|
|
|
0x061d761c, 0xcab77682, 0x44387161, 0x889271ff, |
5514
|
|
|
|
|
|
|
0x825778e6, 0x4efd7878, 0xc0727f9b, 0x0cd87f05, |
5515
|
|
|
|
|
|
|
0xd5f86da9, 0x19526d37, 0x97dd6ad4, 0x5b776a4a, |
5516
|
|
|
|
|
|
|
0x51b26353, 0x9d1863cd, 0x1397642e, 0xdf3d64b0, |
5517
|
|
|
|
|
|
|
0x83d02561, 0x4f7a25ff, 0xc1f5221c, 0x0d5f2282, |
5518
|
|
|
|
|
|
|
0x079a2b9b, 0xcb302b05, 0x45bf2ce6, 0x89152c78, |
5519
|
|
|
|
|
|
|
0x50353ed4, 0x9c9f3e4a, 0x121039a9, 0xdeba3937, |
5520
|
|
|
|
|
|
|
0xd47f302e, 0x18d530b0, 0x965a3753, 0x5af037cd, |
5521
|
|
|
|
|
|
|
0xff6b144a, 0x33c114d4, 0xbd4e1337, 0x71e413a9, |
5522
|
|
|
|
|
|
|
0x7b211ab0, 0xb78b1a2e, 0x39041dcd, 0xf5ae1d53, |
5523
|
|
|
|
|
|
|
0x2c8e0fff, 0xe0240f61, 0x6eab0882, 0xa201081c, |
5524
|
|
|
|
|
|
|
0xa8c40105, 0x646e019b, 0xeae10678, 0x264b06e6, |
5525
|
|
|
|
|
|
|
}; |
5526
|
|
|
|
|
|
|
|
5527
|
|
|
|
|
|
|
|
5528
|
|
|
|
|
|
|
|
5529
|
|
|
|
|
|
|
static u32 MAYBE_UNUSED |
5530
|
29
|
|
|
|
|
|
crc32_slice8(u32 crc, const u8 *p, size_t len) |
5531
|
|
|
|
|
|
|
{ |
5532
|
29
|
|
|
|
|
|
const u8 * const end = p + len; |
5533
|
|
|
|
|
|
|
const u8 *end64; |
5534
|
|
|
|
|
|
|
|
5535
|
29
|
50
|
|
|
|
|
for (; ((uintptr_t)p & 7) && p != end; p++) |
|
|
0
|
|
|
|
|
|
5536
|
0
|
|
|
|
|
|
crc = (crc >> 8) ^ crc32_slice8_table[(u8)crc ^ *p]; |
5537
|
|
|
|
|
|
|
|
5538
|
29
|
|
|
|
|
|
end64 = p + ((end - p) & ~7); |
5539
|
23002
|
100
|
|
|
|
|
for (; p != end64; p += 8) { |
5540
|
22973
|
|
|
|
|
|
u32 v1 = le32_bswap(*(const u32 *)(p + 0)); |
5541
|
22973
|
|
|
|
|
|
u32 v2 = le32_bswap(*(const u32 *)(p + 4)); |
5542
|
|
|
|
|
|
|
|
5543
|
68919
|
|
|
|
|
|
crc = crc32_slice8_table[0x700 + (u8)((crc ^ v1) >> 0)] ^ |
5544
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x600 + (u8)((crc ^ v1) >> 8)] ^ |
5545
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x500 + (u8)((crc ^ v1) >> 16)] ^ |
5546
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x400 + (u8)((crc ^ v1) >> 24)] ^ |
5547
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x300 + (u8)(v2 >> 0)] ^ |
5548
|
45946
|
|
|
|
|
|
crc32_slice8_table[0x200 + (u8)(v2 >> 8)] ^ |
5549
|
22973
|
|
|
|
|
|
crc32_slice8_table[0x100 + (u8)(v2 >> 16)] ^ |
5550
|
22973
|
|
|
|
|
|
crc32_slice8_table[0x000 + (u8)(v2 >> 24)]; |
5551
|
|
|
|
|
|
|
} |
5552
|
|
|
|
|
|
|
|
5553
|
160
|
100
|
|
|
|
|
for (; p != end; p++) |
5554
|
131
|
|
|
|
|
|
crc = (crc >> 8) ^ crc32_slice8_table[(u8)crc ^ *p]; |
5555
|
|
|
|
|
|
|
|
5556
|
29
|
|
|
|
|
|
return crc; |
5557
|
|
|
|
|
|
|
} |
5558
|
|
|
|
|
|
|
|
5559
|
|
|
|
|
|
|
|
5560
|
|
|
|
|
|
|
static forceinline u32 MAYBE_UNUSED |
5561
|
|
|
|
|
|
|
crc32_slice1(u32 crc, const u8 *p, size_t len) |
5562
|
|
|
|
|
|
|
{ |
5563
|
|
|
|
|
|
|
size_t i; |
5564
|
|
|
|
|
|
|
|
5565
|
0
|
0
|
|
|
|
|
for (i = 0; i < len; i++) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
5566
|
0
|
|
|
|
|
|
crc = (crc >> 8) ^ crc32_slice1_table[(u8)crc ^ p[i]]; |
5567
|
0
|
|
|
|
|
|
return crc; |
5568
|
|
|
|
|
|
|
} |
5569
|
|
|
|
|
|
|
|
5570
|
|
|
|
|
|
|
|
5571
|
|
|
|
|
|
|
#undef DEFAULT_IMPL |
5572
|
|
|
|
|
|
|
#undef arch_select_crc32_func |
5573
|
|
|
|
|
|
|
typedef u32 (*crc32_func_t)(u32 crc, const u8 *p, size_t len); |
5574
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
5575
|
|
|
|
|
|
|
/* # include "arm/crc32_impl.h" */ |
5576
|
|
|
|
|
|
|
|
5577
|
|
|
|
|
|
|
|
5578
|
|
|
|
|
|
|
#ifndef LIB_ARM_CRC32_IMPL_H |
5579
|
|
|
|
|
|
|
#define LIB_ARM_CRC32_IMPL_H |
5580
|
|
|
|
|
|
|
|
5581
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
5582
|
|
|
|
|
|
|
|
5583
|
|
|
|
|
|
|
|
5584
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
5585
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
5586
|
|
|
|
|
|
|
|
5587
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
5588
|
|
|
|
|
|
|
|
5589
|
|
|
|
|
|
|
|
5590
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
5591
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
5592
|
|
|
|
|
|
|
|
5593
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
5594
|
|
|
|
|
|
|
|
5595
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
5596
|
|
|
|
|
|
|
#endif |
5597
|
|
|
|
|
|
|
|
5598
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
5599
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
5600
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
5601
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
5602
|
|
|
|
|
|
|
#else |
5603
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
5604
|
|
|
|
|
|
|
#endif |
5605
|
|
|
|
|
|
|
|
5606
|
|
|
|
|
|
|
|
5607
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
5608
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
5609
|
|
|
|
|
|
|
#else |
5610
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
5611
|
|
|
|
|
|
|
#endif |
5612
|
|
|
|
|
|
|
|
5613
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
5614
|
|
|
|
|
|
|
|
5615
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
5616
|
|
|
|
|
|
|
|
5617
|
|
|
|
|
|
|
|
5618
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
5619
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
5620
|
|
|
|
|
|
|
|
5621
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
5622
|
|
|
|
|
|
|
|
5623
|
|
|
|
|
|
|
|
5624
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
5625
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
5626
|
|
|
|
|
|
|
|
5627
|
|
|
|
|
|
|
#include |
5628
|
|
|
|
|
|
|
#include |
5629
|
|
|
|
|
|
|
|
5630
|
|
|
|
|
|
|
#ifdef __cplusplus |
5631
|
|
|
|
|
|
|
extern "C" { |
5632
|
|
|
|
|
|
|
#endif |
5633
|
|
|
|
|
|
|
|
5634
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
5635
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
5636
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
5637
|
|
|
|
|
|
|
|
5638
|
|
|
|
|
|
|
|
5639
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
5640
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
5641
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
5642
|
|
|
|
|
|
|
# else |
5643
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
5644
|
|
|
|
|
|
|
# endif |
5645
|
|
|
|
|
|
|
#endif |
5646
|
|
|
|
|
|
|
|
5647
|
|
|
|
|
|
|
|
5648
|
|
|
|
|
|
|
|
5649
|
|
|
|
|
|
|
|
5650
|
|
|
|
|
|
|
|
5651
|
|
|
|
|
|
|
struct libdeflate_compressor; |
5652
|
|
|
|
|
|
|
|
5653
|
|
|
|
|
|
|
|
5654
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
5655
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
5656
|
|
|
|
|
|
|
|
5657
|
|
|
|
|
|
|
|
5658
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5659
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
5660
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5661
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
5662
|
|
|
|
|
|
|
|
5663
|
|
|
|
|
|
|
|
5664
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5665
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
5666
|
|
|
|
|
|
|
size_t in_nbytes); |
5667
|
|
|
|
|
|
|
|
5668
|
|
|
|
|
|
|
|
5669
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5670
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
5671
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5672
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
5673
|
|
|
|
|
|
|
|
5674
|
|
|
|
|
|
|
|
5675
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5676
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
5677
|
|
|
|
|
|
|
size_t in_nbytes); |
5678
|
|
|
|
|
|
|
|
5679
|
|
|
|
|
|
|
|
5680
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5681
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
5682
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5683
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
5684
|
|
|
|
|
|
|
|
5685
|
|
|
|
|
|
|
|
5686
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
5687
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
5688
|
|
|
|
|
|
|
size_t in_nbytes); |
5689
|
|
|
|
|
|
|
|
5690
|
|
|
|
|
|
|
|
5691
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
5692
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
5693
|
|
|
|
|
|
|
|
5694
|
|
|
|
|
|
|
|
5695
|
|
|
|
|
|
|
|
5696
|
|
|
|
|
|
|
|
5697
|
|
|
|
|
|
|
|
5698
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
5699
|
|
|
|
|
|
|
|
5700
|
|
|
|
|
|
|
|
5701
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
5702
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
5703
|
|
|
|
|
|
|
|
5704
|
|
|
|
|
|
|
|
5705
|
|
|
|
|
|
|
enum libdeflate_result { |
5706
|
|
|
|
|
|
|
|
5707
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
5708
|
|
|
|
|
|
|
|
5709
|
|
|
|
|
|
|
|
5710
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
5711
|
|
|
|
|
|
|
|
5712
|
|
|
|
|
|
|
|
5713
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
5714
|
|
|
|
|
|
|
|
5715
|
|
|
|
|
|
|
|
5716
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
5717
|
|
|
|
|
|
|
}; |
5718
|
|
|
|
|
|
|
|
5719
|
|
|
|
|
|
|
|
5720
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5721
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
5722
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5723
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5724
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5725
|
|
|
|
|
|
|
|
5726
|
|
|
|
|
|
|
|
5727
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5728
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
5729
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5730
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5731
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
5732
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5733
|
|
|
|
|
|
|
|
5734
|
|
|
|
|
|
|
|
5735
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5736
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
5737
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5738
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5739
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5740
|
|
|
|
|
|
|
|
5741
|
|
|
|
|
|
|
|
5742
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5743
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
5744
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5745
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5746
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
5747
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5748
|
|
|
|
|
|
|
|
5749
|
|
|
|
|
|
|
|
5750
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5751
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
5752
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5753
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5754
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5755
|
|
|
|
|
|
|
|
5756
|
|
|
|
|
|
|
|
5757
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
5758
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
5759
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
5760
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
5761
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
5762
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
5763
|
|
|
|
|
|
|
|
5764
|
|
|
|
|
|
|
|
5765
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
5766
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
5767
|
|
|
|
|
|
|
|
5768
|
|
|
|
|
|
|
|
5769
|
|
|
|
|
|
|
|
5770
|
|
|
|
|
|
|
|
5771
|
|
|
|
|
|
|
|
5772
|
|
|
|
|
|
|
|
5773
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
5774
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
5775
|
|
|
|
|
|
|
|
5776
|
|
|
|
|
|
|
|
5777
|
|
|
|
|
|
|
|
5778
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
5779
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
5780
|
|
|
|
|
|
|
|
5781
|
|
|
|
|
|
|
|
5782
|
|
|
|
|
|
|
|
5783
|
|
|
|
|
|
|
|
5784
|
|
|
|
|
|
|
|
5785
|
|
|
|
|
|
|
|
5786
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
5787
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
5788
|
|
|
|
|
|
|
void (*free_func)(void *)); |
5789
|
|
|
|
|
|
|
|
5790
|
|
|
|
|
|
|
#ifdef __cplusplus |
5791
|
|
|
|
|
|
|
} |
5792
|
|
|
|
|
|
|
#endif |
5793
|
|
|
|
|
|
|
|
5794
|
|
|
|
|
|
|
#endif |
5795
|
|
|
|
|
|
|
|
5796
|
|
|
|
|
|
|
|
5797
|
|
|
|
|
|
|
#include |
5798
|
|
|
|
|
|
|
#include |
5799
|
|
|
|
|
|
|
#include |
5800
|
|
|
|
|
|
|
#ifdef _MSC_VER |
5801
|
|
|
|
|
|
|
# include |
5802
|
|
|
|
|
|
|
# include |
5803
|
|
|
|
|
|
|
|
5804
|
|
|
|
|
|
|
|
5805
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
5806
|
|
|
|
|
|
|
|
5807
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
5808
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
5809
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
5810
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
5811
|
|
|
|
|
|
|
|
5812
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
5813
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
5814
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
5815
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
5816
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
5817
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
5818
|
|
|
|
|
|
|
#endif |
5819
|
|
|
|
|
|
|
#ifndef FREESTANDING |
5820
|
|
|
|
|
|
|
# include |
5821
|
|
|
|
|
|
|
#endif |
5822
|
|
|
|
|
|
|
|
5823
|
|
|
|
|
|
|
|
5824
|
|
|
|
|
|
|
|
5825
|
|
|
|
|
|
|
|
5826
|
|
|
|
|
|
|
|
5827
|
|
|
|
|
|
|
|
5828
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
5829
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
5830
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
5831
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
5832
|
|
|
|
|
|
|
#ifdef _MSC_VER |
5833
|
|
|
|
|
|
|
# if defined(_M_X64) |
5834
|
|
|
|
|
|
|
# define ARCH_X86_64 |
5835
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
5836
|
|
|
|
|
|
|
# define ARCH_X86_32 |
5837
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
5838
|
|
|
|
|
|
|
# define ARCH_ARM64 |
5839
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
5840
|
|
|
|
|
|
|
# define ARCH_ARM32 |
5841
|
|
|
|
|
|
|
# endif |
5842
|
|
|
|
|
|
|
#else |
5843
|
|
|
|
|
|
|
# if defined(__x86_64__) |
5844
|
|
|
|
|
|
|
# define ARCH_X86_64 |
5845
|
|
|
|
|
|
|
# elif defined(__i386__) |
5846
|
|
|
|
|
|
|
# define ARCH_X86_32 |
5847
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
5848
|
|
|
|
|
|
|
# define ARCH_ARM64 |
5849
|
|
|
|
|
|
|
# elif defined(__arm__) |
5850
|
|
|
|
|
|
|
# define ARCH_ARM32 |
5851
|
|
|
|
|
|
|
# endif |
5852
|
|
|
|
|
|
|
#endif |
5853
|
|
|
|
|
|
|
|
5854
|
|
|
|
|
|
|
|
5855
|
|
|
|
|
|
|
|
5856
|
|
|
|
|
|
|
|
5857
|
|
|
|
|
|
|
|
5858
|
|
|
|
|
|
|
|
5859
|
|
|
|
|
|
|
typedef uint8_t u8; |
5860
|
|
|
|
|
|
|
typedef uint16_t u16; |
5861
|
|
|
|
|
|
|
typedef uint32_t u32; |
5862
|
|
|
|
|
|
|
typedef uint64_t u64; |
5863
|
|
|
|
|
|
|
typedef int8_t s8; |
5864
|
|
|
|
|
|
|
typedef int16_t s16; |
5865
|
|
|
|
|
|
|
typedef int32_t s32; |
5866
|
|
|
|
|
|
|
typedef int64_t s64; |
5867
|
|
|
|
|
|
|
|
5868
|
|
|
|
|
|
|
|
5869
|
|
|
|
|
|
|
#ifdef _MSC_VER |
5870
|
|
|
|
|
|
|
# ifdef _WIN64 |
5871
|
|
|
|
|
|
|
typedef long long ssize_t; |
5872
|
|
|
|
|
|
|
# else |
5873
|
|
|
|
|
|
|
typedef long ssize_t; |
5874
|
|
|
|
|
|
|
# endif |
5875
|
|
|
|
|
|
|
#endif |
5876
|
|
|
|
|
|
|
|
5877
|
|
|
|
|
|
|
|
5878
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
5879
|
|
|
|
|
|
|
|
5880
|
|
|
|
|
|
|
|
5881
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
5882
|
|
|
|
|
|
|
|
5883
|
|
|
|
|
|
|
|
5884
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
5885
|
|
|
|
|
|
|
|
5886
|
|
|
|
|
|
|
|
5887
|
|
|
|
|
|
|
|
5888
|
|
|
|
|
|
|
|
5889
|
|
|
|
|
|
|
|
5890
|
|
|
|
|
|
|
|
5891
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
5892
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
5893
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
5894
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
5895
|
|
|
|
|
|
|
#else |
5896
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
5897
|
|
|
|
|
|
|
#endif |
5898
|
|
|
|
|
|
|
#ifdef __clang__ |
5899
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
5900
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
5901
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
5902
|
|
|
|
|
|
|
# else |
5903
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
5904
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
5905
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
5906
|
|
|
|
|
|
|
# endif |
5907
|
|
|
|
|
|
|
#else |
5908
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
5909
|
|
|
|
|
|
|
#endif |
5910
|
|
|
|
|
|
|
|
5911
|
|
|
|
|
|
|
|
5912
|
|
|
|
|
|
|
#ifndef __has_attribute |
5913
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
5914
|
|
|
|
|
|
|
#endif |
5915
|
|
|
|
|
|
|
#ifndef __has_builtin |
5916
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
5917
|
|
|
|
|
|
|
#endif |
5918
|
|
|
|
|
|
|
|
5919
|
|
|
|
|
|
|
|
5920
|
|
|
|
|
|
|
#ifdef _MSC_VER |
5921
|
|
|
|
|
|
|
# define inline __inline |
5922
|
|
|
|
|
|
|
#endif |
5923
|
|
|
|
|
|
|
|
5924
|
|
|
|
|
|
|
|
5925
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
5926
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
5927
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
5928
|
|
|
|
|
|
|
# define forceinline __forceinline |
5929
|
|
|
|
|
|
|
#else |
5930
|
|
|
|
|
|
|
# define forceinline inline |
5931
|
|
|
|
|
|
|
#endif |
5932
|
|
|
|
|
|
|
|
5933
|
|
|
|
|
|
|
|
5934
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
5935
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
5936
|
|
|
|
|
|
|
#else |
5937
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
5938
|
|
|
|
|
|
|
#endif |
5939
|
|
|
|
|
|
|
|
5940
|
|
|
|
|
|
|
|
5941
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
5942
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
5943
|
|
|
|
|
|
|
# define restrict __restrict__ |
5944
|
|
|
|
|
|
|
# else |
5945
|
|
|
|
|
|
|
# define restrict |
5946
|
|
|
|
|
|
|
# endif |
5947
|
|
|
|
|
|
|
#endif |
5948
|
|
|
|
|
|
|
|
5949
|
|
|
|
|
|
|
|
5950
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
5951
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
5952
|
|
|
|
|
|
|
#else |
5953
|
|
|
|
|
|
|
# define likely(expr) (expr) |
5954
|
|
|
|
|
|
|
#endif |
5955
|
|
|
|
|
|
|
|
5956
|
|
|
|
|
|
|
|
5957
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
5958
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
5959
|
|
|
|
|
|
|
#else |
5960
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
5961
|
|
|
|
|
|
|
#endif |
5962
|
|
|
|
|
|
|
|
5963
|
|
|
|
|
|
|
|
5964
|
|
|
|
|
|
|
#undef prefetchr |
5965
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
5966
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
5967
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
5968
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
5969
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
5970
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
5971
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
5972
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
5973
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
5974
|
|
|
|
|
|
|
# endif |
5975
|
|
|
|
|
|
|
#endif |
5976
|
|
|
|
|
|
|
#ifndef prefetchr |
5977
|
|
|
|
|
|
|
# define prefetchr(addr) |
5978
|
|
|
|
|
|
|
#endif |
5979
|
|
|
|
|
|
|
|
5980
|
|
|
|
|
|
|
|
5981
|
|
|
|
|
|
|
#undef prefetchw |
5982
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
5983
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
5984
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
5985
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
5986
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
5987
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
5988
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
5989
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
5990
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
5991
|
|
|
|
|
|
|
# endif |
5992
|
|
|
|
|
|
|
#endif |
5993
|
|
|
|
|
|
|
#ifndef prefetchw |
5994
|
|
|
|
|
|
|
# define prefetchw(addr) |
5995
|
|
|
|
|
|
|
#endif |
5996
|
|
|
|
|
|
|
|
5997
|
|
|
|
|
|
|
|
5998
|
|
|
|
|
|
|
#undef _aligned_attribute |
5999
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
6000
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
6001
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6002
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
6003
|
|
|
|
|
|
|
#endif |
6004
|
|
|
|
|
|
|
|
6005
|
|
|
|
|
|
|
|
6006
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
6007
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
6008
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
6009
|
|
|
|
|
|
|
#else |
6010
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
6011
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
6012
|
|
|
|
|
|
|
#endif |
6013
|
|
|
|
|
|
|
|
6014
|
|
|
|
|
|
|
|
6015
|
|
|
|
|
|
|
|
6016
|
|
|
|
|
|
|
|
6017
|
|
|
|
|
|
|
|
6018
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
6019
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
6020
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
6021
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
6022
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
6023
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
6024
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
6025
|
|
|
|
|
|
|
|
6026
|
|
|
|
|
|
|
|
6027
|
|
|
|
|
|
|
|
6028
|
|
|
|
|
|
|
|
6029
|
|
|
|
|
|
|
|
6030
|
|
|
|
|
|
|
|
6031
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
6032
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
6033
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6034
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
6035
|
|
|
|
|
|
|
#else |
6036
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
6037
|
|
|
|
|
|
|
{ |
6038
|
|
|
|
|
|
|
union { |
6039
|
|
|
|
|
|
|
u32 w; |
6040
|
|
|
|
|
|
|
u8 b; |
6041
|
|
|
|
|
|
|
} u; |
6042
|
|
|
|
|
|
|
|
6043
|
|
|
|
|
|
|
u.w = 1; |
6044
|
|
|
|
|
|
|
return u.b; |
6045
|
|
|
|
|
|
|
} |
6046
|
|
|
|
|
|
|
#endif |
6047
|
|
|
|
|
|
|
|
6048
|
|
|
|
|
|
|
|
6049
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
6050
|
|
|
|
|
|
|
{ |
6051
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
6052
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
6053
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6054
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
6055
|
|
|
|
|
|
|
#else |
6056
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
6057
|
|
|
|
|
|
|
#endif |
6058
|
|
|
|
|
|
|
} |
6059
|
|
|
|
|
|
|
|
6060
|
|
|
|
|
|
|
|
6061
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
6062
|
|
|
|
|
|
|
{ |
6063
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
6064
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
6065
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6066
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
6067
|
|
|
|
|
|
|
#else |
6068
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
6069
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
6070
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
6071
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
6072
|
|
|
|
|
|
|
#endif |
6073
|
|
|
|
|
|
|
} |
6074
|
|
|
|
|
|
|
|
6075
|
|
|
|
|
|
|
|
6076
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
6077
|
|
|
|
|
|
|
{ |
6078
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
6079
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
6080
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6081
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
6082
|
|
|
|
|
|
|
#else |
6083
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
6084
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
6085
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
6086
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
6087
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
6088
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
6089
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
6090
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
6091
|
|
|
|
|
|
|
#endif |
6092
|
|
|
|
|
|
|
} |
6093
|
|
|
|
|
|
|
|
6094
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
6095
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
6096
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
6097
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
6098
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
6099
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
6100
|
|
|
|
|
|
|
|
6101
|
|
|
|
|
|
|
|
6102
|
|
|
|
|
|
|
|
6103
|
|
|
|
|
|
|
|
6104
|
|
|
|
|
|
|
|
6105
|
|
|
|
|
|
|
|
6106
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
6107
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
6108
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
6109
|
|
|
|
|
|
|
defined(__wasm__)) |
6110
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
6111
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6112
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
6113
|
|
|
|
|
|
|
#else |
6114
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
6115
|
|
|
|
|
|
|
#endif |
6116
|
|
|
|
|
|
|
|
6117
|
|
|
|
|
|
|
|
6118
|
|
|
|
|
|
|
|
6119
|
|
|
|
|
|
|
#ifdef FREESTANDING |
6120
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
6121
|
|
|
|
|
|
|
#else |
6122
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
6123
|
|
|
|
|
|
|
#endif |
6124
|
|
|
|
|
|
|
|
6125
|
|
|
|
|
|
|
|
6126
|
|
|
|
|
|
|
|
6127
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
6128
|
|
|
|
|
|
|
static forceinline type \ |
6129
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
6130
|
|
|
|
|
|
|
{ \ |
6131
|
|
|
|
|
|
|
type v; \ |
6132
|
|
|
|
|
|
|
\ |
6133
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
6134
|
|
|
|
|
|
|
return v; \ |
6135
|
|
|
|
|
|
|
} \ |
6136
|
|
|
|
|
|
|
\ |
6137
|
|
|
|
|
|
|
static forceinline void \ |
6138
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
6139
|
|
|
|
|
|
|
{ \ |
6140
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
6141
|
|
|
|
|
|
|
} |
6142
|
|
|
|
|
|
|
|
6143
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
6144
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
6145
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
6146
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
6147
|
|
|
|
|
|
|
|
6148
|
|
|
|
|
|
|
#undef MEMCOPY |
6149
|
|
|
|
|
|
|
|
6150
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
6151
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
6152
|
|
|
|
|
|
|
|
6153
|
|
|
|
|
|
|
|
6154
|
|
|
|
|
|
|
|
6155
|
|
|
|
|
|
|
static forceinline u16 |
6156
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
6157
|
|
|
|
|
|
|
{ |
6158
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6159
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
6160
|
|
|
|
|
|
|
else |
6161
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
6162
|
|
|
|
|
|
|
} |
6163
|
|
|
|
|
|
|
|
6164
|
|
|
|
|
|
|
static forceinline u16 |
6165
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
6166
|
|
|
|
|
|
|
{ |
6167
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6168
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
6169
|
|
|
|
|
|
|
else |
6170
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
6171
|
|
|
|
|
|
|
} |
6172
|
|
|
|
|
|
|
|
6173
|
|
|
|
|
|
|
static forceinline u32 |
6174
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
6175
|
|
|
|
|
|
|
{ |
6176
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6177
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
6178
|
|
|
|
|
|
|
else |
6179
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
6180
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
6181
|
|
|
|
|
|
|
} |
6182
|
|
|
|
|
|
|
|
6183
|
|
|
|
|
|
|
static forceinline u32 |
6184
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
6185
|
|
|
|
|
|
|
{ |
6186
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6187
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
6188
|
|
|
|
|
|
|
else |
6189
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
6190
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
6191
|
|
|
|
|
|
|
} |
6192
|
|
|
|
|
|
|
|
6193
|
|
|
|
|
|
|
static forceinline u64 |
6194
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
6195
|
|
|
|
|
|
|
{ |
6196
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
6197
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
6198
|
|
|
|
|
|
|
else |
6199
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
6200
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
6201
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
6202
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
6203
|
|
|
|
|
|
|
} |
6204
|
|
|
|
|
|
|
|
6205
|
|
|
|
|
|
|
static forceinline machine_word_t |
6206
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
6207
|
|
|
|
|
|
|
{ |
6208
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
6209
|
|
|
|
|
|
|
if (WORDBITS == 32) |
6210
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
6211
|
|
|
|
|
|
|
else |
6212
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
6213
|
|
|
|
|
|
|
} |
6214
|
|
|
|
|
|
|
|
6215
|
|
|
|
|
|
|
|
6216
|
|
|
|
|
|
|
|
6217
|
|
|
|
|
|
|
static forceinline void |
6218
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
6219
|
|
|
|
|
|
|
{ |
6220
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6221
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
6222
|
|
|
|
|
|
|
} else { |
6223
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
6224
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
6225
|
|
|
|
|
|
|
} |
6226
|
|
|
|
|
|
|
} |
6227
|
|
|
|
|
|
|
|
6228
|
|
|
|
|
|
|
static forceinline void |
6229
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
6230
|
|
|
|
|
|
|
{ |
6231
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6232
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
6233
|
|
|
|
|
|
|
} else { |
6234
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
6235
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
6236
|
|
|
|
|
|
|
} |
6237
|
|
|
|
|
|
|
} |
6238
|
|
|
|
|
|
|
|
6239
|
|
|
|
|
|
|
static forceinline void |
6240
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
6241
|
|
|
|
|
|
|
{ |
6242
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6243
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
6244
|
|
|
|
|
|
|
} else { |
6245
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
6246
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
6247
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
6248
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
6249
|
|
|
|
|
|
|
} |
6250
|
|
|
|
|
|
|
} |
6251
|
|
|
|
|
|
|
|
6252
|
|
|
|
|
|
|
static forceinline void |
6253
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
6254
|
|
|
|
|
|
|
{ |
6255
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6256
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
6257
|
|
|
|
|
|
|
} else { |
6258
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
6259
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
6260
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
6261
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
6262
|
|
|
|
|
|
|
} |
6263
|
|
|
|
|
|
|
} |
6264
|
|
|
|
|
|
|
|
6265
|
|
|
|
|
|
|
static forceinline void |
6266
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
6267
|
|
|
|
|
|
|
{ |
6268
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
6269
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
6270
|
|
|
|
|
|
|
} else { |
6271
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
6272
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
6273
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
6274
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
6275
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
6276
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
6277
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
6278
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
6279
|
|
|
|
|
|
|
} |
6280
|
|
|
|
|
|
|
} |
6281
|
|
|
|
|
|
|
|
6282
|
|
|
|
|
|
|
static forceinline void |
6283
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
6284
|
|
|
|
|
|
|
{ |
6285
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
6286
|
|
|
|
|
|
|
if (WORDBITS == 32) |
6287
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
6288
|
|
|
|
|
|
|
else |
6289
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
6290
|
|
|
|
|
|
|
} |
6291
|
|
|
|
|
|
|
|
6292
|
|
|
|
|
|
|
|
6293
|
|
|
|
|
|
|
|
6294
|
|
|
|
|
|
|
|
6295
|
|
|
|
|
|
|
|
6296
|
|
|
|
|
|
|
|
6297
|
|
|
|
|
|
|
|
6298
|
|
|
|
|
|
|
static forceinline unsigned |
6299
|
|
|
|
|
|
|
bsr32(u32 v) |
6300
|
|
|
|
|
|
|
{ |
6301
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
6302
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
6303
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6304
|
|
|
|
|
|
|
unsigned long i; |
6305
|
|
|
|
|
|
|
|
6306
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
6307
|
|
|
|
|
|
|
return i; |
6308
|
|
|
|
|
|
|
#else |
6309
|
|
|
|
|
|
|
unsigned i = 0; |
6310
|
|
|
|
|
|
|
|
6311
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
6312
|
|
|
|
|
|
|
i++; |
6313
|
|
|
|
|
|
|
return i; |
6314
|
|
|
|
|
|
|
#endif |
6315
|
|
|
|
|
|
|
} |
6316
|
|
|
|
|
|
|
|
6317
|
|
|
|
|
|
|
static forceinline unsigned |
6318
|
|
|
|
|
|
|
bsr64(u64 v) |
6319
|
|
|
|
|
|
|
{ |
6320
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
6321
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
6322
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
6323
|
|
|
|
|
|
|
unsigned long i; |
6324
|
|
|
|
|
|
|
|
6325
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
6326
|
|
|
|
|
|
|
return i; |
6327
|
|
|
|
|
|
|
#else |
6328
|
|
|
|
|
|
|
unsigned i = 0; |
6329
|
|
|
|
|
|
|
|
6330
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
6331
|
|
|
|
|
|
|
i++; |
6332
|
|
|
|
|
|
|
return i; |
6333
|
|
|
|
|
|
|
#endif |
6334
|
|
|
|
|
|
|
} |
6335
|
|
|
|
|
|
|
|
6336
|
|
|
|
|
|
|
static forceinline unsigned |
6337
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
6338
|
|
|
|
|
|
|
{ |
6339
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
6340
|
|
|
|
|
|
|
if (WORDBITS == 32) |
6341
|
|
|
|
|
|
|
return bsr32(v); |
6342
|
|
|
|
|
|
|
else |
6343
|
|
|
|
|
|
|
return bsr64(v); |
6344
|
|
|
|
|
|
|
} |
6345
|
|
|
|
|
|
|
|
6346
|
|
|
|
|
|
|
|
6347
|
|
|
|
|
|
|
|
6348
|
|
|
|
|
|
|
static forceinline unsigned |
6349
|
|
|
|
|
|
|
bsf32(u32 v) |
6350
|
|
|
|
|
|
|
{ |
6351
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
6352
|
|
|
|
|
|
|
return __builtin_ctz(v); |
6353
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
6354
|
|
|
|
|
|
|
unsigned long i; |
6355
|
|
|
|
|
|
|
|
6356
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
6357
|
|
|
|
|
|
|
return i; |
6358
|
|
|
|
|
|
|
#else |
6359
|
|
|
|
|
|
|
unsigned i = 0; |
6360
|
|
|
|
|
|
|
|
6361
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
6362
|
|
|
|
|
|
|
i++; |
6363
|
|
|
|
|
|
|
return i; |
6364
|
|
|
|
|
|
|
#endif |
6365
|
|
|
|
|
|
|
} |
6366
|
|
|
|
|
|
|
|
6367
|
|
|
|
|
|
|
static forceinline unsigned |
6368
|
|
|
|
|
|
|
bsf64(u64 v) |
6369
|
|
|
|
|
|
|
{ |
6370
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
6371
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
6372
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
6373
|
|
|
|
|
|
|
unsigned long i; |
6374
|
|
|
|
|
|
|
|
6375
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
6376
|
|
|
|
|
|
|
return i; |
6377
|
|
|
|
|
|
|
#else |
6378
|
|
|
|
|
|
|
unsigned i = 0; |
6379
|
|
|
|
|
|
|
|
6380
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
6381
|
|
|
|
|
|
|
i++; |
6382
|
|
|
|
|
|
|
return i; |
6383
|
|
|
|
|
|
|
#endif |
6384
|
|
|
|
|
|
|
} |
6385
|
|
|
|
|
|
|
|
6386
|
|
|
|
|
|
|
static forceinline unsigned |
6387
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
6388
|
|
|
|
|
|
|
{ |
6389
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
6390
|
|
|
|
|
|
|
if (WORDBITS == 32) |
6391
|
|
|
|
|
|
|
return bsf32(v); |
6392
|
|
|
|
|
|
|
else |
6393
|
|
|
|
|
|
|
return bsf64(v); |
6394
|
|
|
|
|
|
|
} |
6395
|
|
|
|
|
|
|
|
6396
|
|
|
|
|
|
|
|
6397
|
|
|
|
|
|
|
#undef rbit32 |
6398
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
6399
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
6400
|
|
|
|
|
|
|
static forceinline u32 |
6401
|
|
|
|
|
|
|
rbit32(u32 v) |
6402
|
|
|
|
|
|
|
{ |
6403
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
6404
|
|
|
|
|
|
|
return v; |
6405
|
|
|
|
|
|
|
} |
6406
|
|
|
|
|
|
|
#define rbit32 rbit32 |
6407
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
6408
|
|
|
|
|
|
|
static forceinline u32 |
6409
|
|
|
|
|
|
|
rbit32(u32 v) |
6410
|
|
|
|
|
|
|
{ |
6411
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
6412
|
|
|
|
|
|
|
return v; |
6413
|
|
|
|
|
|
|
} |
6414
|
|
|
|
|
|
|
#define rbit32 rbit32 |
6415
|
|
|
|
|
|
|
#endif |
6416
|
|
|
|
|
|
|
|
6417
|
|
|
|
|
|
|
#endif |
6418
|
|
|
|
|
|
|
|
6419
|
|
|
|
|
|
|
|
6420
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
6421
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
6422
|
|
|
|
|
|
|
|
6423
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
6424
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
6425
|
|
|
|
|
|
|
|
6426
|
|
|
|
|
|
|
#ifdef FREESTANDING |
6427
|
|
|
|
|
|
|
|
6428
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
6429
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
6430
|
|
|
|
|
|
|
|
6431
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
6432
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
6433
|
|
|
|
|
|
|
|
6434
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
6435
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
6436
|
|
|
|
|
|
|
|
6437
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
6438
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
6439
|
|
|
|
|
|
|
|
6440
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
6441
|
|
|
|
|
|
|
#else |
6442
|
|
|
|
|
|
|
#include |
6443
|
|
|
|
|
|
|
#endif |
6444
|
|
|
|
|
|
|
|
6445
|
|
|
|
|
|
|
|
6446
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
6447
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
6448
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
6449
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
6450
|
|
|
|
|
|
|
#else |
6451
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
6452
|
|
|
|
|
|
|
#endif |
6453
|
|
|
|
|
|
|
|
6454
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
6455
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
6456
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
6457
|
|
|
|
|
|
|
|
6458
|
|
|
|
|
|
|
#endif |
6459
|
|
|
|
|
|
|
|
6460
|
|
|
|
|
|
|
|
6461
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
6462
|
|
|
|
|
|
|
|
6463
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
6464
|
|
|
|
|
|
|
|
6465
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
6466
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
6467
|
|
|
|
|
|
|
(defined(__linux__) || \ |
6468
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
6469
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
6470
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
6471
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
6472
|
|
|
|
|
|
|
#endif |
6473
|
|
|
|
|
|
|
|
6474
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
6475
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
6476
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
6477
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
6478
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
6479
|
|
|
|
|
|
|
|
6480
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
6481
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
6482
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
6483
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
6484
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
6485
|
|
|
|
|
|
|
|
6486
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
6487
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
6488
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
6489
|
|
|
|
|
|
|
|
6490
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
6491
|
|
|
|
|
|
|
|
6492
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
6493
|
|
|
|
|
|
|
{ |
6494
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
6495
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
6496
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
6497
|
|
|
|
|
|
|
} |
6498
|
|
|
|
|
|
|
#else |
6499
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
6500
|
|
|
|
|
|
|
#endif |
6501
|
|
|
|
|
|
|
|
6502
|
|
|
|
|
|
|
|
6503
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
6504
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
6505
|
|
|
|
|
|
|
#else |
6506
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
6507
|
|
|
|
|
|
|
#endif |
6508
|
|
|
|
|
|
|
|
6509
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
6510
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
6511
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
6512
|
|
|
|
|
|
|
#else |
6513
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
6514
|
|
|
|
|
|
|
#endif |
6515
|
|
|
|
|
|
|
|
6516
|
|
|
|
|
|
|
|
6517
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
6518
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
6519
|
|
|
|
|
|
|
#else |
6520
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
6521
|
|
|
|
|
|
|
#endif |
6522
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
6523
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
6524
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
6525
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
6526
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
6527
|
|
|
|
|
|
|
\ |
6528
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
6529
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
6530
|
|
|
|
|
|
|
|
6531
|
|
|
|
|
|
|
# ifdef _MSC_VER |
6532
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
6533
|
|
|
|
|
|
|
# else |
6534
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
6535
|
|
|
|
|
|
|
# endif |
6536
|
|
|
|
|
|
|
#else |
6537
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
6538
|
|
|
|
|
|
|
#endif |
6539
|
|
|
|
|
|
|
|
6540
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
6541
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
6542
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
6543
|
|
|
|
|
|
|
#else |
6544
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
6545
|
|
|
|
|
|
|
#endif |
6546
|
|
|
|
|
|
|
|
6547
|
|
|
|
|
|
|
|
6548
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
6549
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
6550
|
|
|
|
|
|
|
#else |
6551
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
6552
|
|
|
|
|
|
|
#endif |
6553
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
6554
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
6555
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
6556
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
6557
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
6558
|
|
|
|
|
|
|
|
6559
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
6560
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
6561
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
6562
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
6563
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
6564
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
6565
|
|
|
|
|
|
|
# endif |
6566
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
6567
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
6568
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
6569
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
6570
|
|
|
|
|
|
|
# endif |
6571
|
|
|
|
|
|
|
#endif |
6572
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
6573
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
6574
|
|
|
|
|
|
|
#endif |
6575
|
|
|
|
|
|
|
|
6576
|
|
|
|
|
|
|
|
6577
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
6578
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
6579
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
6580
|
|
|
|
|
|
|
# else |
6581
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
6582
|
|
|
|
|
|
|
# endif |
6583
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
6584
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
6585
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
6586
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
6587
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
6588
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
6589
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
6590
|
|
|
|
|
|
|
#else |
6591
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
6592
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
6593
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
6594
|
|
|
|
|
|
|
#endif |
6595
|
|
|
|
|
|
|
|
6596
|
|
|
|
|
|
|
|
6597
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
6598
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
6599
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
6600
|
|
|
|
|
|
|
# else |
6601
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
6602
|
|
|
|
|
|
|
# endif |
6603
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
6604
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
6605
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
6606
|
|
|
|
|
|
|
defined(_MSC_VER))) |
6607
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
6608
|
|
|
|
|
|
|
# else |
6609
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
6610
|
|
|
|
|
|
|
# endif |
6611
|
|
|
|
|
|
|
#else |
6612
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
6613
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
6614
|
|
|
|
|
|
|
#endif |
6615
|
|
|
|
|
|
|
|
6616
|
|
|
|
|
|
|
|
6617
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
6618
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
6619
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
6620
|
|
|
|
|
|
|
#endif |
6621
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
6622
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
6623
|
|
|
|
|
|
|
#endif |
6624
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
6625
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
6626
|
|
|
|
|
|
|
#endif |
6627
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
6628
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
6629
|
|
|
|
|
|
|
# include |
6630
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
6631
|
|
|
|
|
|
|
#endif |
6632
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
6633
|
|
|
|
|
|
|
# include |
6634
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
6635
|
|
|
|
|
|
|
#endif |
6636
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
6637
|
|
|
|
|
|
|
# include |
6638
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
6639
|
|
|
|
|
|
|
#endif |
6640
|
|
|
|
|
|
|
|
6641
|
|
|
|
|
|
|
#endif |
6642
|
|
|
|
|
|
|
|
6643
|
|
|
|
|
|
|
#endif |
6644
|
|
|
|
|
|
|
|
6645
|
|
|
|
|
|
|
|
6646
|
|
|
|
|
|
|
|
6647
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN |
6648
|
|
|
|
|
|
|
# if HAVE_CRC32_NATIVE |
6649
|
|
|
|
|
|
|
# define ATTRIBUTES |
6650
|
|
|
|
|
|
|
# else |
6651
|
|
|
|
|
|
|
# ifdef ARCH_ARM32 |
6652
|
|
|
|
|
|
|
# ifdef __clang__ |
6653
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("armv8-a,crc") |
6654
|
|
|
|
|
|
|
# elif defined(__ARM_PCS_VFP) |
6655
|
|
|
|
|
|
|
|
6656
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8-a+crc+simd") |
6657
|
|
|
|
|
|
|
# else |
6658
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8-a+crc") |
6659
|
|
|
|
|
|
|
# endif |
6660
|
|
|
|
|
|
|
# else |
6661
|
|
|
|
|
|
|
# ifdef __clang__ |
6662
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("crc") |
6663
|
|
|
|
|
|
|
# else |
6664
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crc") |
6665
|
|
|
|
|
|
|
# endif |
6666
|
|
|
|
|
|
|
# endif |
6667
|
|
|
|
|
|
|
# endif |
6668
|
|
|
|
|
|
|
|
6669
|
|
|
|
|
|
|
#ifndef _MSC_VER |
6670
|
|
|
|
|
|
|
# include |
6671
|
|
|
|
|
|
|
#endif |
6672
|
|
|
|
|
|
|
|
6673
|
|
|
|
|
|
|
|
6674
|
|
|
|
|
|
|
static forceinline ATTRIBUTES u32 |
6675
|
|
|
|
|
|
|
combine_crcs_slow(u32 crc0, u32 crc1, u32 crc2, u32 crc3) |
6676
|
|
|
|
|
|
|
{ |
6677
|
|
|
|
|
|
|
u64 res0 = 0, res1 = 0, res2 = 0; |
6678
|
|
|
|
|
|
|
int i; |
6679
|
|
|
|
|
|
|
|
6680
|
|
|
|
|
|
|
|
6681
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) { |
6682
|
|
|
|
|
|
|
if (CRC32_FIXED_CHUNK_MULT_3 & (1U << i)) |
6683
|
|
|
|
|
|
|
res0 ^= (u64)crc0 << i; |
6684
|
|
|
|
|
|
|
if (CRC32_FIXED_CHUNK_MULT_2 & (1U << i)) |
6685
|
|
|
|
|
|
|
res1 ^= (u64)crc1 << i; |
6686
|
|
|
|
|
|
|
if (CRC32_FIXED_CHUNK_MULT_1 & (1U << i)) |
6687
|
|
|
|
|
|
|
res2 ^= (u64)crc2 << i; |
6688
|
|
|
|
|
|
|
} |
6689
|
|
|
|
|
|
|
|
6690
|
|
|
|
|
|
|
return __crc32d(0, res0 ^ res1 ^ res2) ^ crc3; |
6691
|
|
|
|
|
|
|
} |
6692
|
|
|
|
|
|
|
|
6693
|
|
|
|
|
|
|
#define crc32_arm_crc crc32_arm_crc |
6694
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
6695
|
|
|
|
|
|
|
crc32_arm_crc(u32 crc, const u8 *p, size_t len) |
6696
|
|
|
|
|
|
|
{ |
6697
|
|
|
|
|
|
|
if (len >= 64) { |
6698
|
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 7; |
6699
|
|
|
|
|
|
|
|
6700
|
|
|
|
|
|
|
|
6701
|
|
|
|
|
|
|
if (align) { |
6702
|
|
|
|
|
|
|
if (align & 1) |
6703
|
|
|
|
|
|
|
crc = __crc32b(crc, *p++); |
6704
|
|
|
|
|
|
|
if (align & 2) { |
6705
|
|
|
|
|
|
|
crc = __crc32h(crc, le16_bswap(*(u16 *)p)); |
6706
|
|
|
|
|
|
|
p += 2; |
6707
|
|
|
|
|
|
|
} |
6708
|
|
|
|
|
|
|
if (align & 4) { |
6709
|
|
|
|
|
|
|
crc = __crc32w(crc, le32_bswap(*(u32 *)p)); |
6710
|
|
|
|
|
|
|
p += 4; |
6711
|
|
|
|
|
|
|
} |
6712
|
|
|
|
|
|
|
len -= align; |
6713
|
|
|
|
|
|
|
} |
6714
|
|
|
|
|
|
|
|
6715
|
|
|
|
|
|
|
while (len >= CRC32_NUM_CHUNKS * CRC32_FIXED_CHUNK_LEN) { |
6716
|
|
|
|
|
|
|
const u64 *wp0 = (const u64 *)p; |
6717
|
|
|
|
|
|
|
const u64 * const wp0_end = |
6718
|
|
|
|
|
|
|
(const u64 *)(p + CRC32_FIXED_CHUNK_LEN); |
6719
|
|
|
|
|
|
|
u32 crc1 = 0, crc2 = 0, crc3 = 0; |
6720
|
|
|
|
|
|
|
|
6721
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_NUM_CHUNKS == 4); |
6722
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_FIXED_CHUNK_LEN % (4 * 8) == 0); |
6723
|
|
|
|
|
|
|
do { |
6724
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 0*CRC32_FIXED_CHUNK_LEN/8]); |
6725
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 1*CRC32_FIXED_CHUNK_LEN/8]); |
6726
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 2*CRC32_FIXED_CHUNK_LEN/8]); |
6727
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 3*CRC32_FIXED_CHUNK_LEN/8]); |
6728
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_FIXED_CHUNK_LEN/8])); |
6729
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_FIXED_CHUNK_LEN/8])); |
6730
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_FIXED_CHUNK_LEN/8])); |
6731
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_FIXED_CHUNK_LEN/8])); |
6732
|
|
|
|
|
|
|
wp0++; |
6733
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_FIXED_CHUNK_LEN/8])); |
6734
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_FIXED_CHUNK_LEN/8])); |
6735
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_FIXED_CHUNK_LEN/8])); |
6736
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_FIXED_CHUNK_LEN/8])); |
6737
|
|
|
|
|
|
|
wp0++; |
6738
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_FIXED_CHUNK_LEN/8])); |
6739
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_FIXED_CHUNK_LEN/8])); |
6740
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_FIXED_CHUNK_LEN/8])); |
6741
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_FIXED_CHUNK_LEN/8])); |
6742
|
|
|
|
|
|
|
wp0++; |
6743
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_FIXED_CHUNK_LEN/8])); |
6744
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_FIXED_CHUNK_LEN/8])); |
6745
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_FIXED_CHUNK_LEN/8])); |
6746
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_FIXED_CHUNK_LEN/8])); |
6747
|
|
|
|
|
|
|
wp0++; |
6748
|
|
|
|
|
|
|
} while (wp0 != wp0_end); |
6749
|
|
|
|
|
|
|
crc = combine_crcs_slow(crc, crc1, crc2, crc3); |
6750
|
|
|
|
|
|
|
p += CRC32_NUM_CHUNKS * CRC32_FIXED_CHUNK_LEN; |
6751
|
|
|
|
|
|
|
len -= CRC32_NUM_CHUNKS * CRC32_FIXED_CHUNK_LEN; |
6752
|
|
|
|
|
|
|
} |
6753
|
|
|
|
|
|
|
|
6754
|
|
|
|
|
|
|
while (len >= 64) { |
6755
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 0))); |
6756
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 8))); |
6757
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 16))); |
6758
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 24))); |
6759
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 32))); |
6760
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 40))); |
6761
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 48))); |
6762
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 56))); |
6763
|
|
|
|
|
|
|
p += 64; |
6764
|
|
|
|
|
|
|
len -= 64; |
6765
|
|
|
|
|
|
|
} |
6766
|
|
|
|
|
|
|
} |
6767
|
|
|
|
|
|
|
if (len & 32) { |
6768
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 0)); |
6769
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 8)); |
6770
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 16)); |
6771
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 24)); |
6772
|
|
|
|
|
|
|
p += 32; |
6773
|
|
|
|
|
|
|
} |
6774
|
|
|
|
|
|
|
if (len & 16) { |
6775
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 0)); |
6776
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 8)); |
6777
|
|
|
|
|
|
|
p += 16; |
6778
|
|
|
|
|
|
|
} |
6779
|
|
|
|
|
|
|
if (len & 8) { |
6780
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p)); |
6781
|
|
|
|
|
|
|
p += 8; |
6782
|
|
|
|
|
|
|
} |
6783
|
|
|
|
|
|
|
if (len & 4) { |
6784
|
|
|
|
|
|
|
crc = __crc32w(crc, get_unaligned_le32(p)); |
6785
|
|
|
|
|
|
|
p += 4; |
6786
|
|
|
|
|
|
|
} |
6787
|
|
|
|
|
|
|
if (len & 2) { |
6788
|
|
|
|
|
|
|
crc = __crc32h(crc, get_unaligned_le16(p)); |
6789
|
|
|
|
|
|
|
p += 2; |
6790
|
|
|
|
|
|
|
} |
6791
|
|
|
|
|
|
|
if (len & 1) |
6792
|
|
|
|
|
|
|
crc = __crc32b(crc, *p); |
6793
|
|
|
|
|
|
|
return crc; |
6794
|
|
|
|
|
|
|
} |
6795
|
|
|
|
|
|
|
#undef ATTRIBUTES |
6796
|
|
|
|
|
|
|
#endif |
6797
|
|
|
|
|
|
|
|
6798
|
|
|
|
|
|
|
|
6799
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && HAVE_PMULL_INTRIN |
6800
|
|
|
|
|
|
|
# if HAVE_CRC32_NATIVE && HAVE_PMULL_NATIVE && !USE_PMULL_TARGET_EVEN_IF_NATIVE |
6801
|
|
|
|
|
|
|
# define ATTRIBUTES |
6802
|
|
|
|
|
|
|
# else |
6803
|
|
|
|
|
|
|
# ifdef ARCH_ARM32 |
6804
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8-a+crc,fpu=crypto-neon-fp-armv8") |
6805
|
|
|
|
|
|
|
# else |
6806
|
|
|
|
|
|
|
# ifdef __clang__ |
6807
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("crc,aes") |
6808
|
|
|
|
|
|
|
# else |
6809
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crc,+crypto") |
6810
|
|
|
|
|
|
|
# endif |
6811
|
|
|
|
|
|
|
# endif |
6812
|
|
|
|
|
|
|
# endif |
6813
|
|
|
|
|
|
|
|
6814
|
|
|
|
|
|
|
#ifndef _MSC_VER |
6815
|
|
|
|
|
|
|
# include |
6816
|
|
|
|
|
|
|
#endif |
6817
|
|
|
|
|
|
|
#include |
6818
|
|
|
|
|
|
|
|
6819
|
|
|
|
|
|
|
|
6820
|
|
|
|
|
|
|
static forceinline ATTRIBUTES u64 |
6821
|
|
|
|
|
|
|
clmul_u32(u32 a, u32 b) |
6822
|
|
|
|
|
|
|
{ |
6823
|
|
|
|
|
|
|
uint64x2_t res = vreinterpretq_u64_p128( |
6824
|
|
|
|
|
|
|
compat_vmull_p64((poly64_t)a, (poly64_t)b)); |
6825
|
|
|
|
|
|
|
|
6826
|
|
|
|
|
|
|
return vgetq_lane_u64(res, 0); |
6827
|
|
|
|
|
|
|
} |
6828
|
|
|
|
|
|
|
|
6829
|
|
|
|
|
|
|
|
6830
|
|
|
|
|
|
|
static forceinline ATTRIBUTES u32 |
6831
|
|
|
|
|
|
|
combine_crcs_fast(u32 crc0, u32 crc1, u32 crc2, u32 crc3, size_t i) |
6832
|
|
|
|
|
|
|
{ |
6833
|
|
|
|
|
|
|
u64 res0 = clmul_u32(crc0, crc32_mults_for_chunklen[i][0]); |
6834
|
|
|
|
|
|
|
u64 res1 = clmul_u32(crc1, crc32_mults_for_chunklen[i][1]); |
6835
|
|
|
|
|
|
|
u64 res2 = clmul_u32(crc2, crc32_mults_for_chunklen[i][2]); |
6836
|
|
|
|
|
|
|
|
6837
|
|
|
|
|
|
|
return __crc32d(0, res0 ^ res1 ^ res2) ^ crc3; |
6838
|
|
|
|
|
|
|
} |
6839
|
|
|
|
|
|
|
|
6840
|
|
|
|
|
|
|
#define crc32_arm_crc_pmullcombine crc32_arm_crc_pmullcombine |
6841
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
6842
|
|
|
|
|
|
|
crc32_arm_crc_pmullcombine(u32 crc, const u8 *p, size_t len) |
6843
|
|
|
|
|
|
|
{ |
6844
|
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 7; |
6845
|
|
|
|
|
|
|
|
6846
|
|
|
|
|
|
|
if (len >= align + CRC32_NUM_CHUNKS * CRC32_MIN_VARIABLE_CHUNK_LEN) { |
6847
|
|
|
|
|
|
|
|
6848
|
|
|
|
|
|
|
if (align) { |
6849
|
|
|
|
|
|
|
if (align & 1) |
6850
|
|
|
|
|
|
|
crc = __crc32b(crc, *p++); |
6851
|
|
|
|
|
|
|
if (align & 2) { |
6852
|
|
|
|
|
|
|
crc = __crc32h(crc, le16_bswap(*(u16 *)p)); |
6853
|
|
|
|
|
|
|
p += 2; |
6854
|
|
|
|
|
|
|
} |
6855
|
|
|
|
|
|
|
if (align & 4) { |
6856
|
|
|
|
|
|
|
crc = __crc32w(crc, le32_bswap(*(u32 *)p)); |
6857
|
|
|
|
|
|
|
p += 4; |
6858
|
|
|
|
|
|
|
} |
6859
|
|
|
|
|
|
|
len -= align; |
6860
|
|
|
|
|
|
|
} |
6861
|
|
|
|
|
|
|
|
6862
|
|
|
|
|
|
|
while (len >= CRC32_NUM_CHUNKS * CRC32_MAX_VARIABLE_CHUNK_LEN) { |
6863
|
|
|
|
|
|
|
const u64 *wp0 = (const u64 *)p; |
6864
|
|
|
|
|
|
|
const u64 * const wp0_end = |
6865
|
|
|
|
|
|
|
(const u64 *)(p + CRC32_MAX_VARIABLE_CHUNK_LEN); |
6866
|
|
|
|
|
|
|
u32 crc1 = 0, crc2 = 0, crc3 = 0; |
6867
|
|
|
|
|
|
|
|
6868
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_NUM_CHUNKS == 4); |
6869
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_MAX_VARIABLE_CHUNK_LEN % (4 * 8) == 0); |
6870
|
|
|
|
|
|
|
do { |
6871
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 0*CRC32_MAX_VARIABLE_CHUNK_LEN/8]); |
6872
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 1*CRC32_MAX_VARIABLE_CHUNK_LEN/8]); |
6873
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 2*CRC32_MAX_VARIABLE_CHUNK_LEN/8]); |
6874
|
|
|
|
|
|
|
prefetchr(&wp0[64 + 3*CRC32_MAX_VARIABLE_CHUNK_LEN/8]); |
6875
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6876
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6877
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6878
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6879
|
|
|
|
|
|
|
wp0++; |
6880
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6881
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6882
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6883
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6884
|
|
|
|
|
|
|
wp0++; |
6885
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6886
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6887
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6888
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6889
|
|
|
|
|
|
|
wp0++; |
6890
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(wp0[0*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6891
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(wp0[1*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6892
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(wp0[2*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6893
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(wp0[3*CRC32_MAX_VARIABLE_CHUNK_LEN/8])); |
6894
|
|
|
|
|
|
|
wp0++; |
6895
|
|
|
|
|
|
|
} while (wp0 != wp0_end); |
6896
|
|
|
|
|
|
|
crc = combine_crcs_fast(crc, crc1, crc2, crc3, |
6897
|
|
|
|
|
|
|
ARRAY_LEN(crc32_mults_for_chunklen) - 1); |
6898
|
|
|
|
|
|
|
p += CRC32_NUM_CHUNKS * CRC32_MAX_VARIABLE_CHUNK_LEN; |
6899
|
|
|
|
|
|
|
len -= CRC32_NUM_CHUNKS * CRC32_MAX_VARIABLE_CHUNK_LEN; |
6900
|
|
|
|
|
|
|
} |
6901
|
|
|
|
|
|
|
|
6902
|
|
|
|
|
|
|
if (len >= CRC32_NUM_CHUNKS * CRC32_MIN_VARIABLE_CHUNK_LEN) { |
6903
|
|
|
|
|
|
|
const size_t i = len / (CRC32_NUM_CHUNKS * |
6904
|
|
|
|
|
|
|
CRC32_MIN_VARIABLE_CHUNK_LEN); |
6905
|
|
|
|
|
|
|
const size_t chunk_len = |
6906
|
|
|
|
|
|
|
i * CRC32_MIN_VARIABLE_CHUNK_LEN; |
6907
|
|
|
|
|
|
|
const u64 *wp0 = (const u64 *)(p + 0*chunk_len); |
6908
|
|
|
|
|
|
|
const u64 *wp1 = (const u64 *)(p + 1*chunk_len); |
6909
|
|
|
|
|
|
|
const u64 *wp2 = (const u64 *)(p + 2*chunk_len); |
6910
|
|
|
|
|
|
|
const u64 *wp3 = (const u64 *)(p + 3*chunk_len); |
6911
|
|
|
|
|
|
|
const u64 * const wp0_end = wp1; |
6912
|
|
|
|
|
|
|
u32 crc1 = 0, crc2 = 0, crc3 = 0; |
6913
|
|
|
|
|
|
|
|
6914
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_NUM_CHUNKS == 4); |
6915
|
|
|
|
|
|
|
STATIC_ASSERT(CRC32_MIN_VARIABLE_CHUNK_LEN % (4 * 8) == 0); |
6916
|
|
|
|
|
|
|
do { |
6917
|
|
|
|
|
|
|
prefetchr(wp0 + 64); |
6918
|
|
|
|
|
|
|
prefetchr(wp1 + 64); |
6919
|
|
|
|
|
|
|
prefetchr(wp2 + 64); |
6920
|
|
|
|
|
|
|
prefetchr(wp3 + 64); |
6921
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*wp0++)); |
6922
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(*wp1++)); |
6923
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(*wp2++)); |
6924
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(*wp3++)); |
6925
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*wp0++)); |
6926
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(*wp1++)); |
6927
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(*wp2++)); |
6928
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(*wp3++)); |
6929
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*wp0++)); |
6930
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(*wp1++)); |
6931
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(*wp2++)); |
6932
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(*wp3++)); |
6933
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*wp0++)); |
6934
|
|
|
|
|
|
|
crc1 = __crc32d(crc1, le64_bswap(*wp1++)); |
6935
|
|
|
|
|
|
|
crc2 = __crc32d(crc2, le64_bswap(*wp2++)); |
6936
|
|
|
|
|
|
|
crc3 = __crc32d(crc3, le64_bswap(*wp3++)); |
6937
|
|
|
|
|
|
|
} while (wp0 != wp0_end); |
6938
|
|
|
|
|
|
|
crc = combine_crcs_fast(crc, crc1, crc2, crc3, i); |
6939
|
|
|
|
|
|
|
p += CRC32_NUM_CHUNKS * chunk_len; |
6940
|
|
|
|
|
|
|
len -= CRC32_NUM_CHUNKS * chunk_len; |
6941
|
|
|
|
|
|
|
} |
6942
|
|
|
|
|
|
|
|
6943
|
|
|
|
|
|
|
while (len >= 32) { |
6944
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 0))); |
6945
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 8))); |
6946
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 16))); |
6947
|
|
|
|
|
|
|
crc = __crc32d(crc, le64_bswap(*(u64 *)(p + 24))); |
6948
|
|
|
|
|
|
|
p += 32; |
6949
|
|
|
|
|
|
|
len -= 32; |
6950
|
|
|
|
|
|
|
} |
6951
|
|
|
|
|
|
|
} else { |
6952
|
|
|
|
|
|
|
while (len >= 32) { |
6953
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 0)); |
6954
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 8)); |
6955
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 16)); |
6956
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 24)); |
6957
|
|
|
|
|
|
|
p += 32; |
6958
|
|
|
|
|
|
|
len -= 32; |
6959
|
|
|
|
|
|
|
} |
6960
|
|
|
|
|
|
|
} |
6961
|
|
|
|
|
|
|
if (len & 16) { |
6962
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 0)); |
6963
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p + 8)); |
6964
|
|
|
|
|
|
|
p += 16; |
6965
|
|
|
|
|
|
|
} |
6966
|
|
|
|
|
|
|
if (len & 8) { |
6967
|
|
|
|
|
|
|
crc = __crc32d(crc, get_unaligned_le64(p)); |
6968
|
|
|
|
|
|
|
p += 8; |
6969
|
|
|
|
|
|
|
} |
6970
|
|
|
|
|
|
|
if (len & 4) { |
6971
|
|
|
|
|
|
|
crc = __crc32w(crc, get_unaligned_le32(p)); |
6972
|
|
|
|
|
|
|
p += 4; |
6973
|
|
|
|
|
|
|
} |
6974
|
|
|
|
|
|
|
if (len & 2) { |
6975
|
|
|
|
|
|
|
crc = __crc32h(crc, get_unaligned_le16(p)); |
6976
|
|
|
|
|
|
|
p += 2; |
6977
|
|
|
|
|
|
|
} |
6978
|
|
|
|
|
|
|
if (len & 1) |
6979
|
|
|
|
|
|
|
crc = __crc32b(crc, *p); |
6980
|
|
|
|
|
|
|
return crc; |
6981
|
|
|
|
|
|
|
} |
6982
|
|
|
|
|
|
|
#undef ATTRIBUTES |
6983
|
|
|
|
|
|
|
#endif |
6984
|
|
|
|
|
|
|
|
6985
|
|
|
|
|
|
|
|
6986
|
|
|
|
|
|
|
#if HAVE_PMULL_INTRIN |
6987
|
|
|
|
|
|
|
# define crc32_arm_pmullx4 crc32_arm_pmullx4 |
6988
|
|
|
|
|
|
|
# define SUFFIX _pmullx4 |
6989
|
|
|
|
|
|
|
# if HAVE_PMULL_NATIVE && !USE_PMULL_TARGET_EVEN_IF_NATIVE |
6990
|
|
|
|
|
|
|
# define ATTRIBUTES |
6991
|
|
|
|
|
|
|
# else |
6992
|
|
|
|
|
|
|
# ifdef ARCH_ARM32 |
6993
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("fpu=crypto-neon-fp-armv8") |
6994
|
|
|
|
|
|
|
# else |
6995
|
|
|
|
|
|
|
# ifdef __clang__ |
6996
|
|
|
|
|
|
|
|
6997
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("aes") |
6998
|
|
|
|
|
|
|
# else |
6999
|
|
|
|
|
|
|
|
7000
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crypto") |
7001
|
|
|
|
|
|
|
# endif |
7002
|
|
|
|
|
|
|
# endif |
7003
|
|
|
|
|
|
|
# endif |
7004
|
|
|
|
|
|
|
# define ENABLE_EOR3 0 |
7005
|
|
|
|
|
|
|
/* #include "arm-crc32_pmull_helpers.h" */ |
7006
|
|
|
|
|
|
|
|
7007
|
|
|
|
|
|
|
|
7008
|
|
|
|
|
|
|
|
7009
|
|
|
|
|
|
|
|
7010
|
|
|
|
|
|
|
#include |
7011
|
|
|
|
|
|
|
|
7012
|
|
|
|
|
|
|
|
7013
|
|
|
|
|
|
|
#undef u32_to_bytevec |
7014
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7015
|
|
|
|
|
|
|
ADD_SUFFIX(u32_to_bytevec)(u32 a) |
7016
|
|
|
|
|
|
|
{ |
7017
|
|
|
|
|
|
|
return vreinterpretq_u8_u32(vsetq_lane_u32(a, vdupq_n_u32(0), 0)); |
7018
|
|
|
|
|
|
|
} |
7019
|
|
|
|
|
|
|
#define u32_to_bytevec ADD_SUFFIX(u32_to_bytevec) |
7020
|
|
|
|
|
|
|
|
7021
|
|
|
|
|
|
|
|
7022
|
|
|
|
|
|
|
#undef load_multipliers |
7023
|
|
|
|
|
|
|
static forceinline ATTRIBUTES poly64x2_t |
7024
|
|
|
|
|
|
|
ADD_SUFFIX(load_multipliers)(const u64 p[2]) |
7025
|
|
|
|
|
|
|
{ |
7026
|
|
|
|
|
|
|
return vreinterpretq_p64_u64(vld1q_u64(p)); |
7027
|
|
|
|
|
|
|
} |
7028
|
|
|
|
|
|
|
#define load_multipliers ADD_SUFFIX(load_multipliers) |
7029
|
|
|
|
|
|
|
|
7030
|
|
|
|
|
|
|
|
7031
|
|
|
|
|
|
|
#undef clmul_low |
7032
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7033
|
|
|
|
|
|
|
ADD_SUFFIX(clmul_low)(uint8x16_t a, poly64x2_t b) |
7034
|
|
|
|
|
|
|
{ |
7035
|
|
|
|
|
|
|
return vreinterpretq_u8_p128( |
7036
|
|
|
|
|
|
|
compat_vmull_p64(vgetq_lane_p64(vreinterpretq_p64_u8(a), 0), |
7037
|
|
|
|
|
|
|
vgetq_lane_p64(b, 0))); |
7038
|
|
|
|
|
|
|
} |
7039
|
|
|
|
|
|
|
#define clmul_low ADD_SUFFIX(clmul_low) |
7040
|
|
|
|
|
|
|
|
7041
|
|
|
|
|
|
|
|
7042
|
|
|
|
|
|
|
#undef clmul_high |
7043
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7044
|
|
|
|
|
|
|
ADD_SUFFIX(clmul_high)(uint8x16_t a, poly64x2_t b) |
7045
|
|
|
|
|
|
|
{ |
7046
|
|
|
|
|
|
|
#if defined(__clang__) && defined(ARCH_ARM64) |
7047
|
|
|
|
|
|
|
|
7048
|
|
|
|
|
|
|
uint8x16_t res; |
7049
|
|
|
|
|
|
|
|
7050
|
|
|
|
|
|
|
__asm__("pmull2 %0.1q, %1.2d, %2.2d" : "=w" (res) : "w" (a), "w" (b)); |
7051
|
|
|
|
|
|
|
return res; |
7052
|
|
|
|
|
|
|
#else |
7053
|
|
|
|
|
|
|
return vreinterpretq_u8_p128(vmull_high_p64(vreinterpretq_p64_u8(a), b)); |
7054
|
|
|
|
|
|
|
#endif |
7055
|
|
|
|
|
|
|
} |
7056
|
|
|
|
|
|
|
#define clmul_high ADD_SUFFIX(clmul_high) |
7057
|
|
|
|
|
|
|
|
7058
|
|
|
|
|
|
|
#undef eor3 |
7059
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7060
|
|
|
|
|
|
|
ADD_SUFFIX(eor3)(uint8x16_t a, uint8x16_t b, uint8x16_t c) |
7061
|
|
|
|
|
|
|
{ |
7062
|
|
|
|
|
|
|
#if ENABLE_EOR3 |
7063
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN |
7064
|
|
|
|
|
|
|
return veor3q_u8(a, b, c); |
7065
|
|
|
|
|
|
|
#else |
7066
|
|
|
|
|
|
|
uint8x16_t res; |
7067
|
|
|
|
|
|
|
|
7068
|
|
|
|
|
|
|
__asm__("eor3 %0.16b, %1.16b, %2.16b, %3.16b" |
7069
|
|
|
|
|
|
|
: "=w" (res) : "w" (a), "w" (b), "w" (c)); |
7070
|
|
|
|
|
|
|
return res; |
7071
|
|
|
|
|
|
|
#endif |
7072
|
|
|
|
|
|
|
#else |
7073
|
|
|
|
|
|
|
return veorq_u8(veorq_u8(a, b), c); |
7074
|
|
|
|
|
|
|
#endif |
7075
|
|
|
|
|
|
|
} |
7076
|
|
|
|
|
|
|
#define eor3 ADD_SUFFIX(eor3) |
7077
|
|
|
|
|
|
|
|
7078
|
|
|
|
|
|
|
#undef fold_vec |
7079
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7080
|
|
|
|
|
|
|
ADD_SUFFIX(fold_vec)(uint8x16_t src, uint8x16_t dst, poly64x2_t multipliers) |
7081
|
|
|
|
|
|
|
{ |
7082
|
|
|
|
|
|
|
uint8x16_t a = clmul_low(src, multipliers); |
7083
|
|
|
|
|
|
|
uint8x16_t b = clmul_high(src, multipliers); |
7084
|
|
|
|
|
|
|
|
7085
|
|
|
|
|
|
|
return eor3(a, b, dst); |
7086
|
|
|
|
|
|
|
} |
7087
|
|
|
|
|
|
|
#define fold_vec ADD_SUFFIX(fold_vec) |
7088
|
|
|
|
|
|
|
|
7089
|
|
|
|
|
|
|
#undef vtbl |
7090
|
|
|
|
|
|
|
static forceinline ATTRIBUTES uint8x16_t |
7091
|
|
|
|
|
|
|
ADD_SUFFIX(vtbl)(uint8x16_t table, uint8x16_t indices) |
7092
|
|
|
|
|
|
|
{ |
7093
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
7094
|
|
|
|
|
|
|
return vqtbl1q_u8(table, indices); |
7095
|
|
|
|
|
|
|
#else |
7096
|
|
|
|
|
|
|
uint8x8x2_t tab2; |
7097
|
|
|
|
|
|
|
|
7098
|
|
|
|
|
|
|
tab2.val[0] = vget_low_u8(table); |
7099
|
|
|
|
|
|
|
tab2.val[1] = vget_high_u8(table); |
7100
|
|
|
|
|
|
|
|
7101
|
|
|
|
|
|
|
return vcombine_u8(vtbl2_u8(tab2, vget_low_u8(indices)), |
7102
|
|
|
|
|
|
|
vtbl2_u8(tab2, vget_high_u8(indices))); |
7103
|
|
|
|
|
|
|
#endif |
7104
|
|
|
|
|
|
|
} |
7105
|
|
|
|
|
|
|
#define vtbl ADD_SUFFIX(vtbl) |
7106
|
|
|
|
|
|
|
|
7107
|
|
|
|
|
|
|
|
7108
|
|
|
|
|
|
|
#undef fold_partial_vec |
7109
|
|
|
|
|
|
|
static forceinline ATTRIBUTES MAYBE_UNUSED uint8x16_t |
7110
|
|
|
|
|
|
|
ADD_SUFFIX(fold_partial_vec)(uint8x16_t v, const u8 *p, size_t len, |
7111
|
|
|
|
|
|
|
poly64x2_t multipliers_1) |
7112
|
|
|
|
|
|
|
{ |
7113
|
|
|
|
|
|
|
|
7114
|
|
|
|
|
|
|
static const u8 shift_tab[48] = { |
7115
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
7116
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
7117
|
|
|
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
7118
|
|
|
|
|
|
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
7119
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
7120
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
7121
|
|
|
|
|
|
|
}; |
7122
|
|
|
|
|
|
|
const uint8x16_t lshift = vld1q_u8(&shift_tab[len]); |
7123
|
|
|
|
|
|
|
const uint8x16_t rshift = vld1q_u8(&shift_tab[len + 16]); |
7124
|
|
|
|
|
|
|
uint8x16_t x0, x1, bsl_mask; |
7125
|
|
|
|
|
|
|
|
7126
|
|
|
|
|
|
|
|
7127
|
|
|
|
|
|
|
x0 = vtbl(v, lshift); |
7128
|
|
|
|
|
|
|
|
7129
|
|
|
|
|
|
|
|
7130
|
|
|
|
|
|
|
bsl_mask = vreinterpretq_u8_s8( |
7131
|
|
|
|
|
|
|
vshrq_n_s8(vreinterpretq_s8_u8(rshift), 7)); |
7132
|
|
|
|
|
|
|
|
7133
|
|
|
|
|
|
|
|
7134
|
|
|
|
|
|
|
x1 = vbslq_u8(bsl_mask , |
7135
|
|
|
|
|
|
|
vld1q_u8(p + len - 16), vtbl(v, rshift)); |
7136
|
|
|
|
|
|
|
|
7137
|
|
|
|
|
|
|
return fold_vec(x0, x1, multipliers_1); |
7138
|
|
|
|
|
|
|
} |
7139
|
|
|
|
|
|
|
#define fold_partial_vec ADD_SUFFIX(fold_partial_vec) |
7140
|
|
|
|
|
|
|
|
7141
|
|
|
|
|
|
|
|
7142
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
7143
|
|
|
|
|
|
|
crc32_arm_pmullx4(u32 crc, const u8 *p, size_t len) |
7144
|
|
|
|
|
|
|
{ |
7145
|
|
|
|
|
|
|
static const u64 _aligned_attribute(16) mults[3][2] = { |
7146
|
|
|
|
|
|
|
CRC32_1VECS_MULTS, |
7147
|
|
|
|
|
|
|
CRC32_4VECS_MULTS, |
7148
|
|
|
|
|
|
|
CRC32_2VECS_MULTS, |
7149
|
|
|
|
|
|
|
}; |
7150
|
|
|
|
|
|
|
static const u64 _aligned_attribute(16) final_mults[3][2] = { |
7151
|
|
|
|
|
|
|
{ CRC32_FINAL_MULT, 0 }, |
7152
|
|
|
|
|
|
|
{ CRC32_BARRETT_CONSTANT_1, 0 }, |
7153
|
|
|
|
|
|
|
{ CRC32_BARRETT_CONSTANT_2, 0 }, |
7154
|
|
|
|
|
|
|
}; |
7155
|
|
|
|
|
|
|
const uint8x16_t zeroes = vdupq_n_u8(0); |
7156
|
|
|
|
|
|
|
const uint8x16_t mask32 = vreinterpretq_u8_u64(vdupq_n_u64(0xFFFFFFFF)); |
7157
|
|
|
|
|
|
|
const poly64x2_t multipliers_1 = load_multipliers(mults[0]); |
7158
|
|
|
|
|
|
|
uint8x16_t v0, v1, v2, v3; |
7159
|
|
|
|
|
|
|
|
7160
|
|
|
|
|
|
|
if (len < 64 + 15) { |
7161
|
|
|
|
|
|
|
if (len < 16) |
7162
|
|
|
|
|
|
|
return crc32_slice1(crc, p, len); |
7163
|
|
|
|
|
|
|
v0 = veorq_u8(vld1q_u8(p), u32_to_bytevec(crc)); |
7164
|
|
|
|
|
|
|
p += 16; |
7165
|
|
|
|
|
|
|
len -= 16; |
7166
|
|
|
|
|
|
|
while (len >= 16) { |
7167
|
|
|
|
|
|
|
v0 = fold_vec(v0, vld1q_u8(p), multipliers_1); |
7168
|
|
|
|
|
|
|
p += 16; |
7169
|
|
|
|
|
|
|
len -= 16; |
7170
|
|
|
|
|
|
|
} |
7171
|
|
|
|
|
|
|
} else { |
7172
|
|
|
|
|
|
|
const poly64x2_t multipliers_4 = load_multipliers(mults[1]); |
7173
|
|
|
|
|
|
|
const poly64x2_t multipliers_2 = load_multipliers(mults[2]); |
7174
|
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 15; |
7175
|
|
|
|
|
|
|
const uint8x16_t *vp; |
7176
|
|
|
|
|
|
|
|
7177
|
|
|
|
|
|
|
v0 = veorq_u8(vld1q_u8(p), u32_to_bytevec(crc)); |
7178
|
|
|
|
|
|
|
p += 16; |
7179
|
|
|
|
|
|
|
|
7180
|
|
|
|
|
|
|
if (align) { |
7181
|
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, align, multipliers_1); |
7182
|
|
|
|
|
|
|
p += align; |
7183
|
|
|
|
|
|
|
len -= align; |
7184
|
|
|
|
|
|
|
} |
7185
|
|
|
|
|
|
|
vp = (const uint8x16_t *)p; |
7186
|
|
|
|
|
|
|
v1 = *vp++; |
7187
|
|
|
|
|
|
|
v2 = *vp++; |
7188
|
|
|
|
|
|
|
v3 = *vp++; |
7189
|
|
|
|
|
|
|
while (len >= 64 + 64) { |
7190
|
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_4); |
7191
|
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_4); |
7192
|
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_4); |
7193
|
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_4); |
7194
|
|
|
|
|
|
|
len -= 64; |
7195
|
|
|
|
|
|
|
} |
7196
|
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
7197
|
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
7198
|
|
|
|
|
|
|
if (len & 32) { |
7199
|
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_2); |
7200
|
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_2); |
7201
|
|
|
|
|
|
|
} |
7202
|
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
7203
|
|
|
|
|
|
|
if (len & 16) |
7204
|
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_1); |
7205
|
|
|
|
|
|
|
p = (const u8 *)vp; |
7206
|
|
|
|
|
|
|
len &= 15; |
7207
|
|
|
|
|
|
|
} |
7208
|
|
|
|
|
|
|
|
7209
|
|
|
|
|
|
|
|
7210
|
|
|
|
|
|
|
if (len) |
7211
|
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, len, multipliers_1); |
7212
|
|
|
|
|
|
|
|
7213
|
|
|
|
|
|
|
|
7214
|
|
|
|
|
|
|
|
7215
|
|
|
|
|
|
|
v0 = veorq_u8(vextq_u8(v0, zeroes, 8), |
7216
|
|
|
|
|
|
|
clmul_high(vextq_u8(zeroes, v0, 8), multipliers_1)); |
7217
|
|
|
|
|
|
|
|
7218
|
|
|
|
|
|
|
|
7219
|
|
|
|
|
|
|
v0 = veorq_u8(vextq_u8(v0, zeroes, 4), |
7220
|
|
|
|
|
|
|
clmul_low(vandq_u8(v0, mask32), |
7221
|
|
|
|
|
|
|
load_multipliers(final_mults[0]))); |
7222
|
|
|
|
|
|
|
|
7223
|
|
|
|
|
|
|
|
7224
|
|
|
|
|
|
|
v1 = clmul_low(vandq_u8(v0, mask32), load_multipliers(final_mults[1])); |
7225
|
|
|
|
|
|
|
v1 = clmul_low(vandq_u8(v1, mask32), load_multipliers(final_mults[2])); |
7226
|
|
|
|
|
|
|
return vgetq_lane_u32(vreinterpretq_u32_u8(veorq_u8(v0, v1)), 1); |
7227
|
|
|
|
|
|
|
} |
7228
|
|
|
|
|
|
|
#undef SUFFIX |
7229
|
|
|
|
|
|
|
#undef ATTRIBUTES |
7230
|
|
|
|
|
|
|
#undef ENABLE_EOR3 |
7231
|
|
|
|
|
|
|
#endif |
7232
|
|
|
|
|
|
|
|
7233
|
|
|
|
|
|
|
|
7234
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && HAVE_PMULL_INTRIN && HAVE_CRC32_INTRIN |
7235
|
|
|
|
|
|
|
# define crc32_arm_pmullx12_crc crc32_arm_pmullx12_crc |
7236
|
|
|
|
|
|
|
# define SUFFIX _pmullx12_crc |
7237
|
|
|
|
|
|
|
# if HAVE_PMULL_NATIVE && HAVE_CRC32_NATIVE && !USE_PMULL_TARGET_EVEN_IF_NATIVE |
7238
|
|
|
|
|
|
|
# define ATTRIBUTES |
7239
|
|
|
|
|
|
|
# else |
7240
|
|
|
|
|
|
|
# ifdef __clang__ |
7241
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("aes,crc") |
7242
|
|
|
|
|
|
|
# else |
7243
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crypto,+crc") |
7244
|
|
|
|
|
|
|
# endif |
7245
|
|
|
|
|
|
|
# endif |
7246
|
|
|
|
|
|
|
# define ENABLE_EOR3 0 |
7247
|
|
|
|
|
|
|
#include "arm-crc32_pmull_wide.h" |
7248
|
|
|
|
|
|
|
#endif |
7249
|
|
|
|
|
|
|
|
7250
|
|
|
|
|
|
|
|
7251
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && HAVE_PMULL_INTRIN && HAVE_CRC32_INTRIN && \ |
7252
|
|
|
|
|
|
|
(HAVE_SHA3_TARGET || HAVE_SHA3_NATIVE) |
7253
|
|
|
|
|
|
|
# define crc32_arm_pmullx12_crc_eor3 crc32_arm_pmullx12_crc_eor3 |
7254
|
|
|
|
|
|
|
# define SUFFIX _pmullx12_crc_eor3 |
7255
|
|
|
|
|
|
|
# if HAVE_PMULL_NATIVE && HAVE_CRC32_NATIVE && HAVE_SHA3_NATIVE && \ |
7256
|
|
|
|
|
|
|
!USE_PMULL_TARGET_EVEN_IF_NATIVE |
7257
|
|
|
|
|
|
|
# define ATTRIBUTES |
7258
|
|
|
|
|
|
|
# else |
7259
|
|
|
|
|
|
|
# ifdef __clang__ |
7260
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("aes,crc,sha3") |
7261
|
|
|
|
|
|
|
|
7262
|
|
|
|
|
|
|
# elif defined(__ARM_FEATURE_JCVT) |
7263
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("+crypto,+crc,+sha3") |
7264
|
|
|
|
|
|
|
# else |
7265
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("arch=armv8.2-a+crypto+crc+sha3") |
7266
|
|
|
|
|
|
|
# endif |
7267
|
|
|
|
|
|
|
# endif |
7268
|
|
|
|
|
|
|
# define ENABLE_EOR3 1 |
7269
|
|
|
|
|
|
|
#include "arm-crc32_pmull_wide.h" |
7270
|
|
|
|
|
|
|
#endif |
7271
|
|
|
|
|
|
|
|
7272
|
|
|
|
|
|
|
|
7273
|
|
|
|
|
|
|
#define PREFER_PMULL_TO_CRC 0 |
7274
|
|
|
|
|
|
|
#ifdef __APPLE__ |
7275
|
|
|
|
|
|
|
# include |
7276
|
|
|
|
|
|
|
# if TARGET_OS_OSX |
7277
|
|
|
|
|
|
|
# undef PREFER_PMULL_TO_CRC |
7278
|
|
|
|
|
|
|
# define PREFER_PMULL_TO_CRC 1 |
7279
|
|
|
|
|
|
|
# endif |
7280
|
|
|
|
|
|
|
#endif |
7281
|
|
|
|
|
|
|
|
7282
|
|
|
|
|
|
|
|
7283
|
|
|
|
|
|
|
#if PREFER_PMULL_TO_CRC && defined(crc32_arm_pmullx12_crc_eor3) && \ |
7284
|
|
|
|
|
|
|
HAVE_PMULL_NATIVE && HAVE_CRC32_NATIVE && HAVE_SHA3_NATIVE |
7285
|
|
|
|
|
|
|
# define DEFAULT_IMPL crc32_arm_pmullx12_crc_eor3 |
7286
|
|
|
|
|
|
|
#elif !PREFER_PMULL_TO_CRC && defined(crc32_arm_crc_pmullcombine) && \ |
7287
|
|
|
|
|
|
|
HAVE_CRC32_NATIVE && HAVE_PMULL_NATIVE |
7288
|
|
|
|
|
|
|
# define DEFAULT_IMPL crc32_arm_crc_pmullcombine |
7289
|
|
|
|
|
|
|
#else |
7290
|
|
|
|
|
|
|
static inline crc32_func_t |
7291
|
|
|
|
|
|
|
arch_select_crc32_func(void) |
7292
|
|
|
|
|
|
|
{ |
7293
|
|
|
|
|
|
|
const u32 features MAYBE_UNUSED = get_arm_cpu_features(); |
7294
|
|
|
|
|
|
|
|
7295
|
|
|
|
|
|
|
#if PREFER_PMULL_TO_CRC && defined(crc32_arm_pmullx12_crc_eor3) |
7296
|
|
|
|
|
|
|
if (HAVE_PMULL(features) && HAVE_CRC32(features) && HAVE_SHA3(features)) |
7297
|
|
|
|
|
|
|
return crc32_arm_pmullx12_crc_eor3; |
7298
|
|
|
|
|
|
|
#endif |
7299
|
|
|
|
|
|
|
#if PREFER_PMULL_TO_CRC && defined(crc32_arm_pmullx12_crc) |
7300
|
|
|
|
|
|
|
if (HAVE_PMULL(features) && HAVE_CRC32(features)) |
7301
|
|
|
|
|
|
|
return crc32_arm_pmullx12_crc; |
7302
|
|
|
|
|
|
|
#endif |
7303
|
|
|
|
|
|
|
#ifdef crc32_arm_crc_pmullcombine |
7304
|
|
|
|
|
|
|
if (HAVE_CRC32(features) && HAVE_PMULL(features)) |
7305
|
|
|
|
|
|
|
return crc32_arm_crc_pmullcombine; |
7306
|
|
|
|
|
|
|
#endif |
7307
|
|
|
|
|
|
|
#ifdef crc32_arm_crc |
7308
|
|
|
|
|
|
|
if (HAVE_CRC32(features)) |
7309
|
|
|
|
|
|
|
return crc32_arm_crc; |
7310
|
|
|
|
|
|
|
#endif |
7311
|
|
|
|
|
|
|
#ifdef crc32_arm_pmullx4 |
7312
|
|
|
|
|
|
|
if (HAVE_PMULL(features)) |
7313
|
|
|
|
|
|
|
return crc32_arm_pmullx4; |
7314
|
|
|
|
|
|
|
#endif |
7315
|
|
|
|
|
|
|
return NULL; |
7316
|
|
|
|
|
|
|
} |
7317
|
|
|
|
|
|
|
#define arch_select_crc32_func arch_select_crc32_func |
7318
|
|
|
|
|
|
|
#endif |
7319
|
|
|
|
|
|
|
|
7320
|
|
|
|
|
|
|
#endif |
7321
|
|
|
|
|
|
|
|
7322
|
|
|
|
|
|
|
#elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
7323
|
|
|
|
|
|
|
/* # include "x86/crc32_impl.h" */ |
7324
|
|
|
|
|
|
|
|
7325
|
|
|
|
|
|
|
|
7326
|
|
|
|
|
|
|
#ifndef LIB_X86_CRC32_IMPL_H |
7327
|
|
|
|
|
|
|
#define LIB_X86_CRC32_IMPL_H |
7328
|
|
|
|
|
|
|
|
7329
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
7330
|
|
|
|
|
|
|
|
7331
|
|
|
|
|
|
|
|
7332
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
7333
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
7334
|
|
|
|
|
|
|
|
7335
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
7336
|
|
|
|
|
|
|
|
7337
|
|
|
|
|
|
|
|
7338
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
7339
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
7340
|
|
|
|
|
|
|
|
7341
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
7342
|
|
|
|
|
|
|
|
7343
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
7344
|
|
|
|
|
|
|
#endif |
7345
|
|
|
|
|
|
|
|
7346
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
7347
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
7348
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
7349
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
7350
|
|
|
|
|
|
|
#else |
7351
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
7352
|
|
|
|
|
|
|
#endif |
7353
|
|
|
|
|
|
|
|
7354
|
|
|
|
|
|
|
|
7355
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
7356
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
7357
|
|
|
|
|
|
|
#else |
7358
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
7359
|
|
|
|
|
|
|
#endif |
7360
|
|
|
|
|
|
|
|
7361
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
7362
|
|
|
|
|
|
|
|
7363
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
7364
|
|
|
|
|
|
|
|
7365
|
|
|
|
|
|
|
|
7366
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
7367
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
7368
|
|
|
|
|
|
|
|
7369
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
7370
|
|
|
|
|
|
|
|
7371
|
|
|
|
|
|
|
|
7372
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
7373
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
7374
|
|
|
|
|
|
|
|
7375
|
|
|
|
|
|
|
#include |
7376
|
|
|
|
|
|
|
#include |
7377
|
|
|
|
|
|
|
|
7378
|
|
|
|
|
|
|
#ifdef __cplusplus |
7379
|
|
|
|
|
|
|
extern "C" { |
7380
|
|
|
|
|
|
|
#endif |
7381
|
|
|
|
|
|
|
|
7382
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
7383
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
7384
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
7385
|
|
|
|
|
|
|
|
7386
|
|
|
|
|
|
|
|
7387
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
7388
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
7389
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
7390
|
|
|
|
|
|
|
# else |
7391
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
7392
|
|
|
|
|
|
|
# endif |
7393
|
|
|
|
|
|
|
#endif |
7394
|
|
|
|
|
|
|
|
7395
|
|
|
|
|
|
|
|
7396
|
|
|
|
|
|
|
|
7397
|
|
|
|
|
|
|
|
7398
|
|
|
|
|
|
|
|
7399
|
|
|
|
|
|
|
struct libdeflate_compressor; |
7400
|
|
|
|
|
|
|
|
7401
|
|
|
|
|
|
|
|
7402
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
7403
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
7404
|
|
|
|
|
|
|
|
7405
|
|
|
|
|
|
|
|
7406
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7407
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
7408
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7409
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
7410
|
|
|
|
|
|
|
|
7411
|
|
|
|
|
|
|
|
7412
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7413
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
7414
|
|
|
|
|
|
|
size_t in_nbytes); |
7415
|
|
|
|
|
|
|
|
7416
|
|
|
|
|
|
|
|
7417
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7418
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
7419
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7420
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
7421
|
|
|
|
|
|
|
|
7422
|
|
|
|
|
|
|
|
7423
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7424
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
7425
|
|
|
|
|
|
|
size_t in_nbytes); |
7426
|
|
|
|
|
|
|
|
7427
|
|
|
|
|
|
|
|
7428
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7429
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
7430
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7431
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
7432
|
|
|
|
|
|
|
|
7433
|
|
|
|
|
|
|
|
7434
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
7435
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
7436
|
|
|
|
|
|
|
size_t in_nbytes); |
7437
|
|
|
|
|
|
|
|
7438
|
|
|
|
|
|
|
|
7439
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
7440
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
7441
|
|
|
|
|
|
|
|
7442
|
|
|
|
|
|
|
|
7443
|
|
|
|
|
|
|
|
7444
|
|
|
|
|
|
|
|
7445
|
|
|
|
|
|
|
|
7446
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
7447
|
|
|
|
|
|
|
|
7448
|
|
|
|
|
|
|
|
7449
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
7450
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
7451
|
|
|
|
|
|
|
|
7452
|
|
|
|
|
|
|
|
7453
|
|
|
|
|
|
|
enum libdeflate_result { |
7454
|
|
|
|
|
|
|
|
7455
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
7456
|
|
|
|
|
|
|
|
7457
|
|
|
|
|
|
|
|
7458
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
7459
|
|
|
|
|
|
|
|
7460
|
|
|
|
|
|
|
|
7461
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
7462
|
|
|
|
|
|
|
|
7463
|
|
|
|
|
|
|
|
7464
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
7465
|
|
|
|
|
|
|
}; |
7466
|
|
|
|
|
|
|
|
7467
|
|
|
|
|
|
|
|
7468
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7469
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
7470
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7471
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7472
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7473
|
|
|
|
|
|
|
|
7474
|
|
|
|
|
|
|
|
7475
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7476
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
7477
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7478
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7479
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
7480
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7481
|
|
|
|
|
|
|
|
7482
|
|
|
|
|
|
|
|
7483
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7484
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
7485
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7486
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7487
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7488
|
|
|
|
|
|
|
|
7489
|
|
|
|
|
|
|
|
7490
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7491
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
7492
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7493
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7494
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
7495
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7496
|
|
|
|
|
|
|
|
7497
|
|
|
|
|
|
|
|
7498
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7499
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
7500
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7501
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7502
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7503
|
|
|
|
|
|
|
|
7504
|
|
|
|
|
|
|
|
7505
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
7506
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
7507
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
7508
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
7509
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
7510
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
7511
|
|
|
|
|
|
|
|
7512
|
|
|
|
|
|
|
|
7513
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
7514
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
7515
|
|
|
|
|
|
|
|
7516
|
|
|
|
|
|
|
|
7517
|
|
|
|
|
|
|
|
7518
|
|
|
|
|
|
|
|
7519
|
|
|
|
|
|
|
|
7520
|
|
|
|
|
|
|
|
7521
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
7522
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
7523
|
|
|
|
|
|
|
|
7524
|
|
|
|
|
|
|
|
7525
|
|
|
|
|
|
|
|
7526
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
7527
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
7528
|
|
|
|
|
|
|
|
7529
|
|
|
|
|
|
|
|
7530
|
|
|
|
|
|
|
|
7531
|
|
|
|
|
|
|
|
7532
|
|
|
|
|
|
|
|
7533
|
|
|
|
|
|
|
|
7534
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
7535
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
7536
|
|
|
|
|
|
|
void (*free_func)(void *)); |
7537
|
|
|
|
|
|
|
|
7538
|
|
|
|
|
|
|
#ifdef __cplusplus |
7539
|
|
|
|
|
|
|
} |
7540
|
|
|
|
|
|
|
#endif |
7541
|
|
|
|
|
|
|
|
7542
|
|
|
|
|
|
|
#endif |
7543
|
|
|
|
|
|
|
|
7544
|
|
|
|
|
|
|
|
7545
|
|
|
|
|
|
|
#include |
7546
|
|
|
|
|
|
|
#include |
7547
|
|
|
|
|
|
|
#include |
7548
|
|
|
|
|
|
|
#ifdef _MSC_VER |
7549
|
|
|
|
|
|
|
# include |
7550
|
|
|
|
|
|
|
# include |
7551
|
|
|
|
|
|
|
|
7552
|
|
|
|
|
|
|
|
7553
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
7554
|
|
|
|
|
|
|
|
7555
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
7556
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
7557
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
7558
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
7559
|
|
|
|
|
|
|
|
7560
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
7561
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
7562
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
7563
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
7564
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
7565
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
7566
|
|
|
|
|
|
|
#endif |
7567
|
|
|
|
|
|
|
#ifndef FREESTANDING |
7568
|
|
|
|
|
|
|
# include |
7569
|
|
|
|
|
|
|
#endif |
7570
|
|
|
|
|
|
|
|
7571
|
|
|
|
|
|
|
|
7572
|
|
|
|
|
|
|
|
7573
|
|
|
|
|
|
|
|
7574
|
|
|
|
|
|
|
|
7575
|
|
|
|
|
|
|
|
7576
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
7577
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
7578
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
7579
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
7580
|
|
|
|
|
|
|
#ifdef _MSC_VER |
7581
|
|
|
|
|
|
|
# if defined(_M_X64) |
7582
|
|
|
|
|
|
|
# define ARCH_X86_64 |
7583
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
7584
|
|
|
|
|
|
|
# define ARCH_X86_32 |
7585
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
7586
|
|
|
|
|
|
|
# define ARCH_ARM64 |
7587
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
7588
|
|
|
|
|
|
|
# define ARCH_ARM32 |
7589
|
|
|
|
|
|
|
# endif |
7590
|
|
|
|
|
|
|
#else |
7591
|
|
|
|
|
|
|
# if defined(__x86_64__) |
7592
|
|
|
|
|
|
|
# define ARCH_X86_64 |
7593
|
|
|
|
|
|
|
# elif defined(__i386__) |
7594
|
|
|
|
|
|
|
# define ARCH_X86_32 |
7595
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
7596
|
|
|
|
|
|
|
# define ARCH_ARM64 |
7597
|
|
|
|
|
|
|
# elif defined(__arm__) |
7598
|
|
|
|
|
|
|
# define ARCH_ARM32 |
7599
|
|
|
|
|
|
|
# endif |
7600
|
|
|
|
|
|
|
#endif |
7601
|
|
|
|
|
|
|
|
7602
|
|
|
|
|
|
|
|
7603
|
|
|
|
|
|
|
|
7604
|
|
|
|
|
|
|
|
7605
|
|
|
|
|
|
|
|
7606
|
|
|
|
|
|
|
|
7607
|
|
|
|
|
|
|
typedef uint8_t u8; |
7608
|
|
|
|
|
|
|
typedef uint16_t u16; |
7609
|
|
|
|
|
|
|
typedef uint32_t u32; |
7610
|
|
|
|
|
|
|
typedef uint64_t u64; |
7611
|
|
|
|
|
|
|
typedef int8_t s8; |
7612
|
|
|
|
|
|
|
typedef int16_t s16; |
7613
|
|
|
|
|
|
|
typedef int32_t s32; |
7614
|
|
|
|
|
|
|
typedef int64_t s64; |
7615
|
|
|
|
|
|
|
|
7616
|
|
|
|
|
|
|
|
7617
|
|
|
|
|
|
|
#ifdef _MSC_VER |
7618
|
|
|
|
|
|
|
# ifdef _WIN64 |
7619
|
|
|
|
|
|
|
typedef long long ssize_t; |
7620
|
|
|
|
|
|
|
# else |
7621
|
|
|
|
|
|
|
typedef long ssize_t; |
7622
|
|
|
|
|
|
|
# endif |
7623
|
|
|
|
|
|
|
#endif |
7624
|
|
|
|
|
|
|
|
7625
|
|
|
|
|
|
|
|
7626
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
7627
|
|
|
|
|
|
|
|
7628
|
|
|
|
|
|
|
|
7629
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
7630
|
|
|
|
|
|
|
|
7631
|
|
|
|
|
|
|
|
7632
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
7633
|
|
|
|
|
|
|
|
7634
|
|
|
|
|
|
|
|
7635
|
|
|
|
|
|
|
|
7636
|
|
|
|
|
|
|
|
7637
|
|
|
|
|
|
|
|
7638
|
|
|
|
|
|
|
|
7639
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
7640
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
7641
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
7642
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
7643
|
|
|
|
|
|
|
#else |
7644
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
7645
|
|
|
|
|
|
|
#endif |
7646
|
|
|
|
|
|
|
#ifdef __clang__ |
7647
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
7648
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
7649
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
7650
|
|
|
|
|
|
|
# else |
7651
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
7652
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
7653
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
7654
|
|
|
|
|
|
|
# endif |
7655
|
|
|
|
|
|
|
#else |
7656
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
7657
|
|
|
|
|
|
|
#endif |
7658
|
|
|
|
|
|
|
|
7659
|
|
|
|
|
|
|
|
7660
|
|
|
|
|
|
|
#ifndef __has_attribute |
7661
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
7662
|
|
|
|
|
|
|
#endif |
7663
|
|
|
|
|
|
|
#ifndef __has_builtin |
7664
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
7665
|
|
|
|
|
|
|
#endif |
7666
|
|
|
|
|
|
|
|
7667
|
|
|
|
|
|
|
|
7668
|
|
|
|
|
|
|
#ifdef _MSC_VER |
7669
|
|
|
|
|
|
|
# define inline __inline |
7670
|
|
|
|
|
|
|
#endif |
7671
|
|
|
|
|
|
|
|
7672
|
|
|
|
|
|
|
|
7673
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
7674
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
7675
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7676
|
|
|
|
|
|
|
# define forceinline __forceinline |
7677
|
|
|
|
|
|
|
#else |
7678
|
|
|
|
|
|
|
# define forceinline inline |
7679
|
|
|
|
|
|
|
#endif |
7680
|
|
|
|
|
|
|
|
7681
|
|
|
|
|
|
|
|
7682
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
7683
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
7684
|
|
|
|
|
|
|
#else |
7685
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
7686
|
|
|
|
|
|
|
#endif |
7687
|
|
|
|
|
|
|
|
7688
|
|
|
|
|
|
|
|
7689
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
7690
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
7691
|
|
|
|
|
|
|
# define restrict __restrict__ |
7692
|
|
|
|
|
|
|
# else |
7693
|
|
|
|
|
|
|
# define restrict |
7694
|
|
|
|
|
|
|
# endif |
7695
|
|
|
|
|
|
|
#endif |
7696
|
|
|
|
|
|
|
|
7697
|
|
|
|
|
|
|
|
7698
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
7699
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
7700
|
|
|
|
|
|
|
#else |
7701
|
|
|
|
|
|
|
# define likely(expr) (expr) |
7702
|
|
|
|
|
|
|
#endif |
7703
|
|
|
|
|
|
|
|
7704
|
|
|
|
|
|
|
|
7705
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
7706
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
7707
|
|
|
|
|
|
|
#else |
7708
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
7709
|
|
|
|
|
|
|
#endif |
7710
|
|
|
|
|
|
|
|
7711
|
|
|
|
|
|
|
|
7712
|
|
|
|
|
|
|
#undef prefetchr |
7713
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
7714
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
7715
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7716
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
7717
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
7718
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
7719
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
7720
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
7721
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
7722
|
|
|
|
|
|
|
# endif |
7723
|
|
|
|
|
|
|
#endif |
7724
|
|
|
|
|
|
|
#ifndef prefetchr |
7725
|
|
|
|
|
|
|
# define prefetchr(addr) |
7726
|
|
|
|
|
|
|
#endif |
7727
|
|
|
|
|
|
|
|
7728
|
|
|
|
|
|
|
|
7729
|
|
|
|
|
|
|
#undef prefetchw |
7730
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
7731
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
7732
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7733
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
7734
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
7735
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
7736
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
7737
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
7738
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
7739
|
|
|
|
|
|
|
# endif |
7740
|
|
|
|
|
|
|
#endif |
7741
|
|
|
|
|
|
|
#ifndef prefetchw |
7742
|
|
|
|
|
|
|
# define prefetchw(addr) |
7743
|
|
|
|
|
|
|
#endif |
7744
|
|
|
|
|
|
|
|
7745
|
|
|
|
|
|
|
|
7746
|
|
|
|
|
|
|
#undef _aligned_attribute |
7747
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
7748
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
7749
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7750
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
7751
|
|
|
|
|
|
|
#endif |
7752
|
|
|
|
|
|
|
|
7753
|
|
|
|
|
|
|
|
7754
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
7755
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
7756
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
7757
|
|
|
|
|
|
|
#else |
7758
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
7759
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
7760
|
|
|
|
|
|
|
#endif |
7761
|
|
|
|
|
|
|
|
7762
|
|
|
|
|
|
|
|
7763
|
|
|
|
|
|
|
|
7764
|
|
|
|
|
|
|
|
7765
|
|
|
|
|
|
|
|
7766
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
7767
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
7768
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
7769
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
7770
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
7771
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
7772
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
7773
|
|
|
|
|
|
|
|
7774
|
|
|
|
|
|
|
|
7775
|
|
|
|
|
|
|
|
7776
|
|
|
|
|
|
|
|
7777
|
|
|
|
|
|
|
|
7778
|
|
|
|
|
|
|
|
7779
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
7780
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
7781
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7782
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
7783
|
|
|
|
|
|
|
#else |
7784
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
7785
|
|
|
|
|
|
|
{ |
7786
|
|
|
|
|
|
|
union { |
7787
|
|
|
|
|
|
|
u32 w; |
7788
|
|
|
|
|
|
|
u8 b; |
7789
|
|
|
|
|
|
|
} u; |
7790
|
|
|
|
|
|
|
|
7791
|
|
|
|
|
|
|
u.w = 1; |
7792
|
|
|
|
|
|
|
return u.b; |
7793
|
|
|
|
|
|
|
} |
7794
|
|
|
|
|
|
|
#endif |
7795
|
|
|
|
|
|
|
|
7796
|
|
|
|
|
|
|
|
7797
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
7798
|
|
|
|
|
|
|
{ |
7799
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
7800
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
7801
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7802
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
7803
|
|
|
|
|
|
|
#else |
7804
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
7805
|
|
|
|
|
|
|
#endif |
7806
|
|
|
|
|
|
|
} |
7807
|
|
|
|
|
|
|
|
7808
|
|
|
|
|
|
|
|
7809
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
7810
|
|
|
|
|
|
|
{ |
7811
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
7812
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
7813
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7814
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
7815
|
|
|
|
|
|
|
#else |
7816
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
7817
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
7818
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
7819
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
7820
|
|
|
|
|
|
|
#endif |
7821
|
|
|
|
|
|
|
} |
7822
|
|
|
|
|
|
|
|
7823
|
|
|
|
|
|
|
|
7824
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
7825
|
|
|
|
|
|
|
{ |
7826
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
7827
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
7828
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7829
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
7830
|
|
|
|
|
|
|
#else |
7831
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
7832
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
7833
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
7834
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
7835
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
7836
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
7837
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
7838
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
7839
|
|
|
|
|
|
|
#endif |
7840
|
|
|
|
|
|
|
} |
7841
|
|
|
|
|
|
|
|
7842
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
7843
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
7844
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
7845
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
7846
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
7847
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
7848
|
|
|
|
|
|
|
|
7849
|
|
|
|
|
|
|
|
7850
|
|
|
|
|
|
|
|
7851
|
|
|
|
|
|
|
|
7852
|
|
|
|
|
|
|
|
7853
|
|
|
|
|
|
|
|
7854
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
7855
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
7856
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
7857
|
|
|
|
|
|
|
defined(__wasm__)) |
7858
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
7859
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
7860
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
7861
|
|
|
|
|
|
|
#else |
7862
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
7863
|
|
|
|
|
|
|
#endif |
7864
|
|
|
|
|
|
|
|
7865
|
|
|
|
|
|
|
|
7866
|
|
|
|
|
|
|
|
7867
|
|
|
|
|
|
|
#ifdef FREESTANDING |
7868
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
7869
|
|
|
|
|
|
|
#else |
7870
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
7871
|
|
|
|
|
|
|
#endif |
7872
|
|
|
|
|
|
|
|
7873
|
|
|
|
|
|
|
|
7874
|
|
|
|
|
|
|
|
7875
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
7876
|
|
|
|
|
|
|
static forceinline type \ |
7877
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
7878
|
|
|
|
|
|
|
{ \ |
7879
|
|
|
|
|
|
|
type v; \ |
7880
|
|
|
|
|
|
|
\ |
7881
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
7882
|
|
|
|
|
|
|
return v; \ |
7883
|
|
|
|
|
|
|
} \ |
7884
|
|
|
|
|
|
|
\ |
7885
|
|
|
|
|
|
|
static forceinline void \ |
7886
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
7887
|
|
|
|
|
|
|
{ \ |
7888
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
7889
|
|
|
|
|
|
|
} |
7890
|
|
|
|
|
|
|
|
7891
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
7892
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
7893
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
7894
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
7895
|
|
|
|
|
|
|
|
7896
|
|
|
|
|
|
|
#undef MEMCOPY |
7897
|
|
|
|
|
|
|
|
7898
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
7899
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
7900
|
|
|
|
|
|
|
|
7901
|
|
|
|
|
|
|
|
7902
|
|
|
|
|
|
|
|
7903
|
|
|
|
|
|
|
static forceinline u16 |
7904
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
7905
|
|
|
|
|
|
|
{ |
7906
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
7907
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
7908
|
|
|
|
|
|
|
else |
7909
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
7910
|
|
|
|
|
|
|
} |
7911
|
|
|
|
|
|
|
|
7912
|
|
|
|
|
|
|
static forceinline u16 |
7913
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
7914
|
|
|
|
|
|
|
{ |
7915
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
7916
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
7917
|
|
|
|
|
|
|
else |
7918
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
7919
|
|
|
|
|
|
|
} |
7920
|
|
|
|
|
|
|
|
7921
|
|
|
|
|
|
|
static forceinline u32 |
7922
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
7923
|
|
|
|
|
|
|
{ |
7924
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
7925
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
7926
|
|
|
|
|
|
|
else |
7927
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
7928
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
7929
|
|
|
|
|
|
|
} |
7930
|
|
|
|
|
|
|
|
7931
|
|
|
|
|
|
|
static forceinline u32 |
7932
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
7933
|
|
|
|
|
|
|
{ |
7934
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
7935
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
7936
|
|
|
|
|
|
|
else |
7937
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
7938
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
7939
|
|
|
|
|
|
|
} |
7940
|
|
|
|
|
|
|
|
7941
|
|
|
|
|
|
|
static forceinline u64 |
7942
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
7943
|
|
|
|
|
|
|
{ |
7944
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
7945
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
7946
|
|
|
|
|
|
|
else |
7947
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
7948
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
7949
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
7950
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
7951
|
|
|
|
|
|
|
} |
7952
|
|
|
|
|
|
|
|
7953
|
|
|
|
|
|
|
static forceinline machine_word_t |
7954
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
7955
|
|
|
|
|
|
|
{ |
7956
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
7957
|
|
|
|
|
|
|
if (WORDBITS == 32) |
7958
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
7959
|
|
|
|
|
|
|
else |
7960
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
7961
|
|
|
|
|
|
|
} |
7962
|
|
|
|
|
|
|
|
7963
|
|
|
|
|
|
|
|
7964
|
|
|
|
|
|
|
|
7965
|
|
|
|
|
|
|
static forceinline void |
7966
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
7967
|
|
|
|
|
|
|
{ |
7968
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
7969
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
7970
|
|
|
|
|
|
|
} else { |
7971
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
7972
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
7973
|
|
|
|
|
|
|
} |
7974
|
|
|
|
|
|
|
} |
7975
|
|
|
|
|
|
|
|
7976
|
|
|
|
|
|
|
static forceinline void |
7977
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
7978
|
|
|
|
|
|
|
{ |
7979
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
7980
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
7981
|
|
|
|
|
|
|
} else { |
7982
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
7983
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
7984
|
|
|
|
|
|
|
} |
7985
|
|
|
|
|
|
|
} |
7986
|
|
|
|
|
|
|
|
7987
|
|
|
|
|
|
|
static forceinline void |
7988
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
7989
|
|
|
|
|
|
|
{ |
7990
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
7991
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
7992
|
|
|
|
|
|
|
} else { |
7993
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
7994
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
7995
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
7996
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
7997
|
|
|
|
|
|
|
} |
7998
|
|
|
|
|
|
|
} |
7999
|
|
|
|
|
|
|
|
8000
|
|
|
|
|
|
|
static forceinline void |
8001
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
8002
|
|
|
|
|
|
|
{ |
8003
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
8004
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
8005
|
|
|
|
|
|
|
} else { |
8006
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
8007
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
8008
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
8009
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
8010
|
|
|
|
|
|
|
} |
8011
|
|
|
|
|
|
|
} |
8012
|
|
|
|
|
|
|
|
8013
|
|
|
|
|
|
|
static forceinline void |
8014
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
8015
|
|
|
|
|
|
|
{ |
8016
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
8017
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
8018
|
|
|
|
|
|
|
} else { |
8019
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
8020
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
8021
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
8022
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
8023
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
8024
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
8025
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
8026
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
8027
|
|
|
|
|
|
|
} |
8028
|
|
|
|
|
|
|
} |
8029
|
|
|
|
|
|
|
|
8030
|
|
|
|
|
|
|
static forceinline void |
8031
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
8032
|
|
|
|
|
|
|
{ |
8033
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
8034
|
|
|
|
|
|
|
if (WORDBITS == 32) |
8035
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
8036
|
|
|
|
|
|
|
else |
8037
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
8038
|
|
|
|
|
|
|
} |
8039
|
|
|
|
|
|
|
|
8040
|
|
|
|
|
|
|
|
8041
|
|
|
|
|
|
|
|
8042
|
|
|
|
|
|
|
|
8043
|
|
|
|
|
|
|
|
8044
|
|
|
|
|
|
|
|
8045
|
|
|
|
|
|
|
|
8046
|
|
|
|
|
|
|
static forceinline unsigned |
8047
|
|
|
|
|
|
|
bsr32(u32 v) |
8048
|
|
|
|
|
|
|
{ |
8049
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
8050
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
8051
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
8052
|
|
|
|
|
|
|
unsigned long i; |
8053
|
|
|
|
|
|
|
|
8054
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
8055
|
|
|
|
|
|
|
return i; |
8056
|
|
|
|
|
|
|
#else |
8057
|
|
|
|
|
|
|
unsigned i = 0; |
8058
|
|
|
|
|
|
|
|
8059
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
8060
|
|
|
|
|
|
|
i++; |
8061
|
|
|
|
|
|
|
return i; |
8062
|
|
|
|
|
|
|
#endif |
8063
|
|
|
|
|
|
|
} |
8064
|
|
|
|
|
|
|
|
8065
|
|
|
|
|
|
|
static forceinline unsigned |
8066
|
|
|
|
|
|
|
bsr64(u64 v) |
8067
|
|
|
|
|
|
|
{ |
8068
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
8069
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
8070
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
8071
|
|
|
|
|
|
|
unsigned long i; |
8072
|
|
|
|
|
|
|
|
8073
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
8074
|
|
|
|
|
|
|
return i; |
8075
|
|
|
|
|
|
|
#else |
8076
|
|
|
|
|
|
|
unsigned i = 0; |
8077
|
|
|
|
|
|
|
|
8078
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
8079
|
|
|
|
|
|
|
i++; |
8080
|
|
|
|
|
|
|
return i; |
8081
|
|
|
|
|
|
|
#endif |
8082
|
|
|
|
|
|
|
} |
8083
|
|
|
|
|
|
|
|
8084
|
|
|
|
|
|
|
static forceinline unsigned |
8085
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
8086
|
|
|
|
|
|
|
{ |
8087
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
8088
|
|
|
|
|
|
|
if (WORDBITS == 32) |
8089
|
|
|
|
|
|
|
return bsr32(v); |
8090
|
|
|
|
|
|
|
else |
8091
|
|
|
|
|
|
|
return bsr64(v); |
8092
|
|
|
|
|
|
|
} |
8093
|
|
|
|
|
|
|
|
8094
|
|
|
|
|
|
|
|
8095
|
|
|
|
|
|
|
|
8096
|
|
|
|
|
|
|
static forceinline unsigned |
8097
|
|
|
|
|
|
|
bsf32(u32 v) |
8098
|
|
|
|
|
|
|
{ |
8099
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
8100
|
|
|
|
|
|
|
return __builtin_ctz(v); |
8101
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
8102
|
|
|
|
|
|
|
unsigned long i; |
8103
|
|
|
|
|
|
|
|
8104
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
8105
|
|
|
|
|
|
|
return i; |
8106
|
|
|
|
|
|
|
#else |
8107
|
|
|
|
|
|
|
unsigned i = 0; |
8108
|
|
|
|
|
|
|
|
8109
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
8110
|
|
|
|
|
|
|
i++; |
8111
|
|
|
|
|
|
|
return i; |
8112
|
|
|
|
|
|
|
#endif |
8113
|
|
|
|
|
|
|
} |
8114
|
|
|
|
|
|
|
|
8115
|
|
|
|
|
|
|
static forceinline unsigned |
8116
|
|
|
|
|
|
|
bsf64(u64 v) |
8117
|
|
|
|
|
|
|
{ |
8118
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
8119
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
8120
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
8121
|
|
|
|
|
|
|
unsigned long i; |
8122
|
|
|
|
|
|
|
|
8123
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
8124
|
|
|
|
|
|
|
return i; |
8125
|
|
|
|
|
|
|
#else |
8126
|
|
|
|
|
|
|
unsigned i = 0; |
8127
|
|
|
|
|
|
|
|
8128
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
8129
|
|
|
|
|
|
|
i++; |
8130
|
|
|
|
|
|
|
return i; |
8131
|
|
|
|
|
|
|
#endif |
8132
|
|
|
|
|
|
|
} |
8133
|
|
|
|
|
|
|
|
8134
|
|
|
|
|
|
|
static forceinline unsigned |
8135
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
8136
|
|
|
|
|
|
|
{ |
8137
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
8138
|
|
|
|
|
|
|
if (WORDBITS == 32) |
8139
|
|
|
|
|
|
|
return bsf32(v); |
8140
|
|
|
|
|
|
|
else |
8141
|
|
|
|
|
|
|
return bsf64(v); |
8142
|
|
|
|
|
|
|
} |
8143
|
|
|
|
|
|
|
|
8144
|
|
|
|
|
|
|
|
8145
|
|
|
|
|
|
|
#undef rbit32 |
8146
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
8147
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
8148
|
|
|
|
|
|
|
static forceinline u32 |
8149
|
|
|
|
|
|
|
rbit32(u32 v) |
8150
|
|
|
|
|
|
|
{ |
8151
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
8152
|
|
|
|
|
|
|
return v; |
8153
|
|
|
|
|
|
|
} |
8154
|
|
|
|
|
|
|
#define rbit32 rbit32 |
8155
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
8156
|
|
|
|
|
|
|
static forceinline u32 |
8157
|
|
|
|
|
|
|
rbit32(u32 v) |
8158
|
|
|
|
|
|
|
{ |
8159
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
8160
|
|
|
|
|
|
|
return v; |
8161
|
|
|
|
|
|
|
} |
8162
|
|
|
|
|
|
|
#define rbit32 rbit32 |
8163
|
|
|
|
|
|
|
#endif |
8164
|
|
|
|
|
|
|
|
8165
|
|
|
|
|
|
|
#endif |
8166
|
|
|
|
|
|
|
|
8167
|
|
|
|
|
|
|
|
8168
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
8169
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
8170
|
|
|
|
|
|
|
|
8171
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
8172
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
8173
|
|
|
|
|
|
|
|
8174
|
|
|
|
|
|
|
#ifdef FREESTANDING |
8175
|
|
|
|
|
|
|
|
8176
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
8177
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
8178
|
|
|
|
|
|
|
|
8179
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
8180
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
8181
|
|
|
|
|
|
|
|
8182
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
8183
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
8184
|
|
|
|
|
|
|
|
8185
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
8186
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
8187
|
|
|
|
|
|
|
|
8188
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
8189
|
|
|
|
|
|
|
#else |
8190
|
|
|
|
|
|
|
#include |
8191
|
|
|
|
|
|
|
#endif |
8192
|
|
|
|
|
|
|
|
8193
|
|
|
|
|
|
|
|
8194
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
8195
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
8196
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
8197
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
8198
|
|
|
|
|
|
|
#else |
8199
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
8200
|
|
|
|
|
|
|
#endif |
8201
|
|
|
|
|
|
|
|
8202
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
8203
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
8204
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
8205
|
|
|
|
|
|
|
|
8206
|
|
|
|
|
|
|
#endif |
8207
|
|
|
|
|
|
|
|
8208
|
|
|
|
|
|
|
|
8209
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
8210
|
|
|
|
|
|
|
|
8211
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
8212
|
|
|
|
|
|
|
|
8213
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
8214
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
8215
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
8216
|
|
|
|
|
|
|
#endif |
8217
|
|
|
|
|
|
|
|
8218
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
8219
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
8220
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
8221
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
8222
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
8223
|
|
|
|
|
|
|
|
8224
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
8225
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
8226
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
8227
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
8228
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
8229
|
|
|
|
|
|
|
|
8230
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
8231
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
8232
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
8233
|
|
|
|
|
|
|
|
8234
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
8235
|
|
|
|
|
|
|
|
8236
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
8237
|
|
|
|
|
|
|
{ |
8238
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
8239
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
8240
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
8241
|
|
|
|
|
|
|
} |
8242
|
|
|
|
|
|
|
#else |
8243
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
8244
|
|
|
|
|
|
|
#endif |
8245
|
|
|
|
|
|
|
|
8246
|
|
|
|
|
|
|
|
8247
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
8248
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
8249
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
8250
|
|
|
|
|
|
|
#else |
8251
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
8252
|
|
|
|
|
|
|
#endif |
8253
|
|
|
|
|
|
|
|
8254
|
|
|
|
|
|
|
|
8255
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
8256
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
8257
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
8258
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
8259
|
|
|
|
|
|
|
#else |
8260
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
8261
|
|
|
|
|
|
|
#endif |
8262
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
8263
|
|
|
|
|
|
|
|
8264
|
|
|
|
|
|
|
|
8265
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
8266
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
8267
|
|
|
|
|
|
|
#else |
8268
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
8269
|
|
|
|
|
|
|
#endif |
8270
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
8271
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
8272
|
|
|
|
|
|
|
defined(_MSC_VER))) |
8273
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
8274
|
|
|
|
|
|
|
#else |
8275
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
8276
|
|
|
|
|
|
|
#endif |
8277
|
|
|
|
|
|
|
|
8278
|
|
|
|
|
|
|
|
8279
|
|
|
|
|
|
|
#ifdef __AVX__ |
8280
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
8281
|
|
|
|
|
|
|
#else |
8282
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
8283
|
|
|
|
|
|
|
#endif |
8284
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
8285
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
8286
|
|
|
|
|
|
|
defined(_MSC_VER))) |
8287
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
8288
|
|
|
|
|
|
|
#else |
8289
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
8290
|
|
|
|
|
|
|
#endif |
8291
|
|
|
|
|
|
|
|
8292
|
|
|
|
|
|
|
|
8293
|
|
|
|
|
|
|
#ifdef __AVX2__ |
8294
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
8295
|
|
|
|
|
|
|
#else |
8296
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
8297
|
|
|
|
|
|
|
#endif |
8298
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
8299
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
8300
|
|
|
|
|
|
|
defined(_MSC_VER))) |
8301
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
8302
|
|
|
|
|
|
|
#else |
8303
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
8304
|
|
|
|
|
|
|
#endif |
8305
|
|
|
|
|
|
|
|
8306
|
|
|
|
|
|
|
|
8307
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
8308
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
8309
|
|
|
|
|
|
|
#else |
8310
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
8311
|
|
|
|
|
|
|
#endif |
8312
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
8313
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
8314
|
|
|
|
|
|
|
defined(_MSC_VER))) |
8315
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
8316
|
|
|
|
|
|
|
#else |
8317
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
8318
|
|
|
|
|
|
|
#endif |
8319
|
|
|
|
|
|
|
|
8320
|
|
|
|
|
|
|
#endif |
8321
|
|
|
|
|
|
|
|
8322
|
|
|
|
|
|
|
#endif |
8323
|
|
|
|
|
|
|
|
8324
|
|
|
|
|
|
|
|
8325
|
|
|
|
|
|
|
|
8326
|
|
|
|
|
|
|
#if HAVE_PCLMUL_INTRIN |
8327
|
|
|
|
|
|
|
# define crc32_x86_pclmul crc32_x86_pclmul |
8328
|
|
|
|
|
|
|
# define SUFFIX _pclmul |
8329
|
|
|
|
|
|
|
# if HAVE_PCLMUL_NATIVE |
8330
|
|
|
|
|
|
|
# define ATTRIBUTES |
8331
|
|
|
|
|
|
|
# else |
8332
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("pclmul") |
8333
|
|
|
|
|
|
|
# endif |
8334
|
|
|
|
|
|
|
# define FOLD_PARTIAL_VECS 0 |
8335
|
|
|
|
|
|
|
/* #include "x86-crc32_pclmul_template.h" */ |
8336
|
|
|
|
|
|
|
|
8337
|
|
|
|
|
|
|
|
8338
|
|
|
|
|
|
|
|
8339
|
|
|
|
|
|
|
|
8340
|
|
|
|
|
|
|
#include |
8341
|
|
|
|
|
|
|
|
8342
|
|
|
|
|
|
|
#if defined(__clang__) && defined(_MSC_VER) |
8343
|
|
|
|
|
|
|
# include |
8344
|
|
|
|
|
|
|
# include |
8345
|
|
|
|
|
|
|
# include |
8346
|
|
|
|
|
|
|
#endif |
8347
|
|
|
|
|
|
|
|
8348
|
|
|
|
|
|
|
#undef fold_vec |
8349
|
|
|
|
|
|
|
static forceinline ATTRIBUTES __m128i |
8350
|
|
|
|
|
|
|
ADD_SUFFIX(fold_vec)(__m128i src, __m128i dst, __m128i multipliers) |
8351
|
|
|
|
|
|
|
{ |
8352
|
|
|
|
|
|
|
|
8353
|
0
|
|
|
|
|
|
dst = _mm_xor_si128(dst, _mm_clmulepi64_si128(src, multipliers, 0x00)); |
8354
|
0
|
|
|
|
|
|
dst = _mm_xor_si128(dst, _mm_clmulepi64_si128(src, multipliers, 0x11)); |
8355
|
0
|
|
|
|
|
|
return dst; |
8356
|
|
|
|
|
|
|
} |
8357
|
|
|
|
|
|
|
#define fold_vec ADD_SUFFIX(fold_vec) |
8358
|
|
|
|
|
|
|
|
8359
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8360
|
|
|
|
|
|
|
|
8361
|
|
|
|
|
|
|
#undef fold_partial_vec |
8362
|
|
|
|
|
|
|
static forceinline ATTRIBUTES __m128i |
8363
|
|
|
|
|
|
|
ADD_SUFFIX(fold_partial_vec)(__m128i v, const u8 *p, size_t len, |
8364
|
|
|
|
|
|
|
__m128i multipliers_1) |
8365
|
|
|
|
|
|
|
{ |
8366
|
|
|
|
|
|
|
|
8367
|
|
|
|
|
|
|
static const u8 shift_tab[48] = { |
8368
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8369
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8370
|
|
|
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
8371
|
|
|
|
|
|
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
8372
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8373
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8374
|
|
|
|
|
|
|
}; |
8375
|
|
|
|
|
|
|
__m128i lshift = _mm_loadu_si128((const void *)&shift_tab[len]); |
8376
|
|
|
|
|
|
|
__m128i rshift = _mm_loadu_si128((const void *)&shift_tab[len + 16]); |
8377
|
|
|
|
|
|
|
__m128i x0, x1; |
8378
|
|
|
|
|
|
|
|
8379
|
|
|
|
|
|
|
|
8380
|
|
|
|
|
|
|
x0 = _mm_shuffle_epi8(v, lshift); |
8381
|
|
|
|
|
|
|
|
8382
|
|
|
|
|
|
|
|
8383
|
|
|
|
|
|
|
x1 = _mm_blendv_epi8(_mm_shuffle_epi8(v, rshift), |
8384
|
|
|
|
|
|
|
_mm_loadu_si128((const void *)(p + len - 16)), |
8385
|
|
|
|
|
|
|
|
8386
|
|
|
|
|
|
|
rshift); |
8387
|
|
|
|
|
|
|
|
8388
|
|
|
|
|
|
|
return fold_vec(x0, x1, multipliers_1); |
8389
|
|
|
|
|
|
|
} |
8390
|
|
|
|
|
|
|
#define fold_partial_vec ADD_SUFFIX(fold_partial_vec) |
8391
|
|
|
|
|
|
|
#endif |
8392
|
|
|
|
|
|
|
|
8393
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
8394
|
0
|
|
|
|
|
|
ADD_SUFFIX(crc32_x86)(u32 crc, const u8 *p, size_t len) |
8395
|
|
|
|
|
|
|
{ |
8396
|
0
|
|
|
|
|
|
const __m128i multipliers_8 = |
8397
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_8VECS_MULT_2, CRC32_8VECS_MULT_1); |
8398
|
0
|
|
|
|
|
|
const __m128i multipliers_4 = |
8399
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_4VECS_MULT_2, CRC32_4VECS_MULT_1); |
8400
|
0
|
|
|
|
|
|
const __m128i multipliers_2 = |
8401
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_2VECS_MULT_2, CRC32_2VECS_MULT_1); |
8402
|
0
|
|
|
|
|
|
const __m128i multipliers_1 = |
8403
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_1VECS_MULT_2, CRC32_1VECS_MULT_1); |
8404
|
0
|
|
|
|
|
|
const __m128i final_multiplier = |
8405
|
|
|
|
|
|
|
_mm_set_epi64x(0, CRC32_FINAL_MULT); |
8406
|
0
|
|
|
|
|
|
const __m128i mask32 = _mm_set_epi32(0, 0, 0, 0xFFFFFFFF); |
8407
|
0
|
|
|
|
|
|
const __m128i barrett_reduction_constants = |
8408
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_BARRETT_CONSTANT_2, |
8409
|
|
|
|
|
|
|
CRC32_BARRETT_CONSTANT_1); |
8410
|
|
|
|
|
|
|
__m128i v0, v1, v2, v3, v4, v5, v6, v7; |
8411
|
|
|
|
|
|
|
|
8412
|
|
|
|
|
|
|
|
8413
|
0
|
0
|
|
|
|
|
if (len < 1024) { |
8414
|
0
|
0
|
|
|
|
|
if (len < 16) |
8415
|
0
|
|
|
|
|
|
return crc32_slice1(crc, p, len); |
8416
|
|
|
|
|
|
|
|
8417
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_loadu_si128((const void *)p), |
8418
|
|
|
|
|
|
|
_mm_cvtsi32_si128(crc)); |
8419
|
0
|
|
|
|
|
|
p += 16; |
8420
|
|
|
|
|
|
|
|
8421
|
0
|
0
|
|
|
|
|
if (len >= 64) { |
8422
|
0
|
|
|
|
|
|
v1 = _mm_loadu_si128((const void *)(p + 0)); |
8423
|
0
|
|
|
|
|
|
v2 = _mm_loadu_si128((const void *)(p + 16)); |
8424
|
0
|
|
|
|
|
|
v3 = _mm_loadu_si128((const void *)(p + 32)); |
8425
|
0
|
|
|
|
|
|
p += 48; |
8426
|
0
|
0
|
|
|
|
|
while (len >= 64 + 64) { |
8427
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)(p + 0)), |
8428
|
|
|
|
|
|
|
multipliers_4); |
8429
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, _mm_loadu_si128((const void *)(p + 16)), |
8430
|
|
|
|
|
|
|
multipliers_4); |
8431
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, _mm_loadu_si128((const void *)(p + 32)), |
8432
|
|
|
|
|
|
|
multipliers_4); |
8433
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, _mm_loadu_si128((const void *)(p + 48)), |
8434
|
|
|
|
|
|
|
multipliers_4); |
8435
|
0
|
|
|
|
|
|
p += 64; |
8436
|
0
|
|
|
|
|
|
len -= 64; |
8437
|
|
|
|
|
|
|
} |
8438
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
8439
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
8440
|
0
|
0
|
|
|
|
|
if (len & 32) { |
8441
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)(p + 0)), |
8442
|
|
|
|
|
|
|
multipliers_2); |
8443
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, _mm_loadu_si128((const void *)(p + 16)), |
8444
|
|
|
|
|
|
|
multipliers_2); |
8445
|
0
|
|
|
|
|
|
p += 32; |
8446
|
|
|
|
|
|
|
} |
8447
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
8448
|
0
|
0
|
|
|
|
|
if (len & 16) { |
8449
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8450
|
|
|
|
|
|
|
multipliers_1); |
8451
|
0
|
|
|
|
|
|
p += 16; |
8452
|
|
|
|
|
|
|
} |
8453
|
|
|
|
|
|
|
} else { |
8454
|
0
|
0
|
|
|
|
|
if (len >= 32) { |
8455
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8456
|
|
|
|
|
|
|
multipliers_1); |
8457
|
0
|
|
|
|
|
|
p += 16; |
8458
|
0
|
0
|
|
|
|
|
if (len >= 48) { |
8459
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8460
|
|
|
|
|
|
|
multipliers_1); |
8461
|
0
|
|
|
|
|
|
p += 16; |
8462
|
|
|
|
|
|
|
} |
8463
|
|
|
|
|
|
|
} |
8464
|
|
|
|
|
|
|
} |
8465
|
|
|
|
|
|
|
} else { |
8466
|
0
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 15; |
8467
|
|
|
|
|
|
|
const __m128i *vp; |
8468
|
|
|
|
|
|
|
|
8469
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8470
|
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_loadu_si128((const void *)p), |
8471
|
|
|
|
|
|
|
_mm_cvtsi32_si128(crc)); |
8472
|
|
|
|
|
|
|
p += 16; |
8473
|
|
|
|
|
|
|
|
8474
|
|
|
|
|
|
|
if (align) { |
8475
|
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, align, multipliers_1); |
8476
|
|
|
|
|
|
|
p += align; |
8477
|
|
|
|
|
|
|
len -= align; |
8478
|
|
|
|
|
|
|
} |
8479
|
|
|
|
|
|
|
vp = (const __m128i *)p; |
8480
|
|
|
|
|
|
|
#else |
8481
|
|
|
|
|
|
|
|
8482
|
0
|
0
|
|
|
|
|
if (align) { |
8483
|
0
|
|
|
|
|
|
crc = crc32_slice1(crc, p, align); |
8484
|
0
|
|
|
|
|
|
p += align; |
8485
|
0
|
|
|
|
|
|
len -= align; |
8486
|
|
|
|
|
|
|
} |
8487
|
0
|
|
|
|
|
|
vp = (const __m128i *)p; |
8488
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(*vp++, _mm_cvtsi32_si128(crc)); |
8489
|
|
|
|
|
|
|
#endif |
8490
|
0
|
|
|
|
|
|
v1 = *vp++; |
8491
|
0
|
|
|
|
|
|
v2 = *vp++; |
8492
|
0
|
|
|
|
|
|
v3 = *vp++; |
8493
|
0
|
|
|
|
|
|
v4 = *vp++; |
8494
|
0
|
|
|
|
|
|
v5 = *vp++; |
8495
|
0
|
|
|
|
|
|
v6 = *vp++; |
8496
|
0
|
|
|
|
|
|
v7 = *vp++; |
8497
|
|
|
|
|
|
|
do { |
8498
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_8); |
8499
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_8); |
8500
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_8); |
8501
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_8); |
8502
|
0
|
|
|
|
|
|
v4 = fold_vec(v4, *vp++, multipliers_8); |
8503
|
0
|
|
|
|
|
|
v5 = fold_vec(v5, *vp++, multipliers_8); |
8504
|
0
|
|
|
|
|
|
v6 = fold_vec(v6, *vp++, multipliers_8); |
8505
|
0
|
|
|
|
|
|
v7 = fold_vec(v7, *vp++, multipliers_8); |
8506
|
0
|
|
|
|
|
|
len -= 128; |
8507
|
0
|
0
|
|
|
|
|
} while (len >= 128 + 128); |
8508
|
|
|
|
|
|
|
|
8509
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v4, multipliers_4); |
8510
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v5, multipliers_4); |
8511
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, v6, multipliers_4); |
8512
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, v7, multipliers_4); |
8513
|
0
|
0
|
|
|
|
|
if (len & 64) { |
8514
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_4); |
8515
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_4); |
8516
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_4); |
8517
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_4); |
8518
|
|
|
|
|
|
|
} |
8519
|
|
|
|
|
|
|
|
8520
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
8521
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
8522
|
0
|
0
|
|
|
|
|
if (len & 32) { |
8523
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_2); |
8524
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_2); |
8525
|
|
|
|
|
|
|
} |
8526
|
|
|
|
|
|
|
|
8527
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
8528
|
0
|
0
|
|
|
|
|
if (len & 16) |
8529
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_1); |
8530
|
|
|
|
|
|
|
|
8531
|
0
|
|
|
|
|
|
p = (const u8 *)vp; |
8532
|
|
|
|
|
|
|
} |
8533
|
0
|
|
|
|
|
|
len &= 15; |
8534
|
|
|
|
|
|
|
|
8535
|
|
|
|
|
|
|
|
8536
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8537
|
|
|
|
|
|
|
if (len) |
8538
|
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, len, multipliers_1); |
8539
|
|
|
|
|
|
|
#endif |
8540
|
|
|
|
|
|
|
|
8541
|
|
|
|
|
|
|
|
8542
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_srli_si128(v0, 8), |
8543
|
0
|
|
|
|
|
|
_mm_clmulepi64_si128(v0, multipliers_1, 0x10)); |
8544
|
|
|
|
|
|
|
|
8545
|
|
|
|
|
|
|
|
8546
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_srli_si128(v0, 4), |
8547
|
0
|
|
|
|
|
|
_mm_clmulepi64_si128(_mm_and_si128(v0, mask32), |
8548
|
|
|
|
|
|
|
final_multiplier, 0x00)); |
8549
|
|
|
|
|
|
|
|
8550
|
|
|
|
|
|
|
|
8551
|
0
|
|
|
|
|
|
v1 = _mm_clmulepi64_si128(_mm_and_si128(v0, mask32), |
8552
|
|
|
|
|
|
|
barrett_reduction_constants, 0x00); |
8553
|
0
|
|
|
|
|
|
v1 = _mm_clmulepi64_si128(_mm_and_si128(v1, mask32), |
8554
|
|
|
|
|
|
|
barrett_reduction_constants, 0x10); |
8555
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(v0, v1); |
8556
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8557
|
|
|
|
|
|
|
crc = _mm_extract_epi32(v0, 1); |
8558
|
|
|
|
|
|
|
#else |
8559
|
0
|
|
|
|
|
|
crc = _mm_cvtsi128_si32(_mm_shuffle_epi32(v0, 0x01)); |
8560
|
|
|
|
|
|
|
|
8561
|
0
|
|
|
|
|
|
crc = crc32_slice1(crc, p, len); |
8562
|
|
|
|
|
|
|
#endif |
8563
|
0
|
|
|
|
|
|
return crc; |
8564
|
|
|
|
|
|
|
} |
8565
|
|
|
|
|
|
|
|
8566
|
|
|
|
|
|
|
#undef SUFFIX |
8567
|
|
|
|
|
|
|
#undef ATTRIBUTES |
8568
|
|
|
|
|
|
|
#undef FOLD_PARTIAL_VECS |
8569
|
|
|
|
|
|
|
|
8570
|
|
|
|
|
|
|
#endif |
8571
|
|
|
|
|
|
|
|
8572
|
|
|
|
|
|
|
|
8573
|
|
|
|
|
|
|
#if HAVE_PCLMUL_INTRIN && HAVE_AVX_INTRIN |
8574
|
|
|
|
|
|
|
# define crc32_x86_pclmul_avx crc32_x86_pclmul_avx |
8575
|
|
|
|
|
|
|
# define SUFFIX _pclmul_avx |
8576
|
|
|
|
|
|
|
# if HAVE_PCLMUL_NATIVE && HAVE_AVX_NATIVE |
8577
|
|
|
|
|
|
|
# define ATTRIBUTES |
8578
|
|
|
|
|
|
|
# else |
8579
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("pclmul,avx") |
8580
|
|
|
|
|
|
|
# endif |
8581
|
|
|
|
|
|
|
# define FOLD_PARTIAL_VECS 1 |
8582
|
|
|
|
|
|
|
/* #include "x86-crc32_pclmul_template.h" */ |
8583
|
|
|
|
|
|
|
|
8584
|
|
|
|
|
|
|
|
8585
|
|
|
|
|
|
|
|
8586
|
|
|
|
|
|
|
|
8587
|
|
|
|
|
|
|
#include |
8588
|
|
|
|
|
|
|
|
8589
|
|
|
|
|
|
|
#if defined(__clang__) && defined(_MSC_VER) |
8590
|
|
|
|
|
|
|
# include |
8591
|
|
|
|
|
|
|
# include |
8592
|
|
|
|
|
|
|
# include |
8593
|
|
|
|
|
|
|
#endif |
8594
|
|
|
|
|
|
|
|
8595
|
|
|
|
|
|
|
#undef fold_vec |
8596
|
|
|
|
|
|
|
static forceinline ATTRIBUTES __m128i |
8597
|
|
|
|
|
|
|
ADD_SUFFIX(fold_vec)(__m128i src, __m128i dst, __m128i multipliers) |
8598
|
|
|
|
|
|
|
{ |
8599
|
|
|
|
|
|
|
|
8600
|
0
|
|
|
|
|
|
dst = _mm_xor_si128(dst, _mm_clmulepi64_si128(src, multipliers, 0x00)); |
8601
|
0
|
|
|
|
|
|
dst = _mm_xor_si128(dst, _mm_clmulepi64_si128(src, multipliers, 0x11)); |
8602
|
0
|
|
|
|
|
|
return dst; |
8603
|
|
|
|
|
|
|
} |
8604
|
|
|
|
|
|
|
#define fold_vec ADD_SUFFIX(fold_vec) |
8605
|
|
|
|
|
|
|
|
8606
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8607
|
|
|
|
|
|
|
|
8608
|
|
|
|
|
|
|
#undef fold_partial_vec |
8609
|
|
|
|
|
|
|
static forceinline ATTRIBUTES __m128i |
8610
|
|
|
|
|
|
|
ADD_SUFFIX(fold_partial_vec)(__m128i v, const u8 *p, size_t len, |
8611
|
|
|
|
|
|
|
__m128i multipliers_1) |
8612
|
|
|
|
|
|
|
{ |
8613
|
|
|
|
|
|
|
|
8614
|
|
|
|
|
|
|
static const u8 shift_tab[48] = { |
8615
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8616
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8617
|
|
|
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
8618
|
|
|
|
|
|
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
8619
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8620
|
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
8621
|
|
|
|
|
|
|
}; |
8622
|
0
|
|
|
|
|
|
__m128i lshift = _mm_loadu_si128((const void *)&shift_tab[len]); |
8623
|
0
|
|
|
|
|
|
__m128i rshift = _mm_loadu_si128((const void *)&shift_tab[len + 16]); |
8624
|
|
|
|
|
|
|
__m128i x0, x1; |
8625
|
|
|
|
|
|
|
|
8626
|
|
|
|
|
|
|
|
8627
|
0
|
|
|
|
|
|
x0 = _mm_shuffle_epi8(v, lshift); |
8628
|
|
|
|
|
|
|
|
8629
|
|
|
|
|
|
|
|
8630
|
0
|
|
|
|
|
|
x1 = _mm_blendv_epi8(_mm_shuffle_epi8(v, rshift), |
8631
|
0
|
|
|
|
|
|
_mm_loadu_si128((const void *)(p + len - 16)), |
8632
|
|
|
|
|
|
|
|
8633
|
|
|
|
|
|
|
rshift); |
8634
|
|
|
|
|
|
|
|
8635
|
0
|
|
|
|
|
|
return fold_vec(x0, x1, multipliers_1); |
8636
|
|
|
|
|
|
|
} |
8637
|
|
|
|
|
|
|
#define fold_partial_vec ADD_SUFFIX(fold_partial_vec) |
8638
|
|
|
|
|
|
|
#endif |
8639
|
|
|
|
|
|
|
|
8640
|
|
|
|
|
|
|
static u32 ATTRIBUTES MAYBE_UNUSED |
8641
|
0
|
|
|
|
|
|
ADD_SUFFIX(crc32_x86)(u32 crc, const u8 *p, size_t len) |
8642
|
|
|
|
|
|
|
{ |
8643
|
0
|
|
|
|
|
|
const __m128i multipliers_8 = |
8644
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_8VECS_MULT_2, CRC32_8VECS_MULT_1); |
8645
|
0
|
|
|
|
|
|
const __m128i multipliers_4 = |
8646
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_4VECS_MULT_2, CRC32_4VECS_MULT_1); |
8647
|
0
|
|
|
|
|
|
const __m128i multipliers_2 = |
8648
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_2VECS_MULT_2, CRC32_2VECS_MULT_1); |
8649
|
0
|
|
|
|
|
|
const __m128i multipliers_1 = |
8650
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_1VECS_MULT_2, CRC32_1VECS_MULT_1); |
8651
|
0
|
|
|
|
|
|
const __m128i final_multiplier = |
8652
|
|
|
|
|
|
|
_mm_set_epi64x(0, CRC32_FINAL_MULT); |
8653
|
0
|
|
|
|
|
|
const __m128i mask32 = _mm_set_epi32(0, 0, 0, 0xFFFFFFFF); |
8654
|
0
|
|
|
|
|
|
const __m128i barrett_reduction_constants = |
8655
|
|
|
|
|
|
|
_mm_set_epi64x(CRC32_BARRETT_CONSTANT_2, |
8656
|
|
|
|
|
|
|
CRC32_BARRETT_CONSTANT_1); |
8657
|
|
|
|
|
|
|
__m128i v0, v1, v2, v3, v4, v5, v6, v7; |
8658
|
|
|
|
|
|
|
|
8659
|
|
|
|
|
|
|
|
8660
|
0
|
0
|
|
|
|
|
if (len < 1024) { |
8661
|
0
|
0
|
|
|
|
|
if (len < 16) |
8662
|
0
|
|
|
|
|
|
return crc32_slice1(crc, p, len); |
8663
|
|
|
|
|
|
|
|
8664
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_loadu_si128((const void *)p), |
8665
|
|
|
|
|
|
|
_mm_cvtsi32_si128(crc)); |
8666
|
0
|
|
|
|
|
|
p += 16; |
8667
|
|
|
|
|
|
|
|
8668
|
0
|
0
|
|
|
|
|
if (len >= 64) { |
8669
|
0
|
|
|
|
|
|
v1 = _mm_loadu_si128((const void *)(p + 0)); |
8670
|
0
|
|
|
|
|
|
v2 = _mm_loadu_si128((const void *)(p + 16)); |
8671
|
0
|
|
|
|
|
|
v3 = _mm_loadu_si128((const void *)(p + 32)); |
8672
|
0
|
|
|
|
|
|
p += 48; |
8673
|
0
|
0
|
|
|
|
|
while (len >= 64 + 64) { |
8674
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)(p + 0)), |
8675
|
|
|
|
|
|
|
multipliers_4); |
8676
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, _mm_loadu_si128((const void *)(p + 16)), |
8677
|
|
|
|
|
|
|
multipliers_4); |
8678
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, _mm_loadu_si128((const void *)(p + 32)), |
8679
|
|
|
|
|
|
|
multipliers_4); |
8680
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, _mm_loadu_si128((const void *)(p + 48)), |
8681
|
|
|
|
|
|
|
multipliers_4); |
8682
|
0
|
|
|
|
|
|
p += 64; |
8683
|
0
|
|
|
|
|
|
len -= 64; |
8684
|
|
|
|
|
|
|
} |
8685
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
8686
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
8687
|
0
|
0
|
|
|
|
|
if (len & 32) { |
8688
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)(p + 0)), |
8689
|
|
|
|
|
|
|
multipliers_2); |
8690
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, _mm_loadu_si128((const void *)(p + 16)), |
8691
|
|
|
|
|
|
|
multipliers_2); |
8692
|
0
|
|
|
|
|
|
p += 32; |
8693
|
|
|
|
|
|
|
} |
8694
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
8695
|
0
|
0
|
|
|
|
|
if (len & 16) { |
8696
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8697
|
|
|
|
|
|
|
multipliers_1); |
8698
|
0
|
|
|
|
|
|
p += 16; |
8699
|
|
|
|
|
|
|
} |
8700
|
|
|
|
|
|
|
} else { |
8701
|
0
|
0
|
|
|
|
|
if (len >= 32) { |
8702
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8703
|
|
|
|
|
|
|
multipliers_1); |
8704
|
0
|
|
|
|
|
|
p += 16; |
8705
|
0
|
0
|
|
|
|
|
if (len >= 48) { |
8706
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, _mm_loadu_si128((const void *)p), |
8707
|
|
|
|
|
|
|
multipliers_1); |
8708
|
0
|
|
|
|
|
|
p += 16; |
8709
|
|
|
|
|
|
|
} |
8710
|
|
|
|
|
|
|
} |
8711
|
|
|
|
|
|
|
} |
8712
|
|
|
|
|
|
|
} else { |
8713
|
0
|
|
|
|
|
|
const size_t align = -(uintptr_t)p & 15; |
8714
|
|
|
|
|
|
|
const __m128i *vp; |
8715
|
|
|
|
|
|
|
|
8716
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8717
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_loadu_si128((const void *)p), |
8718
|
|
|
|
|
|
|
_mm_cvtsi32_si128(crc)); |
8719
|
0
|
|
|
|
|
|
p += 16; |
8720
|
|
|
|
|
|
|
|
8721
|
0
|
0
|
|
|
|
|
if (align) { |
8722
|
0
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, align, multipliers_1); |
8723
|
0
|
|
|
|
|
|
p += align; |
8724
|
0
|
|
|
|
|
|
len -= align; |
8725
|
|
|
|
|
|
|
} |
8726
|
0
|
|
|
|
|
|
vp = (const __m128i *)p; |
8727
|
|
|
|
|
|
|
#else |
8728
|
|
|
|
|
|
|
|
8729
|
|
|
|
|
|
|
if (align) { |
8730
|
|
|
|
|
|
|
crc = crc32_slice1(crc, p, align); |
8731
|
|
|
|
|
|
|
p += align; |
8732
|
|
|
|
|
|
|
len -= align; |
8733
|
|
|
|
|
|
|
} |
8734
|
|
|
|
|
|
|
vp = (const __m128i *)p; |
8735
|
|
|
|
|
|
|
v0 = _mm_xor_si128(*vp++, _mm_cvtsi32_si128(crc)); |
8736
|
|
|
|
|
|
|
#endif |
8737
|
0
|
|
|
|
|
|
v1 = *vp++; |
8738
|
0
|
|
|
|
|
|
v2 = *vp++; |
8739
|
0
|
|
|
|
|
|
v3 = *vp++; |
8740
|
0
|
|
|
|
|
|
v4 = *vp++; |
8741
|
0
|
|
|
|
|
|
v5 = *vp++; |
8742
|
0
|
|
|
|
|
|
v6 = *vp++; |
8743
|
0
|
|
|
|
|
|
v7 = *vp++; |
8744
|
|
|
|
|
|
|
do { |
8745
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_8); |
8746
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_8); |
8747
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_8); |
8748
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_8); |
8749
|
0
|
|
|
|
|
|
v4 = fold_vec(v4, *vp++, multipliers_8); |
8750
|
0
|
|
|
|
|
|
v5 = fold_vec(v5, *vp++, multipliers_8); |
8751
|
0
|
|
|
|
|
|
v6 = fold_vec(v6, *vp++, multipliers_8); |
8752
|
0
|
|
|
|
|
|
v7 = fold_vec(v7, *vp++, multipliers_8); |
8753
|
0
|
|
|
|
|
|
len -= 128; |
8754
|
0
|
0
|
|
|
|
|
} while (len >= 128 + 128); |
8755
|
|
|
|
|
|
|
|
8756
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v4, multipliers_4); |
8757
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v5, multipliers_4); |
8758
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, v6, multipliers_4); |
8759
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, v7, multipliers_4); |
8760
|
0
|
0
|
|
|
|
|
if (len & 64) { |
8761
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_4); |
8762
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_4); |
8763
|
0
|
|
|
|
|
|
v2 = fold_vec(v2, *vp++, multipliers_4); |
8764
|
0
|
|
|
|
|
|
v3 = fold_vec(v3, *vp++, multipliers_4); |
8765
|
|
|
|
|
|
|
} |
8766
|
|
|
|
|
|
|
|
8767
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v2, multipliers_2); |
8768
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, v3, multipliers_2); |
8769
|
0
|
0
|
|
|
|
|
if (len & 32) { |
8770
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_2); |
8771
|
0
|
|
|
|
|
|
v1 = fold_vec(v1, *vp++, multipliers_2); |
8772
|
|
|
|
|
|
|
} |
8773
|
|
|
|
|
|
|
|
8774
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, v1, multipliers_1); |
8775
|
0
|
0
|
|
|
|
|
if (len & 16) |
8776
|
0
|
|
|
|
|
|
v0 = fold_vec(v0, *vp++, multipliers_1); |
8777
|
|
|
|
|
|
|
|
8778
|
0
|
|
|
|
|
|
p = (const u8 *)vp; |
8779
|
|
|
|
|
|
|
} |
8780
|
0
|
|
|
|
|
|
len &= 15; |
8781
|
|
|
|
|
|
|
|
8782
|
|
|
|
|
|
|
|
8783
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8784
|
0
|
0
|
|
|
|
|
if (len) |
8785
|
0
|
|
|
|
|
|
v0 = fold_partial_vec(v0, p, len, multipliers_1); |
8786
|
|
|
|
|
|
|
#endif |
8787
|
|
|
|
|
|
|
|
8788
|
|
|
|
|
|
|
|
8789
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_srli_si128(v0, 8), |
8790
|
0
|
|
|
|
|
|
_mm_clmulepi64_si128(v0, multipliers_1, 0x10)); |
8791
|
|
|
|
|
|
|
|
8792
|
|
|
|
|
|
|
|
8793
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(_mm_srli_si128(v0, 4), |
8794
|
0
|
|
|
|
|
|
_mm_clmulepi64_si128(_mm_and_si128(v0, mask32), |
8795
|
|
|
|
|
|
|
final_multiplier, 0x00)); |
8796
|
|
|
|
|
|
|
|
8797
|
|
|
|
|
|
|
|
8798
|
0
|
|
|
|
|
|
v1 = _mm_clmulepi64_si128(_mm_and_si128(v0, mask32), |
8799
|
|
|
|
|
|
|
barrett_reduction_constants, 0x00); |
8800
|
0
|
|
|
|
|
|
v1 = _mm_clmulepi64_si128(_mm_and_si128(v1, mask32), |
8801
|
|
|
|
|
|
|
barrett_reduction_constants, 0x10); |
8802
|
0
|
|
|
|
|
|
v0 = _mm_xor_si128(v0, v1); |
8803
|
|
|
|
|
|
|
#if FOLD_PARTIAL_VECS |
8804
|
0
|
|
|
|
|
|
crc = _mm_extract_epi32(v0, 1); |
8805
|
|
|
|
|
|
|
#else |
8806
|
|
|
|
|
|
|
crc = _mm_cvtsi128_si32(_mm_shuffle_epi32(v0, 0x01)); |
8807
|
|
|
|
|
|
|
|
8808
|
|
|
|
|
|
|
crc = crc32_slice1(crc, p, len); |
8809
|
|
|
|
|
|
|
#endif |
8810
|
0
|
|
|
|
|
|
return crc; |
8811
|
|
|
|
|
|
|
} |
8812
|
|
|
|
|
|
|
|
8813
|
|
|
|
|
|
|
#undef SUFFIX |
8814
|
|
|
|
|
|
|
#undef ATTRIBUTES |
8815
|
|
|
|
|
|
|
#undef FOLD_PARTIAL_VECS |
8816
|
|
|
|
|
|
|
|
8817
|
|
|
|
|
|
|
#endif |
8818
|
|
|
|
|
|
|
|
8819
|
|
|
|
|
|
|
|
8820
|
|
|
|
|
|
|
#if defined(crc32_x86_pclmul_avx) && HAVE_PCLMUL_NATIVE && HAVE_AVX_NATIVE |
8821
|
|
|
|
|
|
|
#define DEFAULT_IMPL crc32_x86_pclmul_avx |
8822
|
|
|
|
|
|
|
#else |
8823
|
|
|
|
|
|
|
static inline crc32_func_t |
8824
|
2
|
|
|
|
|
|
arch_select_crc32_func(void) |
8825
|
|
|
|
|
|
|
{ |
8826
|
2
|
|
|
|
|
|
const u32 features MAYBE_UNUSED = get_x86_cpu_features(); |
8827
|
|
|
|
|
|
|
|
8828
|
|
|
|
|
|
|
#ifdef crc32_x86_pclmul_avx |
8829
|
2
|
50
|
|
|
|
|
if (HAVE_PCLMUL(features) && HAVE_AVX(features)) |
|
|
0
|
|
|
|
|
|
8830
|
0
|
|
|
|
|
|
return crc32_x86_pclmul_avx; |
8831
|
|
|
|
|
|
|
#endif |
8832
|
|
|
|
|
|
|
#ifdef crc32_x86_pclmul |
8833
|
2
|
50
|
|
|
|
|
if (HAVE_PCLMUL(features)) |
8834
|
0
|
|
|
|
|
|
return crc32_x86_pclmul; |
8835
|
|
|
|
|
|
|
#endif |
8836
|
2
|
|
|
|
|
|
return NULL; |
8837
|
|
|
|
|
|
|
} |
8838
|
|
|
|
|
|
|
#define arch_select_crc32_func arch_select_crc32_func |
8839
|
|
|
|
|
|
|
#endif |
8840
|
|
|
|
|
|
|
|
8841
|
|
|
|
|
|
|
#endif |
8842
|
|
|
|
|
|
|
|
8843
|
|
|
|
|
|
|
#endif |
8844
|
|
|
|
|
|
|
|
8845
|
|
|
|
|
|
|
#ifndef DEFAULT_IMPL |
8846
|
|
|
|
|
|
|
# define DEFAULT_IMPL crc32_slice8 |
8847
|
|
|
|
|
|
|
#endif |
8848
|
|
|
|
|
|
|
|
8849
|
|
|
|
|
|
|
#ifdef arch_select_crc32_func |
8850
|
|
|
|
|
|
|
static u32 crc32_dispatch_crc32(u32 crc, const u8 *p, size_t len); |
8851
|
|
|
|
|
|
|
|
8852
|
|
|
|
|
|
|
static volatile crc32_func_t crc32_impl = crc32_dispatch_crc32; |
8853
|
|
|
|
|
|
|
|
8854
|
|
|
|
|
|
|
|
8855
|
2
|
|
|
|
|
|
static u32 crc32_dispatch_crc32(u32 crc, const u8 *p, size_t len) |
8856
|
|
|
|
|
|
|
{ |
8857
|
2
|
|
|
|
|
|
crc32_func_t f = arch_select_crc32_func(); |
8858
|
|
|
|
|
|
|
|
8859
|
2
|
50
|
|
|
|
|
if (f == NULL) |
8860
|
2
|
|
|
|
|
|
f = DEFAULT_IMPL; |
8861
|
|
|
|
|
|
|
|
8862
|
2
|
|
|
|
|
|
crc32_impl = f; |
8863
|
2
|
|
|
|
|
|
return f(crc, p, len); |
8864
|
|
|
|
|
|
|
} |
8865
|
|
|
|
|
|
|
#else |
8866
|
|
|
|
|
|
|
|
8867
|
|
|
|
|
|
|
#define crc32_impl DEFAULT_IMPL |
8868
|
|
|
|
|
|
|
#endif |
8869
|
|
|
|
|
|
|
|
8870
|
|
|
|
|
|
|
LIBDEFLATEAPI u32 |
8871
|
29
|
|
|
|
|
|
libdeflate_crc32(u32 crc, const void *p, size_t len) |
8872
|
|
|
|
|
|
|
{ |
8873
|
29
|
50
|
|
|
|
|
if (p == NULL) |
8874
|
0
|
|
|
|
|
|
return 0; |
8875
|
29
|
|
|
|
|
|
return ~crc32_impl(~crc, p, len); |
8876
|
|
|
|
|
|
|
} |
8877
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/deflate_compress.c */ |
8878
|
|
|
|
|
|
|
|
8879
|
|
|
|
|
|
|
|
8880
|
|
|
|
|
|
|
/* #include "deflate_compress.h" */ |
8881
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_COMPRESS_H |
8882
|
|
|
|
|
|
|
#define LIB_DEFLATE_COMPRESS_H |
8883
|
|
|
|
|
|
|
|
8884
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
8885
|
|
|
|
|
|
|
|
8886
|
|
|
|
|
|
|
|
8887
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
8888
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
8889
|
|
|
|
|
|
|
|
8890
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
8891
|
|
|
|
|
|
|
|
8892
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
8893
|
|
|
|
|
|
|
#endif |
8894
|
|
|
|
|
|
|
|
8895
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
8896
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
8897
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
8898
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
8899
|
|
|
|
|
|
|
#else |
8900
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
8901
|
|
|
|
|
|
|
#endif |
8902
|
|
|
|
|
|
|
|
8903
|
|
|
|
|
|
|
|
8904
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
8905
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
8906
|
|
|
|
|
|
|
#else |
8907
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
8908
|
|
|
|
|
|
|
#endif |
8909
|
|
|
|
|
|
|
|
8910
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
8911
|
|
|
|
|
|
|
|
8912
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
8913
|
|
|
|
|
|
|
|
8914
|
|
|
|
|
|
|
|
8915
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
8916
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
8917
|
|
|
|
|
|
|
|
8918
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
8919
|
|
|
|
|
|
|
|
8920
|
|
|
|
|
|
|
|
8921
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
8922
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
8923
|
|
|
|
|
|
|
|
8924
|
|
|
|
|
|
|
#include |
8925
|
|
|
|
|
|
|
#include |
8926
|
|
|
|
|
|
|
|
8927
|
|
|
|
|
|
|
#ifdef __cplusplus |
8928
|
|
|
|
|
|
|
extern "C" { |
8929
|
|
|
|
|
|
|
#endif |
8930
|
|
|
|
|
|
|
|
8931
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
8932
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
8933
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
8934
|
|
|
|
|
|
|
|
8935
|
|
|
|
|
|
|
|
8936
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
8937
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
8938
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
8939
|
|
|
|
|
|
|
# else |
8940
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
8941
|
|
|
|
|
|
|
# endif |
8942
|
|
|
|
|
|
|
#endif |
8943
|
|
|
|
|
|
|
|
8944
|
|
|
|
|
|
|
|
8945
|
|
|
|
|
|
|
|
8946
|
|
|
|
|
|
|
|
8947
|
|
|
|
|
|
|
|
8948
|
|
|
|
|
|
|
struct libdeflate_compressor; |
8949
|
|
|
|
|
|
|
|
8950
|
|
|
|
|
|
|
|
8951
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
8952
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
8953
|
|
|
|
|
|
|
|
8954
|
|
|
|
|
|
|
|
8955
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
8956
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
8957
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
8958
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
8959
|
|
|
|
|
|
|
|
8960
|
|
|
|
|
|
|
|
8961
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
8962
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
8963
|
|
|
|
|
|
|
size_t in_nbytes); |
8964
|
|
|
|
|
|
|
|
8965
|
|
|
|
|
|
|
|
8966
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
8967
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
8968
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
8969
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
8970
|
|
|
|
|
|
|
|
8971
|
|
|
|
|
|
|
|
8972
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
8973
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
8974
|
|
|
|
|
|
|
size_t in_nbytes); |
8975
|
|
|
|
|
|
|
|
8976
|
|
|
|
|
|
|
|
8977
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
8978
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
8979
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
8980
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
8981
|
|
|
|
|
|
|
|
8982
|
|
|
|
|
|
|
|
8983
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
8984
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
8985
|
|
|
|
|
|
|
size_t in_nbytes); |
8986
|
|
|
|
|
|
|
|
8987
|
|
|
|
|
|
|
|
8988
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
8989
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
8990
|
|
|
|
|
|
|
|
8991
|
|
|
|
|
|
|
|
8992
|
|
|
|
|
|
|
|
8993
|
|
|
|
|
|
|
|
8994
|
|
|
|
|
|
|
|
8995
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
8996
|
|
|
|
|
|
|
|
8997
|
|
|
|
|
|
|
|
8998
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
8999
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
9000
|
|
|
|
|
|
|
|
9001
|
|
|
|
|
|
|
|
9002
|
|
|
|
|
|
|
enum libdeflate_result { |
9003
|
|
|
|
|
|
|
|
9004
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
9005
|
|
|
|
|
|
|
|
9006
|
|
|
|
|
|
|
|
9007
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
9008
|
|
|
|
|
|
|
|
9009
|
|
|
|
|
|
|
|
9010
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
9011
|
|
|
|
|
|
|
|
9012
|
|
|
|
|
|
|
|
9013
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
9014
|
|
|
|
|
|
|
}; |
9015
|
|
|
|
|
|
|
|
9016
|
|
|
|
|
|
|
|
9017
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9018
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
9019
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9020
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9021
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9022
|
|
|
|
|
|
|
|
9023
|
|
|
|
|
|
|
|
9024
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9025
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
9026
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9027
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9028
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
9029
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9030
|
|
|
|
|
|
|
|
9031
|
|
|
|
|
|
|
|
9032
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9033
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
9034
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9035
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9036
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9037
|
|
|
|
|
|
|
|
9038
|
|
|
|
|
|
|
|
9039
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9040
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
9041
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9042
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9043
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
9044
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9045
|
|
|
|
|
|
|
|
9046
|
|
|
|
|
|
|
|
9047
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9048
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
9049
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9050
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9051
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9052
|
|
|
|
|
|
|
|
9053
|
|
|
|
|
|
|
|
9054
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
9055
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
9056
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9057
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
9058
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
9059
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
9060
|
|
|
|
|
|
|
|
9061
|
|
|
|
|
|
|
|
9062
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
9063
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
9064
|
|
|
|
|
|
|
|
9065
|
|
|
|
|
|
|
|
9066
|
|
|
|
|
|
|
|
9067
|
|
|
|
|
|
|
|
9068
|
|
|
|
|
|
|
|
9069
|
|
|
|
|
|
|
|
9070
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
9071
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
9072
|
|
|
|
|
|
|
|
9073
|
|
|
|
|
|
|
|
9074
|
|
|
|
|
|
|
|
9075
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
9076
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
9077
|
|
|
|
|
|
|
|
9078
|
|
|
|
|
|
|
|
9079
|
|
|
|
|
|
|
|
9080
|
|
|
|
|
|
|
|
9081
|
|
|
|
|
|
|
|
9082
|
|
|
|
|
|
|
|
9083
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
9084
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
9085
|
|
|
|
|
|
|
void (*free_func)(void *)); |
9086
|
|
|
|
|
|
|
|
9087
|
|
|
|
|
|
|
#ifdef __cplusplus |
9088
|
|
|
|
|
|
|
} |
9089
|
|
|
|
|
|
|
#endif |
9090
|
|
|
|
|
|
|
|
9091
|
|
|
|
|
|
|
#endif |
9092
|
|
|
|
|
|
|
|
9093
|
|
|
|
|
|
|
|
9094
|
|
|
|
|
|
|
#include |
9095
|
|
|
|
|
|
|
#include |
9096
|
|
|
|
|
|
|
#include |
9097
|
|
|
|
|
|
|
#ifdef _MSC_VER |
9098
|
|
|
|
|
|
|
# include |
9099
|
|
|
|
|
|
|
# include |
9100
|
|
|
|
|
|
|
|
9101
|
|
|
|
|
|
|
|
9102
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
9103
|
|
|
|
|
|
|
|
9104
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
9105
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
9106
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
9107
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
9108
|
|
|
|
|
|
|
|
9109
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
9110
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
9111
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
9112
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
9113
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
9114
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
9115
|
|
|
|
|
|
|
#endif |
9116
|
|
|
|
|
|
|
#ifndef FREESTANDING |
9117
|
|
|
|
|
|
|
# include |
9118
|
|
|
|
|
|
|
#endif |
9119
|
|
|
|
|
|
|
|
9120
|
|
|
|
|
|
|
|
9121
|
|
|
|
|
|
|
|
9122
|
|
|
|
|
|
|
|
9123
|
|
|
|
|
|
|
|
9124
|
|
|
|
|
|
|
|
9125
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
9126
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
9127
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
9128
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
9129
|
|
|
|
|
|
|
#ifdef _MSC_VER |
9130
|
|
|
|
|
|
|
# if defined(_M_X64) |
9131
|
|
|
|
|
|
|
# define ARCH_X86_64 |
9132
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
9133
|
|
|
|
|
|
|
# define ARCH_X86_32 |
9134
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
9135
|
|
|
|
|
|
|
# define ARCH_ARM64 |
9136
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
9137
|
|
|
|
|
|
|
# define ARCH_ARM32 |
9138
|
|
|
|
|
|
|
# endif |
9139
|
|
|
|
|
|
|
#else |
9140
|
|
|
|
|
|
|
# if defined(__x86_64__) |
9141
|
|
|
|
|
|
|
# define ARCH_X86_64 |
9142
|
|
|
|
|
|
|
# elif defined(__i386__) |
9143
|
|
|
|
|
|
|
# define ARCH_X86_32 |
9144
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
9145
|
|
|
|
|
|
|
# define ARCH_ARM64 |
9146
|
|
|
|
|
|
|
# elif defined(__arm__) |
9147
|
|
|
|
|
|
|
# define ARCH_ARM32 |
9148
|
|
|
|
|
|
|
# endif |
9149
|
|
|
|
|
|
|
#endif |
9150
|
|
|
|
|
|
|
|
9151
|
|
|
|
|
|
|
|
9152
|
|
|
|
|
|
|
|
9153
|
|
|
|
|
|
|
|
9154
|
|
|
|
|
|
|
|
9155
|
|
|
|
|
|
|
|
9156
|
|
|
|
|
|
|
typedef uint8_t u8; |
9157
|
|
|
|
|
|
|
typedef uint16_t u16; |
9158
|
|
|
|
|
|
|
typedef uint32_t u32; |
9159
|
|
|
|
|
|
|
typedef uint64_t u64; |
9160
|
|
|
|
|
|
|
typedef int8_t s8; |
9161
|
|
|
|
|
|
|
typedef int16_t s16; |
9162
|
|
|
|
|
|
|
typedef int32_t s32; |
9163
|
|
|
|
|
|
|
typedef int64_t s64; |
9164
|
|
|
|
|
|
|
|
9165
|
|
|
|
|
|
|
|
9166
|
|
|
|
|
|
|
#ifdef _MSC_VER |
9167
|
|
|
|
|
|
|
# ifdef _WIN64 |
9168
|
|
|
|
|
|
|
typedef long long ssize_t; |
9169
|
|
|
|
|
|
|
# else |
9170
|
|
|
|
|
|
|
typedef long ssize_t; |
9171
|
|
|
|
|
|
|
# endif |
9172
|
|
|
|
|
|
|
#endif |
9173
|
|
|
|
|
|
|
|
9174
|
|
|
|
|
|
|
|
9175
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
9176
|
|
|
|
|
|
|
|
9177
|
|
|
|
|
|
|
|
9178
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
9179
|
|
|
|
|
|
|
|
9180
|
|
|
|
|
|
|
|
9181
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
9182
|
|
|
|
|
|
|
|
9183
|
|
|
|
|
|
|
|
9184
|
|
|
|
|
|
|
|
9185
|
|
|
|
|
|
|
|
9186
|
|
|
|
|
|
|
|
9187
|
|
|
|
|
|
|
|
9188
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
9189
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
9190
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
9191
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
9192
|
|
|
|
|
|
|
#else |
9193
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
9194
|
|
|
|
|
|
|
#endif |
9195
|
|
|
|
|
|
|
#ifdef __clang__ |
9196
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
9197
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
9198
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
9199
|
|
|
|
|
|
|
# else |
9200
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
9201
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
9202
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
9203
|
|
|
|
|
|
|
# endif |
9204
|
|
|
|
|
|
|
#else |
9205
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
9206
|
|
|
|
|
|
|
#endif |
9207
|
|
|
|
|
|
|
|
9208
|
|
|
|
|
|
|
|
9209
|
|
|
|
|
|
|
#ifndef __has_attribute |
9210
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
9211
|
|
|
|
|
|
|
#endif |
9212
|
|
|
|
|
|
|
#ifndef __has_builtin |
9213
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
9214
|
|
|
|
|
|
|
#endif |
9215
|
|
|
|
|
|
|
|
9216
|
|
|
|
|
|
|
|
9217
|
|
|
|
|
|
|
#ifdef _MSC_VER |
9218
|
|
|
|
|
|
|
# define inline __inline |
9219
|
|
|
|
|
|
|
#endif |
9220
|
|
|
|
|
|
|
|
9221
|
|
|
|
|
|
|
|
9222
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
9223
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
9224
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9225
|
|
|
|
|
|
|
# define forceinline __forceinline |
9226
|
|
|
|
|
|
|
#else |
9227
|
|
|
|
|
|
|
# define forceinline inline |
9228
|
|
|
|
|
|
|
#endif |
9229
|
|
|
|
|
|
|
|
9230
|
|
|
|
|
|
|
|
9231
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
9232
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
9233
|
|
|
|
|
|
|
#else |
9234
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
9235
|
|
|
|
|
|
|
#endif |
9236
|
|
|
|
|
|
|
|
9237
|
|
|
|
|
|
|
|
9238
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
9239
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
9240
|
|
|
|
|
|
|
# define restrict __restrict__ |
9241
|
|
|
|
|
|
|
# else |
9242
|
|
|
|
|
|
|
# define restrict |
9243
|
|
|
|
|
|
|
# endif |
9244
|
|
|
|
|
|
|
#endif |
9245
|
|
|
|
|
|
|
|
9246
|
|
|
|
|
|
|
|
9247
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
9248
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
9249
|
|
|
|
|
|
|
#else |
9250
|
|
|
|
|
|
|
# define likely(expr) (expr) |
9251
|
|
|
|
|
|
|
#endif |
9252
|
|
|
|
|
|
|
|
9253
|
|
|
|
|
|
|
|
9254
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
9255
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
9256
|
|
|
|
|
|
|
#else |
9257
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
9258
|
|
|
|
|
|
|
#endif |
9259
|
|
|
|
|
|
|
|
9260
|
|
|
|
|
|
|
|
9261
|
|
|
|
|
|
|
#undef prefetchr |
9262
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
9263
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
9264
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9265
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
9266
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
9267
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
9268
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
9269
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
9270
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
9271
|
|
|
|
|
|
|
# endif |
9272
|
|
|
|
|
|
|
#endif |
9273
|
|
|
|
|
|
|
#ifndef prefetchr |
9274
|
|
|
|
|
|
|
# define prefetchr(addr) |
9275
|
|
|
|
|
|
|
#endif |
9276
|
|
|
|
|
|
|
|
9277
|
|
|
|
|
|
|
|
9278
|
|
|
|
|
|
|
#undef prefetchw |
9279
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
9280
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
9281
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9282
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
9283
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
9284
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
9285
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
9286
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
9287
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
9288
|
|
|
|
|
|
|
# endif |
9289
|
|
|
|
|
|
|
#endif |
9290
|
|
|
|
|
|
|
#ifndef prefetchw |
9291
|
|
|
|
|
|
|
# define prefetchw(addr) |
9292
|
|
|
|
|
|
|
#endif |
9293
|
|
|
|
|
|
|
|
9294
|
|
|
|
|
|
|
|
9295
|
|
|
|
|
|
|
#undef _aligned_attribute |
9296
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
9297
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
9298
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9299
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
9300
|
|
|
|
|
|
|
#endif |
9301
|
|
|
|
|
|
|
|
9302
|
|
|
|
|
|
|
|
9303
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
9304
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
9305
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
9306
|
|
|
|
|
|
|
#else |
9307
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
9308
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
9309
|
|
|
|
|
|
|
#endif |
9310
|
|
|
|
|
|
|
|
9311
|
|
|
|
|
|
|
|
9312
|
|
|
|
|
|
|
|
9313
|
|
|
|
|
|
|
|
9314
|
|
|
|
|
|
|
|
9315
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
9316
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
9317
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
9318
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
9319
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
9320
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
9321
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
9322
|
|
|
|
|
|
|
|
9323
|
|
|
|
|
|
|
|
9324
|
|
|
|
|
|
|
|
9325
|
|
|
|
|
|
|
|
9326
|
|
|
|
|
|
|
|
9327
|
|
|
|
|
|
|
|
9328
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
9329
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
9330
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9331
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
9332
|
|
|
|
|
|
|
#else |
9333
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
9334
|
|
|
|
|
|
|
{ |
9335
|
|
|
|
|
|
|
union { |
9336
|
|
|
|
|
|
|
u32 w; |
9337
|
|
|
|
|
|
|
u8 b; |
9338
|
|
|
|
|
|
|
} u; |
9339
|
|
|
|
|
|
|
|
9340
|
|
|
|
|
|
|
u.w = 1; |
9341
|
|
|
|
|
|
|
return u.b; |
9342
|
|
|
|
|
|
|
} |
9343
|
|
|
|
|
|
|
#endif |
9344
|
|
|
|
|
|
|
|
9345
|
|
|
|
|
|
|
|
9346
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
9347
|
|
|
|
|
|
|
{ |
9348
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
9349
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
9350
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9351
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
9352
|
|
|
|
|
|
|
#else |
9353
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
9354
|
|
|
|
|
|
|
#endif |
9355
|
|
|
|
|
|
|
} |
9356
|
|
|
|
|
|
|
|
9357
|
|
|
|
|
|
|
|
9358
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
9359
|
|
|
|
|
|
|
{ |
9360
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
9361
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
9362
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9363
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
9364
|
|
|
|
|
|
|
#else |
9365
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
9366
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
9367
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
9368
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
9369
|
|
|
|
|
|
|
#endif |
9370
|
|
|
|
|
|
|
} |
9371
|
|
|
|
|
|
|
|
9372
|
|
|
|
|
|
|
|
9373
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
9374
|
|
|
|
|
|
|
{ |
9375
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
9376
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
9377
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9378
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
9379
|
|
|
|
|
|
|
#else |
9380
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
9381
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
9382
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
9383
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
9384
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
9385
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
9386
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
9387
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
9388
|
|
|
|
|
|
|
#endif |
9389
|
|
|
|
|
|
|
} |
9390
|
|
|
|
|
|
|
|
9391
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
9392
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
9393
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
9394
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
9395
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
9396
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
9397
|
|
|
|
|
|
|
|
9398
|
|
|
|
|
|
|
|
9399
|
|
|
|
|
|
|
|
9400
|
|
|
|
|
|
|
|
9401
|
|
|
|
|
|
|
|
9402
|
|
|
|
|
|
|
|
9403
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
9404
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
9405
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
9406
|
|
|
|
|
|
|
defined(__wasm__)) |
9407
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
9408
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9409
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
9410
|
|
|
|
|
|
|
#else |
9411
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
9412
|
|
|
|
|
|
|
#endif |
9413
|
|
|
|
|
|
|
|
9414
|
|
|
|
|
|
|
|
9415
|
|
|
|
|
|
|
|
9416
|
|
|
|
|
|
|
#ifdef FREESTANDING |
9417
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
9418
|
|
|
|
|
|
|
#else |
9419
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
9420
|
|
|
|
|
|
|
#endif |
9421
|
|
|
|
|
|
|
|
9422
|
|
|
|
|
|
|
|
9423
|
|
|
|
|
|
|
|
9424
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
9425
|
|
|
|
|
|
|
static forceinline type \ |
9426
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
9427
|
|
|
|
|
|
|
{ \ |
9428
|
|
|
|
|
|
|
type v; \ |
9429
|
|
|
|
|
|
|
\ |
9430
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
9431
|
|
|
|
|
|
|
return v; \ |
9432
|
|
|
|
|
|
|
} \ |
9433
|
|
|
|
|
|
|
\ |
9434
|
|
|
|
|
|
|
static forceinline void \ |
9435
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
9436
|
|
|
|
|
|
|
{ \ |
9437
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
9438
|
|
|
|
|
|
|
} |
9439
|
|
|
|
|
|
|
|
9440
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
9441
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
9442
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
9443
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
9444
|
|
|
|
|
|
|
|
9445
|
|
|
|
|
|
|
#undef MEMCOPY |
9446
|
|
|
|
|
|
|
|
9447
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
9448
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
9449
|
|
|
|
|
|
|
|
9450
|
|
|
|
|
|
|
|
9451
|
|
|
|
|
|
|
|
9452
|
|
|
|
|
|
|
static forceinline u16 |
9453
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
9454
|
|
|
|
|
|
|
{ |
9455
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9456
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
9457
|
|
|
|
|
|
|
else |
9458
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
9459
|
|
|
|
|
|
|
} |
9460
|
|
|
|
|
|
|
|
9461
|
|
|
|
|
|
|
static forceinline u16 |
9462
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
9463
|
|
|
|
|
|
|
{ |
9464
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9465
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
9466
|
|
|
|
|
|
|
else |
9467
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
9468
|
|
|
|
|
|
|
} |
9469
|
|
|
|
|
|
|
|
9470
|
|
|
|
|
|
|
static forceinline u32 |
9471
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
9472
|
|
|
|
|
|
|
{ |
9473
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9474
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
9475
|
|
|
|
|
|
|
else |
9476
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
9477
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
9478
|
|
|
|
|
|
|
} |
9479
|
|
|
|
|
|
|
|
9480
|
|
|
|
|
|
|
static forceinline u32 |
9481
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
9482
|
|
|
|
|
|
|
{ |
9483
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9484
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
9485
|
|
|
|
|
|
|
else |
9486
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
9487
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
9488
|
|
|
|
|
|
|
} |
9489
|
|
|
|
|
|
|
|
9490
|
|
|
|
|
|
|
static forceinline u64 |
9491
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
9492
|
|
|
|
|
|
|
{ |
9493
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
9494
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
9495
|
|
|
|
|
|
|
else |
9496
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
9497
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
9498
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
9499
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
9500
|
|
|
|
|
|
|
} |
9501
|
|
|
|
|
|
|
|
9502
|
|
|
|
|
|
|
static forceinline machine_word_t |
9503
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
9504
|
|
|
|
|
|
|
{ |
9505
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
9506
|
|
|
|
|
|
|
if (WORDBITS == 32) |
9507
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
9508
|
|
|
|
|
|
|
else |
9509
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
9510
|
|
|
|
|
|
|
} |
9511
|
|
|
|
|
|
|
|
9512
|
|
|
|
|
|
|
|
9513
|
|
|
|
|
|
|
|
9514
|
|
|
|
|
|
|
static forceinline void |
9515
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
9516
|
|
|
|
|
|
|
{ |
9517
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9518
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
9519
|
|
|
|
|
|
|
} else { |
9520
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
9521
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
9522
|
|
|
|
|
|
|
} |
9523
|
|
|
|
|
|
|
} |
9524
|
|
|
|
|
|
|
|
9525
|
|
|
|
|
|
|
static forceinline void |
9526
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
9527
|
|
|
|
|
|
|
{ |
9528
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9529
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
9530
|
|
|
|
|
|
|
} else { |
9531
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
9532
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
9533
|
|
|
|
|
|
|
} |
9534
|
|
|
|
|
|
|
} |
9535
|
|
|
|
|
|
|
|
9536
|
|
|
|
|
|
|
static forceinline void |
9537
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
9538
|
|
|
|
|
|
|
{ |
9539
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9540
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
9541
|
|
|
|
|
|
|
} else { |
9542
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
9543
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
9544
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
9545
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
9546
|
|
|
|
|
|
|
} |
9547
|
|
|
|
|
|
|
} |
9548
|
|
|
|
|
|
|
|
9549
|
|
|
|
|
|
|
static forceinline void |
9550
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
9551
|
|
|
|
|
|
|
{ |
9552
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9553
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
9554
|
|
|
|
|
|
|
} else { |
9555
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
9556
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
9557
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
9558
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
9559
|
|
|
|
|
|
|
} |
9560
|
|
|
|
|
|
|
} |
9561
|
|
|
|
|
|
|
|
9562
|
|
|
|
|
|
|
static forceinline void |
9563
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
9564
|
|
|
|
|
|
|
{ |
9565
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
9566
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
9567
|
|
|
|
|
|
|
} else { |
9568
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
9569
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
9570
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
9571
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
9572
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
9573
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
9574
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
9575
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
9576
|
|
|
|
|
|
|
} |
9577
|
|
|
|
|
|
|
} |
9578
|
|
|
|
|
|
|
|
9579
|
|
|
|
|
|
|
static forceinline void |
9580
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
9581
|
|
|
|
|
|
|
{ |
9582
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
9583
|
|
|
|
|
|
|
if (WORDBITS == 32) |
9584
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
9585
|
|
|
|
|
|
|
else |
9586
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
9587
|
|
|
|
|
|
|
} |
9588
|
|
|
|
|
|
|
|
9589
|
|
|
|
|
|
|
|
9590
|
|
|
|
|
|
|
|
9591
|
|
|
|
|
|
|
|
9592
|
|
|
|
|
|
|
|
9593
|
|
|
|
|
|
|
|
9594
|
|
|
|
|
|
|
|
9595
|
|
|
|
|
|
|
static forceinline unsigned |
9596
|
|
|
|
|
|
|
bsr32(u32 v) |
9597
|
|
|
|
|
|
|
{ |
9598
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
9599
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
9600
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9601
|
|
|
|
|
|
|
unsigned long i; |
9602
|
|
|
|
|
|
|
|
9603
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
9604
|
|
|
|
|
|
|
return i; |
9605
|
|
|
|
|
|
|
#else |
9606
|
|
|
|
|
|
|
unsigned i = 0; |
9607
|
|
|
|
|
|
|
|
9608
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
9609
|
|
|
|
|
|
|
i++; |
9610
|
|
|
|
|
|
|
return i; |
9611
|
|
|
|
|
|
|
#endif |
9612
|
|
|
|
|
|
|
} |
9613
|
|
|
|
|
|
|
|
9614
|
|
|
|
|
|
|
static forceinline unsigned |
9615
|
|
|
|
|
|
|
bsr64(u64 v) |
9616
|
|
|
|
|
|
|
{ |
9617
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
9618
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
9619
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
9620
|
|
|
|
|
|
|
unsigned long i; |
9621
|
|
|
|
|
|
|
|
9622
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
9623
|
|
|
|
|
|
|
return i; |
9624
|
|
|
|
|
|
|
#else |
9625
|
|
|
|
|
|
|
unsigned i = 0; |
9626
|
|
|
|
|
|
|
|
9627
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
9628
|
|
|
|
|
|
|
i++; |
9629
|
|
|
|
|
|
|
return i; |
9630
|
|
|
|
|
|
|
#endif |
9631
|
|
|
|
|
|
|
} |
9632
|
|
|
|
|
|
|
|
9633
|
|
|
|
|
|
|
static forceinline unsigned |
9634
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
9635
|
|
|
|
|
|
|
{ |
9636
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
9637
|
|
|
|
|
|
|
if (WORDBITS == 32) |
9638
|
|
|
|
|
|
|
return bsr32(v); |
9639
|
|
|
|
|
|
|
else |
9640
|
|
|
|
|
|
|
return bsr64(v); |
9641
|
|
|
|
|
|
|
} |
9642
|
|
|
|
|
|
|
|
9643
|
|
|
|
|
|
|
|
9644
|
|
|
|
|
|
|
|
9645
|
|
|
|
|
|
|
static forceinline unsigned |
9646
|
|
|
|
|
|
|
bsf32(u32 v) |
9647
|
|
|
|
|
|
|
{ |
9648
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
9649
|
|
|
|
|
|
|
return __builtin_ctz(v); |
9650
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
9651
|
|
|
|
|
|
|
unsigned long i; |
9652
|
|
|
|
|
|
|
|
9653
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
9654
|
|
|
|
|
|
|
return i; |
9655
|
|
|
|
|
|
|
#else |
9656
|
|
|
|
|
|
|
unsigned i = 0; |
9657
|
|
|
|
|
|
|
|
9658
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
9659
|
|
|
|
|
|
|
i++; |
9660
|
|
|
|
|
|
|
return i; |
9661
|
|
|
|
|
|
|
#endif |
9662
|
|
|
|
|
|
|
} |
9663
|
|
|
|
|
|
|
|
9664
|
|
|
|
|
|
|
static forceinline unsigned |
9665
|
|
|
|
|
|
|
bsf64(u64 v) |
9666
|
|
|
|
|
|
|
{ |
9667
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
9668
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
9669
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
9670
|
|
|
|
|
|
|
unsigned long i; |
9671
|
|
|
|
|
|
|
|
9672
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
9673
|
|
|
|
|
|
|
return i; |
9674
|
|
|
|
|
|
|
#else |
9675
|
|
|
|
|
|
|
unsigned i = 0; |
9676
|
|
|
|
|
|
|
|
9677
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
9678
|
|
|
|
|
|
|
i++; |
9679
|
|
|
|
|
|
|
return i; |
9680
|
|
|
|
|
|
|
#endif |
9681
|
|
|
|
|
|
|
} |
9682
|
|
|
|
|
|
|
|
9683
|
|
|
|
|
|
|
static forceinline unsigned |
9684
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
9685
|
|
|
|
|
|
|
{ |
9686
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
9687
|
|
|
|
|
|
|
if (WORDBITS == 32) |
9688
|
|
|
|
|
|
|
return bsf32(v); |
9689
|
|
|
|
|
|
|
else |
9690
|
|
|
|
|
|
|
return bsf64(v); |
9691
|
|
|
|
|
|
|
} |
9692
|
|
|
|
|
|
|
|
9693
|
|
|
|
|
|
|
|
9694
|
|
|
|
|
|
|
#undef rbit32 |
9695
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
9696
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
9697
|
|
|
|
|
|
|
static forceinline u32 |
9698
|
|
|
|
|
|
|
rbit32(u32 v) |
9699
|
|
|
|
|
|
|
{ |
9700
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
9701
|
|
|
|
|
|
|
return v; |
9702
|
|
|
|
|
|
|
} |
9703
|
|
|
|
|
|
|
#define rbit32 rbit32 |
9704
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
9705
|
|
|
|
|
|
|
static forceinline u32 |
9706
|
|
|
|
|
|
|
rbit32(u32 v) |
9707
|
|
|
|
|
|
|
{ |
9708
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
9709
|
|
|
|
|
|
|
return v; |
9710
|
|
|
|
|
|
|
} |
9711
|
|
|
|
|
|
|
#define rbit32 rbit32 |
9712
|
|
|
|
|
|
|
#endif |
9713
|
|
|
|
|
|
|
|
9714
|
|
|
|
|
|
|
#endif |
9715
|
|
|
|
|
|
|
|
9716
|
|
|
|
|
|
|
|
9717
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
9718
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
9719
|
|
|
|
|
|
|
|
9720
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
9721
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
9722
|
|
|
|
|
|
|
|
9723
|
|
|
|
|
|
|
#ifdef FREESTANDING |
9724
|
|
|
|
|
|
|
|
9725
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
9726
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
9727
|
|
|
|
|
|
|
|
9728
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
9729
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
9730
|
|
|
|
|
|
|
|
9731
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
9732
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
9733
|
|
|
|
|
|
|
|
9734
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
9735
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
9736
|
|
|
|
|
|
|
|
9737
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
9738
|
|
|
|
|
|
|
#else |
9739
|
|
|
|
|
|
|
#include |
9740
|
|
|
|
|
|
|
#endif |
9741
|
|
|
|
|
|
|
|
9742
|
|
|
|
|
|
|
|
9743
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
9744
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
9745
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
9746
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
9747
|
|
|
|
|
|
|
#else |
9748
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
9749
|
|
|
|
|
|
|
#endif |
9750
|
|
|
|
|
|
|
|
9751
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
9752
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
9753
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
9754
|
|
|
|
|
|
|
|
9755
|
|
|
|
|
|
|
#endif |
9756
|
|
|
|
|
|
|
|
9757
|
|
|
|
|
|
|
|
9758
|
|
|
|
|
|
|
|
9759
|
|
|
|
|
|
|
|
9760
|
|
|
|
|
|
|
struct libdeflate_compressor; |
9761
|
|
|
|
|
|
|
|
9762
|
|
|
|
|
|
|
unsigned int libdeflate_get_compression_level(struct libdeflate_compressor *c); |
9763
|
|
|
|
|
|
|
|
9764
|
|
|
|
|
|
|
#endif |
9765
|
|
|
|
|
|
|
|
9766
|
|
|
|
|
|
|
/* #include "deflate_constants.h" */ |
9767
|
|
|
|
|
|
|
|
9768
|
|
|
|
|
|
|
|
9769
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_CONSTANTS_H |
9770
|
|
|
|
|
|
|
#define LIB_DEFLATE_CONSTANTS_H |
9771
|
|
|
|
|
|
|
|
9772
|
|
|
|
|
|
|
|
9773
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_UNCOMPRESSED 0 |
9774
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_STATIC_HUFFMAN 1 |
9775
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN 2 |
9776
|
|
|
|
|
|
|
|
9777
|
|
|
|
|
|
|
|
9778
|
|
|
|
|
|
|
#define DEFLATE_MIN_MATCH_LEN 3 |
9779
|
|
|
|
|
|
|
#define DEFLATE_MAX_MATCH_LEN 258 |
9780
|
|
|
|
|
|
|
|
9781
|
|
|
|
|
|
|
|
9782
|
|
|
|
|
|
|
#define DEFLATE_MAX_MATCH_OFFSET 32768 |
9783
|
|
|
|
|
|
|
|
9784
|
|
|
|
|
|
|
|
9785
|
|
|
|
|
|
|
#define DEFLATE_WINDOW_ORDER 15 |
9786
|
|
|
|
|
|
|
|
9787
|
|
|
|
|
|
|
|
9788
|
|
|
|
|
|
|
#define DEFLATE_NUM_PRECODE_SYMS 19 |
9789
|
|
|
|
|
|
|
#define DEFLATE_NUM_LITLEN_SYMS 288 |
9790
|
|
|
|
|
|
|
#define DEFLATE_NUM_OFFSET_SYMS 32 |
9791
|
|
|
|
|
|
|
|
9792
|
|
|
|
|
|
|
|
9793
|
|
|
|
|
|
|
#define DEFLATE_MAX_NUM_SYMS 288 |
9794
|
|
|
|
|
|
|
|
9795
|
|
|
|
|
|
|
|
9796
|
|
|
|
|
|
|
#define DEFLATE_NUM_LITERALS 256 |
9797
|
|
|
|
|
|
|
#define DEFLATE_END_OF_BLOCK 256 |
9798
|
|
|
|
|
|
|
#define DEFLATE_FIRST_LEN_SYM 257 |
9799
|
|
|
|
|
|
|
|
9800
|
|
|
|
|
|
|
|
9801
|
|
|
|
|
|
|
#define DEFLATE_MAX_PRE_CODEWORD_LEN 7 |
9802
|
|
|
|
|
|
|
#define DEFLATE_MAX_LITLEN_CODEWORD_LEN 15 |
9803
|
|
|
|
|
|
|
#define DEFLATE_MAX_OFFSET_CODEWORD_LEN 15 |
9804
|
|
|
|
|
|
|
|
9805
|
|
|
|
|
|
|
|
9806
|
|
|
|
|
|
|
#define DEFLATE_MAX_CODEWORD_LEN 15 |
9807
|
|
|
|
|
|
|
|
9808
|
|
|
|
|
|
|
|
9809
|
|
|
|
|
|
|
#define DEFLATE_MAX_LENS_OVERRUN 137 |
9810
|
|
|
|
|
|
|
|
9811
|
|
|
|
|
|
|
|
9812
|
|
|
|
|
|
|
#define DEFLATE_MAX_EXTRA_LENGTH_BITS 5 |
9813
|
|
|
|
|
|
|
#define DEFLATE_MAX_EXTRA_OFFSET_BITS 13 |
9814
|
|
|
|
|
|
|
|
9815
|
|
|
|
|
|
|
#endif |
9816
|
|
|
|
|
|
|
|
9817
|
|
|
|
|
|
|
|
9818
|
|
|
|
|
|
|
|
9819
|
|
|
|
|
|
|
|
9820
|
|
|
|
|
|
|
|
9821
|
|
|
|
|
|
|
|
9822
|
|
|
|
|
|
|
|
9823
|
|
|
|
|
|
|
#define SUPPORT_NEAR_OPTIMAL_PARSING 1 |
9824
|
|
|
|
|
|
|
|
9825
|
|
|
|
|
|
|
|
9826
|
|
|
|
|
|
|
#define MIN_BLOCK_LENGTH 5000 |
9827
|
|
|
|
|
|
|
|
9828
|
|
|
|
|
|
|
|
9829
|
|
|
|
|
|
|
#define SOFT_MAX_BLOCK_LENGTH 300000 |
9830
|
|
|
|
|
|
|
|
9831
|
|
|
|
|
|
|
|
9832
|
|
|
|
|
|
|
#define SEQ_STORE_LENGTH 50000 |
9833
|
|
|
|
|
|
|
|
9834
|
|
|
|
|
|
|
|
9835
|
|
|
|
|
|
|
#define FAST_SOFT_MAX_BLOCK_LENGTH 65535 |
9836
|
|
|
|
|
|
|
|
9837
|
|
|
|
|
|
|
|
9838
|
|
|
|
|
|
|
#define FAST_SEQ_STORE_LENGTH 8192 |
9839
|
|
|
|
|
|
|
|
9840
|
|
|
|
|
|
|
|
9841
|
|
|
|
|
|
|
#define MAX_LITLEN_CODEWORD_LEN 14 |
9842
|
|
|
|
|
|
|
#define MAX_OFFSET_CODEWORD_LEN DEFLATE_MAX_OFFSET_CODEWORD_LEN |
9843
|
|
|
|
|
|
|
#define MAX_PRE_CODEWORD_LEN DEFLATE_MAX_PRE_CODEWORD_LEN |
9844
|
|
|
|
|
|
|
|
9845
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
9846
|
|
|
|
|
|
|
|
9847
|
|
|
|
|
|
|
|
9848
|
|
|
|
|
|
|
|
9849
|
|
|
|
|
|
|
|
9850
|
|
|
|
|
|
|
#define BIT_COST 16 |
9851
|
|
|
|
|
|
|
|
9852
|
|
|
|
|
|
|
|
9853
|
|
|
|
|
|
|
#define LITERAL_NOSTAT_BITS 13 |
9854
|
|
|
|
|
|
|
#define LENGTH_NOSTAT_BITS 13 |
9855
|
|
|
|
|
|
|
#define OFFSET_NOSTAT_BITS 10 |
9856
|
|
|
|
|
|
|
|
9857
|
|
|
|
|
|
|
|
9858
|
|
|
|
|
|
|
#define MATCH_CACHE_LENGTH (SOFT_MAX_BLOCK_LENGTH * 5) |
9859
|
|
|
|
|
|
|
|
9860
|
|
|
|
|
|
|
#endif |
9861
|
|
|
|
|
|
|
|
9862
|
|
|
|
|
|
|
|
9863
|
|
|
|
|
|
|
|
9864
|
|
|
|
|
|
|
|
9865
|
|
|
|
|
|
|
#define MATCHFINDER_WINDOW_ORDER DEFLATE_WINDOW_ORDER |
9866
|
|
|
|
|
|
|
/* #include "hc_matchfinder.h" */ |
9867
|
|
|
|
|
|
|
|
9868
|
|
|
|
|
|
|
|
9869
|
|
|
|
|
|
|
#ifndef LIB_HC_MATCHFINDER_H |
9870
|
|
|
|
|
|
|
#define LIB_HC_MATCHFINDER_H |
9871
|
|
|
|
|
|
|
|
9872
|
|
|
|
|
|
|
/* #include "matchfinder_common.h" */ |
9873
|
|
|
|
|
|
|
|
9874
|
|
|
|
|
|
|
|
9875
|
|
|
|
|
|
|
#ifndef LIB_MATCHFINDER_COMMON_H |
9876
|
|
|
|
|
|
|
#define LIB_MATCHFINDER_COMMON_H |
9877
|
|
|
|
|
|
|
|
9878
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
9879
|
|
|
|
|
|
|
|
9880
|
|
|
|
|
|
|
|
9881
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
9882
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
9883
|
|
|
|
|
|
|
|
9884
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
9885
|
|
|
|
|
|
|
|
9886
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
9887
|
|
|
|
|
|
|
#endif |
9888
|
|
|
|
|
|
|
|
9889
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
9890
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
9891
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
9892
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
9893
|
|
|
|
|
|
|
#else |
9894
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
9895
|
|
|
|
|
|
|
#endif |
9896
|
|
|
|
|
|
|
|
9897
|
|
|
|
|
|
|
|
9898
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
9899
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
9900
|
|
|
|
|
|
|
#else |
9901
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
9902
|
|
|
|
|
|
|
#endif |
9903
|
|
|
|
|
|
|
|
9904
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
9905
|
|
|
|
|
|
|
|
9906
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
9907
|
|
|
|
|
|
|
|
9908
|
|
|
|
|
|
|
|
9909
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
9910
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
9911
|
|
|
|
|
|
|
|
9912
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
9913
|
|
|
|
|
|
|
|
9914
|
|
|
|
|
|
|
|
9915
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
9916
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
9917
|
|
|
|
|
|
|
|
9918
|
|
|
|
|
|
|
#include |
9919
|
|
|
|
|
|
|
#include |
9920
|
|
|
|
|
|
|
|
9921
|
|
|
|
|
|
|
#ifdef __cplusplus |
9922
|
|
|
|
|
|
|
extern "C" { |
9923
|
|
|
|
|
|
|
#endif |
9924
|
|
|
|
|
|
|
|
9925
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
9926
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
9927
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
9928
|
|
|
|
|
|
|
|
9929
|
|
|
|
|
|
|
|
9930
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
9931
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
9932
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
9933
|
|
|
|
|
|
|
# else |
9934
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
9935
|
|
|
|
|
|
|
# endif |
9936
|
|
|
|
|
|
|
#endif |
9937
|
|
|
|
|
|
|
|
9938
|
|
|
|
|
|
|
|
9939
|
|
|
|
|
|
|
|
9940
|
|
|
|
|
|
|
|
9941
|
|
|
|
|
|
|
|
9942
|
|
|
|
|
|
|
struct libdeflate_compressor; |
9943
|
|
|
|
|
|
|
|
9944
|
|
|
|
|
|
|
|
9945
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
9946
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
9947
|
|
|
|
|
|
|
|
9948
|
|
|
|
|
|
|
|
9949
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9950
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
9951
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9952
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
9953
|
|
|
|
|
|
|
|
9954
|
|
|
|
|
|
|
|
9955
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9956
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
9957
|
|
|
|
|
|
|
size_t in_nbytes); |
9958
|
|
|
|
|
|
|
|
9959
|
|
|
|
|
|
|
|
9960
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9961
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
9962
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9963
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
9964
|
|
|
|
|
|
|
|
9965
|
|
|
|
|
|
|
|
9966
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9967
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
9968
|
|
|
|
|
|
|
size_t in_nbytes); |
9969
|
|
|
|
|
|
|
|
9970
|
|
|
|
|
|
|
|
9971
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9972
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
9973
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
9974
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
9975
|
|
|
|
|
|
|
|
9976
|
|
|
|
|
|
|
|
9977
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
9978
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
9979
|
|
|
|
|
|
|
size_t in_nbytes); |
9980
|
|
|
|
|
|
|
|
9981
|
|
|
|
|
|
|
|
9982
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
9983
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
9984
|
|
|
|
|
|
|
|
9985
|
|
|
|
|
|
|
|
9986
|
|
|
|
|
|
|
|
9987
|
|
|
|
|
|
|
|
9988
|
|
|
|
|
|
|
|
9989
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
9990
|
|
|
|
|
|
|
|
9991
|
|
|
|
|
|
|
|
9992
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
9993
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
9994
|
|
|
|
|
|
|
|
9995
|
|
|
|
|
|
|
|
9996
|
|
|
|
|
|
|
enum libdeflate_result { |
9997
|
|
|
|
|
|
|
|
9998
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
9999
|
|
|
|
|
|
|
|
10000
|
|
|
|
|
|
|
|
10001
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
10002
|
|
|
|
|
|
|
|
10003
|
|
|
|
|
|
|
|
10004
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
10005
|
|
|
|
|
|
|
|
10006
|
|
|
|
|
|
|
|
10007
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
10008
|
|
|
|
|
|
|
}; |
10009
|
|
|
|
|
|
|
|
10010
|
|
|
|
|
|
|
|
10011
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10012
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
10013
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10014
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10015
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10016
|
|
|
|
|
|
|
|
10017
|
|
|
|
|
|
|
|
10018
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10019
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
10020
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10021
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10022
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10023
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10024
|
|
|
|
|
|
|
|
10025
|
|
|
|
|
|
|
|
10026
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10027
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
10028
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10029
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10030
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10031
|
|
|
|
|
|
|
|
10032
|
|
|
|
|
|
|
|
10033
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10034
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
10035
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10036
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10037
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10038
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10039
|
|
|
|
|
|
|
|
10040
|
|
|
|
|
|
|
|
10041
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10042
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
10043
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10044
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10045
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10046
|
|
|
|
|
|
|
|
10047
|
|
|
|
|
|
|
|
10048
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10049
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
10050
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10051
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10052
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10053
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10054
|
|
|
|
|
|
|
|
10055
|
|
|
|
|
|
|
|
10056
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
10057
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
10058
|
|
|
|
|
|
|
|
10059
|
|
|
|
|
|
|
|
10060
|
|
|
|
|
|
|
|
10061
|
|
|
|
|
|
|
|
10062
|
|
|
|
|
|
|
|
10063
|
|
|
|
|
|
|
|
10064
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
10065
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
10066
|
|
|
|
|
|
|
|
10067
|
|
|
|
|
|
|
|
10068
|
|
|
|
|
|
|
|
10069
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
10070
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
10071
|
|
|
|
|
|
|
|
10072
|
|
|
|
|
|
|
|
10073
|
|
|
|
|
|
|
|
10074
|
|
|
|
|
|
|
|
10075
|
|
|
|
|
|
|
|
10076
|
|
|
|
|
|
|
|
10077
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
10078
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
10079
|
|
|
|
|
|
|
void (*free_func)(void *)); |
10080
|
|
|
|
|
|
|
|
10081
|
|
|
|
|
|
|
#ifdef __cplusplus |
10082
|
|
|
|
|
|
|
} |
10083
|
|
|
|
|
|
|
#endif |
10084
|
|
|
|
|
|
|
|
10085
|
|
|
|
|
|
|
#endif |
10086
|
|
|
|
|
|
|
|
10087
|
|
|
|
|
|
|
|
10088
|
|
|
|
|
|
|
#include |
10089
|
|
|
|
|
|
|
#include |
10090
|
|
|
|
|
|
|
#include |
10091
|
|
|
|
|
|
|
#ifdef _MSC_VER |
10092
|
|
|
|
|
|
|
# include |
10093
|
|
|
|
|
|
|
# include |
10094
|
|
|
|
|
|
|
|
10095
|
|
|
|
|
|
|
|
10096
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
10097
|
|
|
|
|
|
|
|
10098
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
10099
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
10100
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
10101
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
10102
|
|
|
|
|
|
|
|
10103
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
10104
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
10105
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
10106
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
10107
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
10108
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
10109
|
|
|
|
|
|
|
#endif |
10110
|
|
|
|
|
|
|
#ifndef FREESTANDING |
10111
|
|
|
|
|
|
|
# include |
10112
|
|
|
|
|
|
|
#endif |
10113
|
|
|
|
|
|
|
|
10114
|
|
|
|
|
|
|
|
10115
|
|
|
|
|
|
|
|
10116
|
|
|
|
|
|
|
|
10117
|
|
|
|
|
|
|
|
10118
|
|
|
|
|
|
|
|
10119
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
10120
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
10121
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
10122
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
10123
|
|
|
|
|
|
|
#ifdef _MSC_VER |
10124
|
|
|
|
|
|
|
# if defined(_M_X64) |
10125
|
|
|
|
|
|
|
# define ARCH_X86_64 |
10126
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
10127
|
|
|
|
|
|
|
# define ARCH_X86_32 |
10128
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
10129
|
|
|
|
|
|
|
# define ARCH_ARM64 |
10130
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
10131
|
|
|
|
|
|
|
# define ARCH_ARM32 |
10132
|
|
|
|
|
|
|
# endif |
10133
|
|
|
|
|
|
|
#else |
10134
|
|
|
|
|
|
|
# if defined(__x86_64__) |
10135
|
|
|
|
|
|
|
# define ARCH_X86_64 |
10136
|
|
|
|
|
|
|
# elif defined(__i386__) |
10137
|
|
|
|
|
|
|
# define ARCH_X86_32 |
10138
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
10139
|
|
|
|
|
|
|
# define ARCH_ARM64 |
10140
|
|
|
|
|
|
|
# elif defined(__arm__) |
10141
|
|
|
|
|
|
|
# define ARCH_ARM32 |
10142
|
|
|
|
|
|
|
# endif |
10143
|
|
|
|
|
|
|
#endif |
10144
|
|
|
|
|
|
|
|
10145
|
|
|
|
|
|
|
|
10146
|
|
|
|
|
|
|
|
10147
|
|
|
|
|
|
|
|
10148
|
|
|
|
|
|
|
|
10149
|
|
|
|
|
|
|
|
10150
|
|
|
|
|
|
|
typedef uint8_t u8; |
10151
|
|
|
|
|
|
|
typedef uint16_t u16; |
10152
|
|
|
|
|
|
|
typedef uint32_t u32; |
10153
|
|
|
|
|
|
|
typedef uint64_t u64; |
10154
|
|
|
|
|
|
|
typedef int8_t s8; |
10155
|
|
|
|
|
|
|
typedef int16_t s16; |
10156
|
|
|
|
|
|
|
typedef int32_t s32; |
10157
|
|
|
|
|
|
|
typedef int64_t s64; |
10158
|
|
|
|
|
|
|
|
10159
|
|
|
|
|
|
|
|
10160
|
|
|
|
|
|
|
#ifdef _MSC_VER |
10161
|
|
|
|
|
|
|
# ifdef _WIN64 |
10162
|
|
|
|
|
|
|
typedef long long ssize_t; |
10163
|
|
|
|
|
|
|
# else |
10164
|
|
|
|
|
|
|
typedef long ssize_t; |
10165
|
|
|
|
|
|
|
# endif |
10166
|
|
|
|
|
|
|
#endif |
10167
|
|
|
|
|
|
|
|
10168
|
|
|
|
|
|
|
|
10169
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
10170
|
|
|
|
|
|
|
|
10171
|
|
|
|
|
|
|
|
10172
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
10173
|
|
|
|
|
|
|
|
10174
|
|
|
|
|
|
|
|
10175
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
10176
|
|
|
|
|
|
|
|
10177
|
|
|
|
|
|
|
|
10178
|
|
|
|
|
|
|
|
10179
|
|
|
|
|
|
|
|
10180
|
|
|
|
|
|
|
|
10181
|
|
|
|
|
|
|
|
10182
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
10183
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
10184
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
10185
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
10186
|
|
|
|
|
|
|
#else |
10187
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
10188
|
|
|
|
|
|
|
#endif |
10189
|
|
|
|
|
|
|
#ifdef __clang__ |
10190
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
10191
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
10192
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
10193
|
|
|
|
|
|
|
# else |
10194
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
10195
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
10196
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
10197
|
|
|
|
|
|
|
# endif |
10198
|
|
|
|
|
|
|
#else |
10199
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
10200
|
|
|
|
|
|
|
#endif |
10201
|
|
|
|
|
|
|
|
10202
|
|
|
|
|
|
|
|
10203
|
|
|
|
|
|
|
#ifndef __has_attribute |
10204
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
10205
|
|
|
|
|
|
|
#endif |
10206
|
|
|
|
|
|
|
#ifndef __has_builtin |
10207
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
10208
|
|
|
|
|
|
|
#endif |
10209
|
|
|
|
|
|
|
|
10210
|
|
|
|
|
|
|
|
10211
|
|
|
|
|
|
|
#ifdef _MSC_VER |
10212
|
|
|
|
|
|
|
# define inline __inline |
10213
|
|
|
|
|
|
|
#endif |
10214
|
|
|
|
|
|
|
|
10215
|
|
|
|
|
|
|
|
10216
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
10217
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
10218
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10219
|
|
|
|
|
|
|
# define forceinline __forceinline |
10220
|
|
|
|
|
|
|
#else |
10221
|
|
|
|
|
|
|
# define forceinline inline |
10222
|
|
|
|
|
|
|
#endif |
10223
|
|
|
|
|
|
|
|
10224
|
|
|
|
|
|
|
|
10225
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
10226
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
10227
|
|
|
|
|
|
|
#else |
10228
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
10229
|
|
|
|
|
|
|
#endif |
10230
|
|
|
|
|
|
|
|
10231
|
|
|
|
|
|
|
|
10232
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
10233
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
10234
|
|
|
|
|
|
|
# define restrict __restrict__ |
10235
|
|
|
|
|
|
|
# else |
10236
|
|
|
|
|
|
|
# define restrict |
10237
|
|
|
|
|
|
|
# endif |
10238
|
|
|
|
|
|
|
#endif |
10239
|
|
|
|
|
|
|
|
10240
|
|
|
|
|
|
|
|
10241
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
10242
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
10243
|
|
|
|
|
|
|
#else |
10244
|
|
|
|
|
|
|
# define likely(expr) (expr) |
10245
|
|
|
|
|
|
|
#endif |
10246
|
|
|
|
|
|
|
|
10247
|
|
|
|
|
|
|
|
10248
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
10249
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
10250
|
|
|
|
|
|
|
#else |
10251
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
10252
|
|
|
|
|
|
|
#endif |
10253
|
|
|
|
|
|
|
|
10254
|
|
|
|
|
|
|
|
10255
|
|
|
|
|
|
|
#undef prefetchr |
10256
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
10257
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
10258
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10259
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
10260
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
10261
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
10262
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
10263
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
10264
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
10265
|
|
|
|
|
|
|
# endif |
10266
|
|
|
|
|
|
|
#endif |
10267
|
|
|
|
|
|
|
#ifndef prefetchr |
10268
|
|
|
|
|
|
|
# define prefetchr(addr) |
10269
|
|
|
|
|
|
|
#endif |
10270
|
|
|
|
|
|
|
|
10271
|
|
|
|
|
|
|
|
10272
|
|
|
|
|
|
|
#undef prefetchw |
10273
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
10274
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
10275
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10276
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
10277
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
10278
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
10279
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
10280
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
10281
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
10282
|
|
|
|
|
|
|
# endif |
10283
|
|
|
|
|
|
|
#endif |
10284
|
|
|
|
|
|
|
#ifndef prefetchw |
10285
|
|
|
|
|
|
|
# define prefetchw(addr) |
10286
|
|
|
|
|
|
|
#endif |
10287
|
|
|
|
|
|
|
|
10288
|
|
|
|
|
|
|
|
10289
|
|
|
|
|
|
|
#undef _aligned_attribute |
10290
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
10291
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
10292
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10293
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
10294
|
|
|
|
|
|
|
#endif |
10295
|
|
|
|
|
|
|
|
10296
|
|
|
|
|
|
|
|
10297
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
10298
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
10299
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
10300
|
|
|
|
|
|
|
#else |
10301
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
10302
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
10303
|
|
|
|
|
|
|
#endif |
10304
|
|
|
|
|
|
|
|
10305
|
|
|
|
|
|
|
|
10306
|
|
|
|
|
|
|
|
10307
|
|
|
|
|
|
|
|
10308
|
|
|
|
|
|
|
|
10309
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
10310
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
10311
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
10312
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
10313
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
10314
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
10315
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
10316
|
|
|
|
|
|
|
|
10317
|
|
|
|
|
|
|
|
10318
|
|
|
|
|
|
|
|
10319
|
|
|
|
|
|
|
|
10320
|
|
|
|
|
|
|
|
10321
|
|
|
|
|
|
|
|
10322
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
10323
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
10324
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10325
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
10326
|
|
|
|
|
|
|
#else |
10327
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
10328
|
|
|
|
|
|
|
{ |
10329
|
|
|
|
|
|
|
union { |
10330
|
|
|
|
|
|
|
u32 w; |
10331
|
|
|
|
|
|
|
u8 b; |
10332
|
|
|
|
|
|
|
} u; |
10333
|
|
|
|
|
|
|
|
10334
|
|
|
|
|
|
|
u.w = 1; |
10335
|
|
|
|
|
|
|
return u.b; |
10336
|
|
|
|
|
|
|
} |
10337
|
|
|
|
|
|
|
#endif |
10338
|
|
|
|
|
|
|
|
10339
|
|
|
|
|
|
|
|
10340
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
10341
|
|
|
|
|
|
|
{ |
10342
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
10343
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
10344
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10345
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
10346
|
|
|
|
|
|
|
#else |
10347
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
10348
|
|
|
|
|
|
|
#endif |
10349
|
|
|
|
|
|
|
} |
10350
|
|
|
|
|
|
|
|
10351
|
|
|
|
|
|
|
|
10352
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
10353
|
|
|
|
|
|
|
{ |
10354
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
10355
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
10356
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10357
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
10358
|
|
|
|
|
|
|
#else |
10359
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
10360
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
10361
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
10362
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
10363
|
|
|
|
|
|
|
#endif |
10364
|
|
|
|
|
|
|
} |
10365
|
|
|
|
|
|
|
|
10366
|
|
|
|
|
|
|
|
10367
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
10368
|
|
|
|
|
|
|
{ |
10369
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
10370
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
10371
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10372
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
10373
|
|
|
|
|
|
|
#else |
10374
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
10375
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
10376
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
10377
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
10378
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
10379
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
10380
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
10381
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
10382
|
|
|
|
|
|
|
#endif |
10383
|
|
|
|
|
|
|
} |
10384
|
|
|
|
|
|
|
|
10385
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
10386
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
10387
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
10388
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
10389
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
10390
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
10391
|
|
|
|
|
|
|
|
10392
|
|
|
|
|
|
|
|
10393
|
|
|
|
|
|
|
|
10394
|
|
|
|
|
|
|
|
10395
|
|
|
|
|
|
|
|
10396
|
|
|
|
|
|
|
|
10397
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
10398
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
10399
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
10400
|
|
|
|
|
|
|
defined(__wasm__)) |
10401
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
10402
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10403
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
10404
|
|
|
|
|
|
|
#else |
10405
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
10406
|
|
|
|
|
|
|
#endif |
10407
|
|
|
|
|
|
|
|
10408
|
|
|
|
|
|
|
|
10409
|
|
|
|
|
|
|
|
10410
|
|
|
|
|
|
|
#ifdef FREESTANDING |
10411
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
10412
|
|
|
|
|
|
|
#else |
10413
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
10414
|
|
|
|
|
|
|
#endif |
10415
|
|
|
|
|
|
|
|
10416
|
|
|
|
|
|
|
|
10417
|
|
|
|
|
|
|
|
10418
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
10419
|
|
|
|
|
|
|
static forceinline type \ |
10420
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
10421
|
|
|
|
|
|
|
{ \ |
10422
|
|
|
|
|
|
|
type v; \ |
10423
|
|
|
|
|
|
|
\ |
10424
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
10425
|
|
|
|
|
|
|
return v; \ |
10426
|
|
|
|
|
|
|
} \ |
10427
|
|
|
|
|
|
|
\ |
10428
|
|
|
|
|
|
|
static forceinline void \ |
10429
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
10430
|
|
|
|
|
|
|
{ \ |
10431
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
10432
|
|
|
|
|
|
|
} |
10433
|
|
|
|
|
|
|
|
10434
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
10435
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
10436
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
10437
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
10438
|
|
|
|
|
|
|
|
10439
|
|
|
|
|
|
|
#undef MEMCOPY |
10440
|
|
|
|
|
|
|
|
10441
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
10442
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
10443
|
|
|
|
|
|
|
|
10444
|
|
|
|
|
|
|
|
10445
|
|
|
|
|
|
|
|
10446
|
|
|
|
|
|
|
static forceinline u16 |
10447
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
10448
|
|
|
|
|
|
|
{ |
10449
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10450
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
10451
|
|
|
|
|
|
|
else |
10452
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
10453
|
|
|
|
|
|
|
} |
10454
|
|
|
|
|
|
|
|
10455
|
|
|
|
|
|
|
static forceinline u16 |
10456
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
10457
|
|
|
|
|
|
|
{ |
10458
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10459
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
10460
|
|
|
|
|
|
|
else |
10461
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
10462
|
|
|
|
|
|
|
} |
10463
|
|
|
|
|
|
|
|
10464
|
|
|
|
|
|
|
static forceinline u32 |
10465
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
10466
|
|
|
|
|
|
|
{ |
10467
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10468
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
10469
|
|
|
|
|
|
|
else |
10470
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
10471
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
10472
|
|
|
|
|
|
|
} |
10473
|
|
|
|
|
|
|
|
10474
|
|
|
|
|
|
|
static forceinline u32 |
10475
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
10476
|
|
|
|
|
|
|
{ |
10477
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10478
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
10479
|
|
|
|
|
|
|
else |
10480
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
10481
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
10482
|
|
|
|
|
|
|
} |
10483
|
|
|
|
|
|
|
|
10484
|
|
|
|
|
|
|
static forceinline u64 |
10485
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
10486
|
|
|
|
|
|
|
{ |
10487
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
10488
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
10489
|
|
|
|
|
|
|
else |
10490
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
10491
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
10492
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
10493
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
10494
|
|
|
|
|
|
|
} |
10495
|
|
|
|
|
|
|
|
10496
|
|
|
|
|
|
|
static forceinline machine_word_t |
10497
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
10498
|
|
|
|
|
|
|
{ |
10499
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
10500
|
|
|
|
|
|
|
if (WORDBITS == 32) |
10501
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
10502
|
|
|
|
|
|
|
else |
10503
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
10504
|
|
|
|
|
|
|
} |
10505
|
|
|
|
|
|
|
|
10506
|
|
|
|
|
|
|
|
10507
|
|
|
|
|
|
|
|
10508
|
|
|
|
|
|
|
static forceinline void |
10509
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
10510
|
|
|
|
|
|
|
{ |
10511
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10512
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
10513
|
|
|
|
|
|
|
} else { |
10514
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
10515
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
10516
|
|
|
|
|
|
|
} |
10517
|
|
|
|
|
|
|
} |
10518
|
|
|
|
|
|
|
|
10519
|
|
|
|
|
|
|
static forceinline void |
10520
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
10521
|
|
|
|
|
|
|
{ |
10522
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10523
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
10524
|
|
|
|
|
|
|
} else { |
10525
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
10526
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
10527
|
|
|
|
|
|
|
} |
10528
|
|
|
|
|
|
|
} |
10529
|
|
|
|
|
|
|
|
10530
|
|
|
|
|
|
|
static forceinline void |
10531
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
10532
|
|
|
|
|
|
|
{ |
10533
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10534
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
10535
|
|
|
|
|
|
|
} else { |
10536
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
10537
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
10538
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
10539
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
10540
|
|
|
|
|
|
|
} |
10541
|
|
|
|
|
|
|
} |
10542
|
|
|
|
|
|
|
|
10543
|
|
|
|
|
|
|
static forceinline void |
10544
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
10545
|
|
|
|
|
|
|
{ |
10546
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10547
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
10548
|
|
|
|
|
|
|
} else { |
10549
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
10550
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
10551
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
10552
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
10553
|
|
|
|
|
|
|
} |
10554
|
|
|
|
|
|
|
} |
10555
|
|
|
|
|
|
|
|
10556
|
|
|
|
|
|
|
static forceinline void |
10557
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
10558
|
|
|
|
|
|
|
{ |
10559
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
10560
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
10561
|
|
|
|
|
|
|
} else { |
10562
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
10563
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
10564
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
10565
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
10566
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
10567
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
10568
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
10569
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
10570
|
|
|
|
|
|
|
} |
10571
|
|
|
|
|
|
|
} |
10572
|
|
|
|
|
|
|
|
10573
|
|
|
|
|
|
|
static forceinline void |
10574
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
10575
|
|
|
|
|
|
|
{ |
10576
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
10577
|
|
|
|
|
|
|
if (WORDBITS == 32) |
10578
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
10579
|
|
|
|
|
|
|
else |
10580
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
10581
|
|
|
|
|
|
|
} |
10582
|
|
|
|
|
|
|
|
10583
|
|
|
|
|
|
|
|
10584
|
|
|
|
|
|
|
|
10585
|
|
|
|
|
|
|
|
10586
|
|
|
|
|
|
|
|
10587
|
|
|
|
|
|
|
|
10588
|
|
|
|
|
|
|
|
10589
|
|
|
|
|
|
|
static forceinline unsigned |
10590
|
|
|
|
|
|
|
bsr32(u32 v) |
10591
|
|
|
|
|
|
|
{ |
10592
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
10593
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
10594
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10595
|
|
|
|
|
|
|
unsigned long i; |
10596
|
|
|
|
|
|
|
|
10597
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
10598
|
|
|
|
|
|
|
return i; |
10599
|
|
|
|
|
|
|
#else |
10600
|
|
|
|
|
|
|
unsigned i = 0; |
10601
|
|
|
|
|
|
|
|
10602
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
10603
|
|
|
|
|
|
|
i++; |
10604
|
|
|
|
|
|
|
return i; |
10605
|
|
|
|
|
|
|
#endif |
10606
|
|
|
|
|
|
|
} |
10607
|
|
|
|
|
|
|
|
10608
|
|
|
|
|
|
|
static forceinline unsigned |
10609
|
|
|
|
|
|
|
bsr64(u64 v) |
10610
|
|
|
|
|
|
|
{ |
10611
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
10612
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
10613
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
10614
|
|
|
|
|
|
|
unsigned long i; |
10615
|
|
|
|
|
|
|
|
10616
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
10617
|
|
|
|
|
|
|
return i; |
10618
|
|
|
|
|
|
|
#else |
10619
|
|
|
|
|
|
|
unsigned i = 0; |
10620
|
|
|
|
|
|
|
|
10621
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
10622
|
|
|
|
|
|
|
i++; |
10623
|
|
|
|
|
|
|
return i; |
10624
|
|
|
|
|
|
|
#endif |
10625
|
|
|
|
|
|
|
} |
10626
|
|
|
|
|
|
|
|
10627
|
|
|
|
|
|
|
static forceinline unsigned |
10628
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
10629
|
|
|
|
|
|
|
{ |
10630
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
10631
|
|
|
|
|
|
|
if (WORDBITS == 32) |
10632
|
|
|
|
|
|
|
return bsr32(v); |
10633
|
|
|
|
|
|
|
else |
10634
|
|
|
|
|
|
|
return bsr64(v); |
10635
|
|
|
|
|
|
|
} |
10636
|
|
|
|
|
|
|
|
10637
|
|
|
|
|
|
|
|
10638
|
|
|
|
|
|
|
|
10639
|
|
|
|
|
|
|
static forceinline unsigned |
10640
|
|
|
|
|
|
|
bsf32(u32 v) |
10641
|
|
|
|
|
|
|
{ |
10642
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
10643
|
|
|
|
|
|
|
return __builtin_ctz(v); |
10644
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
10645
|
|
|
|
|
|
|
unsigned long i; |
10646
|
|
|
|
|
|
|
|
10647
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
10648
|
|
|
|
|
|
|
return i; |
10649
|
|
|
|
|
|
|
#else |
10650
|
|
|
|
|
|
|
unsigned i = 0; |
10651
|
|
|
|
|
|
|
|
10652
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
10653
|
|
|
|
|
|
|
i++; |
10654
|
|
|
|
|
|
|
return i; |
10655
|
|
|
|
|
|
|
#endif |
10656
|
|
|
|
|
|
|
} |
10657
|
|
|
|
|
|
|
|
10658
|
|
|
|
|
|
|
static forceinline unsigned |
10659
|
|
|
|
|
|
|
bsf64(u64 v) |
10660
|
|
|
|
|
|
|
{ |
10661
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
10662
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
10663
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
10664
|
|
|
|
|
|
|
unsigned long i; |
10665
|
|
|
|
|
|
|
|
10666
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
10667
|
|
|
|
|
|
|
return i; |
10668
|
|
|
|
|
|
|
#else |
10669
|
|
|
|
|
|
|
unsigned i = 0; |
10670
|
|
|
|
|
|
|
|
10671
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
10672
|
|
|
|
|
|
|
i++; |
10673
|
|
|
|
|
|
|
return i; |
10674
|
|
|
|
|
|
|
#endif |
10675
|
|
|
|
|
|
|
} |
10676
|
|
|
|
|
|
|
|
10677
|
|
|
|
|
|
|
static forceinline unsigned |
10678
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
10679
|
|
|
|
|
|
|
{ |
10680
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
10681
|
|
|
|
|
|
|
if (WORDBITS == 32) |
10682
|
|
|
|
|
|
|
return bsf32(v); |
10683
|
|
|
|
|
|
|
else |
10684
|
|
|
|
|
|
|
return bsf64(v); |
10685
|
|
|
|
|
|
|
} |
10686
|
|
|
|
|
|
|
|
10687
|
|
|
|
|
|
|
|
10688
|
|
|
|
|
|
|
#undef rbit32 |
10689
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
10690
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
10691
|
|
|
|
|
|
|
static forceinline u32 |
10692
|
|
|
|
|
|
|
rbit32(u32 v) |
10693
|
|
|
|
|
|
|
{ |
10694
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
10695
|
|
|
|
|
|
|
return v; |
10696
|
|
|
|
|
|
|
} |
10697
|
|
|
|
|
|
|
#define rbit32 rbit32 |
10698
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
10699
|
|
|
|
|
|
|
static forceinline u32 |
10700
|
|
|
|
|
|
|
rbit32(u32 v) |
10701
|
|
|
|
|
|
|
{ |
10702
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
10703
|
|
|
|
|
|
|
return v; |
10704
|
|
|
|
|
|
|
} |
10705
|
|
|
|
|
|
|
#define rbit32 rbit32 |
10706
|
|
|
|
|
|
|
#endif |
10707
|
|
|
|
|
|
|
|
10708
|
|
|
|
|
|
|
#endif |
10709
|
|
|
|
|
|
|
|
10710
|
|
|
|
|
|
|
|
10711
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
10712
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
10713
|
|
|
|
|
|
|
|
10714
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
10715
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
10716
|
|
|
|
|
|
|
|
10717
|
|
|
|
|
|
|
#ifdef FREESTANDING |
10718
|
|
|
|
|
|
|
|
10719
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
10720
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
10721
|
|
|
|
|
|
|
|
10722
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
10723
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
10724
|
|
|
|
|
|
|
|
10725
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
10726
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
10727
|
|
|
|
|
|
|
|
10728
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
10729
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
10730
|
|
|
|
|
|
|
|
10731
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
10732
|
|
|
|
|
|
|
#else |
10733
|
|
|
|
|
|
|
#include |
10734
|
|
|
|
|
|
|
#endif |
10735
|
|
|
|
|
|
|
|
10736
|
|
|
|
|
|
|
|
10737
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
10738
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
10739
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
10740
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
10741
|
|
|
|
|
|
|
#else |
10742
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
10743
|
|
|
|
|
|
|
#endif |
10744
|
|
|
|
|
|
|
|
10745
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
10746
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
10747
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
10748
|
|
|
|
|
|
|
|
10749
|
|
|
|
|
|
|
#endif |
10750
|
|
|
|
|
|
|
|
10751
|
|
|
|
|
|
|
|
10752
|
|
|
|
|
|
|
#ifndef MATCHFINDER_WINDOW_ORDER |
10753
|
|
|
|
|
|
|
# error "MATCHFINDER_WINDOW_ORDER must be defined!" |
10754
|
|
|
|
|
|
|
#endif |
10755
|
|
|
|
|
|
|
|
10756
|
|
|
|
|
|
|
|
10757
|
|
|
|
|
|
|
static forceinline u32 |
10758
|
|
|
|
|
|
|
loaded_u32_to_u24(u32 v) |
10759
|
|
|
|
|
|
|
{ |
10760
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
10761
|
126
|
|
|
|
|
|
return v & 0xFFFFFF; |
10762
|
|
|
|
|
|
|
else |
10763
|
|
|
|
|
|
|
return v >> 8; |
10764
|
|
|
|
|
|
|
} |
10765
|
|
|
|
|
|
|
|
10766
|
|
|
|
|
|
|
|
10767
|
|
|
|
|
|
|
static forceinline u32 |
10768
|
|
|
|
|
|
|
load_u24_unaligned(const u8 *p) |
10769
|
|
|
|
|
|
|
{ |
10770
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
10771
|
126
|
|
|
|
|
|
return loaded_u32_to_u24(load_u32_unaligned(p)); |
10772
|
|
|
|
|
|
|
#else |
10773
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
10774
|
|
|
|
|
|
|
return ((u32)p[0] << 0) | ((u32)p[1] << 8) | ((u32)p[2] << 16); |
10775
|
|
|
|
|
|
|
else |
10776
|
|
|
|
|
|
|
return ((u32)p[2] << 0) | ((u32)p[1] << 8) | ((u32)p[0] << 16); |
10777
|
|
|
|
|
|
|
#endif |
10778
|
|
|
|
|
|
|
} |
10779
|
|
|
|
|
|
|
|
10780
|
|
|
|
|
|
|
#define MATCHFINDER_WINDOW_SIZE (1UL << MATCHFINDER_WINDOW_ORDER) |
10781
|
|
|
|
|
|
|
|
10782
|
|
|
|
|
|
|
typedef s16 mf_pos_t; |
10783
|
|
|
|
|
|
|
|
10784
|
|
|
|
|
|
|
#define MATCHFINDER_INITVAL ((mf_pos_t)-MATCHFINDER_WINDOW_SIZE) |
10785
|
|
|
|
|
|
|
|
10786
|
|
|
|
|
|
|
|
10787
|
|
|
|
|
|
|
#define MATCHFINDER_MEM_ALIGNMENT 32 |
10788
|
|
|
|
|
|
|
#define MATCHFINDER_SIZE_ALIGNMENT 128 |
10789
|
|
|
|
|
|
|
|
10790
|
|
|
|
|
|
|
#undef matchfinder_init |
10791
|
|
|
|
|
|
|
#undef matchfinder_rebase |
10792
|
|
|
|
|
|
|
#ifdef _aligned_attribute |
10793
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED _aligned_attribute(MATCHFINDER_MEM_ALIGNMENT) |
10794
|
|
|
|
|
|
|
# if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
10795
|
|
|
|
|
|
|
/* # include "arm/matchfinder_impl.h" */ |
10796
|
|
|
|
|
|
|
|
10797
|
|
|
|
|
|
|
|
10798
|
|
|
|
|
|
|
#ifndef LIB_ARM_MATCHFINDER_IMPL_H |
10799
|
|
|
|
|
|
|
#define LIB_ARM_MATCHFINDER_IMPL_H |
10800
|
|
|
|
|
|
|
|
10801
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
10802
|
|
|
|
|
|
|
|
10803
|
|
|
|
|
|
|
|
10804
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
10805
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
10806
|
|
|
|
|
|
|
|
10807
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
10808
|
|
|
|
|
|
|
|
10809
|
|
|
|
|
|
|
|
10810
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
10811
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
10812
|
|
|
|
|
|
|
|
10813
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
10814
|
|
|
|
|
|
|
|
10815
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
10816
|
|
|
|
|
|
|
#endif |
10817
|
|
|
|
|
|
|
|
10818
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
10819
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
10820
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
10821
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
10822
|
|
|
|
|
|
|
#else |
10823
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
10824
|
|
|
|
|
|
|
#endif |
10825
|
|
|
|
|
|
|
|
10826
|
|
|
|
|
|
|
|
10827
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
10828
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
10829
|
|
|
|
|
|
|
#else |
10830
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
10831
|
|
|
|
|
|
|
#endif |
10832
|
|
|
|
|
|
|
|
10833
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
10834
|
|
|
|
|
|
|
|
10835
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
10836
|
|
|
|
|
|
|
|
10837
|
|
|
|
|
|
|
|
10838
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
10839
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
10840
|
|
|
|
|
|
|
|
10841
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
10842
|
|
|
|
|
|
|
|
10843
|
|
|
|
|
|
|
|
10844
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
10845
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
10846
|
|
|
|
|
|
|
|
10847
|
|
|
|
|
|
|
#include |
10848
|
|
|
|
|
|
|
#include |
10849
|
|
|
|
|
|
|
|
10850
|
|
|
|
|
|
|
#ifdef __cplusplus |
10851
|
|
|
|
|
|
|
extern "C" { |
10852
|
|
|
|
|
|
|
#endif |
10853
|
|
|
|
|
|
|
|
10854
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
10855
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
10856
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
10857
|
|
|
|
|
|
|
|
10858
|
|
|
|
|
|
|
|
10859
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
10860
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
10861
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
10862
|
|
|
|
|
|
|
# else |
10863
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
10864
|
|
|
|
|
|
|
# endif |
10865
|
|
|
|
|
|
|
#endif |
10866
|
|
|
|
|
|
|
|
10867
|
|
|
|
|
|
|
|
10868
|
|
|
|
|
|
|
|
10869
|
|
|
|
|
|
|
|
10870
|
|
|
|
|
|
|
|
10871
|
|
|
|
|
|
|
struct libdeflate_compressor; |
10872
|
|
|
|
|
|
|
|
10873
|
|
|
|
|
|
|
|
10874
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
10875
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
10876
|
|
|
|
|
|
|
|
10877
|
|
|
|
|
|
|
|
10878
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10879
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
10880
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10881
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
10882
|
|
|
|
|
|
|
|
10883
|
|
|
|
|
|
|
|
10884
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10885
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
10886
|
|
|
|
|
|
|
size_t in_nbytes); |
10887
|
|
|
|
|
|
|
|
10888
|
|
|
|
|
|
|
|
10889
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10890
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
10891
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10892
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
10893
|
|
|
|
|
|
|
|
10894
|
|
|
|
|
|
|
|
10895
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10896
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
10897
|
|
|
|
|
|
|
size_t in_nbytes); |
10898
|
|
|
|
|
|
|
|
10899
|
|
|
|
|
|
|
|
10900
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10901
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
10902
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10903
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
10904
|
|
|
|
|
|
|
|
10905
|
|
|
|
|
|
|
|
10906
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
10907
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
10908
|
|
|
|
|
|
|
size_t in_nbytes); |
10909
|
|
|
|
|
|
|
|
10910
|
|
|
|
|
|
|
|
10911
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
10912
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
10913
|
|
|
|
|
|
|
|
10914
|
|
|
|
|
|
|
|
10915
|
|
|
|
|
|
|
|
10916
|
|
|
|
|
|
|
|
10917
|
|
|
|
|
|
|
|
10918
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
10919
|
|
|
|
|
|
|
|
10920
|
|
|
|
|
|
|
|
10921
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
10922
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
10923
|
|
|
|
|
|
|
|
10924
|
|
|
|
|
|
|
|
10925
|
|
|
|
|
|
|
enum libdeflate_result { |
10926
|
|
|
|
|
|
|
|
10927
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
10928
|
|
|
|
|
|
|
|
10929
|
|
|
|
|
|
|
|
10930
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
10931
|
|
|
|
|
|
|
|
10932
|
|
|
|
|
|
|
|
10933
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
10934
|
|
|
|
|
|
|
|
10935
|
|
|
|
|
|
|
|
10936
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
10937
|
|
|
|
|
|
|
}; |
10938
|
|
|
|
|
|
|
|
10939
|
|
|
|
|
|
|
|
10940
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10941
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
10942
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10943
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10944
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10945
|
|
|
|
|
|
|
|
10946
|
|
|
|
|
|
|
|
10947
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10948
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
10949
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10950
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10951
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10952
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10953
|
|
|
|
|
|
|
|
10954
|
|
|
|
|
|
|
|
10955
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10956
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
10957
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10958
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10959
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10960
|
|
|
|
|
|
|
|
10961
|
|
|
|
|
|
|
|
10962
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10963
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
10964
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10965
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10966
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10967
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10968
|
|
|
|
|
|
|
|
10969
|
|
|
|
|
|
|
|
10970
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10971
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
10972
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10973
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10974
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10975
|
|
|
|
|
|
|
|
10976
|
|
|
|
|
|
|
|
10977
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
10978
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
10979
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
10980
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
10981
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
10982
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
10983
|
|
|
|
|
|
|
|
10984
|
|
|
|
|
|
|
|
10985
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
10986
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
10987
|
|
|
|
|
|
|
|
10988
|
|
|
|
|
|
|
|
10989
|
|
|
|
|
|
|
|
10990
|
|
|
|
|
|
|
|
10991
|
|
|
|
|
|
|
|
10992
|
|
|
|
|
|
|
|
10993
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
10994
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
10995
|
|
|
|
|
|
|
|
10996
|
|
|
|
|
|
|
|
10997
|
|
|
|
|
|
|
|
10998
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
10999
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
11000
|
|
|
|
|
|
|
|
11001
|
|
|
|
|
|
|
|
11002
|
|
|
|
|
|
|
|
11003
|
|
|
|
|
|
|
|
11004
|
|
|
|
|
|
|
|
11005
|
|
|
|
|
|
|
|
11006
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
11007
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
11008
|
|
|
|
|
|
|
void (*free_func)(void *)); |
11009
|
|
|
|
|
|
|
|
11010
|
|
|
|
|
|
|
#ifdef __cplusplus |
11011
|
|
|
|
|
|
|
} |
11012
|
|
|
|
|
|
|
#endif |
11013
|
|
|
|
|
|
|
|
11014
|
|
|
|
|
|
|
#endif |
11015
|
|
|
|
|
|
|
|
11016
|
|
|
|
|
|
|
|
11017
|
|
|
|
|
|
|
#include |
11018
|
|
|
|
|
|
|
#include |
11019
|
|
|
|
|
|
|
#include |
11020
|
|
|
|
|
|
|
#ifdef _MSC_VER |
11021
|
|
|
|
|
|
|
# include |
11022
|
|
|
|
|
|
|
# include |
11023
|
|
|
|
|
|
|
|
11024
|
|
|
|
|
|
|
|
11025
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
11026
|
|
|
|
|
|
|
|
11027
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
11028
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
11029
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
11030
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
11031
|
|
|
|
|
|
|
|
11032
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
11033
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
11034
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
11035
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
11036
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
11037
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
11038
|
|
|
|
|
|
|
#endif |
11039
|
|
|
|
|
|
|
#ifndef FREESTANDING |
11040
|
|
|
|
|
|
|
# include |
11041
|
|
|
|
|
|
|
#endif |
11042
|
|
|
|
|
|
|
|
11043
|
|
|
|
|
|
|
|
11044
|
|
|
|
|
|
|
|
11045
|
|
|
|
|
|
|
|
11046
|
|
|
|
|
|
|
|
11047
|
|
|
|
|
|
|
|
11048
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
11049
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
11050
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
11051
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
11052
|
|
|
|
|
|
|
#ifdef _MSC_VER |
11053
|
|
|
|
|
|
|
# if defined(_M_X64) |
11054
|
|
|
|
|
|
|
# define ARCH_X86_64 |
11055
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
11056
|
|
|
|
|
|
|
# define ARCH_X86_32 |
11057
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
11058
|
|
|
|
|
|
|
# define ARCH_ARM64 |
11059
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
11060
|
|
|
|
|
|
|
# define ARCH_ARM32 |
11061
|
|
|
|
|
|
|
# endif |
11062
|
|
|
|
|
|
|
#else |
11063
|
|
|
|
|
|
|
# if defined(__x86_64__) |
11064
|
|
|
|
|
|
|
# define ARCH_X86_64 |
11065
|
|
|
|
|
|
|
# elif defined(__i386__) |
11066
|
|
|
|
|
|
|
# define ARCH_X86_32 |
11067
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
11068
|
|
|
|
|
|
|
# define ARCH_ARM64 |
11069
|
|
|
|
|
|
|
# elif defined(__arm__) |
11070
|
|
|
|
|
|
|
# define ARCH_ARM32 |
11071
|
|
|
|
|
|
|
# endif |
11072
|
|
|
|
|
|
|
#endif |
11073
|
|
|
|
|
|
|
|
11074
|
|
|
|
|
|
|
|
11075
|
|
|
|
|
|
|
|
11076
|
|
|
|
|
|
|
|
11077
|
|
|
|
|
|
|
|
11078
|
|
|
|
|
|
|
|
11079
|
|
|
|
|
|
|
typedef uint8_t u8; |
11080
|
|
|
|
|
|
|
typedef uint16_t u16; |
11081
|
|
|
|
|
|
|
typedef uint32_t u32; |
11082
|
|
|
|
|
|
|
typedef uint64_t u64; |
11083
|
|
|
|
|
|
|
typedef int8_t s8; |
11084
|
|
|
|
|
|
|
typedef int16_t s16; |
11085
|
|
|
|
|
|
|
typedef int32_t s32; |
11086
|
|
|
|
|
|
|
typedef int64_t s64; |
11087
|
|
|
|
|
|
|
|
11088
|
|
|
|
|
|
|
|
11089
|
|
|
|
|
|
|
#ifdef _MSC_VER |
11090
|
|
|
|
|
|
|
# ifdef _WIN64 |
11091
|
|
|
|
|
|
|
typedef long long ssize_t; |
11092
|
|
|
|
|
|
|
# else |
11093
|
|
|
|
|
|
|
typedef long ssize_t; |
11094
|
|
|
|
|
|
|
# endif |
11095
|
|
|
|
|
|
|
#endif |
11096
|
|
|
|
|
|
|
|
11097
|
|
|
|
|
|
|
|
11098
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
11099
|
|
|
|
|
|
|
|
11100
|
|
|
|
|
|
|
|
11101
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
11102
|
|
|
|
|
|
|
|
11103
|
|
|
|
|
|
|
|
11104
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
11105
|
|
|
|
|
|
|
|
11106
|
|
|
|
|
|
|
|
11107
|
|
|
|
|
|
|
|
11108
|
|
|
|
|
|
|
|
11109
|
|
|
|
|
|
|
|
11110
|
|
|
|
|
|
|
|
11111
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
11112
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
11113
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
11114
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
11115
|
|
|
|
|
|
|
#else |
11116
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
11117
|
|
|
|
|
|
|
#endif |
11118
|
|
|
|
|
|
|
#ifdef __clang__ |
11119
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
11120
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
11121
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
11122
|
|
|
|
|
|
|
# else |
11123
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
11124
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
11125
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
11126
|
|
|
|
|
|
|
# endif |
11127
|
|
|
|
|
|
|
#else |
11128
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
11129
|
|
|
|
|
|
|
#endif |
11130
|
|
|
|
|
|
|
|
11131
|
|
|
|
|
|
|
|
11132
|
|
|
|
|
|
|
#ifndef __has_attribute |
11133
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
11134
|
|
|
|
|
|
|
#endif |
11135
|
|
|
|
|
|
|
#ifndef __has_builtin |
11136
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
11137
|
|
|
|
|
|
|
#endif |
11138
|
|
|
|
|
|
|
|
11139
|
|
|
|
|
|
|
|
11140
|
|
|
|
|
|
|
#ifdef _MSC_VER |
11141
|
|
|
|
|
|
|
# define inline __inline |
11142
|
|
|
|
|
|
|
#endif |
11143
|
|
|
|
|
|
|
|
11144
|
|
|
|
|
|
|
|
11145
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
11146
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
11147
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11148
|
|
|
|
|
|
|
# define forceinline __forceinline |
11149
|
|
|
|
|
|
|
#else |
11150
|
|
|
|
|
|
|
# define forceinline inline |
11151
|
|
|
|
|
|
|
#endif |
11152
|
|
|
|
|
|
|
|
11153
|
|
|
|
|
|
|
|
11154
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
11155
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
11156
|
|
|
|
|
|
|
#else |
11157
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
11158
|
|
|
|
|
|
|
#endif |
11159
|
|
|
|
|
|
|
|
11160
|
|
|
|
|
|
|
|
11161
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
11162
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
11163
|
|
|
|
|
|
|
# define restrict __restrict__ |
11164
|
|
|
|
|
|
|
# else |
11165
|
|
|
|
|
|
|
# define restrict |
11166
|
|
|
|
|
|
|
# endif |
11167
|
|
|
|
|
|
|
#endif |
11168
|
|
|
|
|
|
|
|
11169
|
|
|
|
|
|
|
|
11170
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
11171
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
11172
|
|
|
|
|
|
|
#else |
11173
|
|
|
|
|
|
|
# define likely(expr) (expr) |
11174
|
|
|
|
|
|
|
#endif |
11175
|
|
|
|
|
|
|
|
11176
|
|
|
|
|
|
|
|
11177
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
11178
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
11179
|
|
|
|
|
|
|
#else |
11180
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
11181
|
|
|
|
|
|
|
#endif |
11182
|
|
|
|
|
|
|
|
11183
|
|
|
|
|
|
|
|
11184
|
|
|
|
|
|
|
#undef prefetchr |
11185
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
11186
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
11187
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11188
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
11189
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
11190
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
11191
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
11192
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
11193
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
11194
|
|
|
|
|
|
|
# endif |
11195
|
|
|
|
|
|
|
#endif |
11196
|
|
|
|
|
|
|
#ifndef prefetchr |
11197
|
|
|
|
|
|
|
# define prefetchr(addr) |
11198
|
|
|
|
|
|
|
#endif |
11199
|
|
|
|
|
|
|
|
11200
|
|
|
|
|
|
|
|
11201
|
|
|
|
|
|
|
#undef prefetchw |
11202
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
11203
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
11204
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11205
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
11206
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
11207
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
11208
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
11209
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
11210
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
11211
|
|
|
|
|
|
|
# endif |
11212
|
|
|
|
|
|
|
#endif |
11213
|
|
|
|
|
|
|
#ifndef prefetchw |
11214
|
|
|
|
|
|
|
# define prefetchw(addr) |
11215
|
|
|
|
|
|
|
#endif |
11216
|
|
|
|
|
|
|
|
11217
|
|
|
|
|
|
|
|
11218
|
|
|
|
|
|
|
#undef _aligned_attribute |
11219
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
11220
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
11221
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11222
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
11223
|
|
|
|
|
|
|
#endif |
11224
|
|
|
|
|
|
|
|
11225
|
|
|
|
|
|
|
|
11226
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
11227
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
11228
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
11229
|
|
|
|
|
|
|
#else |
11230
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
11231
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
11232
|
|
|
|
|
|
|
#endif |
11233
|
|
|
|
|
|
|
|
11234
|
|
|
|
|
|
|
|
11235
|
|
|
|
|
|
|
|
11236
|
|
|
|
|
|
|
|
11237
|
|
|
|
|
|
|
|
11238
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
11239
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
11240
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
11241
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
11242
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
11243
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
11244
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
11245
|
|
|
|
|
|
|
|
11246
|
|
|
|
|
|
|
|
11247
|
|
|
|
|
|
|
|
11248
|
|
|
|
|
|
|
|
11249
|
|
|
|
|
|
|
|
11250
|
|
|
|
|
|
|
|
11251
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
11252
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
11253
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11254
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
11255
|
|
|
|
|
|
|
#else |
11256
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
11257
|
|
|
|
|
|
|
{ |
11258
|
|
|
|
|
|
|
union { |
11259
|
|
|
|
|
|
|
u32 w; |
11260
|
|
|
|
|
|
|
u8 b; |
11261
|
|
|
|
|
|
|
} u; |
11262
|
|
|
|
|
|
|
|
11263
|
|
|
|
|
|
|
u.w = 1; |
11264
|
|
|
|
|
|
|
return u.b; |
11265
|
|
|
|
|
|
|
} |
11266
|
|
|
|
|
|
|
#endif |
11267
|
|
|
|
|
|
|
|
11268
|
|
|
|
|
|
|
|
11269
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
11270
|
|
|
|
|
|
|
{ |
11271
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
11272
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
11273
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11274
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
11275
|
|
|
|
|
|
|
#else |
11276
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
11277
|
|
|
|
|
|
|
#endif |
11278
|
|
|
|
|
|
|
} |
11279
|
|
|
|
|
|
|
|
11280
|
|
|
|
|
|
|
|
11281
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
11282
|
|
|
|
|
|
|
{ |
11283
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
11284
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
11285
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11286
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
11287
|
|
|
|
|
|
|
#else |
11288
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
11289
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
11290
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
11291
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
11292
|
|
|
|
|
|
|
#endif |
11293
|
|
|
|
|
|
|
} |
11294
|
|
|
|
|
|
|
|
11295
|
|
|
|
|
|
|
|
11296
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
11297
|
|
|
|
|
|
|
{ |
11298
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
11299
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
11300
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11301
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
11302
|
|
|
|
|
|
|
#else |
11303
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
11304
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
11305
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
11306
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
11307
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
11308
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
11309
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
11310
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
11311
|
|
|
|
|
|
|
#endif |
11312
|
|
|
|
|
|
|
} |
11313
|
|
|
|
|
|
|
|
11314
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
11315
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
11316
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
11317
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
11318
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
11319
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
11320
|
|
|
|
|
|
|
|
11321
|
|
|
|
|
|
|
|
11322
|
|
|
|
|
|
|
|
11323
|
|
|
|
|
|
|
|
11324
|
|
|
|
|
|
|
|
11325
|
|
|
|
|
|
|
|
11326
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
11327
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
11328
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
11329
|
|
|
|
|
|
|
defined(__wasm__)) |
11330
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
11331
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11332
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
11333
|
|
|
|
|
|
|
#else |
11334
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
11335
|
|
|
|
|
|
|
#endif |
11336
|
|
|
|
|
|
|
|
11337
|
|
|
|
|
|
|
|
11338
|
|
|
|
|
|
|
|
11339
|
|
|
|
|
|
|
#ifdef FREESTANDING |
11340
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
11341
|
|
|
|
|
|
|
#else |
11342
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
11343
|
|
|
|
|
|
|
#endif |
11344
|
|
|
|
|
|
|
|
11345
|
|
|
|
|
|
|
|
11346
|
|
|
|
|
|
|
|
11347
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
11348
|
|
|
|
|
|
|
static forceinline type \ |
11349
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
11350
|
|
|
|
|
|
|
{ \ |
11351
|
|
|
|
|
|
|
type v; \ |
11352
|
|
|
|
|
|
|
\ |
11353
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
11354
|
|
|
|
|
|
|
return v; \ |
11355
|
|
|
|
|
|
|
} \ |
11356
|
|
|
|
|
|
|
\ |
11357
|
|
|
|
|
|
|
static forceinline void \ |
11358
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
11359
|
|
|
|
|
|
|
{ \ |
11360
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
11361
|
|
|
|
|
|
|
} |
11362
|
|
|
|
|
|
|
|
11363
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
11364
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
11365
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
11366
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
11367
|
|
|
|
|
|
|
|
11368
|
|
|
|
|
|
|
#undef MEMCOPY |
11369
|
|
|
|
|
|
|
|
11370
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
11371
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
11372
|
|
|
|
|
|
|
|
11373
|
|
|
|
|
|
|
|
11374
|
|
|
|
|
|
|
|
11375
|
|
|
|
|
|
|
static forceinline u16 |
11376
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
11377
|
|
|
|
|
|
|
{ |
11378
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11379
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
11380
|
|
|
|
|
|
|
else |
11381
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
11382
|
|
|
|
|
|
|
} |
11383
|
|
|
|
|
|
|
|
11384
|
|
|
|
|
|
|
static forceinline u16 |
11385
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
11386
|
|
|
|
|
|
|
{ |
11387
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11388
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
11389
|
|
|
|
|
|
|
else |
11390
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
11391
|
|
|
|
|
|
|
} |
11392
|
|
|
|
|
|
|
|
11393
|
|
|
|
|
|
|
static forceinline u32 |
11394
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
11395
|
|
|
|
|
|
|
{ |
11396
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11397
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
11398
|
|
|
|
|
|
|
else |
11399
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
11400
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
11401
|
|
|
|
|
|
|
} |
11402
|
|
|
|
|
|
|
|
11403
|
|
|
|
|
|
|
static forceinline u32 |
11404
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
11405
|
|
|
|
|
|
|
{ |
11406
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11407
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
11408
|
|
|
|
|
|
|
else |
11409
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
11410
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
11411
|
|
|
|
|
|
|
} |
11412
|
|
|
|
|
|
|
|
11413
|
|
|
|
|
|
|
static forceinline u64 |
11414
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
11415
|
|
|
|
|
|
|
{ |
11416
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
11417
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
11418
|
|
|
|
|
|
|
else |
11419
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
11420
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
11421
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
11422
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
11423
|
|
|
|
|
|
|
} |
11424
|
|
|
|
|
|
|
|
11425
|
|
|
|
|
|
|
static forceinline machine_word_t |
11426
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
11427
|
|
|
|
|
|
|
{ |
11428
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
11429
|
|
|
|
|
|
|
if (WORDBITS == 32) |
11430
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
11431
|
|
|
|
|
|
|
else |
11432
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
11433
|
|
|
|
|
|
|
} |
11434
|
|
|
|
|
|
|
|
11435
|
|
|
|
|
|
|
|
11436
|
|
|
|
|
|
|
|
11437
|
|
|
|
|
|
|
static forceinline void |
11438
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
11439
|
|
|
|
|
|
|
{ |
11440
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11441
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
11442
|
|
|
|
|
|
|
} else { |
11443
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
11444
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
11445
|
|
|
|
|
|
|
} |
11446
|
|
|
|
|
|
|
} |
11447
|
|
|
|
|
|
|
|
11448
|
|
|
|
|
|
|
static forceinline void |
11449
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
11450
|
|
|
|
|
|
|
{ |
11451
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11452
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
11453
|
|
|
|
|
|
|
} else { |
11454
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
11455
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
11456
|
|
|
|
|
|
|
} |
11457
|
|
|
|
|
|
|
} |
11458
|
|
|
|
|
|
|
|
11459
|
|
|
|
|
|
|
static forceinline void |
11460
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
11461
|
|
|
|
|
|
|
{ |
11462
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11463
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
11464
|
|
|
|
|
|
|
} else { |
11465
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
11466
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
11467
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
11468
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
11469
|
|
|
|
|
|
|
} |
11470
|
|
|
|
|
|
|
} |
11471
|
|
|
|
|
|
|
|
11472
|
|
|
|
|
|
|
static forceinline void |
11473
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
11474
|
|
|
|
|
|
|
{ |
11475
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11476
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
11477
|
|
|
|
|
|
|
} else { |
11478
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
11479
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
11480
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
11481
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
11482
|
|
|
|
|
|
|
} |
11483
|
|
|
|
|
|
|
} |
11484
|
|
|
|
|
|
|
|
11485
|
|
|
|
|
|
|
static forceinline void |
11486
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
11487
|
|
|
|
|
|
|
{ |
11488
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
11489
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
11490
|
|
|
|
|
|
|
} else { |
11491
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
11492
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
11493
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
11494
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
11495
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
11496
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
11497
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
11498
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
11499
|
|
|
|
|
|
|
} |
11500
|
|
|
|
|
|
|
} |
11501
|
|
|
|
|
|
|
|
11502
|
|
|
|
|
|
|
static forceinline void |
11503
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
11504
|
|
|
|
|
|
|
{ |
11505
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
11506
|
|
|
|
|
|
|
if (WORDBITS == 32) |
11507
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
11508
|
|
|
|
|
|
|
else |
11509
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
11510
|
|
|
|
|
|
|
} |
11511
|
|
|
|
|
|
|
|
11512
|
|
|
|
|
|
|
|
11513
|
|
|
|
|
|
|
|
11514
|
|
|
|
|
|
|
|
11515
|
|
|
|
|
|
|
|
11516
|
|
|
|
|
|
|
|
11517
|
|
|
|
|
|
|
|
11518
|
|
|
|
|
|
|
static forceinline unsigned |
11519
|
|
|
|
|
|
|
bsr32(u32 v) |
11520
|
|
|
|
|
|
|
{ |
11521
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
11522
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
11523
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11524
|
|
|
|
|
|
|
unsigned long i; |
11525
|
|
|
|
|
|
|
|
11526
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
11527
|
|
|
|
|
|
|
return i; |
11528
|
|
|
|
|
|
|
#else |
11529
|
|
|
|
|
|
|
unsigned i = 0; |
11530
|
|
|
|
|
|
|
|
11531
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
11532
|
|
|
|
|
|
|
i++; |
11533
|
|
|
|
|
|
|
return i; |
11534
|
|
|
|
|
|
|
#endif |
11535
|
|
|
|
|
|
|
} |
11536
|
|
|
|
|
|
|
|
11537
|
|
|
|
|
|
|
static forceinline unsigned |
11538
|
|
|
|
|
|
|
bsr64(u64 v) |
11539
|
|
|
|
|
|
|
{ |
11540
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
11541
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
11542
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
11543
|
|
|
|
|
|
|
unsigned long i; |
11544
|
|
|
|
|
|
|
|
11545
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
11546
|
|
|
|
|
|
|
return i; |
11547
|
|
|
|
|
|
|
#else |
11548
|
|
|
|
|
|
|
unsigned i = 0; |
11549
|
|
|
|
|
|
|
|
11550
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
11551
|
|
|
|
|
|
|
i++; |
11552
|
|
|
|
|
|
|
return i; |
11553
|
|
|
|
|
|
|
#endif |
11554
|
|
|
|
|
|
|
} |
11555
|
|
|
|
|
|
|
|
11556
|
|
|
|
|
|
|
static forceinline unsigned |
11557
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
11558
|
|
|
|
|
|
|
{ |
11559
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
11560
|
|
|
|
|
|
|
if (WORDBITS == 32) |
11561
|
|
|
|
|
|
|
return bsr32(v); |
11562
|
|
|
|
|
|
|
else |
11563
|
|
|
|
|
|
|
return bsr64(v); |
11564
|
|
|
|
|
|
|
} |
11565
|
|
|
|
|
|
|
|
11566
|
|
|
|
|
|
|
|
11567
|
|
|
|
|
|
|
|
11568
|
|
|
|
|
|
|
static forceinline unsigned |
11569
|
|
|
|
|
|
|
bsf32(u32 v) |
11570
|
|
|
|
|
|
|
{ |
11571
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
11572
|
|
|
|
|
|
|
return __builtin_ctz(v); |
11573
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
11574
|
|
|
|
|
|
|
unsigned long i; |
11575
|
|
|
|
|
|
|
|
11576
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
11577
|
|
|
|
|
|
|
return i; |
11578
|
|
|
|
|
|
|
#else |
11579
|
|
|
|
|
|
|
unsigned i = 0; |
11580
|
|
|
|
|
|
|
|
11581
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
11582
|
|
|
|
|
|
|
i++; |
11583
|
|
|
|
|
|
|
return i; |
11584
|
|
|
|
|
|
|
#endif |
11585
|
|
|
|
|
|
|
} |
11586
|
|
|
|
|
|
|
|
11587
|
|
|
|
|
|
|
static forceinline unsigned |
11588
|
|
|
|
|
|
|
bsf64(u64 v) |
11589
|
|
|
|
|
|
|
{ |
11590
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
11591
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
11592
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
11593
|
|
|
|
|
|
|
unsigned long i; |
11594
|
|
|
|
|
|
|
|
11595
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
11596
|
|
|
|
|
|
|
return i; |
11597
|
|
|
|
|
|
|
#else |
11598
|
|
|
|
|
|
|
unsigned i = 0; |
11599
|
|
|
|
|
|
|
|
11600
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
11601
|
|
|
|
|
|
|
i++; |
11602
|
|
|
|
|
|
|
return i; |
11603
|
|
|
|
|
|
|
#endif |
11604
|
|
|
|
|
|
|
} |
11605
|
|
|
|
|
|
|
|
11606
|
|
|
|
|
|
|
static forceinline unsigned |
11607
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
11608
|
|
|
|
|
|
|
{ |
11609
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
11610
|
|
|
|
|
|
|
if (WORDBITS == 32) |
11611
|
|
|
|
|
|
|
return bsf32(v); |
11612
|
|
|
|
|
|
|
else |
11613
|
|
|
|
|
|
|
return bsf64(v); |
11614
|
|
|
|
|
|
|
} |
11615
|
|
|
|
|
|
|
|
11616
|
|
|
|
|
|
|
|
11617
|
|
|
|
|
|
|
#undef rbit32 |
11618
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
11619
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
11620
|
|
|
|
|
|
|
static forceinline u32 |
11621
|
|
|
|
|
|
|
rbit32(u32 v) |
11622
|
|
|
|
|
|
|
{ |
11623
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
11624
|
|
|
|
|
|
|
return v; |
11625
|
|
|
|
|
|
|
} |
11626
|
|
|
|
|
|
|
#define rbit32 rbit32 |
11627
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
11628
|
|
|
|
|
|
|
static forceinline u32 |
11629
|
|
|
|
|
|
|
rbit32(u32 v) |
11630
|
|
|
|
|
|
|
{ |
11631
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
11632
|
|
|
|
|
|
|
return v; |
11633
|
|
|
|
|
|
|
} |
11634
|
|
|
|
|
|
|
#define rbit32 rbit32 |
11635
|
|
|
|
|
|
|
#endif |
11636
|
|
|
|
|
|
|
|
11637
|
|
|
|
|
|
|
#endif |
11638
|
|
|
|
|
|
|
|
11639
|
|
|
|
|
|
|
|
11640
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
11641
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
11642
|
|
|
|
|
|
|
|
11643
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
11644
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
11645
|
|
|
|
|
|
|
|
11646
|
|
|
|
|
|
|
#ifdef FREESTANDING |
11647
|
|
|
|
|
|
|
|
11648
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
11649
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
11650
|
|
|
|
|
|
|
|
11651
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
11652
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
11653
|
|
|
|
|
|
|
|
11654
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
11655
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
11656
|
|
|
|
|
|
|
|
11657
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
11658
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
11659
|
|
|
|
|
|
|
|
11660
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
11661
|
|
|
|
|
|
|
#else |
11662
|
|
|
|
|
|
|
#include |
11663
|
|
|
|
|
|
|
#endif |
11664
|
|
|
|
|
|
|
|
11665
|
|
|
|
|
|
|
|
11666
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
11667
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
11668
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
11669
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
11670
|
|
|
|
|
|
|
#else |
11671
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
11672
|
|
|
|
|
|
|
#endif |
11673
|
|
|
|
|
|
|
|
11674
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
11675
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
11676
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
11677
|
|
|
|
|
|
|
|
11678
|
|
|
|
|
|
|
#endif |
11679
|
|
|
|
|
|
|
|
11680
|
|
|
|
|
|
|
|
11681
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
11682
|
|
|
|
|
|
|
|
11683
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
11684
|
|
|
|
|
|
|
|
11685
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
11686
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
11687
|
|
|
|
|
|
|
(defined(__linux__) || \ |
11688
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
11689
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
11690
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
11691
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
11692
|
|
|
|
|
|
|
#endif |
11693
|
|
|
|
|
|
|
|
11694
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
11695
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
11696
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
11697
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
11698
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
11699
|
|
|
|
|
|
|
|
11700
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
11701
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
11702
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
11703
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
11704
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
11705
|
|
|
|
|
|
|
|
11706
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
11707
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
11708
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
11709
|
|
|
|
|
|
|
|
11710
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
11711
|
|
|
|
|
|
|
|
11712
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
11713
|
|
|
|
|
|
|
{ |
11714
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
11715
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
11716
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
11717
|
|
|
|
|
|
|
} |
11718
|
|
|
|
|
|
|
#else |
11719
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
11720
|
|
|
|
|
|
|
#endif |
11721
|
|
|
|
|
|
|
|
11722
|
|
|
|
|
|
|
|
11723
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
11724
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
11725
|
|
|
|
|
|
|
#else |
11726
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
11727
|
|
|
|
|
|
|
#endif |
11728
|
|
|
|
|
|
|
|
11729
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
11730
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
11731
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
11732
|
|
|
|
|
|
|
#else |
11733
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
11734
|
|
|
|
|
|
|
#endif |
11735
|
|
|
|
|
|
|
|
11736
|
|
|
|
|
|
|
|
11737
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
11738
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
11739
|
|
|
|
|
|
|
#else |
11740
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
11741
|
|
|
|
|
|
|
#endif |
11742
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
11743
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
11744
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
11745
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
11746
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
11747
|
|
|
|
|
|
|
\ |
11748
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
11749
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
11750
|
|
|
|
|
|
|
|
11751
|
|
|
|
|
|
|
# ifdef _MSC_VER |
11752
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
11753
|
|
|
|
|
|
|
# else |
11754
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
11755
|
|
|
|
|
|
|
# endif |
11756
|
|
|
|
|
|
|
#else |
11757
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
11758
|
|
|
|
|
|
|
#endif |
11759
|
|
|
|
|
|
|
|
11760
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
11761
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
11762
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
11763
|
|
|
|
|
|
|
#else |
11764
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
11765
|
|
|
|
|
|
|
#endif |
11766
|
|
|
|
|
|
|
|
11767
|
|
|
|
|
|
|
|
11768
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
11769
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
11770
|
|
|
|
|
|
|
#else |
11771
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
11772
|
|
|
|
|
|
|
#endif |
11773
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
11774
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
11775
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
11776
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
11777
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
11778
|
|
|
|
|
|
|
|
11779
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
11780
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
11781
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
11782
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
11783
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
11784
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
11785
|
|
|
|
|
|
|
# endif |
11786
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
11787
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
11788
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
11789
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
11790
|
|
|
|
|
|
|
# endif |
11791
|
|
|
|
|
|
|
#endif |
11792
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
11793
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
11794
|
|
|
|
|
|
|
#endif |
11795
|
|
|
|
|
|
|
|
11796
|
|
|
|
|
|
|
|
11797
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
11798
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
11799
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
11800
|
|
|
|
|
|
|
# else |
11801
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
11802
|
|
|
|
|
|
|
# endif |
11803
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
11804
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
11805
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
11806
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
11807
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
11808
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
11809
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
11810
|
|
|
|
|
|
|
#else |
11811
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
11812
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
11813
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
11814
|
|
|
|
|
|
|
#endif |
11815
|
|
|
|
|
|
|
|
11816
|
|
|
|
|
|
|
|
11817
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
11818
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
11819
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
11820
|
|
|
|
|
|
|
# else |
11821
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
11822
|
|
|
|
|
|
|
# endif |
11823
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
11824
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
11825
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
11826
|
|
|
|
|
|
|
defined(_MSC_VER))) |
11827
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
11828
|
|
|
|
|
|
|
# else |
11829
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
11830
|
|
|
|
|
|
|
# endif |
11831
|
|
|
|
|
|
|
#else |
11832
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
11833
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
11834
|
|
|
|
|
|
|
#endif |
11835
|
|
|
|
|
|
|
|
11836
|
|
|
|
|
|
|
|
11837
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
11838
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
11839
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
11840
|
|
|
|
|
|
|
#endif |
11841
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
11842
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
11843
|
|
|
|
|
|
|
#endif |
11844
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
11845
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
11846
|
|
|
|
|
|
|
#endif |
11847
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
11848
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
11849
|
|
|
|
|
|
|
# include |
11850
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
11851
|
|
|
|
|
|
|
#endif |
11852
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
11853
|
|
|
|
|
|
|
# include |
11854
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
11855
|
|
|
|
|
|
|
#endif |
11856
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
11857
|
|
|
|
|
|
|
# include |
11858
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
11859
|
|
|
|
|
|
|
#endif |
11860
|
|
|
|
|
|
|
|
11861
|
|
|
|
|
|
|
#endif |
11862
|
|
|
|
|
|
|
|
11863
|
|
|
|
|
|
|
#endif |
11864
|
|
|
|
|
|
|
|
11865
|
|
|
|
|
|
|
|
11866
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE |
11867
|
|
|
|
|
|
|
# include |
11868
|
|
|
|
|
|
|
static forceinline void |
11869
|
|
|
|
|
|
|
matchfinder_init_neon(mf_pos_t *data, size_t size) |
11870
|
|
|
|
|
|
|
{ |
11871
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
11872
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16(MATCHFINDER_INITVAL); |
11873
|
|
|
|
|
|
|
|
11874
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
11875
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
11876
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
11877
|
|
|
|
|
|
|
|
11878
|
|
|
|
|
|
|
do { |
11879
|
|
|
|
|
|
|
p[0] = v; |
11880
|
|
|
|
|
|
|
p[1] = v; |
11881
|
|
|
|
|
|
|
p[2] = v; |
11882
|
|
|
|
|
|
|
p[3] = v; |
11883
|
|
|
|
|
|
|
p += 4; |
11884
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
11885
|
|
|
|
|
|
|
} while (size != 0); |
11886
|
|
|
|
|
|
|
} |
11887
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_neon |
11888
|
|
|
|
|
|
|
|
11889
|
|
|
|
|
|
|
static forceinline void |
11890
|
|
|
|
|
|
|
matchfinder_rebase_neon(mf_pos_t *data, size_t size) |
11891
|
|
|
|
|
|
|
{ |
11892
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
11893
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16((u16)-MATCHFINDER_WINDOW_SIZE); |
11894
|
|
|
|
|
|
|
|
11895
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
11896
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
11897
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
11898
|
|
|
|
|
|
|
|
11899
|
|
|
|
|
|
|
do { |
11900
|
|
|
|
|
|
|
p[0] = vqaddq_s16(p[0], v); |
11901
|
|
|
|
|
|
|
p[1] = vqaddq_s16(p[1], v); |
11902
|
|
|
|
|
|
|
p[2] = vqaddq_s16(p[2], v); |
11903
|
|
|
|
|
|
|
p[3] = vqaddq_s16(p[3], v); |
11904
|
|
|
|
|
|
|
p += 4; |
11905
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
11906
|
|
|
|
|
|
|
} while (size != 0); |
11907
|
|
|
|
|
|
|
} |
11908
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_neon |
11909
|
|
|
|
|
|
|
|
11910
|
|
|
|
|
|
|
#endif |
11911
|
|
|
|
|
|
|
|
11912
|
|
|
|
|
|
|
#endif |
11913
|
|
|
|
|
|
|
|
11914
|
|
|
|
|
|
|
# elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
11915
|
|
|
|
|
|
|
/* # include "x86/matchfinder_impl.h" */ |
11916
|
|
|
|
|
|
|
|
11917
|
|
|
|
|
|
|
|
11918
|
|
|
|
|
|
|
#ifndef LIB_X86_MATCHFINDER_IMPL_H |
11919
|
|
|
|
|
|
|
#define LIB_X86_MATCHFINDER_IMPL_H |
11920
|
|
|
|
|
|
|
|
11921
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
11922
|
|
|
|
|
|
|
|
11923
|
|
|
|
|
|
|
|
11924
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
11925
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
11926
|
|
|
|
|
|
|
|
11927
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
11928
|
|
|
|
|
|
|
|
11929
|
|
|
|
|
|
|
|
11930
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
11931
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
11932
|
|
|
|
|
|
|
|
11933
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
11934
|
|
|
|
|
|
|
|
11935
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
11936
|
|
|
|
|
|
|
#endif |
11937
|
|
|
|
|
|
|
|
11938
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
11939
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
11940
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
11941
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
11942
|
|
|
|
|
|
|
#else |
11943
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
11944
|
|
|
|
|
|
|
#endif |
11945
|
|
|
|
|
|
|
|
11946
|
|
|
|
|
|
|
|
11947
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
11948
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
11949
|
|
|
|
|
|
|
#else |
11950
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
11951
|
|
|
|
|
|
|
#endif |
11952
|
|
|
|
|
|
|
|
11953
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
11954
|
|
|
|
|
|
|
|
11955
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
11956
|
|
|
|
|
|
|
|
11957
|
|
|
|
|
|
|
|
11958
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
11959
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
11960
|
|
|
|
|
|
|
|
11961
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
11962
|
|
|
|
|
|
|
|
11963
|
|
|
|
|
|
|
|
11964
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
11965
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
11966
|
|
|
|
|
|
|
|
11967
|
|
|
|
|
|
|
#include |
11968
|
|
|
|
|
|
|
#include |
11969
|
|
|
|
|
|
|
|
11970
|
|
|
|
|
|
|
#ifdef __cplusplus |
11971
|
|
|
|
|
|
|
extern "C" { |
11972
|
|
|
|
|
|
|
#endif |
11973
|
|
|
|
|
|
|
|
11974
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
11975
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
11976
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
11977
|
|
|
|
|
|
|
|
11978
|
|
|
|
|
|
|
|
11979
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
11980
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
11981
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
11982
|
|
|
|
|
|
|
# else |
11983
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
11984
|
|
|
|
|
|
|
# endif |
11985
|
|
|
|
|
|
|
#endif |
11986
|
|
|
|
|
|
|
|
11987
|
|
|
|
|
|
|
|
11988
|
|
|
|
|
|
|
|
11989
|
|
|
|
|
|
|
|
11990
|
|
|
|
|
|
|
|
11991
|
|
|
|
|
|
|
struct libdeflate_compressor; |
11992
|
|
|
|
|
|
|
|
11993
|
|
|
|
|
|
|
|
11994
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
11995
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
11996
|
|
|
|
|
|
|
|
11997
|
|
|
|
|
|
|
|
11998
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
11999
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
12000
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12001
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
12002
|
|
|
|
|
|
|
|
12003
|
|
|
|
|
|
|
|
12004
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12005
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
12006
|
|
|
|
|
|
|
size_t in_nbytes); |
12007
|
|
|
|
|
|
|
|
12008
|
|
|
|
|
|
|
|
12009
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12010
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
12011
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12012
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
12013
|
|
|
|
|
|
|
|
12014
|
|
|
|
|
|
|
|
12015
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12016
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
12017
|
|
|
|
|
|
|
size_t in_nbytes); |
12018
|
|
|
|
|
|
|
|
12019
|
|
|
|
|
|
|
|
12020
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12021
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
12022
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12023
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
12024
|
|
|
|
|
|
|
|
12025
|
|
|
|
|
|
|
|
12026
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
12027
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
12028
|
|
|
|
|
|
|
size_t in_nbytes); |
12029
|
|
|
|
|
|
|
|
12030
|
|
|
|
|
|
|
|
12031
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
12032
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
12033
|
|
|
|
|
|
|
|
12034
|
|
|
|
|
|
|
|
12035
|
|
|
|
|
|
|
|
12036
|
|
|
|
|
|
|
|
12037
|
|
|
|
|
|
|
|
12038
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
12039
|
|
|
|
|
|
|
|
12040
|
|
|
|
|
|
|
|
12041
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
12042
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
12043
|
|
|
|
|
|
|
|
12044
|
|
|
|
|
|
|
|
12045
|
|
|
|
|
|
|
enum libdeflate_result { |
12046
|
|
|
|
|
|
|
|
12047
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
12048
|
|
|
|
|
|
|
|
12049
|
|
|
|
|
|
|
|
12050
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
12051
|
|
|
|
|
|
|
|
12052
|
|
|
|
|
|
|
|
12053
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
12054
|
|
|
|
|
|
|
|
12055
|
|
|
|
|
|
|
|
12056
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
12057
|
|
|
|
|
|
|
}; |
12058
|
|
|
|
|
|
|
|
12059
|
|
|
|
|
|
|
|
12060
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12061
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
12062
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12063
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12064
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12065
|
|
|
|
|
|
|
|
12066
|
|
|
|
|
|
|
|
12067
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12068
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
12069
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12070
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12071
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
12072
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12073
|
|
|
|
|
|
|
|
12074
|
|
|
|
|
|
|
|
12075
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12076
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
12077
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12078
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12079
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12080
|
|
|
|
|
|
|
|
12081
|
|
|
|
|
|
|
|
12082
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12083
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
12084
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12085
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12086
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
12087
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12088
|
|
|
|
|
|
|
|
12089
|
|
|
|
|
|
|
|
12090
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12091
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
12092
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12093
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12094
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12095
|
|
|
|
|
|
|
|
12096
|
|
|
|
|
|
|
|
12097
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
12098
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
12099
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
12100
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
12101
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
12102
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
12103
|
|
|
|
|
|
|
|
12104
|
|
|
|
|
|
|
|
12105
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
12106
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
12107
|
|
|
|
|
|
|
|
12108
|
|
|
|
|
|
|
|
12109
|
|
|
|
|
|
|
|
12110
|
|
|
|
|
|
|
|
12111
|
|
|
|
|
|
|
|
12112
|
|
|
|
|
|
|
|
12113
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
12114
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
12115
|
|
|
|
|
|
|
|
12116
|
|
|
|
|
|
|
|
12117
|
|
|
|
|
|
|
|
12118
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
12119
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
12120
|
|
|
|
|
|
|
|
12121
|
|
|
|
|
|
|
|
12122
|
|
|
|
|
|
|
|
12123
|
|
|
|
|
|
|
|
12124
|
|
|
|
|
|
|
|
12125
|
|
|
|
|
|
|
|
12126
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
12127
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
12128
|
|
|
|
|
|
|
void (*free_func)(void *)); |
12129
|
|
|
|
|
|
|
|
12130
|
|
|
|
|
|
|
#ifdef __cplusplus |
12131
|
|
|
|
|
|
|
} |
12132
|
|
|
|
|
|
|
#endif |
12133
|
|
|
|
|
|
|
|
12134
|
|
|
|
|
|
|
#endif |
12135
|
|
|
|
|
|
|
|
12136
|
|
|
|
|
|
|
|
12137
|
|
|
|
|
|
|
#include |
12138
|
|
|
|
|
|
|
#include |
12139
|
|
|
|
|
|
|
#include |
12140
|
|
|
|
|
|
|
#ifdef _MSC_VER |
12141
|
|
|
|
|
|
|
# include |
12142
|
|
|
|
|
|
|
# include |
12143
|
|
|
|
|
|
|
|
12144
|
|
|
|
|
|
|
|
12145
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
12146
|
|
|
|
|
|
|
|
12147
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
12148
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
12149
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
12150
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
12151
|
|
|
|
|
|
|
|
12152
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
12153
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
12154
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
12155
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
12156
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
12157
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
12158
|
|
|
|
|
|
|
#endif |
12159
|
|
|
|
|
|
|
#ifndef FREESTANDING |
12160
|
|
|
|
|
|
|
# include |
12161
|
|
|
|
|
|
|
#endif |
12162
|
|
|
|
|
|
|
|
12163
|
|
|
|
|
|
|
|
12164
|
|
|
|
|
|
|
|
12165
|
|
|
|
|
|
|
|
12166
|
|
|
|
|
|
|
|
12167
|
|
|
|
|
|
|
|
12168
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
12169
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
12170
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
12171
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
12172
|
|
|
|
|
|
|
#ifdef _MSC_VER |
12173
|
|
|
|
|
|
|
# if defined(_M_X64) |
12174
|
|
|
|
|
|
|
# define ARCH_X86_64 |
12175
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
12176
|
|
|
|
|
|
|
# define ARCH_X86_32 |
12177
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
12178
|
|
|
|
|
|
|
# define ARCH_ARM64 |
12179
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
12180
|
|
|
|
|
|
|
# define ARCH_ARM32 |
12181
|
|
|
|
|
|
|
# endif |
12182
|
|
|
|
|
|
|
#else |
12183
|
|
|
|
|
|
|
# if defined(__x86_64__) |
12184
|
|
|
|
|
|
|
# define ARCH_X86_64 |
12185
|
|
|
|
|
|
|
# elif defined(__i386__) |
12186
|
|
|
|
|
|
|
# define ARCH_X86_32 |
12187
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
12188
|
|
|
|
|
|
|
# define ARCH_ARM64 |
12189
|
|
|
|
|
|
|
# elif defined(__arm__) |
12190
|
|
|
|
|
|
|
# define ARCH_ARM32 |
12191
|
|
|
|
|
|
|
# endif |
12192
|
|
|
|
|
|
|
#endif |
12193
|
|
|
|
|
|
|
|
12194
|
|
|
|
|
|
|
|
12195
|
|
|
|
|
|
|
|
12196
|
|
|
|
|
|
|
|
12197
|
|
|
|
|
|
|
|
12198
|
|
|
|
|
|
|
|
12199
|
|
|
|
|
|
|
typedef uint8_t u8; |
12200
|
|
|
|
|
|
|
typedef uint16_t u16; |
12201
|
|
|
|
|
|
|
typedef uint32_t u32; |
12202
|
|
|
|
|
|
|
typedef uint64_t u64; |
12203
|
|
|
|
|
|
|
typedef int8_t s8; |
12204
|
|
|
|
|
|
|
typedef int16_t s16; |
12205
|
|
|
|
|
|
|
typedef int32_t s32; |
12206
|
|
|
|
|
|
|
typedef int64_t s64; |
12207
|
|
|
|
|
|
|
|
12208
|
|
|
|
|
|
|
|
12209
|
|
|
|
|
|
|
#ifdef _MSC_VER |
12210
|
|
|
|
|
|
|
# ifdef _WIN64 |
12211
|
|
|
|
|
|
|
typedef long long ssize_t; |
12212
|
|
|
|
|
|
|
# else |
12213
|
|
|
|
|
|
|
typedef long ssize_t; |
12214
|
|
|
|
|
|
|
# endif |
12215
|
|
|
|
|
|
|
#endif |
12216
|
|
|
|
|
|
|
|
12217
|
|
|
|
|
|
|
|
12218
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
12219
|
|
|
|
|
|
|
|
12220
|
|
|
|
|
|
|
|
12221
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
12222
|
|
|
|
|
|
|
|
12223
|
|
|
|
|
|
|
|
12224
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
12225
|
|
|
|
|
|
|
|
12226
|
|
|
|
|
|
|
|
12227
|
|
|
|
|
|
|
|
12228
|
|
|
|
|
|
|
|
12229
|
|
|
|
|
|
|
|
12230
|
|
|
|
|
|
|
|
12231
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
12232
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
12233
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
12234
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
12235
|
|
|
|
|
|
|
#else |
12236
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
12237
|
|
|
|
|
|
|
#endif |
12238
|
|
|
|
|
|
|
#ifdef __clang__ |
12239
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
12240
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
12241
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
12242
|
|
|
|
|
|
|
# else |
12243
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
12244
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
12245
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
12246
|
|
|
|
|
|
|
# endif |
12247
|
|
|
|
|
|
|
#else |
12248
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
12249
|
|
|
|
|
|
|
#endif |
12250
|
|
|
|
|
|
|
|
12251
|
|
|
|
|
|
|
|
12252
|
|
|
|
|
|
|
#ifndef __has_attribute |
12253
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
12254
|
|
|
|
|
|
|
#endif |
12255
|
|
|
|
|
|
|
#ifndef __has_builtin |
12256
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
12257
|
|
|
|
|
|
|
#endif |
12258
|
|
|
|
|
|
|
|
12259
|
|
|
|
|
|
|
|
12260
|
|
|
|
|
|
|
#ifdef _MSC_VER |
12261
|
|
|
|
|
|
|
# define inline __inline |
12262
|
|
|
|
|
|
|
#endif |
12263
|
|
|
|
|
|
|
|
12264
|
|
|
|
|
|
|
|
12265
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
12266
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
12267
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12268
|
|
|
|
|
|
|
# define forceinline __forceinline |
12269
|
|
|
|
|
|
|
#else |
12270
|
|
|
|
|
|
|
# define forceinline inline |
12271
|
|
|
|
|
|
|
#endif |
12272
|
|
|
|
|
|
|
|
12273
|
|
|
|
|
|
|
|
12274
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
12275
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
12276
|
|
|
|
|
|
|
#else |
12277
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
12278
|
|
|
|
|
|
|
#endif |
12279
|
|
|
|
|
|
|
|
12280
|
|
|
|
|
|
|
|
12281
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
12282
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
12283
|
|
|
|
|
|
|
# define restrict __restrict__ |
12284
|
|
|
|
|
|
|
# else |
12285
|
|
|
|
|
|
|
# define restrict |
12286
|
|
|
|
|
|
|
# endif |
12287
|
|
|
|
|
|
|
#endif |
12288
|
|
|
|
|
|
|
|
12289
|
|
|
|
|
|
|
|
12290
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
12291
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
12292
|
|
|
|
|
|
|
#else |
12293
|
|
|
|
|
|
|
# define likely(expr) (expr) |
12294
|
|
|
|
|
|
|
#endif |
12295
|
|
|
|
|
|
|
|
12296
|
|
|
|
|
|
|
|
12297
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
12298
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
12299
|
|
|
|
|
|
|
#else |
12300
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
12301
|
|
|
|
|
|
|
#endif |
12302
|
|
|
|
|
|
|
|
12303
|
|
|
|
|
|
|
|
12304
|
|
|
|
|
|
|
#undef prefetchr |
12305
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
12306
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
12307
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12308
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
12309
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
12310
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
12311
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
12312
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
12313
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
12314
|
|
|
|
|
|
|
# endif |
12315
|
|
|
|
|
|
|
#endif |
12316
|
|
|
|
|
|
|
#ifndef prefetchr |
12317
|
|
|
|
|
|
|
# define prefetchr(addr) |
12318
|
|
|
|
|
|
|
#endif |
12319
|
|
|
|
|
|
|
|
12320
|
|
|
|
|
|
|
|
12321
|
|
|
|
|
|
|
#undef prefetchw |
12322
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
12323
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
12324
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12325
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
12326
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
12327
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
12328
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
12329
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
12330
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
12331
|
|
|
|
|
|
|
# endif |
12332
|
|
|
|
|
|
|
#endif |
12333
|
|
|
|
|
|
|
#ifndef prefetchw |
12334
|
|
|
|
|
|
|
# define prefetchw(addr) |
12335
|
|
|
|
|
|
|
#endif |
12336
|
|
|
|
|
|
|
|
12337
|
|
|
|
|
|
|
|
12338
|
|
|
|
|
|
|
#undef _aligned_attribute |
12339
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
12340
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
12341
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12342
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
12343
|
|
|
|
|
|
|
#endif |
12344
|
|
|
|
|
|
|
|
12345
|
|
|
|
|
|
|
|
12346
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
12347
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
12348
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
12349
|
|
|
|
|
|
|
#else |
12350
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
12351
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
12352
|
|
|
|
|
|
|
#endif |
12353
|
|
|
|
|
|
|
|
12354
|
|
|
|
|
|
|
|
12355
|
|
|
|
|
|
|
|
12356
|
|
|
|
|
|
|
|
12357
|
|
|
|
|
|
|
|
12358
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
12359
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
12360
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
12361
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
12362
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
12363
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
12364
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
12365
|
|
|
|
|
|
|
|
12366
|
|
|
|
|
|
|
|
12367
|
|
|
|
|
|
|
|
12368
|
|
|
|
|
|
|
|
12369
|
|
|
|
|
|
|
|
12370
|
|
|
|
|
|
|
|
12371
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
12372
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
12373
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12374
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
12375
|
|
|
|
|
|
|
#else |
12376
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
12377
|
|
|
|
|
|
|
{ |
12378
|
|
|
|
|
|
|
union { |
12379
|
|
|
|
|
|
|
u32 w; |
12380
|
|
|
|
|
|
|
u8 b; |
12381
|
|
|
|
|
|
|
} u; |
12382
|
|
|
|
|
|
|
|
12383
|
|
|
|
|
|
|
u.w = 1; |
12384
|
|
|
|
|
|
|
return u.b; |
12385
|
|
|
|
|
|
|
} |
12386
|
|
|
|
|
|
|
#endif |
12387
|
|
|
|
|
|
|
|
12388
|
|
|
|
|
|
|
|
12389
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
12390
|
|
|
|
|
|
|
{ |
12391
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
12392
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
12393
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12394
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
12395
|
|
|
|
|
|
|
#else |
12396
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
12397
|
|
|
|
|
|
|
#endif |
12398
|
|
|
|
|
|
|
} |
12399
|
|
|
|
|
|
|
|
12400
|
|
|
|
|
|
|
|
12401
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
12402
|
|
|
|
|
|
|
{ |
12403
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
12404
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
12405
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12406
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
12407
|
|
|
|
|
|
|
#else |
12408
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
12409
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
12410
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
12411
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
12412
|
|
|
|
|
|
|
#endif |
12413
|
|
|
|
|
|
|
} |
12414
|
|
|
|
|
|
|
|
12415
|
|
|
|
|
|
|
|
12416
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
12417
|
|
|
|
|
|
|
{ |
12418
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
12419
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
12420
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12421
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
12422
|
|
|
|
|
|
|
#else |
12423
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
12424
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
12425
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
12426
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
12427
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
12428
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
12429
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
12430
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
12431
|
|
|
|
|
|
|
#endif |
12432
|
|
|
|
|
|
|
} |
12433
|
|
|
|
|
|
|
|
12434
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
12435
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
12436
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
12437
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
12438
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
12439
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
12440
|
|
|
|
|
|
|
|
12441
|
|
|
|
|
|
|
|
12442
|
|
|
|
|
|
|
|
12443
|
|
|
|
|
|
|
|
12444
|
|
|
|
|
|
|
|
12445
|
|
|
|
|
|
|
|
12446
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
12447
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
12448
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
12449
|
|
|
|
|
|
|
defined(__wasm__)) |
12450
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
12451
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12452
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
12453
|
|
|
|
|
|
|
#else |
12454
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
12455
|
|
|
|
|
|
|
#endif |
12456
|
|
|
|
|
|
|
|
12457
|
|
|
|
|
|
|
|
12458
|
|
|
|
|
|
|
|
12459
|
|
|
|
|
|
|
#ifdef FREESTANDING |
12460
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
12461
|
|
|
|
|
|
|
#else |
12462
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
12463
|
|
|
|
|
|
|
#endif |
12464
|
|
|
|
|
|
|
|
12465
|
|
|
|
|
|
|
|
12466
|
|
|
|
|
|
|
|
12467
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
12468
|
|
|
|
|
|
|
static forceinline type \ |
12469
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
12470
|
|
|
|
|
|
|
{ \ |
12471
|
|
|
|
|
|
|
type v; \ |
12472
|
|
|
|
|
|
|
\ |
12473
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
12474
|
|
|
|
|
|
|
return v; \ |
12475
|
|
|
|
|
|
|
} \ |
12476
|
|
|
|
|
|
|
\ |
12477
|
|
|
|
|
|
|
static forceinline void \ |
12478
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
12479
|
|
|
|
|
|
|
{ \ |
12480
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
12481
|
|
|
|
|
|
|
} |
12482
|
|
|
|
|
|
|
|
12483
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
12484
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
12485
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
12486
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
12487
|
|
|
|
|
|
|
|
12488
|
|
|
|
|
|
|
#undef MEMCOPY |
12489
|
|
|
|
|
|
|
|
12490
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
12491
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
12492
|
|
|
|
|
|
|
|
12493
|
|
|
|
|
|
|
|
12494
|
|
|
|
|
|
|
|
12495
|
|
|
|
|
|
|
static forceinline u16 |
12496
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
12497
|
|
|
|
|
|
|
{ |
12498
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12499
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
12500
|
|
|
|
|
|
|
else |
12501
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
12502
|
|
|
|
|
|
|
} |
12503
|
|
|
|
|
|
|
|
12504
|
|
|
|
|
|
|
static forceinline u16 |
12505
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
12506
|
|
|
|
|
|
|
{ |
12507
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12508
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
12509
|
|
|
|
|
|
|
else |
12510
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
12511
|
|
|
|
|
|
|
} |
12512
|
|
|
|
|
|
|
|
12513
|
|
|
|
|
|
|
static forceinline u32 |
12514
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
12515
|
|
|
|
|
|
|
{ |
12516
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12517
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
12518
|
|
|
|
|
|
|
else |
12519
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
12520
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
12521
|
|
|
|
|
|
|
} |
12522
|
|
|
|
|
|
|
|
12523
|
|
|
|
|
|
|
static forceinline u32 |
12524
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
12525
|
|
|
|
|
|
|
{ |
12526
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12527
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
12528
|
|
|
|
|
|
|
else |
12529
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
12530
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
12531
|
|
|
|
|
|
|
} |
12532
|
|
|
|
|
|
|
|
12533
|
|
|
|
|
|
|
static forceinline u64 |
12534
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
12535
|
|
|
|
|
|
|
{ |
12536
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
12537
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
12538
|
|
|
|
|
|
|
else |
12539
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
12540
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
12541
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
12542
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
12543
|
|
|
|
|
|
|
} |
12544
|
|
|
|
|
|
|
|
12545
|
|
|
|
|
|
|
static forceinline machine_word_t |
12546
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
12547
|
|
|
|
|
|
|
{ |
12548
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
12549
|
|
|
|
|
|
|
if (WORDBITS == 32) |
12550
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
12551
|
|
|
|
|
|
|
else |
12552
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
12553
|
|
|
|
|
|
|
} |
12554
|
|
|
|
|
|
|
|
12555
|
|
|
|
|
|
|
|
12556
|
|
|
|
|
|
|
|
12557
|
|
|
|
|
|
|
static forceinline void |
12558
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
12559
|
|
|
|
|
|
|
{ |
12560
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12561
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
12562
|
|
|
|
|
|
|
} else { |
12563
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
12564
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
12565
|
|
|
|
|
|
|
} |
12566
|
|
|
|
|
|
|
} |
12567
|
|
|
|
|
|
|
|
12568
|
|
|
|
|
|
|
static forceinline void |
12569
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
12570
|
|
|
|
|
|
|
{ |
12571
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12572
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
12573
|
|
|
|
|
|
|
} else { |
12574
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
12575
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
12576
|
|
|
|
|
|
|
} |
12577
|
|
|
|
|
|
|
} |
12578
|
|
|
|
|
|
|
|
12579
|
|
|
|
|
|
|
static forceinline void |
12580
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
12581
|
|
|
|
|
|
|
{ |
12582
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12583
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
12584
|
|
|
|
|
|
|
} else { |
12585
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
12586
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
12587
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
12588
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
12589
|
|
|
|
|
|
|
} |
12590
|
|
|
|
|
|
|
} |
12591
|
|
|
|
|
|
|
|
12592
|
|
|
|
|
|
|
static forceinline void |
12593
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
12594
|
|
|
|
|
|
|
{ |
12595
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12596
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
12597
|
|
|
|
|
|
|
} else { |
12598
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
12599
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
12600
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
12601
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
12602
|
|
|
|
|
|
|
} |
12603
|
|
|
|
|
|
|
} |
12604
|
|
|
|
|
|
|
|
12605
|
|
|
|
|
|
|
static forceinline void |
12606
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
12607
|
|
|
|
|
|
|
{ |
12608
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
12609
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
12610
|
|
|
|
|
|
|
} else { |
12611
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
12612
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
12613
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
12614
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
12615
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
12616
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
12617
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
12618
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
12619
|
|
|
|
|
|
|
} |
12620
|
|
|
|
|
|
|
} |
12621
|
|
|
|
|
|
|
|
12622
|
|
|
|
|
|
|
static forceinline void |
12623
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
12624
|
|
|
|
|
|
|
{ |
12625
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
12626
|
|
|
|
|
|
|
if (WORDBITS == 32) |
12627
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
12628
|
|
|
|
|
|
|
else |
12629
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
12630
|
|
|
|
|
|
|
} |
12631
|
|
|
|
|
|
|
|
12632
|
|
|
|
|
|
|
|
12633
|
|
|
|
|
|
|
|
12634
|
|
|
|
|
|
|
|
12635
|
|
|
|
|
|
|
|
12636
|
|
|
|
|
|
|
|
12637
|
|
|
|
|
|
|
|
12638
|
|
|
|
|
|
|
static forceinline unsigned |
12639
|
|
|
|
|
|
|
bsr32(u32 v) |
12640
|
|
|
|
|
|
|
{ |
12641
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
12642
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
12643
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12644
|
|
|
|
|
|
|
unsigned long i; |
12645
|
|
|
|
|
|
|
|
12646
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
12647
|
|
|
|
|
|
|
return i; |
12648
|
|
|
|
|
|
|
#else |
12649
|
|
|
|
|
|
|
unsigned i = 0; |
12650
|
|
|
|
|
|
|
|
12651
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
12652
|
|
|
|
|
|
|
i++; |
12653
|
|
|
|
|
|
|
return i; |
12654
|
|
|
|
|
|
|
#endif |
12655
|
|
|
|
|
|
|
} |
12656
|
|
|
|
|
|
|
|
12657
|
|
|
|
|
|
|
static forceinline unsigned |
12658
|
|
|
|
|
|
|
bsr64(u64 v) |
12659
|
|
|
|
|
|
|
{ |
12660
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
12661
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
12662
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
12663
|
|
|
|
|
|
|
unsigned long i; |
12664
|
|
|
|
|
|
|
|
12665
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
12666
|
|
|
|
|
|
|
return i; |
12667
|
|
|
|
|
|
|
#else |
12668
|
|
|
|
|
|
|
unsigned i = 0; |
12669
|
|
|
|
|
|
|
|
12670
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
12671
|
|
|
|
|
|
|
i++; |
12672
|
|
|
|
|
|
|
return i; |
12673
|
|
|
|
|
|
|
#endif |
12674
|
|
|
|
|
|
|
} |
12675
|
|
|
|
|
|
|
|
12676
|
|
|
|
|
|
|
static forceinline unsigned |
12677
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
12678
|
|
|
|
|
|
|
{ |
12679
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
12680
|
|
|
|
|
|
|
if (WORDBITS == 32) |
12681
|
|
|
|
|
|
|
return bsr32(v); |
12682
|
|
|
|
|
|
|
else |
12683
|
|
|
|
|
|
|
return bsr64(v); |
12684
|
|
|
|
|
|
|
} |
12685
|
|
|
|
|
|
|
|
12686
|
|
|
|
|
|
|
|
12687
|
|
|
|
|
|
|
|
12688
|
|
|
|
|
|
|
static forceinline unsigned |
12689
|
|
|
|
|
|
|
bsf32(u32 v) |
12690
|
|
|
|
|
|
|
{ |
12691
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
12692
|
|
|
|
|
|
|
return __builtin_ctz(v); |
12693
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
12694
|
|
|
|
|
|
|
unsigned long i; |
12695
|
|
|
|
|
|
|
|
12696
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
12697
|
|
|
|
|
|
|
return i; |
12698
|
|
|
|
|
|
|
#else |
12699
|
|
|
|
|
|
|
unsigned i = 0; |
12700
|
|
|
|
|
|
|
|
12701
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
12702
|
|
|
|
|
|
|
i++; |
12703
|
|
|
|
|
|
|
return i; |
12704
|
|
|
|
|
|
|
#endif |
12705
|
|
|
|
|
|
|
} |
12706
|
|
|
|
|
|
|
|
12707
|
|
|
|
|
|
|
static forceinline unsigned |
12708
|
|
|
|
|
|
|
bsf64(u64 v) |
12709
|
|
|
|
|
|
|
{ |
12710
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
12711
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
12712
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
12713
|
|
|
|
|
|
|
unsigned long i; |
12714
|
|
|
|
|
|
|
|
12715
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
12716
|
|
|
|
|
|
|
return i; |
12717
|
|
|
|
|
|
|
#else |
12718
|
|
|
|
|
|
|
unsigned i = 0; |
12719
|
|
|
|
|
|
|
|
12720
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
12721
|
|
|
|
|
|
|
i++; |
12722
|
|
|
|
|
|
|
return i; |
12723
|
|
|
|
|
|
|
#endif |
12724
|
|
|
|
|
|
|
} |
12725
|
|
|
|
|
|
|
|
12726
|
|
|
|
|
|
|
static forceinline unsigned |
12727
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
12728
|
|
|
|
|
|
|
{ |
12729
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
12730
|
|
|
|
|
|
|
if (WORDBITS == 32) |
12731
|
|
|
|
|
|
|
return bsf32(v); |
12732
|
|
|
|
|
|
|
else |
12733
|
|
|
|
|
|
|
return bsf64(v); |
12734
|
|
|
|
|
|
|
} |
12735
|
|
|
|
|
|
|
|
12736
|
|
|
|
|
|
|
|
12737
|
|
|
|
|
|
|
#undef rbit32 |
12738
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
12739
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
12740
|
|
|
|
|
|
|
static forceinline u32 |
12741
|
|
|
|
|
|
|
rbit32(u32 v) |
12742
|
|
|
|
|
|
|
{ |
12743
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
12744
|
|
|
|
|
|
|
return v; |
12745
|
|
|
|
|
|
|
} |
12746
|
|
|
|
|
|
|
#define rbit32 rbit32 |
12747
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
12748
|
|
|
|
|
|
|
static forceinline u32 |
12749
|
|
|
|
|
|
|
rbit32(u32 v) |
12750
|
|
|
|
|
|
|
{ |
12751
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
12752
|
|
|
|
|
|
|
return v; |
12753
|
|
|
|
|
|
|
} |
12754
|
|
|
|
|
|
|
#define rbit32 rbit32 |
12755
|
|
|
|
|
|
|
#endif |
12756
|
|
|
|
|
|
|
|
12757
|
|
|
|
|
|
|
#endif |
12758
|
|
|
|
|
|
|
|
12759
|
|
|
|
|
|
|
|
12760
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
12761
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
12762
|
|
|
|
|
|
|
|
12763
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
12764
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
12765
|
|
|
|
|
|
|
|
12766
|
|
|
|
|
|
|
#ifdef FREESTANDING |
12767
|
|
|
|
|
|
|
|
12768
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
12769
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
12770
|
|
|
|
|
|
|
|
12771
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
12772
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
12773
|
|
|
|
|
|
|
|
12774
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
12775
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
12776
|
|
|
|
|
|
|
|
12777
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
12778
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
12779
|
|
|
|
|
|
|
|
12780
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
12781
|
|
|
|
|
|
|
#else |
12782
|
|
|
|
|
|
|
#include |
12783
|
|
|
|
|
|
|
#endif |
12784
|
|
|
|
|
|
|
|
12785
|
|
|
|
|
|
|
|
12786
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
12787
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
12788
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
12789
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
12790
|
|
|
|
|
|
|
#else |
12791
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
12792
|
|
|
|
|
|
|
#endif |
12793
|
|
|
|
|
|
|
|
12794
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
12795
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
12796
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
12797
|
|
|
|
|
|
|
|
12798
|
|
|
|
|
|
|
#endif |
12799
|
|
|
|
|
|
|
|
12800
|
|
|
|
|
|
|
|
12801
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
12802
|
|
|
|
|
|
|
|
12803
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
12804
|
|
|
|
|
|
|
|
12805
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
12806
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
12807
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
12808
|
|
|
|
|
|
|
#endif |
12809
|
|
|
|
|
|
|
|
12810
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
12811
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
12812
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
12813
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
12814
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
12815
|
|
|
|
|
|
|
|
12816
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
12817
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
12818
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
12819
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
12820
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
12821
|
|
|
|
|
|
|
|
12822
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
12823
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
12824
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
12825
|
|
|
|
|
|
|
|
12826
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
12827
|
|
|
|
|
|
|
|
12828
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
12829
|
|
|
|
|
|
|
{ |
12830
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
12831
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
12832
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
12833
|
|
|
|
|
|
|
} |
12834
|
|
|
|
|
|
|
#else |
12835
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
12836
|
|
|
|
|
|
|
#endif |
12837
|
|
|
|
|
|
|
|
12838
|
|
|
|
|
|
|
|
12839
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
12840
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
12841
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
12842
|
|
|
|
|
|
|
#else |
12843
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
12844
|
|
|
|
|
|
|
#endif |
12845
|
|
|
|
|
|
|
|
12846
|
|
|
|
|
|
|
|
12847
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
12848
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
12849
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
12850
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
12851
|
|
|
|
|
|
|
#else |
12852
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
12853
|
|
|
|
|
|
|
#endif |
12854
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
12855
|
|
|
|
|
|
|
|
12856
|
|
|
|
|
|
|
|
12857
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
12858
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
12859
|
|
|
|
|
|
|
#else |
12860
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
12861
|
|
|
|
|
|
|
#endif |
12862
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
12863
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
12864
|
|
|
|
|
|
|
defined(_MSC_VER))) |
12865
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
12866
|
|
|
|
|
|
|
#else |
12867
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
12868
|
|
|
|
|
|
|
#endif |
12869
|
|
|
|
|
|
|
|
12870
|
|
|
|
|
|
|
|
12871
|
|
|
|
|
|
|
#ifdef __AVX__ |
12872
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
12873
|
|
|
|
|
|
|
#else |
12874
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
12875
|
|
|
|
|
|
|
#endif |
12876
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
12877
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
12878
|
|
|
|
|
|
|
defined(_MSC_VER))) |
12879
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
12880
|
|
|
|
|
|
|
#else |
12881
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
12882
|
|
|
|
|
|
|
#endif |
12883
|
|
|
|
|
|
|
|
12884
|
|
|
|
|
|
|
|
12885
|
|
|
|
|
|
|
#ifdef __AVX2__ |
12886
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
12887
|
|
|
|
|
|
|
#else |
12888
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
12889
|
|
|
|
|
|
|
#endif |
12890
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
12891
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
12892
|
|
|
|
|
|
|
defined(_MSC_VER))) |
12893
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
12894
|
|
|
|
|
|
|
#else |
12895
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
12896
|
|
|
|
|
|
|
#endif |
12897
|
|
|
|
|
|
|
|
12898
|
|
|
|
|
|
|
|
12899
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
12900
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
12901
|
|
|
|
|
|
|
#else |
12902
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
12903
|
|
|
|
|
|
|
#endif |
12904
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
12905
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
12906
|
|
|
|
|
|
|
defined(_MSC_VER))) |
12907
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
12908
|
|
|
|
|
|
|
#else |
12909
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
12910
|
|
|
|
|
|
|
#endif |
12911
|
|
|
|
|
|
|
|
12912
|
|
|
|
|
|
|
#endif |
12913
|
|
|
|
|
|
|
|
12914
|
|
|
|
|
|
|
#endif |
12915
|
|
|
|
|
|
|
|
12916
|
|
|
|
|
|
|
|
12917
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE |
12918
|
|
|
|
|
|
|
# include |
12919
|
|
|
|
|
|
|
static forceinline void |
12920
|
|
|
|
|
|
|
matchfinder_init_avx2(mf_pos_t *data, size_t size) |
12921
|
|
|
|
|
|
|
{ |
12922
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
12923
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16(MATCHFINDER_INITVAL); |
12924
|
|
|
|
|
|
|
|
12925
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
12926
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
12927
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
12928
|
|
|
|
|
|
|
|
12929
|
|
|
|
|
|
|
do { |
12930
|
|
|
|
|
|
|
p[0] = v; |
12931
|
|
|
|
|
|
|
p[1] = v; |
12932
|
|
|
|
|
|
|
p[2] = v; |
12933
|
|
|
|
|
|
|
p[3] = v; |
12934
|
|
|
|
|
|
|
p += 4; |
12935
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
12936
|
|
|
|
|
|
|
} while (size != 0); |
12937
|
|
|
|
|
|
|
} |
12938
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_avx2 |
12939
|
|
|
|
|
|
|
|
12940
|
|
|
|
|
|
|
static forceinline void |
12941
|
|
|
|
|
|
|
matchfinder_rebase_avx2(mf_pos_t *data, size_t size) |
12942
|
|
|
|
|
|
|
{ |
12943
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
12944
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
12945
|
|
|
|
|
|
|
|
12946
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
12947
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
12948
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
12949
|
|
|
|
|
|
|
|
12950
|
|
|
|
|
|
|
do { |
12951
|
|
|
|
|
|
|
|
12952
|
|
|
|
|
|
|
p[0] = _mm256_adds_epi16(p[0], v); |
12953
|
|
|
|
|
|
|
p[1] = _mm256_adds_epi16(p[1], v); |
12954
|
|
|
|
|
|
|
p[2] = _mm256_adds_epi16(p[2], v); |
12955
|
|
|
|
|
|
|
p[3] = _mm256_adds_epi16(p[3], v); |
12956
|
|
|
|
|
|
|
p += 4; |
12957
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
12958
|
|
|
|
|
|
|
} while (size != 0); |
12959
|
|
|
|
|
|
|
} |
12960
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_avx2 |
12961
|
|
|
|
|
|
|
|
12962
|
|
|
|
|
|
|
#elif HAVE_SSE2_NATIVE |
12963
|
|
|
|
|
|
|
# include |
12964
|
|
|
|
|
|
|
static forceinline void |
12965
|
|
|
|
|
|
|
matchfinder_init_sse2(mf_pos_t *data, size_t size) |
12966
|
|
|
|
|
|
|
{ |
12967
|
37
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
12968
|
37
|
|
|
|
|
|
__m128i v = _mm_set1_epi16(MATCHFINDER_INITVAL); |
12969
|
|
|
|
|
|
|
|
12970
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
12971
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
12972
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
12973
|
|
|
|
|
|
|
|
12974
|
|
|
|
|
|
|
do { |
12975
|
138240
|
|
|
|
|
|
p[0] = v; |
12976
|
138240
|
|
|
|
|
|
p[1] = v; |
12977
|
138240
|
|
|
|
|
|
p[2] = v; |
12978
|
138240
|
|
|
|
|
|
p[3] = v; |
12979
|
138240
|
|
|
|
|
|
p += 4; |
12980
|
138240
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
12981
|
138240
|
100
|
|
|
|
|
} while (size != 0); |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
12982
|
|
|
|
|
|
|
} |
12983
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_sse2 |
12984
|
|
|
|
|
|
|
|
12985
|
|
|
|
|
|
|
static forceinline void |
12986
|
|
|
|
|
|
|
matchfinder_rebase_sse2(mf_pos_t *data, size_t size) |
12987
|
|
|
|
|
|
|
{ |
12988
|
0
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
12989
|
0
|
|
|
|
|
|
__m128i v = _mm_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
12990
|
|
|
|
|
|
|
|
12991
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
12992
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
12993
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
12994
|
|
|
|
|
|
|
|
12995
|
|
|
|
|
|
|
do { |
12996
|
|
|
|
|
|
|
|
12997
|
0
|
|
|
|
|
|
p[0] = _mm_adds_epi16(p[0], v); |
12998
|
0
|
|
|
|
|
|
p[1] = _mm_adds_epi16(p[1], v); |
12999
|
0
|
|
|
|
|
|
p[2] = _mm_adds_epi16(p[2], v); |
13000
|
0
|
|
|
|
|
|
p[3] = _mm_adds_epi16(p[3], v); |
13001
|
0
|
|
|
|
|
|
p += 4; |
13002
|
0
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
13003
|
0
|
0
|
|
|
|
|
} while (size != 0); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13004
|
|
|
|
|
|
|
} |
13005
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_sse2 |
13006
|
|
|
|
|
|
|
#endif |
13007
|
|
|
|
|
|
|
|
13008
|
|
|
|
|
|
|
#endif |
13009
|
|
|
|
|
|
|
|
13010
|
|
|
|
|
|
|
# endif |
13011
|
|
|
|
|
|
|
#else |
13012
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED |
13013
|
|
|
|
|
|
|
#endif |
13014
|
|
|
|
|
|
|
|
13015
|
|
|
|
|
|
|
|
13016
|
|
|
|
|
|
|
#ifndef matchfinder_init |
13017
|
|
|
|
|
|
|
static forceinline void |
13018
|
|
|
|
|
|
|
matchfinder_init(mf_pos_t *data, size_t size) |
13019
|
|
|
|
|
|
|
{ |
13020
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
13021
|
|
|
|
|
|
|
size_t i; |
13022
|
|
|
|
|
|
|
|
13023
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
13024
|
|
|
|
|
|
|
data[i] = MATCHFINDER_INITVAL; |
13025
|
|
|
|
|
|
|
} |
13026
|
|
|
|
|
|
|
#endif |
13027
|
|
|
|
|
|
|
|
13028
|
|
|
|
|
|
|
|
13029
|
|
|
|
|
|
|
#ifndef matchfinder_rebase |
13030
|
|
|
|
|
|
|
static forceinline void |
13031
|
|
|
|
|
|
|
matchfinder_rebase(mf_pos_t *data, size_t size) |
13032
|
|
|
|
|
|
|
{ |
13033
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
13034
|
|
|
|
|
|
|
size_t i; |
13035
|
|
|
|
|
|
|
|
13036
|
|
|
|
|
|
|
if (MATCHFINDER_WINDOW_SIZE == 32768) { |
13037
|
|
|
|
|
|
|
|
13038
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
13039
|
|
|
|
|
|
|
data[i] = 0x8000 | (data[i] & ~(data[i] >> 15)); |
13040
|
|
|
|
|
|
|
} else { |
13041
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) { |
13042
|
|
|
|
|
|
|
if (data[i] >= 0) |
13043
|
|
|
|
|
|
|
data[i] -= (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
13044
|
|
|
|
|
|
|
else |
13045
|
|
|
|
|
|
|
data[i] = (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
13046
|
|
|
|
|
|
|
} |
13047
|
|
|
|
|
|
|
} |
13048
|
|
|
|
|
|
|
} |
13049
|
|
|
|
|
|
|
#endif |
13050
|
|
|
|
|
|
|
|
13051
|
|
|
|
|
|
|
|
13052
|
|
|
|
|
|
|
static forceinline u32 |
13053
|
|
|
|
|
|
|
lz_hash(u32 seq, unsigned num_bits) |
13054
|
|
|
|
|
|
|
{ |
13055
|
86187
|
|
|
|
|
|
return (u32)(seq * 0x1E35A7BD) >> (32 - num_bits); |
13056
|
|
|
|
|
|
|
} |
13057
|
|
|
|
|
|
|
|
13058
|
|
|
|
|
|
|
|
13059
|
|
|
|
|
|
|
static forceinline unsigned |
13060
|
|
|
|
|
|
|
lz_extend(const u8 * const strptr, const u8 * const matchptr, |
13061
|
|
|
|
|
|
|
const unsigned start_len, const unsigned max_len) |
13062
|
|
|
|
|
|
|
{ |
13063
|
17924
|
|
|
|
|
|
unsigned len = start_len; |
13064
|
|
|
|
|
|
|
machine_word_t v_word; |
13065
|
|
|
|
|
|
|
|
13066
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
13067
|
|
|
|
|
|
|
|
13068
|
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
|
|
|
|
|
|
13069
|
|
|
|
|
|
|
|
13070
|
|
|
|
|
|
|
#define COMPARE_WORD_STEP \ |
13071
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ \ |
13072
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); \ |
13073
|
|
|
|
|
|
|
if (v_word != 0) \ |
13074
|
|
|
|
|
|
|
goto word_differs; \ |
13075
|
|
|
|
|
|
|
len += WORDBYTES; \ |
13076
|
|
|
|
|
|
|
|
13077
|
17668
|
50
|
|
|
|
|
COMPARE_WORD_STEP |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13078
|
16077
|
50
|
|
|
|
|
COMPARE_WORD_STEP |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13079
|
15496
|
50
|
|
|
|
|
COMPARE_WORD_STEP |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13080
|
15442
|
50
|
|
|
|
|
COMPARE_WORD_STEP |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13081
|
|
|
|
|
|
|
#undef COMPARE_WORD_STEP |
13082
|
|
|
|
|
|
|
} |
13083
|
|
|
|
|
|
|
|
13084
|
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
|
|
|
|
|
|
13085
|
678300
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ |
13086
|
452200
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); |
13087
|
226100
|
50
|
|
|
|
|
if (v_word != 0) |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13088
|
|
|
|
|
|
|
goto word_differs; |
13089
|
226010
|
|
|
|
|
|
len += WORDBYTES; |
13090
|
|
|
|
|
|
|
} |
13091
|
|
|
|
|
|
|
} |
13092
|
|
|
|
|
|
|
|
13093
|
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
|
|
|
|
|
|
13094
|
42804
|
|
|
|
|
|
len++; |
13095
|
15292
|
|
|
|
|
|
return len; |
13096
|
|
|
|
|
|
|
|
13097
|
|
|
|
|
|
|
word_differs: |
13098
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
13099
|
2632
|
|
|
|
|
|
len += (bsfw(v_word) >> 3); |
13100
|
|
|
|
|
|
|
else |
13101
|
|
|
|
|
|
|
len += (WORDBITS - 1 - bsrw(v_word)) >> 3; |
13102
|
2632
|
|
|
|
|
|
return len; |
13103
|
|
|
|
|
|
|
} |
13104
|
|
|
|
|
|
|
|
13105
|
|
|
|
|
|
|
#endif |
13106
|
|
|
|
|
|
|
|
13107
|
|
|
|
|
|
|
|
13108
|
|
|
|
|
|
|
#define HC_MATCHFINDER_HASH3_ORDER 15 |
13109
|
|
|
|
|
|
|
#define HC_MATCHFINDER_HASH4_ORDER 16 |
13110
|
|
|
|
|
|
|
|
13111
|
|
|
|
|
|
|
#define HC_MATCHFINDER_TOTAL_HASH_SIZE \ |
13112
|
|
|
|
|
|
|
(((1UL << HC_MATCHFINDER_HASH3_ORDER) + \ |
13113
|
|
|
|
|
|
|
(1UL << HC_MATCHFINDER_HASH4_ORDER)) * sizeof(mf_pos_t)) |
13114
|
|
|
|
|
|
|
|
13115
|
|
|
|
|
|
|
struct MATCHFINDER_ALIGNED hc_matchfinder { |
13116
|
|
|
|
|
|
|
|
13117
|
|
|
|
|
|
|
|
13118
|
|
|
|
|
|
|
mf_pos_t hash3_tab[1UL << HC_MATCHFINDER_HASH3_ORDER]; |
13119
|
|
|
|
|
|
|
|
13120
|
|
|
|
|
|
|
|
13121
|
|
|
|
|
|
|
mf_pos_t hash4_tab[1UL << HC_MATCHFINDER_HASH4_ORDER]; |
13122
|
|
|
|
|
|
|
|
13123
|
|
|
|
|
|
|
|
13124
|
|
|
|
|
|
|
mf_pos_t next_tab[MATCHFINDER_WINDOW_SIZE]; |
13125
|
|
|
|
|
|
|
}; |
13126
|
|
|
|
|
|
|
|
13127
|
|
|
|
|
|
|
|
13128
|
|
|
|
|
|
|
static forceinline void |
13129
|
|
|
|
|
|
|
hc_matchfinder_init(struct hc_matchfinder *mf) |
13130
|
|
|
|
|
|
|
{ |
13131
|
|
|
|
|
|
|
STATIC_ASSERT(HC_MATCHFINDER_TOTAL_HASH_SIZE % |
13132
|
|
|
|
|
|
|
MATCHFINDER_SIZE_ALIGNMENT == 0); |
13133
|
|
|
|
|
|
|
|
13134
|
|
|
|
|
|
|
matchfinder_init((mf_pos_t *)mf, HC_MATCHFINDER_TOTAL_HASH_SIZE); |
13135
|
|
|
|
|
|
|
} |
13136
|
|
|
|
|
|
|
|
13137
|
|
|
|
|
|
|
static forceinline void |
13138
|
|
|
|
|
|
|
hc_matchfinder_slide_window(struct hc_matchfinder *mf) |
13139
|
|
|
|
|
|
|
{ |
13140
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(*mf) % MATCHFINDER_SIZE_ALIGNMENT == 0); |
13141
|
|
|
|
|
|
|
|
13142
|
|
|
|
|
|
|
matchfinder_rebase((mf_pos_t *)mf, sizeof(*mf)); |
13143
|
|
|
|
|
|
|
} |
13144
|
|
|
|
|
|
|
|
13145
|
|
|
|
|
|
|
|
13146
|
|
|
|
|
|
|
static forceinline u32 |
13147
|
|
|
|
|
|
|
hc_matchfinder_longest_match(struct hc_matchfinder * const mf, |
13148
|
|
|
|
|
|
|
const u8 ** const in_base_p, |
13149
|
|
|
|
|
|
|
const u8 * const in_next, |
13150
|
|
|
|
|
|
|
u32 best_len, |
13151
|
|
|
|
|
|
|
const u32 max_len, |
13152
|
|
|
|
|
|
|
const u32 nice_len, |
13153
|
|
|
|
|
|
|
const u32 max_search_depth, |
13154
|
|
|
|
|
|
|
u32 * const next_hashes, |
13155
|
|
|
|
|
|
|
u32 * const offset_ret) |
13156
|
|
|
|
|
|
|
{ |
13157
|
7046
|
|
|
|
|
|
u32 depth_remaining = max_search_depth; |
13158
|
7046
|
|
|
|
|
|
const u8 *best_matchptr = in_next; |
13159
|
|
|
|
|
|
|
mf_pos_t cur_node3, cur_node4; |
13160
|
|
|
|
|
|
|
u32 hash3, hash4; |
13161
|
|
|
|
|
|
|
u32 next_hashseq; |
13162
|
|
|
|
|
|
|
u32 seq4; |
13163
|
|
|
|
|
|
|
const u8 *matchptr; |
13164
|
|
|
|
|
|
|
u32 len; |
13165
|
7046
|
|
|
|
|
|
u32 cur_pos = in_next - *in_base_p; |
13166
|
|
|
|
|
|
|
const u8 *in_base; |
13167
|
|
|
|
|
|
|
mf_pos_t cutoff; |
13168
|
|
|
|
|
|
|
|
13169
|
7046
|
50
|
|
|
|
|
if (cur_pos == MATCHFINDER_WINDOW_SIZE) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13170
|
|
|
|
|
|
|
hc_matchfinder_slide_window(mf); |
13171
|
0
|
|
|
|
|
|
*in_base_p += MATCHFINDER_WINDOW_SIZE; |
13172
|
0
|
|
|
|
|
|
cur_pos = 0; |
13173
|
|
|
|
|
|
|
} |
13174
|
|
|
|
|
|
|
|
13175
|
7046
|
|
|
|
|
|
in_base = *in_base_p; |
13176
|
7046
|
|
|
|
|
|
cutoff = cur_pos - MATCHFINDER_WINDOW_SIZE; |
13177
|
|
|
|
|
|
|
|
13178
|
7046
|
50
|
|
|
|
|
if (unlikely(max_len < 5)) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13179
|
|
|
|
|
|
|
goto out; |
13180
|
|
|
|
|
|
|
|
13181
|
|
|
|
|
|
|
|
13182
|
7046
|
|
|
|
|
|
hash3 = next_hashes[0]; |
13183
|
7046
|
|
|
|
|
|
hash4 = next_hashes[1]; |
13184
|
|
|
|
|
|
|
|
13185
|
|
|
|
|
|
|
|
13186
|
7046
|
|
|
|
|
|
cur_node3 = mf->hash3_tab[hash3]; |
13187
|
7046
|
|
|
|
|
|
cur_node4 = mf->hash4_tab[hash4]; |
13188
|
|
|
|
|
|
|
|
13189
|
|
|
|
|
|
|
|
13190
|
7046
|
|
|
|
|
|
mf->hash3_tab[hash3] = cur_pos; |
13191
|
|
|
|
|
|
|
|
13192
|
|
|
|
|
|
|
|
13193
|
7046
|
|
|
|
|
|
mf->hash4_tab[hash4] = cur_pos; |
13194
|
7046
|
|
|
|
|
|
mf->next_tab[cur_pos] = cur_node4; |
13195
|
|
|
|
|
|
|
|
13196
|
|
|
|
|
|
|
|
13197
|
14092
|
|
|
|
|
|
next_hashseq = get_unaligned_le32(in_next + 1); |
13198
|
14092
|
|
|
|
|
|
next_hashes[0] = lz_hash(next_hashseq & 0xFFFFFF, HC_MATCHFINDER_HASH3_ORDER); |
13199
|
14092
|
|
|
|
|
|
next_hashes[1] = lz_hash(next_hashseq, HC_MATCHFINDER_HASH4_ORDER); |
13200
|
7046
|
|
|
|
|
|
prefetchw(&mf->hash3_tab[next_hashes[0]]); |
13201
|
7046
|
|
|
|
|
|
prefetchw(&mf->hash4_tab[next_hashes[1]]); |
13202
|
|
|
|
|
|
|
|
13203
|
7046
|
|
|
|
|
|
if (best_len < 4) { |
13204
|
|
|
|
|
|
|
|
13205
|
|
|
|
|
|
|
|
13206
|
|
|
|
|
|
|
|
13207
|
4747
|
0
|
|
|
|
|
if (cur_node3 <= cutoff) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13208
|
|
|
|
|
|
|
goto out; |
13209
|
|
|
|
|
|
|
|
13210
|
2859
|
|
|
|
|
|
seq4 = load_u32_unaligned(in_next); |
13211
|
|
|
|
|
|
|
|
13212
|
2859
|
0
|
|
|
|
|
if (best_len < 3) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13213
|
0
|
|
|
|
|
|
matchptr = &in_base[cur_node3]; |
13214
|
0
|
0
|
|
|
|
|
if (load_u24_unaligned(matchptr) == loaded_u32_to_u24(seq4)) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13215
|
0
|
|
|
|
|
|
best_len = 3; |
13216
|
0
|
|
|
|
|
|
best_matchptr = matchptr; |
13217
|
|
|
|
|
|
|
} |
13218
|
|
|
|
|
|
|
} |
13219
|
|
|
|
|
|
|
|
13220
|
|
|
|
|
|
|
|
13221
|
|
|
|
|
|
|
|
13222
|
2859
|
0
|
|
|
|
|
if (cur_node4 <= cutoff) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13223
|
|
|
|
|
|
|
goto out; |
13224
|
|
|
|
|
|
|
|
13225
|
|
|
|
|
|
|
for (;;) { |
13226
|
|
|
|
|
|
|
|
13227
|
2180
|
|
|
|
|
|
matchptr = &in_base[cur_node4]; |
13228
|
|
|
|
|
|
|
|
13229
|
2180
|
0
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq4) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13230
|
|
|
|
|
|
|
break; |
13231
|
|
|
|
|
|
|
|
13232
|
|
|
|
|
|
|
|
13233
|
216
|
|
|
|
|
|
cur_node4 = mf->next_tab[cur_node4 & (MATCHFINDER_WINDOW_SIZE - 1)]; |
13234
|
216
|
0
|
|
|
|
|
if (cur_node4 <= cutoff || !--depth_remaining) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13235
|
|
|
|
|
|
|
goto out; |
13236
|
|
|
|
|
|
|
} |
13237
|
|
|
|
|
|
|
|
13238
|
|
|
|
|
|
|
|
13239
|
1964
|
|
|
|
|
|
best_matchptr = matchptr; |
13240
|
1964
|
|
|
|
|
|
best_len = lz_extend(in_next, best_matchptr, 4, max_len); |
13241
|
1964
|
0
|
|
|
|
|
if (best_len >= nice_len) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13242
|
|
|
|
|
|
|
goto out; |
13243
|
1963
|
|
|
|
|
|
cur_node4 = mf->next_tab[cur_node4 & (MATCHFINDER_WINDOW_SIZE - 1)]; |
13244
|
1963
|
0
|
|
|
|
|
if (cur_node4 <= cutoff || !--depth_remaining) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13245
|
|
|
|
|
|
|
goto out; |
13246
|
|
|
|
|
|
|
} else { |
13247
|
2299
|
100
|
|
|
|
|
if (cur_node4 <= cutoff || best_len >= nice_len) |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13248
|
|
|
|
|
|
|
goto out; |
13249
|
|
|
|
|
|
|
} |
13250
|
|
|
|
|
|
|
|
13251
|
|
|
|
|
|
|
|
13252
|
|
|
|
|
|
|
|
13253
|
|
|
|
|
|
|
for (;;) { |
13254
|
|
|
|
|
|
|
for (;;) { |
13255
|
36147
|
|
|
|
|
|
matchptr = &in_base[cur_node4]; |
13256
|
|
|
|
|
|
|
|
13257
|
|
|
|
|
|
|
|
13258
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
13259
|
36147
|
50
|
|
|
|
|
if ((load_u32_unaligned(matchptr + best_len - 3) == |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13260
|
837
|
50
|
|
|
|
|
load_u32_unaligned(in_next + best_len - 3)) && |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13261
|
837
|
|
|
|
|
|
(load_u32_unaligned(matchptr) == |
13262
|
837
|
|
|
|
|
|
load_u32_unaligned(in_next))) |
13263
|
|
|
|
|
|
|
#else |
13264
|
|
|
|
|
|
|
if (matchptr[best_len] == in_next[best_len]) |
13265
|
|
|
|
|
|
|
#endif |
13266
|
|
|
|
|
|
|
break; |
13267
|
|
|
|
|
|
|
|
13268
|
|
|
|
|
|
|
|
13269
|
35310
|
|
|
|
|
|
cur_node4 = mf->next_tab[cur_node4 & (MATCHFINDER_WINDOW_SIZE - 1)]; |
13270
|
35310
|
0
|
|
|
|
|
if (cur_node4 <= cutoff || !--depth_remaining) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13271
|
|
|
|
|
|
|
goto out; |
13272
|
|
|
|
|
|
|
} |
13273
|
|
|
|
|
|
|
|
13274
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
13275
|
837
|
|
|
|
|
|
len = 4; |
13276
|
|
|
|
|
|
|
#else |
13277
|
|
|
|
|
|
|
len = 0; |
13278
|
|
|
|
|
|
|
#endif |
13279
|
837
|
|
|
|
|
|
len = lz_extend(in_next, matchptr, len, max_len); |
13280
|
837
|
50
|
|
|
|
|
if (len > best_len) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13281
|
|
|
|
|
|
|
|
13282
|
831
|
|
|
|
|
|
best_len = len; |
13283
|
831
|
|
|
|
|
|
best_matchptr = matchptr; |
13284
|
831
|
50
|
|
|
|
|
if (best_len >= nice_len) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13285
|
|
|
|
|
|
|
goto out; |
13286
|
|
|
|
|
|
|
} |
13287
|
|
|
|
|
|
|
|
13288
|
|
|
|
|
|
|
|
13289
|
669
|
|
|
|
|
|
cur_node4 = mf->next_tab[cur_node4 & (MATCHFINDER_WINDOW_SIZE - 1)]; |
13290
|
669
|
0
|
|
|
|
|
if (cur_node4 <= cutoff || !--depth_remaining) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
13291
|
|
|
|
|
|
|
goto out; |
13292
|
|
|
|
|
|
|
} |
13293
|
|
|
|
|
|
|
out: |
13294
|
7046
|
|
|
|
|
|
*offset_ret = in_next - best_matchptr; |
13295
|
7046
|
|
|
|
|
|
return best_len; |
13296
|
|
|
|
|
|
|
} |
13297
|
|
|
|
|
|
|
|
13298
|
|
|
|
|
|
|
|
13299
|
|
|
|
|
|
|
static forceinline void |
13300
|
|
|
|
|
|
|
hc_matchfinder_skip_bytes(struct hc_matchfinder * const mf, |
13301
|
|
|
|
|
|
|
const u8 ** const in_base_p, |
13302
|
|
|
|
|
|
|
const u8 *in_next, |
13303
|
|
|
|
|
|
|
const u8 * const in_end, |
13304
|
|
|
|
|
|
|
const u32 count, |
13305
|
|
|
|
|
|
|
u32 * const next_hashes) |
13306
|
|
|
|
|
|
|
{ |
13307
|
|
|
|
|
|
|
u32 cur_pos; |
13308
|
|
|
|
|
|
|
u32 hash3, hash4; |
13309
|
|
|
|
|
|
|
u32 next_hashseq; |
13310
|
2070
|
|
|
|
|
|
u32 remaining = count; |
13311
|
|
|
|
|
|
|
|
13312
|
2070
|
100
|
|
|
|
|
if (unlikely(count + 5 > in_end - in_next)) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
13313
|
|
|
|
|
|
|
return; |
13314
|
|
|
|
|
|
|
|
13315
|
2045
|
|
|
|
|
|
cur_pos = in_next - *in_base_p; |
13316
|
2045
|
|
|
|
|
|
hash3 = next_hashes[0]; |
13317
|
2045
|
|
|
|
|
|
hash4 = next_hashes[1]; |
13318
|
|
|
|
|
|
|
do { |
13319
|
59176
|
50
|
|
|
|
|
if (cur_pos == MATCHFINDER_WINDOW_SIZE) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
13320
|
|
|
|
|
|
|
hc_matchfinder_slide_window(mf); |
13321
|
0
|
|
|
|
|
|
*in_base_p += MATCHFINDER_WINDOW_SIZE; |
13322
|
0
|
|
|
|
|
|
cur_pos = 0; |
13323
|
|
|
|
|
|
|
} |
13324
|
59176
|
|
|
|
|
|
mf->hash3_tab[hash3] = cur_pos; |
13325
|
59176
|
|
|
|
|
|
mf->next_tab[cur_pos] = mf->hash4_tab[hash4]; |
13326
|
59176
|
|
|
|
|
|
mf->hash4_tab[hash4] = cur_pos; |
13327
|
|
|
|
|
|
|
|
13328
|
118352
|
|
|
|
|
|
next_hashseq = get_unaligned_le32(++in_next); |
13329
|
118352
|
|
|
|
|
|
hash3 = lz_hash(next_hashseq & 0xFFFFFF, HC_MATCHFINDER_HASH3_ORDER); |
13330
|
59176
|
|
|
|
|
|
hash4 = lz_hash(next_hashseq, HC_MATCHFINDER_HASH4_ORDER); |
13331
|
59176
|
|
|
|
|
|
cur_pos++; |
13332
|
59176
|
100
|
|
|
|
|
} while (--remaining); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
13333
|
|
|
|
|
|
|
|
13334
|
2045
|
|
|
|
|
|
prefetchw(&mf->hash3_tab[hash3]); |
13335
|
2045
|
|
|
|
|
|
prefetchw(&mf->hash4_tab[hash4]); |
13336
|
2045
|
|
|
|
|
|
next_hashes[0] = hash3; |
13337
|
2045
|
|
|
|
|
|
next_hashes[1] = hash4; |
13338
|
|
|
|
|
|
|
} |
13339
|
|
|
|
|
|
|
|
13340
|
|
|
|
|
|
|
#endif |
13341
|
|
|
|
|
|
|
|
13342
|
|
|
|
|
|
|
/* #include "ht_matchfinder.h" */ |
13343
|
|
|
|
|
|
|
|
13344
|
|
|
|
|
|
|
|
13345
|
|
|
|
|
|
|
#ifndef LIB_HT_MATCHFINDER_H |
13346
|
|
|
|
|
|
|
#define LIB_HT_MATCHFINDER_H |
13347
|
|
|
|
|
|
|
|
13348
|
|
|
|
|
|
|
/* #include "matchfinder_common.h" */ |
13349
|
|
|
|
|
|
|
|
13350
|
|
|
|
|
|
|
|
13351
|
|
|
|
|
|
|
#ifndef LIB_MATCHFINDER_COMMON_H |
13352
|
|
|
|
|
|
|
#define LIB_MATCHFINDER_COMMON_H |
13353
|
|
|
|
|
|
|
|
13354
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
13355
|
|
|
|
|
|
|
|
13356
|
|
|
|
|
|
|
|
13357
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
13358
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
13359
|
|
|
|
|
|
|
|
13360
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
13361
|
|
|
|
|
|
|
|
13362
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
13363
|
|
|
|
|
|
|
#endif |
13364
|
|
|
|
|
|
|
|
13365
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
13366
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
13367
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
13368
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
13369
|
|
|
|
|
|
|
#else |
13370
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
13371
|
|
|
|
|
|
|
#endif |
13372
|
|
|
|
|
|
|
|
13373
|
|
|
|
|
|
|
|
13374
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
13375
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
13376
|
|
|
|
|
|
|
#else |
13377
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
13378
|
|
|
|
|
|
|
#endif |
13379
|
|
|
|
|
|
|
|
13380
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
13381
|
|
|
|
|
|
|
|
13382
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
13383
|
|
|
|
|
|
|
|
13384
|
|
|
|
|
|
|
|
13385
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
13386
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
13387
|
|
|
|
|
|
|
|
13388
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
13389
|
|
|
|
|
|
|
|
13390
|
|
|
|
|
|
|
|
13391
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
13392
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
13393
|
|
|
|
|
|
|
|
13394
|
|
|
|
|
|
|
#include |
13395
|
|
|
|
|
|
|
#include |
13396
|
|
|
|
|
|
|
|
13397
|
|
|
|
|
|
|
#ifdef __cplusplus |
13398
|
|
|
|
|
|
|
extern "C" { |
13399
|
|
|
|
|
|
|
#endif |
13400
|
|
|
|
|
|
|
|
13401
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
13402
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
13403
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
13404
|
|
|
|
|
|
|
|
13405
|
|
|
|
|
|
|
|
13406
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
13407
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
13408
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
13409
|
|
|
|
|
|
|
# else |
13410
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
13411
|
|
|
|
|
|
|
# endif |
13412
|
|
|
|
|
|
|
#endif |
13413
|
|
|
|
|
|
|
|
13414
|
|
|
|
|
|
|
|
13415
|
|
|
|
|
|
|
|
13416
|
|
|
|
|
|
|
|
13417
|
|
|
|
|
|
|
|
13418
|
|
|
|
|
|
|
struct libdeflate_compressor; |
13419
|
|
|
|
|
|
|
|
13420
|
|
|
|
|
|
|
|
13421
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
13422
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
13423
|
|
|
|
|
|
|
|
13424
|
|
|
|
|
|
|
|
13425
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13426
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
13427
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13428
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
13429
|
|
|
|
|
|
|
|
13430
|
|
|
|
|
|
|
|
13431
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13432
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
13433
|
|
|
|
|
|
|
size_t in_nbytes); |
13434
|
|
|
|
|
|
|
|
13435
|
|
|
|
|
|
|
|
13436
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13437
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
13438
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13439
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
13440
|
|
|
|
|
|
|
|
13441
|
|
|
|
|
|
|
|
13442
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13443
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
13444
|
|
|
|
|
|
|
size_t in_nbytes); |
13445
|
|
|
|
|
|
|
|
13446
|
|
|
|
|
|
|
|
13447
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13448
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
13449
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13450
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
13451
|
|
|
|
|
|
|
|
13452
|
|
|
|
|
|
|
|
13453
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
13454
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
13455
|
|
|
|
|
|
|
size_t in_nbytes); |
13456
|
|
|
|
|
|
|
|
13457
|
|
|
|
|
|
|
|
13458
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
13459
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
13460
|
|
|
|
|
|
|
|
13461
|
|
|
|
|
|
|
|
13462
|
|
|
|
|
|
|
|
13463
|
|
|
|
|
|
|
|
13464
|
|
|
|
|
|
|
|
13465
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
13466
|
|
|
|
|
|
|
|
13467
|
|
|
|
|
|
|
|
13468
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
13469
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
13470
|
|
|
|
|
|
|
|
13471
|
|
|
|
|
|
|
|
13472
|
|
|
|
|
|
|
enum libdeflate_result { |
13473
|
|
|
|
|
|
|
|
13474
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
13475
|
|
|
|
|
|
|
|
13476
|
|
|
|
|
|
|
|
13477
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
13478
|
|
|
|
|
|
|
|
13479
|
|
|
|
|
|
|
|
13480
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
13481
|
|
|
|
|
|
|
|
13482
|
|
|
|
|
|
|
|
13483
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
13484
|
|
|
|
|
|
|
}; |
13485
|
|
|
|
|
|
|
|
13486
|
|
|
|
|
|
|
|
13487
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13488
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
13489
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13490
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13491
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13492
|
|
|
|
|
|
|
|
13493
|
|
|
|
|
|
|
|
13494
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13495
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
13496
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13497
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13498
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
13499
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13500
|
|
|
|
|
|
|
|
13501
|
|
|
|
|
|
|
|
13502
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13503
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
13504
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13505
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13506
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13507
|
|
|
|
|
|
|
|
13508
|
|
|
|
|
|
|
|
13509
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13510
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
13511
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13512
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13513
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
13514
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13515
|
|
|
|
|
|
|
|
13516
|
|
|
|
|
|
|
|
13517
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13518
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
13519
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13520
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13521
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13522
|
|
|
|
|
|
|
|
13523
|
|
|
|
|
|
|
|
13524
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
13525
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
13526
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
13527
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
13528
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
13529
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
13530
|
|
|
|
|
|
|
|
13531
|
|
|
|
|
|
|
|
13532
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
13533
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
13534
|
|
|
|
|
|
|
|
13535
|
|
|
|
|
|
|
|
13536
|
|
|
|
|
|
|
|
13537
|
|
|
|
|
|
|
|
13538
|
|
|
|
|
|
|
|
13539
|
|
|
|
|
|
|
|
13540
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
13541
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
13542
|
|
|
|
|
|
|
|
13543
|
|
|
|
|
|
|
|
13544
|
|
|
|
|
|
|
|
13545
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
13546
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
13547
|
|
|
|
|
|
|
|
13548
|
|
|
|
|
|
|
|
13549
|
|
|
|
|
|
|
|
13550
|
|
|
|
|
|
|
|
13551
|
|
|
|
|
|
|
|
13552
|
|
|
|
|
|
|
|
13553
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
13554
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
13555
|
|
|
|
|
|
|
void (*free_func)(void *)); |
13556
|
|
|
|
|
|
|
|
13557
|
|
|
|
|
|
|
#ifdef __cplusplus |
13558
|
|
|
|
|
|
|
} |
13559
|
|
|
|
|
|
|
#endif |
13560
|
|
|
|
|
|
|
|
13561
|
|
|
|
|
|
|
#endif |
13562
|
|
|
|
|
|
|
|
13563
|
|
|
|
|
|
|
|
13564
|
|
|
|
|
|
|
#include |
13565
|
|
|
|
|
|
|
#include |
13566
|
|
|
|
|
|
|
#include |
13567
|
|
|
|
|
|
|
#ifdef _MSC_VER |
13568
|
|
|
|
|
|
|
# include |
13569
|
|
|
|
|
|
|
# include |
13570
|
|
|
|
|
|
|
|
13571
|
|
|
|
|
|
|
|
13572
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
13573
|
|
|
|
|
|
|
|
13574
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
13575
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
13576
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
13577
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
13578
|
|
|
|
|
|
|
|
13579
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
13580
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
13581
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
13582
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
13583
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
13584
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
13585
|
|
|
|
|
|
|
#endif |
13586
|
|
|
|
|
|
|
#ifndef FREESTANDING |
13587
|
|
|
|
|
|
|
# include |
13588
|
|
|
|
|
|
|
#endif |
13589
|
|
|
|
|
|
|
|
13590
|
|
|
|
|
|
|
|
13591
|
|
|
|
|
|
|
|
13592
|
|
|
|
|
|
|
|
13593
|
|
|
|
|
|
|
|
13594
|
|
|
|
|
|
|
|
13595
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
13596
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
13597
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
13598
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
13599
|
|
|
|
|
|
|
#ifdef _MSC_VER |
13600
|
|
|
|
|
|
|
# if defined(_M_X64) |
13601
|
|
|
|
|
|
|
# define ARCH_X86_64 |
13602
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
13603
|
|
|
|
|
|
|
# define ARCH_X86_32 |
13604
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
13605
|
|
|
|
|
|
|
# define ARCH_ARM64 |
13606
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
13607
|
|
|
|
|
|
|
# define ARCH_ARM32 |
13608
|
|
|
|
|
|
|
# endif |
13609
|
|
|
|
|
|
|
#else |
13610
|
|
|
|
|
|
|
# if defined(__x86_64__) |
13611
|
|
|
|
|
|
|
# define ARCH_X86_64 |
13612
|
|
|
|
|
|
|
# elif defined(__i386__) |
13613
|
|
|
|
|
|
|
# define ARCH_X86_32 |
13614
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
13615
|
|
|
|
|
|
|
# define ARCH_ARM64 |
13616
|
|
|
|
|
|
|
# elif defined(__arm__) |
13617
|
|
|
|
|
|
|
# define ARCH_ARM32 |
13618
|
|
|
|
|
|
|
# endif |
13619
|
|
|
|
|
|
|
#endif |
13620
|
|
|
|
|
|
|
|
13621
|
|
|
|
|
|
|
|
13622
|
|
|
|
|
|
|
|
13623
|
|
|
|
|
|
|
|
13624
|
|
|
|
|
|
|
|
13625
|
|
|
|
|
|
|
|
13626
|
|
|
|
|
|
|
typedef uint8_t u8; |
13627
|
|
|
|
|
|
|
typedef uint16_t u16; |
13628
|
|
|
|
|
|
|
typedef uint32_t u32; |
13629
|
|
|
|
|
|
|
typedef uint64_t u64; |
13630
|
|
|
|
|
|
|
typedef int8_t s8; |
13631
|
|
|
|
|
|
|
typedef int16_t s16; |
13632
|
|
|
|
|
|
|
typedef int32_t s32; |
13633
|
|
|
|
|
|
|
typedef int64_t s64; |
13634
|
|
|
|
|
|
|
|
13635
|
|
|
|
|
|
|
|
13636
|
|
|
|
|
|
|
#ifdef _MSC_VER |
13637
|
|
|
|
|
|
|
# ifdef _WIN64 |
13638
|
|
|
|
|
|
|
typedef long long ssize_t; |
13639
|
|
|
|
|
|
|
# else |
13640
|
|
|
|
|
|
|
typedef long ssize_t; |
13641
|
|
|
|
|
|
|
# endif |
13642
|
|
|
|
|
|
|
#endif |
13643
|
|
|
|
|
|
|
|
13644
|
|
|
|
|
|
|
|
13645
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
13646
|
|
|
|
|
|
|
|
13647
|
|
|
|
|
|
|
|
13648
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
13649
|
|
|
|
|
|
|
|
13650
|
|
|
|
|
|
|
|
13651
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
13652
|
|
|
|
|
|
|
|
13653
|
|
|
|
|
|
|
|
13654
|
|
|
|
|
|
|
|
13655
|
|
|
|
|
|
|
|
13656
|
|
|
|
|
|
|
|
13657
|
|
|
|
|
|
|
|
13658
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
13659
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
13660
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
13661
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
13662
|
|
|
|
|
|
|
#else |
13663
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
13664
|
|
|
|
|
|
|
#endif |
13665
|
|
|
|
|
|
|
#ifdef __clang__ |
13666
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
13667
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
13668
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
13669
|
|
|
|
|
|
|
# else |
13670
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
13671
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
13672
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
13673
|
|
|
|
|
|
|
# endif |
13674
|
|
|
|
|
|
|
#else |
13675
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
13676
|
|
|
|
|
|
|
#endif |
13677
|
|
|
|
|
|
|
|
13678
|
|
|
|
|
|
|
|
13679
|
|
|
|
|
|
|
#ifndef __has_attribute |
13680
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
13681
|
|
|
|
|
|
|
#endif |
13682
|
|
|
|
|
|
|
#ifndef __has_builtin |
13683
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
13684
|
|
|
|
|
|
|
#endif |
13685
|
|
|
|
|
|
|
|
13686
|
|
|
|
|
|
|
|
13687
|
|
|
|
|
|
|
#ifdef _MSC_VER |
13688
|
|
|
|
|
|
|
# define inline __inline |
13689
|
|
|
|
|
|
|
#endif |
13690
|
|
|
|
|
|
|
|
13691
|
|
|
|
|
|
|
|
13692
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
13693
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
13694
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13695
|
|
|
|
|
|
|
# define forceinline __forceinline |
13696
|
|
|
|
|
|
|
#else |
13697
|
|
|
|
|
|
|
# define forceinline inline |
13698
|
|
|
|
|
|
|
#endif |
13699
|
|
|
|
|
|
|
|
13700
|
|
|
|
|
|
|
|
13701
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
13702
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
13703
|
|
|
|
|
|
|
#else |
13704
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
13705
|
|
|
|
|
|
|
#endif |
13706
|
|
|
|
|
|
|
|
13707
|
|
|
|
|
|
|
|
13708
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
13709
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
13710
|
|
|
|
|
|
|
# define restrict __restrict__ |
13711
|
|
|
|
|
|
|
# else |
13712
|
|
|
|
|
|
|
# define restrict |
13713
|
|
|
|
|
|
|
# endif |
13714
|
|
|
|
|
|
|
#endif |
13715
|
|
|
|
|
|
|
|
13716
|
|
|
|
|
|
|
|
13717
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
13718
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
13719
|
|
|
|
|
|
|
#else |
13720
|
|
|
|
|
|
|
# define likely(expr) (expr) |
13721
|
|
|
|
|
|
|
#endif |
13722
|
|
|
|
|
|
|
|
13723
|
|
|
|
|
|
|
|
13724
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
13725
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
13726
|
|
|
|
|
|
|
#else |
13727
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
13728
|
|
|
|
|
|
|
#endif |
13729
|
|
|
|
|
|
|
|
13730
|
|
|
|
|
|
|
|
13731
|
|
|
|
|
|
|
#undef prefetchr |
13732
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
13733
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
13734
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13735
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
13736
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
13737
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
13738
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
13739
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
13740
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
13741
|
|
|
|
|
|
|
# endif |
13742
|
|
|
|
|
|
|
#endif |
13743
|
|
|
|
|
|
|
#ifndef prefetchr |
13744
|
|
|
|
|
|
|
# define prefetchr(addr) |
13745
|
|
|
|
|
|
|
#endif |
13746
|
|
|
|
|
|
|
|
13747
|
|
|
|
|
|
|
|
13748
|
|
|
|
|
|
|
#undef prefetchw |
13749
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
13750
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
13751
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13752
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
13753
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
13754
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
13755
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
13756
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
13757
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
13758
|
|
|
|
|
|
|
# endif |
13759
|
|
|
|
|
|
|
#endif |
13760
|
|
|
|
|
|
|
#ifndef prefetchw |
13761
|
|
|
|
|
|
|
# define prefetchw(addr) |
13762
|
|
|
|
|
|
|
#endif |
13763
|
|
|
|
|
|
|
|
13764
|
|
|
|
|
|
|
|
13765
|
|
|
|
|
|
|
#undef _aligned_attribute |
13766
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
13767
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
13768
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13769
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
13770
|
|
|
|
|
|
|
#endif |
13771
|
|
|
|
|
|
|
|
13772
|
|
|
|
|
|
|
|
13773
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
13774
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
13775
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
13776
|
|
|
|
|
|
|
#else |
13777
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
13778
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
13779
|
|
|
|
|
|
|
#endif |
13780
|
|
|
|
|
|
|
|
13781
|
|
|
|
|
|
|
|
13782
|
|
|
|
|
|
|
|
13783
|
|
|
|
|
|
|
|
13784
|
|
|
|
|
|
|
|
13785
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
13786
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
13787
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
13788
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
13789
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
13790
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
13791
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
13792
|
|
|
|
|
|
|
|
13793
|
|
|
|
|
|
|
|
13794
|
|
|
|
|
|
|
|
13795
|
|
|
|
|
|
|
|
13796
|
|
|
|
|
|
|
|
13797
|
|
|
|
|
|
|
|
13798
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
13799
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
13800
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13801
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
13802
|
|
|
|
|
|
|
#else |
13803
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
13804
|
|
|
|
|
|
|
{ |
13805
|
|
|
|
|
|
|
union { |
13806
|
|
|
|
|
|
|
u32 w; |
13807
|
|
|
|
|
|
|
u8 b; |
13808
|
|
|
|
|
|
|
} u; |
13809
|
|
|
|
|
|
|
|
13810
|
|
|
|
|
|
|
u.w = 1; |
13811
|
|
|
|
|
|
|
return u.b; |
13812
|
|
|
|
|
|
|
} |
13813
|
|
|
|
|
|
|
#endif |
13814
|
|
|
|
|
|
|
|
13815
|
|
|
|
|
|
|
|
13816
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
13817
|
|
|
|
|
|
|
{ |
13818
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
13819
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
13820
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13821
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
13822
|
|
|
|
|
|
|
#else |
13823
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
13824
|
|
|
|
|
|
|
#endif |
13825
|
|
|
|
|
|
|
} |
13826
|
|
|
|
|
|
|
|
13827
|
|
|
|
|
|
|
|
13828
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
13829
|
|
|
|
|
|
|
{ |
13830
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
13831
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
13832
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13833
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
13834
|
|
|
|
|
|
|
#else |
13835
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
13836
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
13837
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
13838
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
13839
|
|
|
|
|
|
|
#endif |
13840
|
|
|
|
|
|
|
} |
13841
|
|
|
|
|
|
|
|
13842
|
|
|
|
|
|
|
|
13843
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
13844
|
|
|
|
|
|
|
{ |
13845
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
13846
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
13847
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13848
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
13849
|
|
|
|
|
|
|
#else |
13850
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
13851
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
13852
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
13853
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
13854
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
13855
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
13856
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
13857
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
13858
|
|
|
|
|
|
|
#endif |
13859
|
|
|
|
|
|
|
} |
13860
|
|
|
|
|
|
|
|
13861
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
13862
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
13863
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
13864
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
13865
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
13866
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
13867
|
|
|
|
|
|
|
|
13868
|
|
|
|
|
|
|
|
13869
|
|
|
|
|
|
|
|
13870
|
|
|
|
|
|
|
|
13871
|
|
|
|
|
|
|
|
13872
|
|
|
|
|
|
|
|
13873
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
13874
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
13875
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
13876
|
|
|
|
|
|
|
defined(__wasm__)) |
13877
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
13878
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
13879
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
13880
|
|
|
|
|
|
|
#else |
13881
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
13882
|
|
|
|
|
|
|
#endif |
13883
|
|
|
|
|
|
|
|
13884
|
|
|
|
|
|
|
|
13885
|
|
|
|
|
|
|
|
13886
|
|
|
|
|
|
|
#ifdef FREESTANDING |
13887
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
13888
|
|
|
|
|
|
|
#else |
13889
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
13890
|
|
|
|
|
|
|
#endif |
13891
|
|
|
|
|
|
|
|
13892
|
|
|
|
|
|
|
|
13893
|
|
|
|
|
|
|
|
13894
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
13895
|
|
|
|
|
|
|
static forceinline type \ |
13896
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
13897
|
|
|
|
|
|
|
{ \ |
13898
|
|
|
|
|
|
|
type v; \ |
13899
|
|
|
|
|
|
|
\ |
13900
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
13901
|
|
|
|
|
|
|
return v; \ |
13902
|
|
|
|
|
|
|
} \ |
13903
|
|
|
|
|
|
|
\ |
13904
|
|
|
|
|
|
|
static forceinline void \ |
13905
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
13906
|
|
|
|
|
|
|
{ \ |
13907
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
13908
|
|
|
|
|
|
|
} |
13909
|
|
|
|
|
|
|
|
13910
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
13911
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
13912
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
13913
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
13914
|
|
|
|
|
|
|
|
13915
|
|
|
|
|
|
|
#undef MEMCOPY |
13916
|
|
|
|
|
|
|
|
13917
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
13918
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
13919
|
|
|
|
|
|
|
|
13920
|
|
|
|
|
|
|
|
13921
|
|
|
|
|
|
|
|
13922
|
|
|
|
|
|
|
static forceinline u16 |
13923
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
13924
|
|
|
|
|
|
|
{ |
13925
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
13926
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
13927
|
|
|
|
|
|
|
else |
13928
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
13929
|
|
|
|
|
|
|
} |
13930
|
|
|
|
|
|
|
|
13931
|
|
|
|
|
|
|
static forceinline u16 |
13932
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
13933
|
|
|
|
|
|
|
{ |
13934
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
13935
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
13936
|
|
|
|
|
|
|
else |
13937
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
13938
|
|
|
|
|
|
|
} |
13939
|
|
|
|
|
|
|
|
13940
|
|
|
|
|
|
|
static forceinline u32 |
13941
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
13942
|
|
|
|
|
|
|
{ |
13943
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
13944
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
13945
|
|
|
|
|
|
|
else |
13946
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
13947
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
13948
|
|
|
|
|
|
|
} |
13949
|
|
|
|
|
|
|
|
13950
|
|
|
|
|
|
|
static forceinline u32 |
13951
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
13952
|
|
|
|
|
|
|
{ |
13953
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
13954
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
13955
|
|
|
|
|
|
|
else |
13956
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
13957
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
13958
|
|
|
|
|
|
|
} |
13959
|
|
|
|
|
|
|
|
13960
|
|
|
|
|
|
|
static forceinline u64 |
13961
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
13962
|
|
|
|
|
|
|
{ |
13963
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
13964
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
13965
|
|
|
|
|
|
|
else |
13966
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
13967
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
13968
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
13969
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
13970
|
|
|
|
|
|
|
} |
13971
|
|
|
|
|
|
|
|
13972
|
|
|
|
|
|
|
static forceinline machine_word_t |
13973
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
13974
|
|
|
|
|
|
|
{ |
13975
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
13976
|
|
|
|
|
|
|
if (WORDBITS == 32) |
13977
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
13978
|
|
|
|
|
|
|
else |
13979
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
13980
|
|
|
|
|
|
|
} |
13981
|
|
|
|
|
|
|
|
13982
|
|
|
|
|
|
|
|
13983
|
|
|
|
|
|
|
|
13984
|
|
|
|
|
|
|
static forceinline void |
13985
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
13986
|
|
|
|
|
|
|
{ |
13987
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
13988
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
13989
|
|
|
|
|
|
|
} else { |
13990
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
13991
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
13992
|
|
|
|
|
|
|
} |
13993
|
|
|
|
|
|
|
} |
13994
|
|
|
|
|
|
|
|
13995
|
|
|
|
|
|
|
static forceinline void |
13996
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
13997
|
|
|
|
|
|
|
{ |
13998
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
13999
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
14000
|
|
|
|
|
|
|
} else { |
14001
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
14002
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
14003
|
|
|
|
|
|
|
} |
14004
|
|
|
|
|
|
|
} |
14005
|
|
|
|
|
|
|
|
14006
|
|
|
|
|
|
|
static forceinline void |
14007
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
14008
|
|
|
|
|
|
|
{ |
14009
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14010
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
14011
|
|
|
|
|
|
|
} else { |
14012
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
14013
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
14014
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
14015
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
14016
|
|
|
|
|
|
|
} |
14017
|
|
|
|
|
|
|
} |
14018
|
|
|
|
|
|
|
|
14019
|
|
|
|
|
|
|
static forceinline void |
14020
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
14021
|
|
|
|
|
|
|
{ |
14022
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14023
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
14024
|
|
|
|
|
|
|
} else { |
14025
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
14026
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
14027
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
14028
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
14029
|
|
|
|
|
|
|
} |
14030
|
|
|
|
|
|
|
} |
14031
|
|
|
|
|
|
|
|
14032
|
|
|
|
|
|
|
static forceinline void |
14033
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
14034
|
|
|
|
|
|
|
{ |
14035
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14036
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
14037
|
|
|
|
|
|
|
} else { |
14038
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
14039
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
14040
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
14041
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
14042
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
14043
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
14044
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
14045
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
14046
|
|
|
|
|
|
|
} |
14047
|
|
|
|
|
|
|
} |
14048
|
|
|
|
|
|
|
|
14049
|
|
|
|
|
|
|
static forceinline void |
14050
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
14051
|
|
|
|
|
|
|
{ |
14052
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14053
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14054
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
14055
|
|
|
|
|
|
|
else |
14056
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
14057
|
|
|
|
|
|
|
} |
14058
|
|
|
|
|
|
|
|
14059
|
|
|
|
|
|
|
|
14060
|
|
|
|
|
|
|
|
14061
|
|
|
|
|
|
|
|
14062
|
|
|
|
|
|
|
|
14063
|
|
|
|
|
|
|
|
14064
|
|
|
|
|
|
|
|
14065
|
|
|
|
|
|
|
static forceinline unsigned |
14066
|
|
|
|
|
|
|
bsr32(u32 v) |
14067
|
|
|
|
|
|
|
{ |
14068
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
14069
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
14070
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14071
|
|
|
|
|
|
|
unsigned long i; |
14072
|
|
|
|
|
|
|
|
14073
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
14074
|
|
|
|
|
|
|
return i; |
14075
|
|
|
|
|
|
|
#else |
14076
|
|
|
|
|
|
|
unsigned i = 0; |
14077
|
|
|
|
|
|
|
|
14078
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
14079
|
|
|
|
|
|
|
i++; |
14080
|
|
|
|
|
|
|
return i; |
14081
|
|
|
|
|
|
|
#endif |
14082
|
|
|
|
|
|
|
} |
14083
|
|
|
|
|
|
|
|
14084
|
|
|
|
|
|
|
static forceinline unsigned |
14085
|
|
|
|
|
|
|
bsr64(u64 v) |
14086
|
|
|
|
|
|
|
{ |
14087
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
14088
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
14089
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
14090
|
|
|
|
|
|
|
unsigned long i; |
14091
|
|
|
|
|
|
|
|
14092
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
14093
|
|
|
|
|
|
|
return i; |
14094
|
|
|
|
|
|
|
#else |
14095
|
|
|
|
|
|
|
unsigned i = 0; |
14096
|
|
|
|
|
|
|
|
14097
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
14098
|
|
|
|
|
|
|
i++; |
14099
|
|
|
|
|
|
|
return i; |
14100
|
|
|
|
|
|
|
#endif |
14101
|
|
|
|
|
|
|
} |
14102
|
|
|
|
|
|
|
|
14103
|
|
|
|
|
|
|
static forceinline unsigned |
14104
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
14105
|
|
|
|
|
|
|
{ |
14106
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14107
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14108
|
|
|
|
|
|
|
return bsr32(v); |
14109
|
|
|
|
|
|
|
else |
14110
|
|
|
|
|
|
|
return bsr64(v); |
14111
|
|
|
|
|
|
|
} |
14112
|
|
|
|
|
|
|
|
14113
|
|
|
|
|
|
|
|
14114
|
|
|
|
|
|
|
|
14115
|
|
|
|
|
|
|
static forceinline unsigned |
14116
|
|
|
|
|
|
|
bsf32(u32 v) |
14117
|
|
|
|
|
|
|
{ |
14118
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
14119
|
|
|
|
|
|
|
return __builtin_ctz(v); |
14120
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14121
|
|
|
|
|
|
|
unsigned long i; |
14122
|
|
|
|
|
|
|
|
14123
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
14124
|
|
|
|
|
|
|
return i; |
14125
|
|
|
|
|
|
|
#else |
14126
|
|
|
|
|
|
|
unsigned i = 0; |
14127
|
|
|
|
|
|
|
|
14128
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
14129
|
|
|
|
|
|
|
i++; |
14130
|
|
|
|
|
|
|
return i; |
14131
|
|
|
|
|
|
|
#endif |
14132
|
|
|
|
|
|
|
} |
14133
|
|
|
|
|
|
|
|
14134
|
|
|
|
|
|
|
static forceinline unsigned |
14135
|
|
|
|
|
|
|
bsf64(u64 v) |
14136
|
|
|
|
|
|
|
{ |
14137
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
14138
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
14139
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
14140
|
|
|
|
|
|
|
unsigned long i; |
14141
|
|
|
|
|
|
|
|
14142
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
14143
|
|
|
|
|
|
|
return i; |
14144
|
|
|
|
|
|
|
#else |
14145
|
|
|
|
|
|
|
unsigned i = 0; |
14146
|
|
|
|
|
|
|
|
14147
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
14148
|
|
|
|
|
|
|
i++; |
14149
|
|
|
|
|
|
|
return i; |
14150
|
|
|
|
|
|
|
#endif |
14151
|
|
|
|
|
|
|
} |
14152
|
|
|
|
|
|
|
|
14153
|
|
|
|
|
|
|
static forceinline unsigned |
14154
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
14155
|
|
|
|
|
|
|
{ |
14156
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14157
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14158
|
|
|
|
|
|
|
return bsf32(v); |
14159
|
|
|
|
|
|
|
else |
14160
|
|
|
|
|
|
|
return bsf64(v); |
14161
|
|
|
|
|
|
|
} |
14162
|
|
|
|
|
|
|
|
14163
|
|
|
|
|
|
|
|
14164
|
|
|
|
|
|
|
#undef rbit32 |
14165
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
14166
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
14167
|
|
|
|
|
|
|
static forceinline u32 |
14168
|
|
|
|
|
|
|
rbit32(u32 v) |
14169
|
|
|
|
|
|
|
{ |
14170
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
14171
|
|
|
|
|
|
|
return v; |
14172
|
|
|
|
|
|
|
} |
14173
|
|
|
|
|
|
|
#define rbit32 rbit32 |
14174
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
14175
|
|
|
|
|
|
|
static forceinline u32 |
14176
|
|
|
|
|
|
|
rbit32(u32 v) |
14177
|
|
|
|
|
|
|
{ |
14178
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
14179
|
|
|
|
|
|
|
return v; |
14180
|
|
|
|
|
|
|
} |
14181
|
|
|
|
|
|
|
#define rbit32 rbit32 |
14182
|
|
|
|
|
|
|
#endif |
14183
|
|
|
|
|
|
|
|
14184
|
|
|
|
|
|
|
#endif |
14185
|
|
|
|
|
|
|
|
14186
|
|
|
|
|
|
|
|
14187
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
14188
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
14189
|
|
|
|
|
|
|
|
14190
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
14191
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
14192
|
|
|
|
|
|
|
|
14193
|
|
|
|
|
|
|
#ifdef FREESTANDING |
14194
|
|
|
|
|
|
|
|
14195
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
14196
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
14197
|
|
|
|
|
|
|
|
14198
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
14199
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
14200
|
|
|
|
|
|
|
|
14201
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
14202
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
14203
|
|
|
|
|
|
|
|
14204
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
14205
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
14206
|
|
|
|
|
|
|
|
14207
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
14208
|
|
|
|
|
|
|
#else |
14209
|
|
|
|
|
|
|
#include |
14210
|
|
|
|
|
|
|
#endif |
14211
|
|
|
|
|
|
|
|
14212
|
|
|
|
|
|
|
|
14213
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
14214
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
14215
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
14216
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
14217
|
|
|
|
|
|
|
#else |
14218
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
14219
|
|
|
|
|
|
|
#endif |
14220
|
|
|
|
|
|
|
|
14221
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
14222
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
14223
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
14224
|
|
|
|
|
|
|
|
14225
|
|
|
|
|
|
|
#endif |
14226
|
|
|
|
|
|
|
|
14227
|
|
|
|
|
|
|
|
14228
|
|
|
|
|
|
|
#ifndef MATCHFINDER_WINDOW_ORDER |
14229
|
|
|
|
|
|
|
# error "MATCHFINDER_WINDOW_ORDER must be defined!" |
14230
|
|
|
|
|
|
|
#endif |
14231
|
|
|
|
|
|
|
|
14232
|
|
|
|
|
|
|
|
14233
|
|
|
|
|
|
|
static forceinline u32 |
14234
|
|
|
|
|
|
|
loaded_u32_to_u24(u32 v) |
14235
|
|
|
|
|
|
|
{ |
14236
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
14237
|
|
|
|
|
|
|
return v & 0xFFFFFF; |
14238
|
|
|
|
|
|
|
else |
14239
|
|
|
|
|
|
|
return v >> 8; |
14240
|
|
|
|
|
|
|
} |
14241
|
|
|
|
|
|
|
|
14242
|
|
|
|
|
|
|
|
14243
|
|
|
|
|
|
|
static forceinline u32 |
14244
|
|
|
|
|
|
|
load_u24_unaligned(const u8 *p) |
14245
|
|
|
|
|
|
|
{ |
14246
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
14247
|
|
|
|
|
|
|
return loaded_u32_to_u24(load_u32_unaligned(p)); |
14248
|
|
|
|
|
|
|
#else |
14249
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
14250
|
|
|
|
|
|
|
return ((u32)p[0] << 0) | ((u32)p[1] << 8) | ((u32)p[2] << 16); |
14251
|
|
|
|
|
|
|
else |
14252
|
|
|
|
|
|
|
return ((u32)p[2] << 0) | ((u32)p[1] << 8) | ((u32)p[0] << 16); |
14253
|
|
|
|
|
|
|
#endif |
14254
|
|
|
|
|
|
|
} |
14255
|
|
|
|
|
|
|
|
14256
|
|
|
|
|
|
|
#define MATCHFINDER_WINDOW_SIZE (1UL << MATCHFINDER_WINDOW_ORDER) |
14257
|
|
|
|
|
|
|
|
14258
|
|
|
|
|
|
|
typedef s16 mf_pos_t; |
14259
|
|
|
|
|
|
|
|
14260
|
|
|
|
|
|
|
#define MATCHFINDER_INITVAL ((mf_pos_t)-MATCHFINDER_WINDOW_SIZE) |
14261
|
|
|
|
|
|
|
|
14262
|
|
|
|
|
|
|
|
14263
|
|
|
|
|
|
|
#define MATCHFINDER_MEM_ALIGNMENT 32 |
14264
|
|
|
|
|
|
|
#define MATCHFINDER_SIZE_ALIGNMENT 128 |
14265
|
|
|
|
|
|
|
|
14266
|
|
|
|
|
|
|
#undef matchfinder_init |
14267
|
|
|
|
|
|
|
#undef matchfinder_rebase |
14268
|
|
|
|
|
|
|
#ifdef _aligned_attribute |
14269
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED _aligned_attribute(MATCHFINDER_MEM_ALIGNMENT) |
14270
|
|
|
|
|
|
|
# if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
14271
|
|
|
|
|
|
|
/* # include "arm/matchfinder_impl.h" */ |
14272
|
|
|
|
|
|
|
|
14273
|
|
|
|
|
|
|
|
14274
|
|
|
|
|
|
|
#ifndef LIB_ARM_MATCHFINDER_IMPL_H |
14275
|
|
|
|
|
|
|
#define LIB_ARM_MATCHFINDER_IMPL_H |
14276
|
|
|
|
|
|
|
|
14277
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
14278
|
|
|
|
|
|
|
|
14279
|
|
|
|
|
|
|
|
14280
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
14281
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
14282
|
|
|
|
|
|
|
|
14283
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
14284
|
|
|
|
|
|
|
|
14285
|
|
|
|
|
|
|
|
14286
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
14287
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
14288
|
|
|
|
|
|
|
|
14289
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
14290
|
|
|
|
|
|
|
|
14291
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
14292
|
|
|
|
|
|
|
#endif |
14293
|
|
|
|
|
|
|
|
14294
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
14295
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
14296
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
14297
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
14298
|
|
|
|
|
|
|
#else |
14299
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
14300
|
|
|
|
|
|
|
#endif |
14301
|
|
|
|
|
|
|
|
14302
|
|
|
|
|
|
|
|
14303
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
14304
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
14305
|
|
|
|
|
|
|
#else |
14306
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
14307
|
|
|
|
|
|
|
#endif |
14308
|
|
|
|
|
|
|
|
14309
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
14310
|
|
|
|
|
|
|
|
14311
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
14312
|
|
|
|
|
|
|
|
14313
|
|
|
|
|
|
|
|
14314
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
14315
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
14316
|
|
|
|
|
|
|
|
14317
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
14318
|
|
|
|
|
|
|
|
14319
|
|
|
|
|
|
|
|
14320
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
14321
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
14322
|
|
|
|
|
|
|
|
14323
|
|
|
|
|
|
|
#include |
14324
|
|
|
|
|
|
|
#include |
14325
|
|
|
|
|
|
|
|
14326
|
|
|
|
|
|
|
#ifdef __cplusplus |
14327
|
|
|
|
|
|
|
extern "C" { |
14328
|
|
|
|
|
|
|
#endif |
14329
|
|
|
|
|
|
|
|
14330
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
14331
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
14332
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
14333
|
|
|
|
|
|
|
|
14334
|
|
|
|
|
|
|
|
14335
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
14336
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
14337
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
14338
|
|
|
|
|
|
|
# else |
14339
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
14340
|
|
|
|
|
|
|
# endif |
14341
|
|
|
|
|
|
|
#endif |
14342
|
|
|
|
|
|
|
|
14343
|
|
|
|
|
|
|
|
14344
|
|
|
|
|
|
|
|
14345
|
|
|
|
|
|
|
|
14346
|
|
|
|
|
|
|
|
14347
|
|
|
|
|
|
|
struct libdeflate_compressor; |
14348
|
|
|
|
|
|
|
|
14349
|
|
|
|
|
|
|
|
14350
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
14351
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
14352
|
|
|
|
|
|
|
|
14353
|
|
|
|
|
|
|
|
14354
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14355
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
14356
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14357
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
14358
|
|
|
|
|
|
|
|
14359
|
|
|
|
|
|
|
|
14360
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14361
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
14362
|
|
|
|
|
|
|
size_t in_nbytes); |
14363
|
|
|
|
|
|
|
|
14364
|
|
|
|
|
|
|
|
14365
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14366
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
14367
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14368
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
14369
|
|
|
|
|
|
|
|
14370
|
|
|
|
|
|
|
|
14371
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14372
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
14373
|
|
|
|
|
|
|
size_t in_nbytes); |
14374
|
|
|
|
|
|
|
|
14375
|
|
|
|
|
|
|
|
14376
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14377
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
14378
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14379
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
14380
|
|
|
|
|
|
|
|
14381
|
|
|
|
|
|
|
|
14382
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
14383
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
14384
|
|
|
|
|
|
|
size_t in_nbytes); |
14385
|
|
|
|
|
|
|
|
14386
|
|
|
|
|
|
|
|
14387
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
14388
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
14389
|
|
|
|
|
|
|
|
14390
|
|
|
|
|
|
|
|
14391
|
|
|
|
|
|
|
|
14392
|
|
|
|
|
|
|
|
14393
|
|
|
|
|
|
|
|
14394
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
14395
|
|
|
|
|
|
|
|
14396
|
|
|
|
|
|
|
|
14397
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
14398
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
14399
|
|
|
|
|
|
|
|
14400
|
|
|
|
|
|
|
|
14401
|
|
|
|
|
|
|
enum libdeflate_result { |
14402
|
|
|
|
|
|
|
|
14403
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
14404
|
|
|
|
|
|
|
|
14405
|
|
|
|
|
|
|
|
14406
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
14407
|
|
|
|
|
|
|
|
14408
|
|
|
|
|
|
|
|
14409
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
14410
|
|
|
|
|
|
|
|
14411
|
|
|
|
|
|
|
|
14412
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
14413
|
|
|
|
|
|
|
}; |
14414
|
|
|
|
|
|
|
|
14415
|
|
|
|
|
|
|
|
14416
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14417
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
14418
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14419
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14420
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14421
|
|
|
|
|
|
|
|
14422
|
|
|
|
|
|
|
|
14423
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14424
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
14425
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14426
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14427
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
14428
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14429
|
|
|
|
|
|
|
|
14430
|
|
|
|
|
|
|
|
14431
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14432
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
14433
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14434
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14435
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14436
|
|
|
|
|
|
|
|
14437
|
|
|
|
|
|
|
|
14438
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14439
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
14440
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14441
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14442
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
14443
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14444
|
|
|
|
|
|
|
|
14445
|
|
|
|
|
|
|
|
14446
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14447
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
14448
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14449
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14450
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14451
|
|
|
|
|
|
|
|
14452
|
|
|
|
|
|
|
|
14453
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
14454
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
14455
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
14456
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
14457
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
14458
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
14459
|
|
|
|
|
|
|
|
14460
|
|
|
|
|
|
|
|
14461
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
14462
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
14463
|
|
|
|
|
|
|
|
14464
|
|
|
|
|
|
|
|
14465
|
|
|
|
|
|
|
|
14466
|
|
|
|
|
|
|
|
14467
|
|
|
|
|
|
|
|
14468
|
|
|
|
|
|
|
|
14469
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
14470
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
14471
|
|
|
|
|
|
|
|
14472
|
|
|
|
|
|
|
|
14473
|
|
|
|
|
|
|
|
14474
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
14475
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
14476
|
|
|
|
|
|
|
|
14477
|
|
|
|
|
|
|
|
14478
|
|
|
|
|
|
|
|
14479
|
|
|
|
|
|
|
|
14480
|
|
|
|
|
|
|
|
14481
|
|
|
|
|
|
|
|
14482
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
14483
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
14484
|
|
|
|
|
|
|
void (*free_func)(void *)); |
14485
|
|
|
|
|
|
|
|
14486
|
|
|
|
|
|
|
#ifdef __cplusplus |
14487
|
|
|
|
|
|
|
} |
14488
|
|
|
|
|
|
|
#endif |
14489
|
|
|
|
|
|
|
|
14490
|
|
|
|
|
|
|
#endif |
14491
|
|
|
|
|
|
|
|
14492
|
|
|
|
|
|
|
|
14493
|
|
|
|
|
|
|
#include |
14494
|
|
|
|
|
|
|
#include |
14495
|
|
|
|
|
|
|
#include |
14496
|
|
|
|
|
|
|
#ifdef _MSC_VER |
14497
|
|
|
|
|
|
|
# include |
14498
|
|
|
|
|
|
|
# include |
14499
|
|
|
|
|
|
|
|
14500
|
|
|
|
|
|
|
|
14501
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
14502
|
|
|
|
|
|
|
|
14503
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
14504
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
14505
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
14506
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
14507
|
|
|
|
|
|
|
|
14508
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
14509
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
14510
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
14511
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
14512
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
14513
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
14514
|
|
|
|
|
|
|
#endif |
14515
|
|
|
|
|
|
|
#ifndef FREESTANDING |
14516
|
|
|
|
|
|
|
# include |
14517
|
|
|
|
|
|
|
#endif |
14518
|
|
|
|
|
|
|
|
14519
|
|
|
|
|
|
|
|
14520
|
|
|
|
|
|
|
|
14521
|
|
|
|
|
|
|
|
14522
|
|
|
|
|
|
|
|
14523
|
|
|
|
|
|
|
|
14524
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
14525
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
14526
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
14527
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
14528
|
|
|
|
|
|
|
#ifdef _MSC_VER |
14529
|
|
|
|
|
|
|
# if defined(_M_X64) |
14530
|
|
|
|
|
|
|
# define ARCH_X86_64 |
14531
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
14532
|
|
|
|
|
|
|
# define ARCH_X86_32 |
14533
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
14534
|
|
|
|
|
|
|
# define ARCH_ARM64 |
14535
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
14536
|
|
|
|
|
|
|
# define ARCH_ARM32 |
14537
|
|
|
|
|
|
|
# endif |
14538
|
|
|
|
|
|
|
#else |
14539
|
|
|
|
|
|
|
# if defined(__x86_64__) |
14540
|
|
|
|
|
|
|
# define ARCH_X86_64 |
14541
|
|
|
|
|
|
|
# elif defined(__i386__) |
14542
|
|
|
|
|
|
|
# define ARCH_X86_32 |
14543
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
14544
|
|
|
|
|
|
|
# define ARCH_ARM64 |
14545
|
|
|
|
|
|
|
# elif defined(__arm__) |
14546
|
|
|
|
|
|
|
# define ARCH_ARM32 |
14547
|
|
|
|
|
|
|
# endif |
14548
|
|
|
|
|
|
|
#endif |
14549
|
|
|
|
|
|
|
|
14550
|
|
|
|
|
|
|
|
14551
|
|
|
|
|
|
|
|
14552
|
|
|
|
|
|
|
|
14553
|
|
|
|
|
|
|
|
14554
|
|
|
|
|
|
|
|
14555
|
|
|
|
|
|
|
typedef uint8_t u8; |
14556
|
|
|
|
|
|
|
typedef uint16_t u16; |
14557
|
|
|
|
|
|
|
typedef uint32_t u32; |
14558
|
|
|
|
|
|
|
typedef uint64_t u64; |
14559
|
|
|
|
|
|
|
typedef int8_t s8; |
14560
|
|
|
|
|
|
|
typedef int16_t s16; |
14561
|
|
|
|
|
|
|
typedef int32_t s32; |
14562
|
|
|
|
|
|
|
typedef int64_t s64; |
14563
|
|
|
|
|
|
|
|
14564
|
|
|
|
|
|
|
|
14565
|
|
|
|
|
|
|
#ifdef _MSC_VER |
14566
|
|
|
|
|
|
|
# ifdef _WIN64 |
14567
|
|
|
|
|
|
|
typedef long long ssize_t; |
14568
|
|
|
|
|
|
|
# else |
14569
|
|
|
|
|
|
|
typedef long ssize_t; |
14570
|
|
|
|
|
|
|
# endif |
14571
|
|
|
|
|
|
|
#endif |
14572
|
|
|
|
|
|
|
|
14573
|
|
|
|
|
|
|
|
14574
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
14575
|
|
|
|
|
|
|
|
14576
|
|
|
|
|
|
|
|
14577
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
14578
|
|
|
|
|
|
|
|
14579
|
|
|
|
|
|
|
|
14580
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
14581
|
|
|
|
|
|
|
|
14582
|
|
|
|
|
|
|
|
14583
|
|
|
|
|
|
|
|
14584
|
|
|
|
|
|
|
|
14585
|
|
|
|
|
|
|
|
14586
|
|
|
|
|
|
|
|
14587
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
14588
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
14589
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
14590
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
14591
|
|
|
|
|
|
|
#else |
14592
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
14593
|
|
|
|
|
|
|
#endif |
14594
|
|
|
|
|
|
|
#ifdef __clang__ |
14595
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
14596
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
14597
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
14598
|
|
|
|
|
|
|
# else |
14599
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
14600
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
14601
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
14602
|
|
|
|
|
|
|
# endif |
14603
|
|
|
|
|
|
|
#else |
14604
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
14605
|
|
|
|
|
|
|
#endif |
14606
|
|
|
|
|
|
|
|
14607
|
|
|
|
|
|
|
|
14608
|
|
|
|
|
|
|
#ifndef __has_attribute |
14609
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
14610
|
|
|
|
|
|
|
#endif |
14611
|
|
|
|
|
|
|
#ifndef __has_builtin |
14612
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
14613
|
|
|
|
|
|
|
#endif |
14614
|
|
|
|
|
|
|
|
14615
|
|
|
|
|
|
|
|
14616
|
|
|
|
|
|
|
#ifdef _MSC_VER |
14617
|
|
|
|
|
|
|
# define inline __inline |
14618
|
|
|
|
|
|
|
#endif |
14619
|
|
|
|
|
|
|
|
14620
|
|
|
|
|
|
|
|
14621
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
14622
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
14623
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14624
|
|
|
|
|
|
|
# define forceinline __forceinline |
14625
|
|
|
|
|
|
|
#else |
14626
|
|
|
|
|
|
|
# define forceinline inline |
14627
|
|
|
|
|
|
|
#endif |
14628
|
|
|
|
|
|
|
|
14629
|
|
|
|
|
|
|
|
14630
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
14631
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
14632
|
|
|
|
|
|
|
#else |
14633
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
14634
|
|
|
|
|
|
|
#endif |
14635
|
|
|
|
|
|
|
|
14636
|
|
|
|
|
|
|
|
14637
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
14638
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
14639
|
|
|
|
|
|
|
# define restrict __restrict__ |
14640
|
|
|
|
|
|
|
# else |
14641
|
|
|
|
|
|
|
# define restrict |
14642
|
|
|
|
|
|
|
# endif |
14643
|
|
|
|
|
|
|
#endif |
14644
|
|
|
|
|
|
|
|
14645
|
|
|
|
|
|
|
|
14646
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
14647
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
14648
|
|
|
|
|
|
|
#else |
14649
|
|
|
|
|
|
|
# define likely(expr) (expr) |
14650
|
|
|
|
|
|
|
#endif |
14651
|
|
|
|
|
|
|
|
14652
|
|
|
|
|
|
|
|
14653
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
14654
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
14655
|
|
|
|
|
|
|
#else |
14656
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
14657
|
|
|
|
|
|
|
#endif |
14658
|
|
|
|
|
|
|
|
14659
|
|
|
|
|
|
|
|
14660
|
|
|
|
|
|
|
#undef prefetchr |
14661
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
14662
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
14663
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14664
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
14665
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
14666
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
14667
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
14668
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
14669
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
14670
|
|
|
|
|
|
|
# endif |
14671
|
|
|
|
|
|
|
#endif |
14672
|
|
|
|
|
|
|
#ifndef prefetchr |
14673
|
|
|
|
|
|
|
# define prefetchr(addr) |
14674
|
|
|
|
|
|
|
#endif |
14675
|
|
|
|
|
|
|
|
14676
|
|
|
|
|
|
|
|
14677
|
|
|
|
|
|
|
#undef prefetchw |
14678
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
14679
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
14680
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14681
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
14682
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
14683
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
14684
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
14685
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
14686
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
14687
|
|
|
|
|
|
|
# endif |
14688
|
|
|
|
|
|
|
#endif |
14689
|
|
|
|
|
|
|
#ifndef prefetchw |
14690
|
|
|
|
|
|
|
# define prefetchw(addr) |
14691
|
|
|
|
|
|
|
#endif |
14692
|
|
|
|
|
|
|
|
14693
|
|
|
|
|
|
|
|
14694
|
|
|
|
|
|
|
#undef _aligned_attribute |
14695
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
14696
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
14697
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14698
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
14699
|
|
|
|
|
|
|
#endif |
14700
|
|
|
|
|
|
|
|
14701
|
|
|
|
|
|
|
|
14702
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
14703
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
14704
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
14705
|
|
|
|
|
|
|
#else |
14706
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
14707
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
14708
|
|
|
|
|
|
|
#endif |
14709
|
|
|
|
|
|
|
|
14710
|
|
|
|
|
|
|
|
14711
|
|
|
|
|
|
|
|
14712
|
|
|
|
|
|
|
|
14713
|
|
|
|
|
|
|
|
14714
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
14715
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
14716
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
14717
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
14718
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
14719
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
14720
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
14721
|
|
|
|
|
|
|
|
14722
|
|
|
|
|
|
|
|
14723
|
|
|
|
|
|
|
|
14724
|
|
|
|
|
|
|
|
14725
|
|
|
|
|
|
|
|
14726
|
|
|
|
|
|
|
|
14727
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
14728
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
14729
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14730
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
14731
|
|
|
|
|
|
|
#else |
14732
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
14733
|
|
|
|
|
|
|
{ |
14734
|
|
|
|
|
|
|
union { |
14735
|
|
|
|
|
|
|
u32 w; |
14736
|
|
|
|
|
|
|
u8 b; |
14737
|
|
|
|
|
|
|
} u; |
14738
|
|
|
|
|
|
|
|
14739
|
|
|
|
|
|
|
u.w = 1; |
14740
|
|
|
|
|
|
|
return u.b; |
14741
|
|
|
|
|
|
|
} |
14742
|
|
|
|
|
|
|
#endif |
14743
|
|
|
|
|
|
|
|
14744
|
|
|
|
|
|
|
|
14745
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
14746
|
|
|
|
|
|
|
{ |
14747
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
14748
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
14749
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14750
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
14751
|
|
|
|
|
|
|
#else |
14752
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
14753
|
|
|
|
|
|
|
#endif |
14754
|
|
|
|
|
|
|
} |
14755
|
|
|
|
|
|
|
|
14756
|
|
|
|
|
|
|
|
14757
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
14758
|
|
|
|
|
|
|
{ |
14759
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
14760
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
14761
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14762
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
14763
|
|
|
|
|
|
|
#else |
14764
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
14765
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
14766
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
14767
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
14768
|
|
|
|
|
|
|
#endif |
14769
|
|
|
|
|
|
|
} |
14770
|
|
|
|
|
|
|
|
14771
|
|
|
|
|
|
|
|
14772
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
14773
|
|
|
|
|
|
|
{ |
14774
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
14775
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
14776
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14777
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
14778
|
|
|
|
|
|
|
#else |
14779
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
14780
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
14781
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
14782
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
14783
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
14784
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
14785
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
14786
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
14787
|
|
|
|
|
|
|
#endif |
14788
|
|
|
|
|
|
|
} |
14789
|
|
|
|
|
|
|
|
14790
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
14791
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
14792
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
14793
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
14794
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
14795
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
14796
|
|
|
|
|
|
|
|
14797
|
|
|
|
|
|
|
|
14798
|
|
|
|
|
|
|
|
14799
|
|
|
|
|
|
|
|
14800
|
|
|
|
|
|
|
|
14801
|
|
|
|
|
|
|
|
14802
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
14803
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
14804
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
14805
|
|
|
|
|
|
|
defined(__wasm__)) |
14806
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
14807
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
14808
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
14809
|
|
|
|
|
|
|
#else |
14810
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
14811
|
|
|
|
|
|
|
#endif |
14812
|
|
|
|
|
|
|
|
14813
|
|
|
|
|
|
|
|
14814
|
|
|
|
|
|
|
|
14815
|
|
|
|
|
|
|
#ifdef FREESTANDING |
14816
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
14817
|
|
|
|
|
|
|
#else |
14818
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
14819
|
|
|
|
|
|
|
#endif |
14820
|
|
|
|
|
|
|
|
14821
|
|
|
|
|
|
|
|
14822
|
|
|
|
|
|
|
|
14823
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
14824
|
|
|
|
|
|
|
static forceinline type \ |
14825
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
14826
|
|
|
|
|
|
|
{ \ |
14827
|
|
|
|
|
|
|
type v; \ |
14828
|
|
|
|
|
|
|
\ |
14829
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
14830
|
|
|
|
|
|
|
return v; \ |
14831
|
|
|
|
|
|
|
} \ |
14832
|
|
|
|
|
|
|
\ |
14833
|
|
|
|
|
|
|
static forceinline void \ |
14834
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
14835
|
|
|
|
|
|
|
{ \ |
14836
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
14837
|
|
|
|
|
|
|
} |
14838
|
|
|
|
|
|
|
|
14839
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
14840
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
14841
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
14842
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
14843
|
|
|
|
|
|
|
|
14844
|
|
|
|
|
|
|
#undef MEMCOPY |
14845
|
|
|
|
|
|
|
|
14846
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
14847
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
14848
|
|
|
|
|
|
|
|
14849
|
|
|
|
|
|
|
|
14850
|
|
|
|
|
|
|
|
14851
|
|
|
|
|
|
|
static forceinline u16 |
14852
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
14853
|
|
|
|
|
|
|
{ |
14854
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14855
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
14856
|
|
|
|
|
|
|
else |
14857
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
14858
|
|
|
|
|
|
|
} |
14859
|
|
|
|
|
|
|
|
14860
|
|
|
|
|
|
|
static forceinline u16 |
14861
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
14862
|
|
|
|
|
|
|
{ |
14863
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14864
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
14865
|
|
|
|
|
|
|
else |
14866
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
14867
|
|
|
|
|
|
|
} |
14868
|
|
|
|
|
|
|
|
14869
|
|
|
|
|
|
|
static forceinline u32 |
14870
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
14871
|
|
|
|
|
|
|
{ |
14872
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14873
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
14874
|
|
|
|
|
|
|
else |
14875
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
14876
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
14877
|
|
|
|
|
|
|
} |
14878
|
|
|
|
|
|
|
|
14879
|
|
|
|
|
|
|
static forceinline u32 |
14880
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
14881
|
|
|
|
|
|
|
{ |
14882
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14883
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
14884
|
|
|
|
|
|
|
else |
14885
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
14886
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
14887
|
|
|
|
|
|
|
} |
14888
|
|
|
|
|
|
|
|
14889
|
|
|
|
|
|
|
static forceinline u64 |
14890
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
14891
|
|
|
|
|
|
|
{ |
14892
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
14893
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
14894
|
|
|
|
|
|
|
else |
14895
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
14896
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
14897
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
14898
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
14899
|
|
|
|
|
|
|
} |
14900
|
|
|
|
|
|
|
|
14901
|
|
|
|
|
|
|
static forceinline machine_word_t |
14902
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
14903
|
|
|
|
|
|
|
{ |
14904
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14905
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14906
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
14907
|
|
|
|
|
|
|
else |
14908
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
14909
|
|
|
|
|
|
|
} |
14910
|
|
|
|
|
|
|
|
14911
|
|
|
|
|
|
|
|
14912
|
|
|
|
|
|
|
|
14913
|
|
|
|
|
|
|
static forceinline void |
14914
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
14915
|
|
|
|
|
|
|
{ |
14916
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14917
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
14918
|
|
|
|
|
|
|
} else { |
14919
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
14920
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
14921
|
|
|
|
|
|
|
} |
14922
|
|
|
|
|
|
|
} |
14923
|
|
|
|
|
|
|
|
14924
|
|
|
|
|
|
|
static forceinline void |
14925
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
14926
|
|
|
|
|
|
|
{ |
14927
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14928
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
14929
|
|
|
|
|
|
|
} else { |
14930
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
14931
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
14932
|
|
|
|
|
|
|
} |
14933
|
|
|
|
|
|
|
} |
14934
|
|
|
|
|
|
|
|
14935
|
|
|
|
|
|
|
static forceinline void |
14936
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
14937
|
|
|
|
|
|
|
{ |
14938
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14939
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
14940
|
|
|
|
|
|
|
} else { |
14941
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
14942
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
14943
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
14944
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
14945
|
|
|
|
|
|
|
} |
14946
|
|
|
|
|
|
|
} |
14947
|
|
|
|
|
|
|
|
14948
|
|
|
|
|
|
|
static forceinline void |
14949
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
14950
|
|
|
|
|
|
|
{ |
14951
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14952
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
14953
|
|
|
|
|
|
|
} else { |
14954
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
14955
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
14956
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
14957
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
14958
|
|
|
|
|
|
|
} |
14959
|
|
|
|
|
|
|
} |
14960
|
|
|
|
|
|
|
|
14961
|
|
|
|
|
|
|
static forceinline void |
14962
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
14963
|
|
|
|
|
|
|
{ |
14964
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
14965
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
14966
|
|
|
|
|
|
|
} else { |
14967
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
14968
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
14969
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
14970
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
14971
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
14972
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
14973
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
14974
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
14975
|
|
|
|
|
|
|
} |
14976
|
|
|
|
|
|
|
} |
14977
|
|
|
|
|
|
|
|
14978
|
|
|
|
|
|
|
static forceinline void |
14979
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
14980
|
|
|
|
|
|
|
{ |
14981
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
14982
|
|
|
|
|
|
|
if (WORDBITS == 32) |
14983
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
14984
|
|
|
|
|
|
|
else |
14985
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
14986
|
|
|
|
|
|
|
} |
14987
|
|
|
|
|
|
|
|
14988
|
|
|
|
|
|
|
|
14989
|
|
|
|
|
|
|
|
14990
|
|
|
|
|
|
|
|
14991
|
|
|
|
|
|
|
|
14992
|
|
|
|
|
|
|
|
14993
|
|
|
|
|
|
|
|
14994
|
|
|
|
|
|
|
static forceinline unsigned |
14995
|
|
|
|
|
|
|
bsr32(u32 v) |
14996
|
|
|
|
|
|
|
{ |
14997
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
14998
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
14999
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15000
|
|
|
|
|
|
|
unsigned long i; |
15001
|
|
|
|
|
|
|
|
15002
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
15003
|
|
|
|
|
|
|
return i; |
15004
|
|
|
|
|
|
|
#else |
15005
|
|
|
|
|
|
|
unsigned i = 0; |
15006
|
|
|
|
|
|
|
|
15007
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
15008
|
|
|
|
|
|
|
i++; |
15009
|
|
|
|
|
|
|
return i; |
15010
|
|
|
|
|
|
|
#endif |
15011
|
|
|
|
|
|
|
} |
15012
|
|
|
|
|
|
|
|
15013
|
|
|
|
|
|
|
static forceinline unsigned |
15014
|
|
|
|
|
|
|
bsr64(u64 v) |
15015
|
|
|
|
|
|
|
{ |
15016
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
15017
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
15018
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
15019
|
|
|
|
|
|
|
unsigned long i; |
15020
|
|
|
|
|
|
|
|
15021
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
15022
|
|
|
|
|
|
|
return i; |
15023
|
|
|
|
|
|
|
#else |
15024
|
|
|
|
|
|
|
unsigned i = 0; |
15025
|
|
|
|
|
|
|
|
15026
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
15027
|
|
|
|
|
|
|
i++; |
15028
|
|
|
|
|
|
|
return i; |
15029
|
|
|
|
|
|
|
#endif |
15030
|
|
|
|
|
|
|
} |
15031
|
|
|
|
|
|
|
|
15032
|
|
|
|
|
|
|
static forceinline unsigned |
15033
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
15034
|
|
|
|
|
|
|
{ |
15035
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
15036
|
|
|
|
|
|
|
if (WORDBITS == 32) |
15037
|
|
|
|
|
|
|
return bsr32(v); |
15038
|
|
|
|
|
|
|
else |
15039
|
|
|
|
|
|
|
return bsr64(v); |
15040
|
|
|
|
|
|
|
} |
15041
|
|
|
|
|
|
|
|
15042
|
|
|
|
|
|
|
|
15043
|
|
|
|
|
|
|
|
15044
|
|
|
|
|
|
|
static forceinline unsigned |
15045
|
|
|
|
|
|
|
bsf32(u32 v) |
15046
|
|
|
|
|
|
|
{ |
15047
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
15048
|
|
|
|
|
|
|
return __builtin_ctz(v); |
15049
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15050
|
|
|
|
|
|
|
unsigned long i; |
15051
|
|
|
|
|
|
|
|
15052
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
15053
|
|
|
|
|
|
|
return i; |
15054
|
|
|
|
|
|
|
#else |
15055
|
|
|
|
|
|
|
unsigned i = 0; |
15056
|
|
|
|
|
|
|
|
15057
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
15058
|
|
|
|
|
|
|
i++; |
15059
|
|
|
|
|
|
|
return i; |
15060
|
|
|
|
|
|
|
#endif |
15061
|
|
|
|
|
|
|
} |
15062
|
|
|
|
|
|
|
|
15063
|
|
|
|
|
|
|
static forceinline unsigned |
15064
|
|
|
|
|
|
|
bsf64(u64 v) |
15065
|
|
|
|
|
|
|
{ |
15066
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
15067
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
15068
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
15069
|
|
|
|
|
|
|
unsigned long i; |
15070
|
|
|
|
|
|
|
|
15071
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
15072
|
|
|
|
|
|
|
return i; |
15073
|
|
|
|
|
|
|
#else |
15074
|
|
|
|
|
|
|
unsigned i = 0; |
15075
|
|
|
|
|
|
|
|
15076
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
15077
|
|
|
|
|
|
|
i++; |
15078
|
|
|
|
|
|
|
return i; |
15079
|
|
|
|
|
|
|
#endif |
15080
|
|
|
|
|
|
|
} |
15081
|
|
|
|
|
|
|
|
15082
|
|
|
|
|
|
|
static forceinline unsigned |
15083
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
15084
|
|
|
|
|
|
|
{ |
15085
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
15086
|
|
|
|
|
|
|
if (WORDBITS == 32) |
15087
|
|
|
|
|
|
|
return bsf32(v); |
15088
|
|
|
|
|
|
|
else |
15089
|
|
|
|
|
|
|
return bsf64(v); |
15090
|
|
|
|
|
|
|
} |
15091
|
|
|
|
|
|
|
|
15092
|
|
|
|
|
|
|
|
15093
|
|
|
|
|
|
|
#undef rbit32 |
15094
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
15095
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
15096
|
|
|
|
|
|
|
static forceinline u32 |
15097
|
|
|
|
|
|
|
rbit32(u32 v) |
15098
|
|
|
|
|
|
|
{ |
15099
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
15100
|
|
|
|
|
|
|
return v; |
15101
|
|
|
|
|
|
|
} |
15102
|
|
|
|
|
|
|
#define rbit32 rbit32 |
15103
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
15104
|
|
|
|
|
|
|
static forceinline u32 |
15105
|
|
|
|
|
|
|
rbit32(u32 v) |
15106
|
|
|
|
|
|
|
{ |
15107
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
15108
|
|
|
|
|
|
|
return v; |
15109
|
|
|
|
|
|
|
} |
15110
|
|
|
|
|
|
|
#define rbit32 rbit32 |
15111
|
|
|
|
|
|
|
#endif |
15112
|
|
|
|
|
|
|
|
15113
|
|
|
|
|
|
|
#endif |
15114
|
|
|
|
|
|
|
|
15115
|
|
|
|
|
|
|
|
15116
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
15117
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
15118
|
|
|
|
|
|
|
|
15119
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
15120
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
15121
|
|
|
|
|
|
|
|
15122
|
|
|
|
|
|
|
#ifdef FREESTANDING |
15123
|
|
|
|
|
|
|
|
15124
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
15125
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
15126
|
|
|
|
|
|
|
|
15127
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
15128
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
15129
|
|
|
|
|
|
|
|
15130
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
15131
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
15132
|
|
|
|
|
|
|
|
15133
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
15134
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
15135
|
|
|
|
|
|
|
|
15136
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
15137
|
|
|
|
|
|
|
#else |
15138
|
|
|
|
|
|
|
#include |
15139
|
|
|
|
|
|
|
#endif |
15140
|
|
|
|
|
|
|
|
15141
|
|
|
|
|
|
|
|
15142
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
15143
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
15144
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
15145
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
15146
|
|
|
|
|
|
|
#else |
15147
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
15148
|
|
|
|
|
|
|
#endif |
15149
|
|
|
|
|
|
|
|
15150
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
15151
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
15152
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
15153
|
|
|
|
|
|
|
|
15154
|
|
|
|
|
|
|
#endif |
15155
|
|
|
|
|
|
|
|
15156
|
|
|
|
|
|
|
|
15157
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
15158
|
|
|
|
|
|
|
|
15159
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
15160
|
|
|
|
|
|
|
|
15161
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
15162
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
15163
|
|
|
|
|
|
|
(defined(__linux__) || \ |
15164
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
15165
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
15166
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
15167
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
15168
|
|
|
|
|
|
|
#endif |
15169
|
|
|
|
|
|
|
|
15170
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
15171
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
15172
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
15173
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
15174
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
15175
|
|
|
|
|
|
|
|
15176
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
15177
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
15178
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
15179
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
15180
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
15181
|
|
|
|
|
|
|
|
15182
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
15183
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
15184
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
15185
|
|
|
|
|
|
|
|
15186
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
15187
|
|
|
|
|
|
|
|
15188
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
15189
|
|
|
|
|
|
|
{ |
15190
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
15191
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
15192
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
15193
|
|
|
|
|
|
|
} |
15194
|
|
|
|
|
|
|
#else |
15195
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
15196
|
|
|
|
|
|
|
#endif |
15197
|
|
|
|
|
|
|
|
15198
|
|
|
|
|
|
|
|
15199
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
15200
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
15201
|
|
|
|
|
|
|
#else |
15202
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
15203
|
|
|
|
|
|
|
#endif |
15204
|
|
|
|
|
|
|
|
15205
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
15206
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
15207
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
15208
|
|
|
|
|
|
|
#else |
15209
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
15210
|
|
|
|
|
|
|
#endif |
15211
|
|
|
|
|
|
|
|
15212
|
|
|
|
|
|
|
|
15213
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
15214
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
15215
|
|
|
|
|
|
|
#else |
15216
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
15217
|
|
|
|
|
|
|
#endif |
15218
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
15219
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
15220
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
15221
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
15222
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
15223
|
|
|
|
|
|
|
\ |
15224
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
15225
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
15226
|
|
|
|
|
|
|
|
15227
|
|
|
|
|
|
|
# ifdef _MSC_VER |
15228
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
15229
|
|
|
|
|
|
|
# else |
15230
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
15231
|
|
|
|
|
|
|
# endif |
15232
|
|
|
|
|
|
|
#else |
15233
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
15234
|
|
|
|
|
|
|
#endif |
15235
|
|
|
|
|
|
|
|
15236
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
15237
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
15238
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
15239
|
|
|
|
|
|
|
#else |
15240
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
15241
|
|
|
|
|
|
|
#endif |
15242
|
|
|
|
|
|
|
|
15243
|
|
|
|
|
|
|
|
15244
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
15245
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
15246
|
|
|
|
|
|
|
#else |
15247
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
15248
|
|
|
|
|
|
|
#endif |
15249
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
15250
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
15251
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
15252
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
15253
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
15254
|
|
|
|
|
|
|
|
15255
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
15256
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
15257
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
15258
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
15259
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
15260
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
15261
|
|
|
|
|
|
|
# endif |
15262
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
15263
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
15264
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
15265
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
15266
|
|
|
|
|
|
|
# endif |
15267
|
|
|
|
|
|
|
#endif |
15268
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
15269
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
15270
|
|
|
|
|
|
|
#endif |
15271
|
|
|
|
|
|
|
|
15272
|
|
|
|
|
|
|
|
15273
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
15274
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
15275
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
15276
|
|
|
|
|
|
|
# else |
15277
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
15278
|
|
|
|
|
|
|
# endif |
15279
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
15280
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
15281
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
15282
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
15283
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
15284
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
15285
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
15286
|
|
|
|
|
|
|
#else |
15287
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
15288
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
15289
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
15290
|
|
|
|
|
|
|
#endif |
15291
|
|
|
|
|
|
|
|
15292
|
|
|
|
|
|
|
|
15293
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
15294
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
15295
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
15296
|
|
|
|
|
|
|
# else |
15297
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
15298
|
|
|
|
|
|
|
# endif |
15299
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
15300
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
15301
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
15302
|
|
|
|
|
|
|
defined(_MSC_VER))) |
15303
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
15304
|
|
|
|
|
|
|
# else |
15305
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
15306
|
|
|
|
|
|
|
# endif |
15307
|
|
|
|
|
|
|
#else |
15308
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
15309
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
15310
|
|
|
|
|
|
|
#endif |
15311
|
|
|
|
|
|
|
|
15312
|
|
|
|
|
|
|
|
15313
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
15314
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
15315
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
15316
|
|
|
|
|
|
|
#endif |
15317
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
15318
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
15319
|
|
|
|
|
|
|
#endif |
15320
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
15321
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
15322
|
|
|
|
|
|
|
#endif |
15323
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
15324
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
15325
|
|
|
|
|
|
|
# include |
15326
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
15327
|
|
|
|
|
|
|
#endif |
15328
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
15329
|
|
|
|
|
|
|
# include |
15330
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
15331
|
|
|
|
|
|
|
#endif |
15332
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
15333
|
|
|
|
|
|
|
# include |
15334
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
15335
|
|
|
|
|
|
|
#endif |
15336
|
|
|
|
|
|
|
|
15337
|
|
|
|
|
|
|
#endif |
15338
|
|
|
|
|
|
|
|
15339
|
|
|
|
|
|
|
#endif |
15340
|
|
|
|
|
|
|
|
15341
|
|
|
|
|
|
|
|
15342
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE |
15343
|
|
|
|
|
|
|
# include |
15344
|
|
|
|
|
|
|
static forceinline void |
15345
|
|
|
|
|
|
|
matchfinder_init_neon(mf_pos_t *data, size_t size) |
15346
|
|
|
|
|
|
|
{ |
15347
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
15348
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16(MATCHFINDER_INITVAL); |
15349
|
|
|
|
|
|
|
|
15350
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
15351
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
15352
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
15353
|
|
|
|
|
|
|
|
15354
|
|
|
|
|
|
|
do { |
15355
|
|
|
|
|
|
|
p[0] = v; |
15356
|
|
|
|
|
|
|
p[1] = v; |
15357
|
|
|
|
|
|
|
p[2] = v; |
15358
|
|
|
|
|
|
|
p[3] = v; |
15359
|
|
|
|
|
|
|
p += 4; |
15360
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
15361
|
|
|
|
|
|
|
} while (size != 0); |
15362
|
|
|
|
|
|
|
} |
15363
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_neon |
15364
|
|
|
|
|
|
|
|
15365
|
|
|
|
|
|
|
static forceinline void |
15366
|
|
|
|
|
|
|
matchfinder_rebase_neon(mf_pos_t *data, size_t size) |
15367
|
|
|
|
|
|
|
{ |
15368
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
15369
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16((u16)-MATCHFINDER_WINDOW_SIZE); |
15370
|
|
|
|
|
|
|
|
15371
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
15372
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
15373
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
15374
|
|
|
|
|
|
|
|
15375
|
|
|
|
|
|
|
do { |
15376
|
|
|
|
|
|
|
p[0] = vqaddq_s16(p[0], v); |
15377
|
|
|
|
|
|
|
p[1] = vqaddq_s16(p[1], v); |
15378
|
|
|
|
|
|
|
p[2] = vqaddq_s16(p[2], v); |
15379
|
|
|
|
|
|
|
p[3] = vqaddq_s16(p[3], v); |
15380
|
|
|
|
|
|
|
p += 4; |
15381
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
15382
|
|
|
|
|
|
|
} while (size != 0); |
15383
|
|
|
|
|
|
|
} |
15384
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_neon |
15385
|
|
|
|
|
|
|
|
15386
|
|
|
|
|
|
|
#endif |
15387
|
|
|
|
|
|
|
|
15388
|
|
|
|
|
|
|
#endif |
15389
|
|
|
|
|
|
|
|
15390
|
|
|
|
|
|
|
# elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
15391
|
|
|
|
|
|
|
/* # include "x86/matchfinder_impl.h" */ |
15392
|
|
|
|
|
|
|
|
15393
|
|
|
|
|
|
|
|
15394
|
|
|
|
|
|
|
#ifndef LIB_X86_MATCHFINDER_IMPL_H |
15395
|
|
|
|
|
|
|
#define LIB_X86_MATCHFINDER_IMPL_H |
15396
|
|
|
|
|
|
|
|
15397
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
15398
|
|
|
|
|
|
|
|
15399
|
|
|
|
|
|
|
|
15400
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
15401
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
15402
|
|
|
|
|
|
|
|
15403
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
15404
|
|
|
|
|
|
|
|
15405
|
|
|
|
|
|
|
|
15406
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
15407
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
15408
|
|
|
|
|
|
|
|
15409
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
15410
|
|
|
|
|
|
|
|
15411
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
15412
|
|
|
|
|
|
|
#endif |
15413
|
|
|
|
|
|
|
|
15414
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
15415
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
15416
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
15417
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
15418
|
|
|
|
|
|
|
#else |
15419
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
15420
|
|
|
|
|
|
|
#endif |
15421
|
|
|
|
|
|
|
|
15422
|
|
|
|
|
|
|
|
15423
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
15424
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
15425
|
|
|
|
|
|
|
#else |
15426
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
15427
|
|
|
|
|
|
|
#endif |
15428
|
|
|
|
|
|
|
|
15429
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
15430
|
|
|
|
|
|
|
|
15431
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
15432
|
|
|
|
|
|
|
|
15433
|
|
|
|
|
|
|
|
15434
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
15435
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
15436
|
|
|
|
|
|
|
|
15437
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
15438
|
|
|
|
|
|
|
|
15439
|
|
|
|
|
|
|
|
15440
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
15441
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
15442
|
|
|
|
|
|
|
|
15443
|
|
|
|
|
|
|
#include |
15444
|
|
|
|
|
|
|
#include |
15445
|
|
|
|
|
|
|
|
15446
|
|
|
|
|
|
|
#ifdef __cplusplus |
15447
|
|
|
|
|
|
|
extern "C" { |
15448
|
|
|
|
|
|
|
#endif |
15449
|
|
|
|
|
|
|
|
15450
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
15451
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
15452
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
15453
|
|
|
|
|
|
|
|
15454
|
|
|
|
|
|
|
|
15455
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
15456
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
15457
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
15458
|
|
|
|
|
|
|
# else |
15459
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
15460
|
|
|
|
|
|
|
# endif |
15461
|
|
|
|
|
|
|
#endif |
15462
|
|
|
|
|
|
|
|
15463
|
|
|
|
|
|
|
|
15464
|
|
|
|
|
|
|
|
15465
|
|
|
|
|
|
|
|
15466
|
|
|
|
|
|
|
|
15467
|
|
|
|
|
|
|
struct libdeflate_compressor; |
15468
|
|
|
|
|
|
|
|
15469
|
|
|
|
|
|
|
|
15470
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
15471
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
15472
|
|
|
|
|
|
|
|
15473
|
|
|
|
|
|
|
|
15474
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15475
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
15476
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15477
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
15478
|
|
|
|
|
|
|
|
15479
|
|
|
|
|
|
|
|
15480
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15481
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
15482
|
|
|
|
|
|
|
size_t in_nbytes); |
15483
|
|
|
|
|
|
|
|
15484
|
|
|
|
|
|
|
|
15485
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15486
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
15487
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15488
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
15489
|
|
|
|
|
|
|
|
15490
|
|
|
|
|
|
|
|
15491
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15492
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
15493
|
|
|
|
|
|
|
size_t in_nbytes); |
15494
|
|
|
|
|
|
|
|
15495
|
|
|
|
|
|
|
|
15496
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15497
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
15498
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15499
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
15500
|
|
|
|
|
|
|
|
15501
|
|
|
|
|
|
|
|
15502
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
15503
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
15504
|
|
|
|
|
|
|
size_t in_nbytes); |
15505
|
|
|
|
|
|
|
|
15506
|
|
|
|
|
|
|
|
15507
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
15508
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
15509
|
|
|
|
|
|
|
|
15510
|
|
|
|
|
|
|
|
15511
|
|
|
|
|
|
|
|
15512
|
|
|
|
|
|
|
|
15513
|
|
|
|
|
|
|
|
15514
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
15515
|
|
|
|
|
|
|
|
15516
|
|
|
|
|
|
|
|
15517
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
15518
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
15519
|
|
|
|
|
|
|
|
15520
|
|
|
|
|
|
|
|
15521
|
|
|
|
|
|
|
enum libdeflate_result { |
15522
|
|
|
|
|
|
|
|
15523
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
15524
|
|
|
|
|
|
|
|
15525
|
|
|
|
|
|
|
|
15526
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
15527
|
|
|
|
|
|
|
|
15528
|
|
|
|
|
|
|
|
15529
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
15530
|
|
|
|
|
|
|
|
15531
|
|
|
|
|
|
|
|
15532
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
15533
|
|
|
|
|
|
|
}; |
15534
|
|
|
|
|
|
|
|
15535
|
|
|
|
|
|
|
|
15536
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15537
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
15538
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15539
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15540
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15541
|
|
|
|
|
|
|
|
15542
|
|
|
|
|
|
|
|
15543
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15544
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
15545
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15546
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15547
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
15548
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15549
|
|
|
|
|
|
|
|
15550
|
|
|
|
|
|
|
|
15551
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15552
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
15553
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15554
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15555
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15556
|
|
|
|
|
|
|
|
15557
|
|
|
|
|
|
|
|
15558
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15559
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
15560
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15561
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15562
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
15563
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15564
|
|
|
|
|
|
|
|
15565
|
|
|
|
|
|
|
|
15566
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15567
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
15568
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15569
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15570
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15571
|
|
|
|
|
|
|
|
15572
|
|
|
|
|
|
|
|
15573
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
15574
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
15575
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
15576
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
15577
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
15578
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
15579
|
|
|
|
|
|
|
|
15580
|
|
|
|
|
|
|
|
15581
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
15582
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
15583
|
|
|
|
|
|
|
|
15584
|
|
|
|
|
|
|
|
15585
|
|
|
|
|
|
|
|
15586
|
|
|
|
|
|
|
|
15587
|
|
|
|
|
|
|
|
15588
|
|
|
|
|
|
|
|
15589
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
15590
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
15591
|
|
|
|
|
|
|
|
15592
|
|
|
|
|
|
|
|
15593
|
|
|
|
|
|
|
|
15594
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
15595
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
15596
|
|
|
|
|
|
|
|
15597
|
|
|
|
|
|
|
|
15598
|
|
|
|
|
|
|
|
15599
|
|
|
|
|
|
|
|
15600
|
|
|
|
|
|
|
|
15601
|
|
|
|
|
|
|
|
15602
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
15603
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
15604
|
|
|
|
|
|
|
void (*free_func)(void *)); |
15605
|
|
|
|
|
|
|
|
15606
|
|
|
|
|
|
|
#ifdef __cplusplus |
15607
|
|
|
|
|
|
|
} |
15608
|
|
|
|
|
|
|
#endif |
15609
|
|
|
|
|
|
|
|
15610
|
|
|
|
|
|
|
#endif |
15611
|
|
|
|
|
|
|
|
15612
|
|
|
|
|
|
|
|
15613
|
|
|
|
|
|
|
#include |
15614
|
|
|
|
|
|
|
#include |
15615
|
|
|
|
|
|
|
#include |
15616
|
|
|
|
|
|
|
#ifdef _MSC_VER |
15617
|
|
|
|
|
|
|
# include |
15618
|
|
|
|
|
|
|
# include |
15619
|
|
|
|
|
|
|
|
15620
|
|
|
|
|
|
|
|
15621
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
15622
|
|
|
|
|
|
|
|
15623
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
15624
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
15625
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
15626
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
15627
|
|
|
|
|
|
|
|
15628
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
15629
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
15630
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
15631
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
15632
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
15633
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
15634
|
|
|
|
|
|
|
#endif |
15635
|
|
|
|
|
|
|
#ifndef FREESTANDING |
15636
|
|
|
|
|
|
|
# include |
15637
|
|
|
|
|
|
|
#endif |
15638
|
|
|
|
|
|
|
|
15639
|
|
|
|
|
|
|
|
15640
|
|
|
|
|
|
|
|
15641
|
|
|
|
|
|
|
|
15642
|
|
|
|
|
|
|
|
15643
|
|
|
|
|
|
|
|
15644
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
15645
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
15646
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
15647
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
15648
|
|
|
|
|
|
|
#ifdef _MSC_VER |
15649
|
|
|
|
|
|
|
# if defined(_M_X64) |
15650
|
|
|
|
|
|
|
# define ARCH_X86_64 |
15651
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
15652
|
|
|
|
|
|
|
# define ARCH_X86_32 |
15653
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
15654
|
|
|
|
|
|
|
# define ARCH_ARM64 |
15655
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
15656
|
|
|
|
|
|
|
# define ARCH_ARM32 |
15657
|
|
|
|
|
|
|
# endif |
15658
|
|
|
|
|
|
|
#else |
15659
|
|
|
|
|
|
|
# if defined(__x86_64__) |
15660
|
|
|
|
|
|
|
# define ARCH_X86_64 |
15661
|
|
|
|
|
|
|
# elif defined(__i386__) |
15662
|
|
|
|
|
|
|
# define ARCH_X86_32 |
15663
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
15664
|
|
|
|
|
|
|
# define ARCH_ARM64 |
15665
|
|
|
|
|
|
|
# elif defined(__arm__) |
15666
|
|
|
|
|
|
|
# define ARCH_ARM32 |
15667
|
|
|
|
|
|
|
# endif |
15668
|
|
|
|
|
|
|
#endif |
15669
|
|
|
|
|
|
|
|
15670
|
|
|
|
|
|
|
|
15671
|
|
|
|
|
|
|
|
15672
|
|
|
|
|
|
|
|
15673
|
|
|
|
|
|
|
|
15674
|
|
|
|
|
|
|
|
15675
|
|
|
|
|
|
|
typedef uint8_t u8; |
15676
|
|
|
|
|
|
|
typedef uint16_t u16; |
15677
|
|
|
|
|
|
|
typedef uint32_t u32; |
15678
|
|
|
|
|
|
|
typedef uint64_t u64; |
15679
|
|
|
|
|
|
|
typedef int8_t s8; |
15680
|
|
|
|
|
|
|
typedef int16_t s16; |
15681
|
|
|
|
|
|
|
typedef int32_t s32; |
15682
|
|
|
|
|
|
|
typedef int64_t s64; |
15683
|
|
|
|
|
|
|
|
15684
|
|
|
|
|
|
|
|
15685
|
|
|
|
|
|
|
#ifdef _MSC_VER |
15686
|
|
|
|
|
|
|
# ifdef _WIN64 |
15687
|
|
|
|
|
|
|
typedef long long ssize_t; |
15688
|
|
|
|
|
|
|
# else |
15689
|
|
|
|
|
|
|
typedef long ssize_t; |
15690
|
|
|
|
|
|
|
# endif |
15691
|
|
|
|
|
|
|
#endif |
15692
|
|
|
|
|
|
|
|
15693
|
|
|
|
|
|
|
|
15694
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
15695
|
|
|
|
|
|
|
|
15696
|
|
|
|
|
|
|
|
15697
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
15698
|
|
|
|
|
|
|
|
15699
|
|
|
|
|
|
|
|
15700
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
15701
|
|
|
|
|
|
|
|
15702
|
|
|
|
|
|
|
|
15703
|
|
|
|
|
|
|
|
15704
|
|
|
|
|
|
|
|
15705
|
|
|
|
|
|
|
|
15706
|
|
|
|
|
|
|
|
15707
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
15708
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
15709
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
15710
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
15711
|
|
|
|
|
|
|
#else |
15712
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
15713
|
|
|
|
|
|
|
#endif |
15714
|
|
|
|
|
|
|
#ifdef __clang__ |
15715
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
15716
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
15717
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
15718
|
|
|
|
|
|
|
# else |
15719
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
15720
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
15721
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
15722
|
|
|
|
|
|
|
# endif |
15723
|
|
|
|
|
|
|
#else |
15724
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
15725
|
|
|
|
|
|
|
#endif |
15726
|
|
|
|
|
|
|
|
15727
|
|
|
|
|
|
|
|
15728
|
|
|
|
|
|
|
#ifndef __has_attribute |
15729
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
15730
|
|
|
|
|
|
|
#endif |
15731
|
|
|
|
|
|
|
#ifndef __has_builtin |
15732
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
15733
|
|
|
|
|
|
|
#endif |
15734
|
|
|
|
|
|
|
|
15735
|
|
|
|
|
|
|
|
15736
|
|
|
|
|
|
|
#ifdef _MSC_VER |
15737
|
|
|
|
|
|
|
# define inline __inline |
15738
|
|
|
|
|
|
|
#endif |
15739
|
|
|
|
|
|
|
|
15740
|
|
|
|
|
|
|
|
15741
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
15742
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
15743
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15744
|
|
|
|
|
|
|
# define forceinline __forceinline |
15745
|
|
|
|
|
|
|
#else |
15746
|
|
|
|
|
|
|
# define forceinline inline |
15747
|
|
|
|
|
|
|
#endif |
15748
|
|
|
|
|
|
|
|
15749
|
|
|
|
|
|
|
|
15750
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
15751
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
15752
|
|
|
|
|
|
|
#else |
15753
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
15754
|
|
|
|
|
|
|
#endif |
15755
|
|
|
|
|
|
|
|
15756
|
|
|
|
|
|
|
|
15757
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
15758
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
15759
|
|
|
|
|
|
|
# define restrict __restrict__ |
15760
|
|
|
|
|
|
|
# else |
15761
|
|
|
|
|
|
|
# define restrict |
15762
|
|
|
|
|
|
|
# endif |
15763
|
|
|
|
|
|
|
#endif |
15764
|
|
|
|
|
|
|
|
15765
|
|
|
|
|
|
|
|
15766
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
15767
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
15768
|
|
|
|
|
|
|
#else |
15769
|
|
|
|
|
|
|
# define likely(expr) (expr) |
15770
|
|
|
|
|
|
|
#endif |
15771
|
|
|
|
|
|
|
|
15772
|
|
|
|
|
|
|
|
15773
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
15774
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
15775
|
|
|
|
|
|
|
#else |
15776
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
15777
|
|
|
|
|
|
|
#endif |
15778
|
|
|
|
|
|
|
|
15779
|
|
|
|
|
|
|
|
15780
|
|
|
|
|
|
|
#undef prefetchr |
15781
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
15782
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
15783
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15784
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
15785
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
15786
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
15787
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
15788
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
15789
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
15790
|
|
|
|
|
|
|
# endif |
15791
|
|
|
|
|
|
|
#endif |
15792
|
|
|
|
|
|
|
#ifndef prefetchr |
15793
|
|
|
|
|
|
|
# define prefetchr(addr) |
15794
|
|
|
|
|
|
|
#endif |
15795
|
|
|
|
|
|
|
|
15796
|
|
|
|
|
|
|
|
15797
|
|
|
|
|
|
|
#undef prefetchw |
15798
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
15799
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
15800
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15801
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
15802
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
15803
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
15804
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
15805
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
15806
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
15807
|
|
|
|
|
|
|
# endif |
15808
|
|
|
|
|
|
|
#endif |
15809
|
|
|
|
|
|
|
#ifndef prefetchw |
15810
|
|
|
|
|
|
|
# define prefetchw(addr) |
15811
|
|
|
|
|
|
|
#endif |
15812
|
|
|
|
|
|
|
|
15813
|
|
|
|
|
|
|
|
15814
|
|
|
|
|
|
|
#undef _aligned_attribute |
15815
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
15816
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
15817
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15818
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
15819
|
|
|
|
|
|
|
#endif |
15820
|
|
|
|
|
|
|
|
15821
|
|
|
|
|
|
|
|
15822
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
15823
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
15824
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
15825
|
|
|
|
|
|
|
#else |
15826
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
15827
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
15828
|
|
|
|
|
|
|
#endif |
15829
|
|
|
|
|
|
|
|
15830
|
|
|
|
|
|
|
|
15831
|
|
|
|
|
|
|
|
15832
|
|
|
|
|
|
|
|
15833
|
|
|
|
|
|
|
|
15834
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
15835
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
15836
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
15837
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
15838
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
15839
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
15840
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
15841
|
|
|
|
|
|
|
|
15842
|
|
|
|
|
|
|
|
15843
|
|
|
|
|
|
|
|
15844
|
|
|
|
|
|
|
|
15845
|
|
|
|
|
|
|
|
15846
|
|
|
|
|
|
|
|
15847
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
15848
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
15849
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15850
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
15851
|
|
|
|
|
|
|
#else |
15852
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
15853
|
|
|
|
|
|
|
{ |
15854
|
|
|
|
|
|
|
union { |
15855
|
|
|
|
|
|
|
u32 w; |
15856
|
|
|
|
|
|
|
u8 b; |
15857
|
|
|
|
|
|
|
} u; |
15858
|
|
|
|
|
|
|
|
15859
|
|
|
|
|
|
|
u.w = 1; |
15860
|
|
|
|
|
|
|
return u.b; |
15861
|
|
|
|
|
|
|
} |
15862
|
|
|
|
|
|
|
#endif |
15863
|
|
|
|
|
|
|
|
15864
|
|
|
|
|
|
|
|
15865
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
15866
|
|
|
|
|
|
|
{ |
15867
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
15868
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
15869
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15870
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
15871
|
|
|
|
|
|
|
#else |
15872
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
15873
|
|
|
|
|
|
|
#endif |
15874
|
|
|
|
|
|
|
} |
15875
|
|
|
|
|
|
|
|
15876
|
|
|
|
|
|
|
|
15877
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
15878
|
|
|
|
|
|
|
{ |
15879
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
15880
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
15881
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15882
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
15883
|
|
|
|
|
|
|
#else |
15884
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
15885
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
15886
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
15887
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
15888
|
|
|
|
|
|
|
#endif |
15889
|
|
|
|
|
|
|
} |
15890
|
|
|
|
|
|
|
|
15891
|
|
|
|
|
|
|
|
15892
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
15893
|
|
|
|
|
|
|
{ |
15894
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
15895
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
15896
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15897
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
15898
|
|
|
|
|
|
|
#else |
15899
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
15900
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
15901
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
15902
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
15903
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
15904
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
15905
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
15906
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
15907
|
|
|
|
|
|
|
#endif |
15908
|
|
|
|
|
|
|
} |
15909
|
|
|
|
|
|
|
|
15910
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
15911
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
15912
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
15913
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
15914
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
15915
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
15916
|
|
|
|
|
|
|
|
15917
|
|
|
|
|
|
|
|
15918
|
|
|
|
|
|
|
|
15919
|
|
|
|
|
|
|
|
15920
|
|
|
|
|
|
|
|
15921
|
|
|
|
|
|
|
|
15922
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
15923
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
15924
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
15925
|
|
|
|
|
|
|
defined(__wasm__)) |
15926
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
15927
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
15928
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
15929
|
|
|
|
|
|
|
#else |
15930
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
15931
|
|
|
|
|
|
|
#endif |
15932
|
|
|
|
|
|
|
|
15933
|
|
|
|
|
|
|
|
15934
|
|
|
|
|
|
|
|
15935
|
|
|
|
|
|
|
#ifdef FREESTANDING |
15936
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
15937
|
|
|
|
|
|
|
#else |
15938
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
15939
|
|
|
|
|
|
|
#endif |
15940
|
|
|
|
|
|
|
|
15941
|
|
|
|
|
|
|
|
15942
|
|
|
|
|
|
|
|
15943
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
15944
|
|
|
|
|
|
|
static forceinline type \ |
15945
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
15946
|
|
|
|
|
|
|
{ \ |
15947
|
|
|
|
|
|
|
type v; \ |
15948
|
|
|
|
|
|
|
\ |
15949
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
15950
|
|
|
|
|
|
|
return v; \ |
15951
|
|
|
|
|
|
|
} \ |
15952
|
|
|
|
|
|
|
\ |
15953
|
|
|
|
|
|
|
static forceinline void \ |
15954
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
15955
|
|
|
|
|
|
|
{ \ |
15956
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
15957
|
|
|
|
|
|
|
} |
15958
|
|
|
|
|
|
|
|
15959
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
15960
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
15961
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
15962
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
15963
|
|
|
|
|
|
|
|
15964
|
|
|
|
|
|
|
#undef MEMCOPY |
15965
|
|
|
|
|
|
|
|
15966
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
15967
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
15968
|
|
|
|
|
|
|
|
15969
|
|
|
|
|
|
|
|
15970
|
|
|
|
|
|
|
|
15971
|
|
|
|
|
|
|
static forceinline u16 |
15972
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
15973
|
|
|
|
|
|
|
{ |
15974
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
15975
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
15976
|
|
|
|
|
|
|
else |
15977
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
15978
|
|
|
|
|
|
|
} |
15979
|
|
|
|
|
|
|
|
15980
|
|
|
|
|
|
|
static forceinline u16 |
15981
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
15982
|
|
|
|
|
|
|
{ |
15983
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
15984
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
15985
|
|
|
|
|
|
|
else |
15986
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
15987
|
|
|
|
|
|
|
} |
15988
|
|
|
|
|
|
|
|
15989
|
|
|
|
|
|
|
static forceinline u32 |
15990
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
15991
|
|
|
|
|
|
|
{ |
15992
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
15993
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
15994
|
|
|
|
|
|
|
else |
15995
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
15996
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
15997
|
|
|
|
|
|
|
} |
15998
|
|
|
|
|
|
|
|
15999
|
|
|
|
|
|
|
static forceinline u32 |
16000
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
16001
|
|
|
|
|
|
|
{ |
16002
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
16003
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
16004
|
|
|
|
|
|
|
else |
16005
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
16006
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
16007
|
|
|
|
|
|
|
} |
16008
|
|
|
|
|
|
|
|
16009
|
|
|
|
|
|
|
static forceinline u64 |
16010
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
16011
|
|
|
|
|
|
|
{ |
16012
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
16013
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
16014
|
|
|
|
|
|
|
else |
16015
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
16016
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
16017
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
16018
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
16019
|
|
|
|
|
|
|
} |
16020
|
|
|
|
|
|
|
|
16021
|
|
|
|
|
|
|
static forceinline machine_word_t |
16022
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
16023
|
|
|
|
|
|
|
{ |
16024
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
16025
|
|
|
|
|
|
|
if (WORDBITS == 32) |
16026
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
16027
|
|
|
|
|
|
|
else |
16028
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
16029
|
|
|
|
|
|
|
} |
16030
|
|
|
|
|
|
|
|
16031
|
|
|
|
|
|
|
|
16032
|
|
|
|
|
|
|
|
16033
|
|
|
|
|
|
|
static forceinline void |
16034
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
16035
|
|
|
|
|
|
|
{ |
16036
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16037
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
16038
|
|
|
|
|
|
|
} else { |
16039
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
16040
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
16041
|
|
|
|
|
|
|
} |
16042
|
|
|
|
|
|
|
} |
16043
|
|
|
|
|
|
|
|
16044
|
|
|
|
|
|
|
static forceinline void |
16045
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
16046
|
|
|
|
|
|
|
{ |
16047
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16048
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
16049
|
|
|
|
|
|
|
} else { |
16050
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
16051
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
16052
|
|
|
|
|
|
|
} |
16053
|
|
|
|
|
|
|
} |
16054
|
|
|
|
|
|
|
|
16055
|
|
|
|
|
|
|
static forceinline void |
16056
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
16057
|
|
|
|
|
|
|
{ |
16058
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16059
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
16060
|
|
|
|
|
|
|
} else { |
16061
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
16062
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
16063
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
16064
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
16065
|
|
|
|
|
|
|
} |
16066
|
|
|
|
|
|
|
} |
16067
|
|
|
|
|
|
|
|
16068
|
|
|
|
|
|
|
static forceinline void |
16069
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
16070
|
|
|
|
|
|
|
{ |
16071
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16072
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
16073
|
|
|
|
|
|
|
} else { |
16074
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
16075
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
16076
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
16077
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
16078
|
|
|
|
|
|
|
} |
16079
|
|
|
|
|
|
|
} |
16080
|
|
|
|
|
|
|
|
16081
|
|
|
|
|
|
|
static forceinline void |
16082
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
16083
|
|
|
|
|
|
|
{ |
16084
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16085
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
16086
|
|
|
|
|
|
|
} else { |
16087
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
16088
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
16089
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
16090
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
16091
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
16092
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
16093
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
16094
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
16095
|
|
|
|
|
|
|
} |
16096
|
|
|
|
|
|
|
} |
16097
|
|
|
|
|
|
|
|
16098
|
|
|
|
|
|
|
static forceinline void |
16099
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
16100
|
|
|
|
|
|
|
{ |
16101
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
16102
|
|
|
|
|
|
|
if (WORDBITS == 32) |
16103
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
16104
|
|
|
|
|
|
|
else |
16105
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
16106
|
|
|
|
|
|
|
} |
16107
|
|
|
|
|
|
|
|
16108
|
|
|
|
|
|
|
|
16109
|
|
|
|
|
|
|
|
16110
|
|
|
|
|
|
|
|
16111
|
|
|
|
|
|
|
|
16112
|
|
|
|
|
|
|
|
16113
|
|
|
|
|
|
|
|
16114
|
|
|
|
|
|
|
static forceinline unsigned |
16115
|
|
|
|
|
|
|
bsr32(u32 v) |
16116
|
|
|
|
|
|
|
{ |
16117
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
16118
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
16119
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16120
|
|
|
|
|
|
|
unsigned long i; |
16121
|
|
|
|
|
|
|
|
16122
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
16123
|
|
|
|
|
|
|
return i; |
16124
|
|
|
|
|
|
|
#else |
16125
|
|
|
|
|
|
|
unsigned i = 0; |
16126
|
|
|
|
|
|
|
|
16127
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
16128
|
|
|
|
|
|
|
i++; |
16129
|
|
|
|
|
|
|
return i; |
16130
|
|
|
|
|
|
|
#endif |
16131
|
|
|
|
|
|
|
} |
16132
|
|
|
|
|
|
|
|
16133
|
|
|
|
|
|
|
static forceinline unsigned |
16134
|
|
|
|
|
|
|
bsr64(u64 v) |
16135
|
|
|
|
|
|
|
{ |
16136
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
16137
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
16138
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
16139
|
|
|
|
|
|
|
unsigned long i; |
16140
|
|
|
|
|
|
|
|
16141
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
16142
|
|
|
|
|
|
|
return i; |
16143
|
|
|
|
|
|
|
#else |
16144
|
|
|
|
|
|
|
unsigned i = 0; |
16145
|
|
|
|
|
|
|
|
16146
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
16147
|
|
|
|
|
|
|
i++; |
16148
|
|
|
|
|
|
|
return i; |
16149
|
|
|
|
|
|
|
#endif |
16150
|
|
|
|
|
|
|
} |
16151
|
|
|
|
|
|
|
|
16152
|
|
|
|
|
|
|
static forceinline unsigned |
16153
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
16154
|
|
|
|
|
|
|
{ |
16155
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
16156
|
|
|
|
|
|
|
if (WORDBITS == 32) |
16157
|
|
|
|
|
|
|
return bsr32(v); |
16158
|
|
|
|
|
|
|
else |
16159
|
|
|
|
|
|
|
return bsr64(v); |
16160
|
|
|
|
|
|
|
} |
16161
|
|
|
|
|
|
|
|
16162
|
|
|
|
|
|
|
|
16163
|
|
|
|
|
|
|
|
16164
|
|
|
|
|
|
|
static forceinline unsigned |
16165
|
|
|
|
|
|
|
bsf32(u32 v) |
16166
|
|
|
|
|
|
|
{ |
16167
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
16168
|
|
|
|
|
|
|
return __builtin_ctz(v); |
16169
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
16170
|
|
|
|
|
|
|
unsigned long i; |
16171
|
|
|
|
|
|
|
|
16172
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
16173
|
|
|
|
|
|
|
return i; |
16174
|
|
|
|
|
|
|
#else |
16175
|
|
|
|
|
|
|
unsigned i = 0; |
16176
|
|
|
|
|
|
|
|
16177
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
16178
|
|
|
|
|
|
|
i++; |
16179
|
|
|
|
|
|
|
return i; |
16180
|
|
|
|
|
|
|
#endif |
16181
|
|
|
|
|
|
|
} |
16182
|
|
|
|
|
|
|
|
16183
|
|
|
|
|
|
|
static forceinline unsigned |
16184
|
|
|
|
|
|
|
bsf64(u64 v) |
16185
|
|
|
|
|
|
|
{ |
16186
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
16187
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
16188
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
16189
|
|
|
|
|
|
|
unsigned long i; |
16190
|
|
|
|
|
|
|
|
16191
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
16192
|
|
|
|
|
|
|
return i; |
16193
|
|
|
|
|
|
|
#else |
16194
|
|
|
|
|
|
|
unsigned i = 0; |
16195
|
|
|
|
|
|
|
|
16196
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
16197
|
|
|
|
|
|
|
i++; |
16198
|
|
|
|
|
|
|
return i; |
16199
|
|
|
|
|
|
|
#endif |
16200
|
|
|
|
|
|
|
} |
16201
|
|
|
|
|
|
|
|
16202
|
|
|
|
|
|
|
static forceinline unsigned |
16203
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
16204
|
|
|
|
|
|
|
{ |
16205
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
16206
|
|
|
|
|
|
|
if (WORDBITS == 32) |
16207
|
|
|
|
|
|
|
return bsf32(v); |
16208
|
|
|
|
|
|
|
else |
16209
|
|
|
|
|
|
|
return bsf64(v); |
16210
|
|
|
|
|
|
|
} |
16211
|
|
|
|
|
|
|
|
16212
|
|
|
|
|
|
|
|
16213
|
|
|
|
|
|
|
#undef rbit32 |
16214
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
16215
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
16216
|
|
|
|
|
|
|
static forceinline u32 |
16217
|
|
|
|
|
|
|
rbit32(u32 v) |
16218
|
|
|
|
|
|
|
{ |
16219
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
16220
|
|
|
|
|
|
|
return v; |
16221
|
|
|
|
|
|
|
} |
16222
|
|
|
|
|
|
|
#define rbit32 rbit32 |
16223
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
16224
|
|
|
|
|
|
|
static forceinline u32 |
16225
|
|
|
|
|
|
|
rbit32(u32 v) |
16226
|
|
|
|
|
|
|
{ |
16227
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
16228
|
|
|
|
|
|
|
return v; |
16229
|
|
|
|
|
|
|
} |
16230
|
|
|
|
|
|
|
#define rbit32 rbit32 |
16231
|
|
|
|
|
|
|
#endif |
16232
|
|
|
|
|
|
|
|
16233
|
|
|
|
|
|
|
#endif |
16234
|
|
|
|
|
|
|
|
16235
|
|
|
|
|
|
|
|
16236
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
16237
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
16238
|
|
|
|
|
|
|
|
16239
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
16240
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
16241
|
|
|
|
|
|
|
|
16242
|
|
|
|
|
|
|
#ifdef FREESTANDING |
16243
|
|
|
|
|
|
|
|
16244
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
16245
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
16246
|
|
|
|
|
|
|
|
16247
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
16248
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
16249
|
|
|
|
|
|
|
|
16250
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
16251
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
16252
|
|
|
|
|
|
|
|
16253
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
16254
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
16255
|
|
|
|
|
|
|
|
16256
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
16257
|
|
|
|
|
|
|
#else |
16258
|
|
|
|
|
|
|
#include |
16259
|
|
|
|
|
|
|
#endif |
16260
|
|
|
|
|
|
|
|
16261
|
|
|
|
|
|
|
|
16262
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
16263
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
16264
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
16265
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
16266
|
|
|
|
|
|
|
#else |
16267
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
16268
|
|
|
|
|
|
|
#endif |
16269
|
|
|
|
|
|
|
|
16270
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
16271
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
16272
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
16273
|
|
|
|
|
|
|
|
16274
|
|
|
|
|
|
|
#endif |
16275
|
|
|
|
|
|
|
|
16276
|
|
|
|
|
|
|
|
16277
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
16278
|
|
|
|
|
|
|
|
16279
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
16280
|
|
|
|
|
|
|
|
16281
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
16282
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
16283
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
16284
|
|
|
|
|
|
|
#endif |
16285
|
|
|
|
|
|
|
|
16286
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
16287
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
16288
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
16289
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
16290
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
16291
|
|
|
|
|
|
|
|
16292
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
16293
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
16294
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
16295
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
16296
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
16297
|
|
|
|
|
|
|
|
16298
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
16299
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
16300
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
16301
|
|
|
|
|
|
|
|
16302
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
16303
|
|
|
|
|
|
|
|
16304
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
16305
|
|
|
|
|
|
|
{ |
16306
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
16307
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
16308
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
16309
|
|
|
|
|
|
|
} |
16310
|
|
|
|
|
|
|
#else |
16311
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
16312
|
|
|
|
|
|
|
#endif |
16313
|
|
|
|
|
|
|
|
16314
|
|
|
|
|
|
|
|
16315
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
16316
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
16317
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
16318
|
|
|
|
|
|
|
#else |
16319
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
16320
|
|
|
|
|
|
|
#endif |
16321
|
|
|
|
|
|
|
|
16322
|
|
|
|
|
|
|
|
16323
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
16324
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
16325
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
16326
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
16327
|
|
|
|
|
|
|
#else |
16328
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
16329
|
|
|
|
|
|
|
#endif |
16330
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
16331
|
|
|
|
|
|
|
|
16332
|
|
|
|
|
|
|
|
16333
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
16334
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
16335
|
|
|
|
|
|
|
#else |
16336
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
16337
|
|
|
|
|
|
|
#endif |
16338
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
16339
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
16340
|
|
|
|
|
|
|
defined(_MSC_VER))) |
16341
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
16342
|
|
|
|
|
|
|
#else |
16343
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
16344
|
|
|
|
|
|
|
#endif |
16345
|
|
|
|
|
|
|
|
16346
|
|
|
|
|
|
|
|
16347
|
|
|
|
|
|
|
#ifdef __AVX__ |
16348
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
16349
|
|
|
|
|
|
|
#else |
16350
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
16351
|
|
|
|
|
|
|
#endif |
16352
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
16353
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
16354
|
|
|
|
|
|
|
defined(_MSC_VER))) |
16355
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
16356
|
|
|
|
|
|
|
#else |
16357
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
16358
|
|
|
|
|
|
|
#endif |
16359
|
|
|
|
|
|
|
|
16360
|
|
|
|
|
|
|
|
16361
|
|
|
|
|
|
|
#ifdef __AVX2__ |
16362
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
16363
|
|
|
|
|
|
|
#else |
16364
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
16365
|
|
|
|
|
|
|
#endif |
16366
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
16367
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
16368
|
|
|
|
|
|
|
defined(_MSC_VER))) |
16369
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
16370
|
|
|
|
|
|
|
#else |
16371
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
16372
|
|
|
|
|
|
|
#endif |
16373
|
|
|
|
|
|
|
|
16374
|
|
|
|
|
|
|
|
16375
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
16376
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
16377
|
|
|
|
|
|
|
#else |
16378
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
16379
|
|
|
|
|
|
|
#endif |
16380
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
16381
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
16382
|
|
|
|
|
|
|
defined(_MSC_VER))) |
16383
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
16384
|
|
|
|
|
|
|
#else |
16385
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
16386
|
|
|
|
|
|
|
#endif |
16387
|
|
|
|
|
|
|
|
16388
|
|
|
|
|
|
|
#endif |
16389
|
|
|
|
|
|
|
|
16390
|
|
|
|
|
|
|
#endif |
16391
|
|
|
|
|
|
|
|
16392
|
|
|
|
|
|
|
|
16393
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE |
16394
|
|
|
|
|
|
|
# include |
16395
|
|
|
|
|
|
|
static forceinline void |
16396
|
|
|
|
|
|
|
matchfinder_init_avx2(mf_pos_t *data, size_t size) |
16397
|
|
|
|
|
|
|
{ |
16398
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
16399
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16(MATCHFINDER_INITVAL); |
16400
|
|
|
|
|
|
|
|
16401
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
16402
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
16403
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
16404
|
|
|
|
|
|
|
|
16405
|
|
|
|
|
|
|
do { |
16406
|
|
|
|
|
|
|
p[0] = v; |
16407
|
|
|
|
|
|
|
p[1] = v; |
16408
|
|
|
|
|
|
|
p[2] = v; |
16409
|
|
|
|
|
|
|
p[3] = v; |
16410
|
|
|
|
|
|
|
p += 4; |
16411
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
16412
|
|
|
|
|
|
|
} while (size != 0); |
16413
|
|
|
|
|
|
|
} |
16414
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_avx2 |
16415
|
|
|
|
|
|
|
|
16416
|
|
|
|
|
|
|
static forceinline void |
16417
|
|
|
|
|
|
|
matchfinder_rebase_avx2(mf_pos_t *data, size_t size) |
16418
|
|
|
|
|
|
|
{ |
16419
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
16420
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
16421
|
|
|
|
|
|
|
|
16422
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
16423
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
16424
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
16425
|
|
|
|
|
|
|
|
16426
|
|
|
|
|
|
|
do { |
16427
|
|
|
|
|
|
|
|
16428
|
|
|
|
|
|
|
p[0] = _mm256_adds_epi16(p[0], v); |
16429
|
|
|
|
|
|
|
p[1] = _mm256_adds_epi16(p[1], v); |
16430
|
|
|
|
|
|
|
p[2] = _mm256_adds_epi16(p[2], v); |
16431
|
|
|
|
|
|
|
p[3] = _mm256_adds_epi16(p[3], v); |
16432
|
|
|
|
|
|
|
p += 4; |
16433
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
16434
|
|
|
|
|
|
|
} while (size != 0); |
16435
|
|
|
|
|
|
|
} |
16436
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_avx2 |
16437
|
|
|
|
|
|
|
|
16438
|
|
|
|
|
|
|
#elif HAVE_SSE2_NATIVE |
16439
|
|
|
|
|
|
|
# include |
16440
|
|
|
|
|
|
|
static forceinline void |
16441
|
|
|
|
|
|
|
matchfinder_init_sse2(mf_pos_t *data, size_t size) |
16442
|
|
|
|
|
|
|
{ |
16443
|
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
16444
|
|
|
|
|
|
|
__m128i v = _mm_set1_epi16(MATCHFINDER_INITVAL); |
16445
|
|
|
|
|
|
|
|
16446
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
16447
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
16448
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
16449
|
|
|
|
|
|
|
|
16450
|
|
|
|
|
|
|
do { |
16451
|
|
|
|
|
|
|
p[0] = v; |
16452
|
|
|
|
|
|
|
p[1] = v; |
16453
|
|
|
|
|
|
|
p[2] = v; |
16454
|
|
|
|
|
|
|
p[3] = v; |
16455
|
|
|
|
|
|
|
p += 4; |
16456
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
16457
|
|
|
|
|
|
|
} while (size != 0); |
16458
|
|
|
|
|
|
|
} |
16459
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_sse2 |
16460
|
|
|
|
|
|
|
|
16461
|
|
|
|
|
|
|
static forceinline void |
16462
|
|
|
|
|
|
|
matchfinder_rebase_sse2(mf_pos_t *data, size_t size) |
16463
|
|
|
|
|
|
|
{ |
16464
|
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
16465
|
|
|
|
|
|
|
__m128i v = _mm_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
16466
|
|
|
|
|
|
|
|
16467
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
16468
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
16469
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
16470
|
|
|
|
|
|
|
|
16471
|
|
|
|
|
|
|
do { |
16472
|
|
|
|
|
|
|
|
16473
|
|
|
|
|
|
|
p[0] = _mm_adds_epi16(p[0], v); |
16474
|
|
|
|
|
|
|
p[1] = _mm_adds_epi16(p[1], v); |
16475
|
|
|
|
|
|
|
p[2] = _mm_adds_epi16(p[2], v); |
16476
|
|
|
|
|
|
|
p[3] = _mm_adds_epi16(p[3], v); |
16477
|
|
|
|
|
|
|
p += 4; |
16478
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
16479
|
|
|
|
|
|
|
} while (size != 0); |
16480
|
|
|
|
|
|
|
} |
16481
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_sse2 |
16482
|
|
|
|
|
|
|
#endif |
16483
|
|
|
|
|
|
|
|
16484
|
|
|
|
|
|
|
#endif |
16485
|
|
|
|
|
|
|
|
16486
|
|
|
|
|
|
|
# endif |
16487
|
|
|
|
|
|
|
#else |
16488
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED |
16489
|
|
|
|
|
|
|
#endif |
16490
|
|
|
|
|
|
|
|
16491
|
|
|
|
|
|
|
|
16492
|
|
|
|
|
|
|
#ifndef matchfinder_init |
16493
|
|
|
|
|
|
|
static forceinline void |
16494
|
|
|
|
|
|
|
matchfinder_init(mf_pos_t *data, size_t size) |
16495
|
|
|
|
|
|
|
{ |
16496
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
16497
|
|
|
|
|
|
|
size_t i; |
16498
|
|
|
|
|
|
|
|
16499
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
16500
|
|
|
|
|
|
|
data[i] = MATCHFINDER_INITVAL; |
16501
|
|
|
|
|
|
|
} |
16502
|
|
|
|
|
|
|
#endif |
16503
|
|
|
|
|
|
|
|
16504
|
|
|
|
|
|
|
|
16505
|
|
|
|
|
|
|
#ifndef matchfinder_rebase |
16506
|
|
|
|
|
|
|
static forceinline void |
16507
|
|
|
|
|
|
|
matchfinder_rebase(mf_pos_t *data, size_t size) |
16508
|
|
|
|
|
|
|
{ |
16509
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
16510
|
|
|
|
|
|
|
size_t i; |
16511
|
|
|
|
|
|
|
|
16512
|
|
|
|
|
|
|
if (MATCHFINDER_WINDOW_SIZE == 32768) { |
16513
|
|
|
|
|
|
|
|
16514
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
16515
|
|
|
|
|
|
|
data[i] = 0x8000 | (data[i] & ~(data[i] >> 15)); |
16516
|
|
|
|
|
|
|
} else { |
16517
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) { |
16518
|
|
|
|
|
|
|
if (data[i] >= 0) |
16519
|
|
|
|
|
|
|
data[i] -= (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
16520
|
|
|
|
|
|
|
else |
16521
|
|
|
|
|
|
|
data[i] = (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
16522
|
|
|
|
|
|
|
} |
16523
|
|
|
|
|
|
|
} |
16524
|
|
|
|
|
|
|
} |
16525
|
|
|
|
|
|
|
#endif |
16526
|
|
|
|
|
|
|
|
16527
|
|
|
|
|
|
|
|
16528
|
|
|
|
|
|
|
static forceinline u32 |
16529
|
|
|
|
|
|
|
lz_hash(u32 seq, unsigned num_bits) |
16530
|
|
|
|
|
|
|
{ |
16531
|
|
|
|
|
|
|
return (u32)(seq * 0x1E35A7BD) >> (32 - num_bits); |
16532
|
|
|
|
|
|
|
} |
16533
|
|
|
|
|
|
|
|
16534
|
|
|
|
|
|
|
|
16535
|
|
|
|
|
|
|
static forceinline unsigned |
16536
|
|
|
|
|
|
|
lz_extend(const u8 * const strptr, const u8 * const matchptr, |
16537
|
|
|
|
|
|
|
const unsigned start_len, const unsigned max_len) |
16538
|
|
|
|
|
|
|
{ |
16539
|
|
|
|
|
|
|
unsigned len = start_len; |
16540
|
|
|
|
|
|
|
machine_word_t v_word; |
16541
|
|
|
|
|
|
|
|
16542
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
16543
|
|
|
|
|
|
|
|
16544
|
|
|
|
|
|
|
if (likely(max_len - len >= 4 * WORDBYTES)) { |
16545
|
|
|
|
|
|
|
|
16546
|
|
|
|
|
|
|
#define COMPARE_WORD_STEP \ |
16547
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ \ |
16548
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); \ |
16549
|
|
|
|
|
|
|
if (v_word != 0) \ |
16550
|
|
|
|
|
|
|
goto word_differs; \ |
16551
|
|
|
|
|
|
|
len += WORDBYTES; \ |
16552
|
|
|
|
|
|
|
|
16553
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
16554
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
16555
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
16556
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
16557
|
|
|
|
|
|
|
#undef COMPARE_WORD_STEP |
16558
|
|
|
|
|
|
|
} |
16559
|
|
|
|
|
|
|
|
16560
|
|
|
|
|
|
|
while (len + WORDBYTES <= max_len) { |
16561
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ |
16562
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); |
16563
|
|
|
|
|
|
|
if (v_word != 0) |
16564
|
|
|
|
|
|
|
goto word_differs; |
16565
|
|
|
|
|
|
|
len += WORDBYTES; |
16566
|
|
|
|
|
|
|
} |
16567
|
|
|
|
|
|
|
} |
16568
|
|
|
|
|
|
|
|
16569
|
|
|
|
|
|
|
while (len < max_len && matchptr[len] == strptr[len]) |
16570
|
|
|
|
|
|
|
len++; |
16571
|
|
|
|
|
|
|
return len; |
16572
|
|
|
|
|
|
|
|
16573
|
|
|
|
|
|
|
word_differs: |
16574
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
16575
|
|
|
|
|
|
|
len += (bsfw(v_word) >> 3); |
16576
|
|
|
|
|
|
|
else |
16577
|
|
|
|
|
|
|
len += (WORDBITS - 1 - bsrw(v_word)) >> 3; |
16578
|
|
|
|
|
|
|
return len; |
16579
|
|
|
|
|
|
|
} |
16580
|
|
|
|
|
|
|
|
16581
|
|
|
|
|
|
|
#endif |
16582
|
|
|
|
|
|
|
|
16583
|
|
|
|
|
|
|
|
16584
|
|
|
|
|
|
|
#define HT_MATCHFINDER_HASH_ORDER 15 |
16585
|
|
|
|
|
|
|
#define HT_MATCHFINDER_BUCKET_SIZE 2 |
16586
|
|
|
|
|
|
|
|
16587
|
|
|
|
|
|
|
#define HT_MATCHFINDER_MIN_MATCH_LEN 4 |
16588
|
|
|
|
|
|
|
|
16589
|
|
|
|
|
|
|
#define HT_MATCHFINDER_REQUIRED_NBYTES 5 |
16590
|
|
|
|
|
|
|
|
16591
|
|
|
|
|
|
|
struct MATCHFINDER_ALIGNED ht_matchfinder { |
16592
|
|
|
|
|
|
|
mf_pos_t hash_tab[1UL << HT_MATCHFINDER_HASH_ORDER] |
16593
|
|
|
|
|
|
|
[HT_MATCHFINDER_BUCKET_SIZE]; |
16594
|
|
|
|
|
|
|
}; |
16595
|
|
|
|
|
|
|
|
16596
|
|
|
|
|
|
|
static forceinline void |
16597
|
|
|
|
|
|
|
ht_matchfinder_init(struct ht_matchfinder *mf) |
16598
|
|
|
|
|
|
|
{ |
16599
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(*mf) % MATCHFINDER_SIZE_ALIGNMENT == 0); |
16600
|
|
|
|
|
|
|
|
16601
|
|
|
|
|
|
|
matchfinder_init((mf_pos_t *)mf, sizeof(*mf)); |
16602
|
|
|
|
|
|
|
} |
16603
|
|
|
|
|
|
|
|
16604
|
|
|
|
|
|
|
static forceinline void |
16605
|
|
|
|
|
|
|
ht_matchfinder_slide_window(struct ht_matchfinder *mf) |
16606
|
|
|
|
|
|
|
{ |
16607
|
|
|
|
|
|
|
matchfinder_rebase((mf_pos_t *)mf, sizeof(*mf)); |
16608
|
|
|
|
|
|
|
} |
16609
|
|
|
|
|
|
|
|
16610
|
|
|
|
|
|
|
|
16611
|
|
|
|
|
|
|
static forceinline u32 |
16612
|
|
|
|
|
|
|
ht_matchfinder_longest_match(struct ht_matchfinder * const mf, |
16613
|
|
|
|
|
|
|
const u8 ** const in_base_p, |
16614
|
|
|
|
|
|
|
const u8 * const in_next, |
16615
|
|
|
|
|
|
|
const u32 max_len, |
16616
|
|
|
|
|
|
|
const u32 nice_len, |
16617
|
|
|
|
|
|
|
u32 * const next_hash, |
16618
|
|
|
|
|
|
|
u32 * const offset_ret) |
16619
|
|
|
|
|
|
|
{ |
16620
|
75
|
|
|
|
|
|
u32 best_len = 0; |
16621
|
75
|
|
|
|
|
|
const u8 *best_matchptr = in_next; |
16622
|
75
|
|
|
|
|
|
u32 cur_pos = in_next - *in_base_p; |
16623
|
|
|
|
|
|
|
const u8 *in_base; |
16624
|
|
|
|
|
|
|
mf_pos_t cutoff; |
16625
|
|
|
|
|
|
|
u32 hash; |
16626
|
|
|
|
|
|
|
u32 seq; |
16627
|
|
|
|
|
|
|
mf_pos_t cur_node; |
16628
|
|
|
|
|
|
|
const u8 *matchptr; |
16629
|
|
|
|
|
|
|
#if HT_MATCHFINDER_BUCKET_SIZE > 1 |
16630
|
|
|
|
|
|
|
mf_pos_t to_insert; |
16631
|
|
|
|
|
|
|
u32 len; |
16632
|
|
|
|
|
|
|
#endif |
16633
|
|
|
|
|
|
|
#if HT_MATCHFINDER_BUCKET_SIZE > 2 |
16634
|
|
|
|
|
|
|
int i; |
16635
|
|
|
|
|
|
|
#endif |
16636
|
|
|
|
|
|
|
|
16637
|
|
|
|
|
|
|
|
16638
|
|
|
|
|
|
|
STATIC_ASSERT(HT_MATCHFINDER_MIN_MATCH_LEN == 4); |
16639
|
|
|
|
|
|
|
|
16640
|
75
|
50
|
|
|
|
|
if (cur_pos == MATCHFINDER_WINDOW_SIZE) { |
16641
|
|
|
|
|
|
|
ht_matchfinder_slide_window(mf); |
16642
|
0
|
|
|
|
|
|
*in_base_p += MATCHFINDER_WINDOW_SIZE; |
16643
|
0
|
|
|
|
|
|
cur_pos = 0; |
16644
|
|
|
|
|
|
|
} |
16645
|
75
|
|
|
|
|
|
in_base = *in_base_p; |
16646
|
75
|
|
|
|
|
|
cutoff = cur_pos - MATCHFINDER_WINDOW_SIZE; |
16647
|
|
|
|
|
|
|
|
16648
|
75
|
|
|
|
|
|
hash = *next_hash; |
16649
|
|
|
|
|
|
|
STATIC_ASSERT(HT_MATCHFINDER_REQUIRED_NBYTES == 5); |
16650
|
225
|
|
|
|
|
|
*next_hash = lz_hash(get_unaligned_le32(in_next + 1), |
16651
|
|
|
|
|
|
|
HT_MATCHFINDER_HASH_ORDER); |
16652
|
75
|
|
|
|
|
|
seq = load_u32_unaligned(in_next); |
16653
|
75
|
|
|
|
|
|
prefetchw(&mf->hash_tab[*next_hash]); |
16654
|
|
|
|
|
|
|
#if HT_MATCHFINDER_BUCKET_SIZE == 1 |
16655
|
|
|
|
|
|
|
|
16656
|
|
|
|
|
|
|
cur_node = mf->hash_tab[hash][0]; |
16657
|
|
|
|
|
|
|
mf->hash_tab[hash][0] = cur_pos; |
16658
|
|
|
|
|
|
|
if (cur_node <= cutoff) |
16659
|
|
|
|
|
|
|
goto out; |
16660
|
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
16661
|
|
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq) { |
16662
|
|
|
|
|
|
|
best_len = lz_extend(in_next, matchptr, 4, max_len); |
16663
|
|
|
|
|
|
|
best_matchptr = matchptr; |
16664
|
|
|
|
|
|
|
} |
16665
|
|
|
|
|
|
|
#elif HT_MATCHFINDER_BUCKET_SIZE == 2 |
16666
|
|
|
|
|
|
|
|
16667
|
75
|
|
|
|
|
|
cur_node = mf->hash_tab[hash][0]; |
16668
|
75
|
|
|
|
|
|
mf->hash_tab[hash][0] = cur_pos; |
16669
|
75
|
100
|
|
|
|
|
if (cur_node <= cutoff) |
16670
|
|
|
|
|
|
|
goto out; |
16671
|
21
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
16672
|
|
|
|
|
|
|
|
16673
|
21
|
|
|
|
|
|
to_insert = cur_node; |
16674
|
21
|
|
|
|
|
|
cur_node = mf->hash_tab[hash][1]; |
16675
|
21
|
|
|
|
|
|
mf->hash_tab[hash][1] = to_insert; |
16676
|
|
|
|
|
|
|
|
16677
|
21
|
50
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq) { |
16678
|
21
|
|
|
|
|
|
best_len = lz_extend(in_next, matchptr, 4, max_len); |
16679
|
21
|
|
|
|
|
|
best_matchptr = matchptr; |
16680
|
21
|
100
|
|
|
|
|
if (cur_node <= cutoff || best_len >= nice_len) |
|
|
50
|
|
|
|
|
|
16681
|
|
|
|
|
|
|
goto out; |
16682
|
0
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
16683
|
0
|
0
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq && |
|
|
0
|
|
|
|
|
|
16684
|
0
|
|
|
|
|
|
load_u32_unaligned(matchptr + best_len - 3) == |
16685
|
0
|
|
|
|
|
|
load_u32_unaligned(in_next + best_len - 3)) { |
16686
|
0
|
|
|
|
|
|
len = lz_extend(in_next, matchptr, 4, max_len); |
16687
|
0
|
0
|
|
|
|
|
if (len > best_len) { |
16688
|
0
|
|
|
|
|
|
best_len = len; |
16689
|
0
|
|
|
|
|
|
best_matchptr = matchptr; |
16690
|
|
|
|
|
|
|
} |
16691
|
|
|
|
|
|
|
} |
16692
|
|
|
|
|
|
|
} else { |
16693
|
0
|
0
|
|
|
|
|
if (cur_node <= cutoff) |
16694
|
|
|
|
|
|
|
goto out; |
16695
|
0
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
16696
|
0
|
0
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq) { |
16697
|
0
|
|
|
|
|
|
best_len = lz_extend(in_next, matchptr, 4, max_len); |
16698
|
0
|
|
|
|
|
|
best_matchptr = matchptr; |
16699
|
|
|
|
|
|
|
} |
16700
|
|
|
|
|
|
|
} |
16701
|
|
|
|
|
|
|
#else |
16702
|
|
|
|
|
|
|
|
16703
|
|
|
|
|
|
|
to_insert = cur_pos; |
16704
|
|
|
|
|
|
|
for (i = 0; i < HT_MATCHFINDER_BUCKET_SIZE; i++) { |
16705
|
|
|
|
|
|
|
cur_node = mf->hash_tab[hash][i]; |
16706
|
|
|
|
|
|
|
mf->hash_tab[hash][i] = to_insert; |
16707
|
|
|
|
|
|
|
if (cur_node <= cutoff) |
16708
|
|
|
|
|
|
|
goto out; |
16709
|
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
16710
|
|
|
|
|
|
|
if (load_u32_unaligned(matchptr) == seq) { |
16711
|
|
|
|
|
|
|
len = lz_extend(in_next, matchptr, 4, max_len); |
16712
|
|
|
|
|
|
|
if (len > best_len) { |
16713
|
|
|
|
|
|
|
best_len = len; |
16714
|
|
|
|
|
|
|
best_matchptr = matchptr; |
16715
|
|
|
|
|
|
|
if (best_len >= nice_len) |
16716
|
|
|
|
|
|
|
goto out; |
16717
|
|
|
|
|
|
|
} |
16718
|
|
|
|
|
|
|
} |
16719
|
|
|
|
|
|
|
to_insert = cur_node; |
16720
|
|
|
|
|
|
|
} |
16721
|
|
|
|
|
|
|
#endif |
16722
|
|
|
|
|
|
|
out: |
16723
|
75
|
|
|
|
|
|
*offset_ret = in_next - best_matchptr; |
16724
|
75
|
|
|
|
|
|
return best_len; |
16725
|
|
|
|
|
|
|
} |
16726
|
|
|
|
|
|
|
|
16727
|
|
|
|
|
|
|
static forceinline void |
16728
|
|
|
|
|
|
|
ht_matchfinder_skip_bytes(struct ht_matchfinder * const mf, |
16729
|
|
|
|
|
|
|
const u8 ** const in_base_p, |
16730
|
|
|
|
|
|
|
const u8 *in_next, |
16731
|
|
|
|
|
|
|
const u8 * const in_end, |
16732
|
|
|
|
|
|
|
const u32 count, |
16733
|
|
|
|
|
|
|
u32 * const next_hash) |
16734
|
|
|
|
|
|
|
{ |
16735
|
21
|
|
|
|
|
|
s32 cur_pos = in_next - *in_base_p; |
16736
|
|
|
|
|
|
|
u32 hash; |
16737
|
21
|
|
|
|
|
|
u32 remaining = count; |
16738
|
|
|
|
|
|
|
int i; |
16739
|
|
|
|
|
|
|
|
16740
|
21
|
100
|
|
|
|
|
if (unlikely(count + HT_MATCHFINDER_REQUIRED_NBYTES > in_end - in_next)) |
16741
|
|
|
|
|
|
|
return; |
16742
|
|
|
|
|
|
|
|
16743
|
18
|
50
|
|
|
|
|
if (cur_pos + count - 1 >= MATCHFINDER_WINDOW_SIZE) { |
16744
|
|
|
|
|
|
|
ht_matchfinder_slide_window(mf); |
16745
|
0
|
|
|
|
|
|
*in_base_p += MATCHFINDER_WINDOW_SIZE; |
16746
|
0
|
|
|
|
|
|
cur_pos -= MATCHFINDER_WINDOW_SIZE; |
16747
|
|
|
|
|
|
|
} |
16748
|
|
|
|
|
|
|
|
16749
|
18
|
|
|
|
|
|
hash = *next_hash; |
16750
|
|
|
|
|
|
|
do { |
16751
|
9252
|
100
|
|
|
|
|
for (i = HT_MATCHFINDER_BUCKET_SIZE - 1; i > 0; i--) |
16752
|
4626
|
|
|
|
|
|
mf->hash_tab[hash][i] = mf->hash_tab[hash][i - 1]; |
16753
|
4626
|
|
|
|
|
|
mf->hash_tab[hash][0] = cur_pos; |
16754
|
|
|
|
|
|
|
|
16755
|
13878
|
|
|
|
|
|
hash = lz_hash(get_unaligned_le32(++in_next), |
16756
|
|
|
|
|
|
|
HT_MATCHFINDER_HASH_ORDER); |
16757
|
4626
|
|
|
|
|
|
cur_pos++; |
16758
|
4626
|
100
|
|
|
|
|
} while (--remaining); |
16759
|
|
|
|
|
|
|
|
16760
|
18
|
|
|
|
|
|
prefetchw(&mf->hash_tab[hash]); |
16761
|
18
|
|
|
|
|
|
*next_hash = hash; |
16762
|
|
|
|
|
|
|
} |
16763
|
|
|
|
|
|
|
|
16764
|
|
|
|
|
|
|
#endif |
16765
|
|
|
|
|
|
|
|
16766
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
16767
|
|
|
|
|
|
|
/* # include "bt_matchfinder.h" */ |
16768
|
|
|
|
|
|
|
|
16769
|
|
|
|
|
|
|
|
16770
|
|
|
|
|
|
|
#ifndef LIB_BT_MATCHFINDER_H |
16771
|
|
|
|
|
|
|
#define LIB_BT_MATCHFINDER_H |
16772
|
|
|
|
|
|
|
|
16773
|
|
|
|
|
|
|
/* #include "matchfinder_common.h" */ |
16774
|
|
|
|
|
|
|
|
16775
|
|
|
|
|
|
|
|
16776
|
|
|
|
|
|
|
#ifndef LIB_MATCHFINDER_COMMON_H |
16777
|
|
|
|
|
|
|
#define LIB_MATCHFINDER_COMMON_H |
16778
|
|
|
|
|
|
|
|
16779
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
16780
|
|
|
|
|
|
|
|
16781
|
|
|
|
|
|
|
|
16782
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
16783
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
16784
|
|
|
|
|
|
|
|
16785
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
16786
|
|
|
|
|
|
|
|
16787
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
16788
|
|
|
|
|
|
|
#endif |
16789
|
|
|
|
|
|
|
|
16790
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
16791
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
16792
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
16793
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
16794
|
|
|
|
|
|
|
#else |
16795
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
16796
|
|
|
|
|
|
|
#endif |
16797
|
|
|
|
|
|
|
|
16798
|
|
|
|
|
|
|
|
16799
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
16800
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
16801
|
|
|
|
|
|
|
#else |
16802
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
16803
|
|
|
|
|
|
|
#endif |
16804
|
|
|
|
|
|
|
|
16805
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
16806
|
|
|
|
|
|
|
|
16807
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
16808
|
|
|
|
|
|
|
|
16809
|
|
|
|
|
|
|
|
16810
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
16811
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
16812
|
|
|
|
|
|
|
|
16813
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
16814
|
|
|
|
|
|
|
|
16815
|
|
|
|
|
|
|
|
16816
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
16817
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
16818
|
|
|
|
|
|
|
|
16819
|
|
|
|
|
|
|
#include |
16820
|
|
|
|
|
|
|
#include |
16821
|
|
|
|
|
|
|
|
16822
|
|
|
|
|
|
|
#ifdef __cplusplus |
16823
|
|
|
|
|
|
|
extern "C" { |
16824
|
|
|
|
|
|
|
#endif |
16825
|
|
|
|
|
|
|
|
16826
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
16827
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
16828
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
16829
|
|
|
|
|
|
|
|
16830
|
|
|
|
|
|
|
|
16831
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
16832
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
16833
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
16834
|
|
|
|
|
|
|
# else |
16835
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
16836
|
|
|
|
|
|
|
# endif |
16837
|
|
|
|
|
|
|
#endif |
16838
|
|
|
|
|
|
|
|
16839
|
|
|
|
|
|
|
|
16840
|
|
|
|
|
|
|
|
16841
|
|
|
|
|
|
|
|
16842
|
|
|
|
|
|
|
|
16843
|
|
|
|
|
|
|
struct libdeflate_compressor; |
16844
|
|
|
|
|
|
|
|
16845
|
|
|
|
|
|
|
|
16846
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
16847
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
16848
|
|
|
|
|
|
|
|
16849
|
|
|
|
|
|
|
|
16850
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
16851
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
16852
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16853
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
16854
|
|
|
|
|
|
|
|
16855
|
|
|
|
|
|
|
|
16856
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
16857
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
16858
|
|
|
|
|
|
|
size_t in_nbytes); |
16859
|
|
|
|
|
|
|
|
16860
|
|
|
|
|
|
|
|
16861
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
16862
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
16863
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16864
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
16865
|
|
|
|
|
|
|
|
16866
|
|
|
|
|
|
|
|
16867
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
16868
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
16869
|
|
|
|
|
|
|
size_t in_nbytes); |
16870
|
|
|
|
|
|
|
|
16871
|
|
|
|
|
|
|
|
16872
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
16873
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
16874
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16875
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
16876
|
|
|
|
|
|
|
|
16877
|
|
|
|
|
|
|
|
16878
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
16879
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
16880
|
|
|
|
|
|
|
size_t in_nbytes); |
16881
|
|
|
|
|
|
|
|
16882
|
|
|
|
|
|
|
|
16883
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
16884
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
16885
|
|
|
|
|
|
|
|
16886
|
|
|
|
|
|
|
|
16887
|
|
|
|
|
|
|
|
16888
|
|
|
|
|
|
|
|
16889
|
|
|
|
|
|
|
|
16890
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
16891
|
|
|
|
|
|
|
|
16892
|
|
|
|
|
|
|
|
16893
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
16894
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
16895
|
|
|
|
|
|
|
|
16896
|
|
|
|
|
|
|
|
16897
|
|
|
|
|
|
|
enum libdeflate_result { |
16898
|
|
|
|
|
|
|
|
16899
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
16900
|
|
|
|
|
|
|
|
16901
|
|
|
|
|
|
|
|
16902
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
16903
|
|
|
|
|
|
|
|
16904
|
|
|
|
|
|
|
|
16905
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
16906
|
|
|
|
|
|
|
|
16907
|
|
|
|
|
|
|
|
16908
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
16909
|
|
|
|
|
|
|
}; |
16910
|
|
|
|
|
|
|
|
16911
|
|
|
|
|
|
|
|
16912
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
16913
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
16914
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16915
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
16916
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
16917
|
|
|
|
|
|
|
|
16918
|
|
|
|
|
|
|
|
16919
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
16920
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
16921
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16922
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
16923
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
16924
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
16925
|
|
|
|
|
|
|
|
16926
|
|
|
|
|
|
|
|
16927
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
16928
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
16929
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16930
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
16931
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
16932
|
|
|
|
|
|
|
|
16933
|
|
|
|
|
|
|
|
16934
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
16935
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
16936
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16937
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
16938
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
16939
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
16940
|
|
|
|
|
|
|
|
16941
|
|
|
|
|
|
|
|
16942
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
16943
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
16944
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16945
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
16946
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
16947
|
|
|
|
|
|
|
|
16948
|
|
|
|
|
|
|
|
16949
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
16950
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
16951
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
16952
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
16953
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
16954
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
16955
|
|
|
|
|
|
|
|
16956
|
|
|
|
|
|
|
|
16957
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
16958
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
16959
|
|
|
|
|
|
|
|
16960
|
|
|
|
|
|
|
|
16961
|
|
|
|
|
|
|
|
16962
|
|
|
|
|
|
|
|
16963
|
|
|
|
|
|
|
|
16964
|
|
|
|
|
|
|
|
16965
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
16966
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
16967
|
|
|
|
|
|
|
|
16968
|
|
|
|
|
|
|
|
16969
|
|
|
|
|
|
|
|
16970
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
16971
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
16972
|
|
|
|
|
|
|
|
16973
|
|
|
|
|
|
|
|
16974
|
|
|
|
|
|
|
|
16975
|
|
|
|
|
|
|
|
16976
|
|
|
|
|
|
|
|
16977
|
|
|
|
|
|
|
|
16978
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
16979
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
16980
|
|
|
|
|
|
|
void (*free_func)(void *)); |
16981
|
|
|
|
|
|
|
|
16982
|
|
|
|
|
|
|
#ifdef __cplusplus |
16983
|
|
|
|
|
|
|
} |
16984
|
|
|
|
|
|
|
#endif |
16985
|
|
|
|
|
|
|
|
16986
|
|
|
|
|
|
|
#endif |
16987
|
|
|
|
|
|
|
|
16988
|
|
|
|
|
|
|
|
16989
|
|
|
|
|
|
|
#include |
16990
|
|
|
|
|
|
|
#include |
16991
|
|
|
|
|
|
|
#include |
16992
|
|
|
|
|
|
|
#ifdef _MSC_VER |
16993
|
|
|
|
|
|
|
# include |
16994
|
|
|
|
|
|
|
# include |
16995
|
|
|
|
|
|
|
|
16996
|
|
|
|
|
|
|
|
16997
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
16998
|
|
|
|
|
|
|
|
16999
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
17000
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
17001
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
17002
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
17003
|
|
|
|
|
|
|
|
17004
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
17005
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
17006
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
17007
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
17008
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
17009
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
17010
|
|
|
|
|
|
|
#endif |
17011
|
|
|
|
|
|
|
#ifndef FREESTANDING |
17012
|
|
|
|
|
|
|
# include |
17013
|
|
|
|
|
|
|
#endif |
17014
|
|
|
|
|
|
|
|
17015
|
|
|
|
|
|
|
|
17016
|
|
|
|
|
|
|
|
17017
|
|
|
|
|
|
|
|
17018
|
|
|
|
|
|
|
|
17019
|
|
|
|
|
|
|
|
17020
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
17021
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
17022
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
17023
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
17024
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17025
|
|
|
|
|
|
|
# if defined(_M_X64) |
17026
|
|
|
|
|
|
|
# define ARCH_X86_64 |
17027
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
17028
|
|
|
|
|
|
|
# define ARCH_X86_32 |
17029
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
17030
|
|
|
|
|
|
|
# define ARCH_ARM64 |
17031
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
17032
|
|
|
|
|
|
|
# define ARCH_ARM32 |
17033
|
|
|
|
|
|
|
# endif |
17034
|
|
|
|
|
|
|
#else |
17035
|
|
|
|
|
|
|
# if defined(__x86_64__) |
17036
|
|
|
|
|
|
|
# define ARCH_X86_64 |
17037
|
|
|
|
|
|
|
# elif defined(__i386__) |
17038
|
|
|
|
|
|
|
# define ARCH_X86_32 |
17039
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
17040
|
|
|
|
|
|
|
# define ARCH_ARM64 |
17041
|
|
|
|
|
|
|
# elif defined(__arm__) |
17042
|
|
|
|
|
|
|
# define ARCH_ARM32 |
17043
|
|
|
|
|
|
|
# endif |
17044
|
|
|
|
|
|
|
#endif |
17045
|
|
|
|
|
|
|
|
17046
|
|
|
|
|
|
|
|
17047
|
|
|
|
|
|
|
|
17048
|
|
|
|
|
|
|
|
17049
|
|
|
|
|
|
|
|
17050
|
|
|
|
|
|
|
|
17051
|
|
|
|
|
|
|
typedef uint8_t u8; |
17052
|
|
|
|
|
|
|
typedef uint16_t u16; |
17053
|
|
|
|
|
|
|
typedef uint32_t u32; |
17054
|
|
|
|
|
|
|
typedef uint64_t u64; |
17055
|
|
|
|
|
|
|
typedef int8_t s8; |
17056
|
|
|
|
|
|
|
typedef int16_t s16; |
17057
|
|
|
|
|
|
|
typedef int32_t s32; |
17058
|
|
|
|
|
|
|
typedef int64_t s64; |
17059
|
|
|
|
|
|
|
|
17060
|
|
|
|
|
|
|
|
17061
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17062
|
|
|
|
|
|
|
# ifdef _WIN64 |
17063
|
|
|
|
|
|
|
typedef long long ssize_t; |
17064
|
|
|
|
|
|
|
# else |
17065
|
|
|
|
|
|
|
typedef long ssize_t; |
17066
|
|
|
|
|
|
|
# endif |
17067
|
|
|
|
|
|
|
#endif |
17068
|
|
|
|
|
|
|
|
17069
|
|
|
|
|
|
|
|
17070
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
17071
|
|
|
|
|
|
|
|
17072
|
|
|
|
|
|
|
|
17073
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
17074
|
|
|
|
|
|
|
|
17075
|
|
|
|
|
|
|
|
17076
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
17077
|
|
|
|
|
|
|
|
17078
|
|
|
|
|
|
|
|
17079
|
|
|
|
|
|
|
|
17080
|
|
|
|
|
|
|
|
17081
|
|
|
|
|
|
|
|
17082
|
|
|
|
|
|
|
|
17083
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
17084
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
17085
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
17086
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
17087
|
|
|
|
|
|
|
#else |
17088
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
17089
|
|
|
|
|
|
|
#endif |
17090
|
|
|
|
|
|
|
#ifdef __clang__ |
17091
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
17092
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
17093
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
17094
|
|
|
|
|
|
|
# else |
17095
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
17096
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
17097
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
17098
|
|
|
|
|
|
|
# endif |
17099
|
|
|
|
|
|
|
#else |
17100
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
17101
|
|
|
|
|
|
|
#endif |
17102
|
|
|
|
|
|
|
|
17103
|
|
|
|
|
|
|
|
17104
|
|
|
|
|
|
|
#ifndef __has_attribute |
17105
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
17106
|
|
|
|
|
|
|
#endif |
17107
|
|
|
|
|
|
|
#ifndef __has_builtin |
17108
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
17109
|
|
|
|
|
|
|
#endif |
17110
|
|
|
|
|
|
|
|
17111
|
|
|
|
|
|
|
|
17112
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17113
|
|
|
|
|
|
|
# define inline __inline |
17114
|
|
|
|
|
|
|
#endif |
17115
|
|
|
|
|
|
|
|
17116
|
|
|
|
|
|
|
|
17117
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
17118
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
17119
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17120
|
|
|
|
|
|
|
# define forceinline __forceinline |
17121
|
|
|
|
|
|
|
#else |
17122
|
|
|
|
|
|
|
# define forceinline inline |
17123
|
|
|
|
|
|
|
#endif |
17124
|
|
|
|
|
|
|
|
17125
|
|
|
|
|
|
|
|
17126
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
17127
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
17128
|
|
|
|
|
|
|
#else |
17129
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
17130
|
|
|
|
|
|
|
#endif |
17131
|
|
|
|
|
|
|
|
17132
|
|
|
|
|
|
|
|
17133
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
17134
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
17135
|
|
|
|
|
|
|
# define restrict __restrict__ |
17136
|
|
|
|
|
|
|
# else |
17137
|
|
|
|
|
|
|
# define restrict |
17138
|
|
|
|
|
|
|
# endif |
17139
|
|
|
|
|
|
|
#endif |
17140
|
|
|
|
|
|
|
|
17141
|
|
|
|
|
|
|
|
17142
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
17143
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
17144
|
|
|
|
|
|
|
#else |
17145
|
|
|
|
|
|
|
# define likely(expr) (expr) |
17146
|
|
|
|
|
|
|
#endif |
17147
|
|
|
|
|
|
|
|
17148
|
|
|
|
|
|
|
|
17149
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
17150
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
17151
|
|
|
|
|
|
|
#else |
17152
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
17153
|
|
|
|
|
|
|
#endif |
17154
|
|
|
|
|
|
|
|
17155
|
|
|
|
|
|
|
|
17156
|
|
|
|
|
|
|
#undef prefetchr |
17157
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
17158
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
17159
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17160
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
17161
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
17162
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
17163
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
17164
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
17165
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
17166
|
|
|
|
|
|
|
# endif |
17167
|
|
|
|
|
|
|
#endif |
17168
|
|
|
|
|
|
|
#ifndef prefetchr |
17169
|
|
|
|
|
|
|
# define prefetchr(addr) |
17170
|
|
|
|
|
|
|
#endif |
17171
|
|
|
|
|
|
|
|
17172
|
|
|
|
|
|
|
|
17173
|
|
|
|
|
|
|
#undef prefetchw |
17174
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
17175
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
17176
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17177
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
17178
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
17179
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
17180
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
17181
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
17182
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
17183
|
|
|
|
|
|
|
# endif |
17184
|
|
|
|
|
|
|
#endif |
17185
|
|
|
|
|
|
|
#ifndef prefetchw |
17186
|
|
|
|
|
|
|
# define prefetchw(addr) |
17187
|
|
|
|
|
|
|
#endif |
17188
|
|
|
|
|
|
|
|
17189
|
|
|
|
|
|
|
|
17190
|
|
|
|
|
|
|
#undef _aligned_attribute |
17191
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
17192
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
17193
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17194
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
17195
|
|
|
|
|
|
|
#endif |
17196
|
|
|
|
|
|
|
|
17197
|
|
|
|
|
|
|
|
17198
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
17199
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
17200
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
17201
|
|
|
|
|
|
|
#else |
17202
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
17203
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
17204
|
|
|
|
|
|
|
#endif |
17205
|
|
|
|
|
|
|
|
17206
|
|
|
|
|
|
|
|
17207
|
|
|
|
|
|
|
|
17208
|
|
|
|
|
|
|
|
17209
|
|
|
|
|
|
|
|
17210
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
17211
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
17212
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
17213
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
17214
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
17215
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
17216
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
17217
|
|
|
|
|
|
|
|
17218
|
|
|
|
|
|
|
|
17219
|
|
|
|
|
|
|
|
17220
|
|
|
|
|
|
|
|
17221
|
|
|
|
|
|
|
|
17222
|
|
|
|
|
|
|
|
17223
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
17224
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
17225
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17226
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
17227
|
|
|
|
|
|
|
#else |
17228
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
17229
|
|
|
|
|
|
|
{ |
17230
|
|
|
|
|
|
|
union { |
17231
|
|
|
|
|
|
|
u32 w; |
17232
|
|
|
|
|
|
|
u8 b; |
17233
|
|
|
|
|
|
|
} u; |
17234
|
|
|
|
|
|
|
|
17235
|
|
|
|
|
|
|
u.w = 1; |
17236
|
|
|
|
|
|
|
return u.b; |
17237
|
|
|
|
|
|
|
} |
17238
|
|
|
|
|
|
|
#endif |
17239
|
|
|
|
|
|
|
|
17240
|
|
|
|
|
|
|
|
17241
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
17242
|
|
|
|
|
|
|
{ |
17243
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
17244
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
17245
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17246
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
17247
|
|
|
|
|
|
|
#else |
17248
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
17249
|
|
|
|
|
|
|
#endif |
17250
|
|
|
|
|
|
|
} |
17251
|
|
|
|
|
|
|
|
17252
|
|
|
|
|
|
|
|
17253
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
17254
|
|
|
|
|
|
|
{ |
17255
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
17256
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
17257
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17258
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
17259
|
|
|
|
|
|
|
#else |
17260
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
17261
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
17262
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
17263
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
17264
|
|
|
|
|
|
|
#endif |
17265
|
|
|
|
|
|
|
} |
17266
|
|
|
|
|
|
|
|
17267
|
|
|
|
|
|
|
|
17268
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
17269
|
|
|
|
|
|
|
{ |
17270
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
17271
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
17272
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17273
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
17274
|
|
|
|
|
|
|
#else |
17275
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
17276
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
17277
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
17278
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
17279
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
17280
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
17281
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
17282
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
17283
|
|
|
|
|
|
|
#endif |
17284
|
|
|
|
|
|
|
} |
17285
|
|
|
|
|
|
|
|
17286
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
17287
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
17288
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
17289
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
17290
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
17291
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
17292
|
|
|
|
|
|
|
|
17293
|
|
|
|
|
|
|
|
17294
|
|
|
|
|
|
|
|
17295
|
|
|
|
|
|
|
|
17296
|
|
|
|
|
|
|
|
17297
|
|
|
|
|
|
|
|
17298
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
17299
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
17300
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
17301
|
|
|
|
|
|
|
defined(__wasm__)) |
17302
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
17303
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17304
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
17305
|
|
|
|
|
|
|
#else |
17306
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
17307
|
|
|
|
|
|
|
#endif |
17308
|
|
|
|
|
|
|
|
17309
|
|
|
|
|
|
|
|
17310
|
|
|
|
|
|
|
|
17311
|
|
|
|
|
|
|
#ifdef FREESTANDING |
17312
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
17313
|
|
|
|
|
|
|
#else |
17314
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
17315
|
|
|
|
|
|
|
#endif |
17316
|
|
|
|
|
|
|
|
17317
|
|
|
|
|
|
|
|
17318
|
|
|
|
|
|
|
|
17319
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
17320
|
|
|
|
|
|
|
static forceinline type \ |
17321
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
17322
|
|
|
|
|
|
|
{ \ |
17323
|
|
|
|
|
|
|
type v; \ |
17324
|
|
|
|
|
|
|
\ |
17325
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
17326
|
|
|
|
|
|
|
return v; \ |
17327
|
|
|
|
|
|
|
} \ |
17328
|
|
|
|
|
|
|
\ |
17329
|
|
|
|
|
|
|
static forceinline void \ |
17330
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
17331
|
|
|
|
|
|
|
{ \ |
17332
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
17333
|
|
|
|
|
|
|
} |
17334
|
|
|
|
|
|
|
|
17335
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
17336
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
17337
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
17338
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
17339
|
|
|
|
|
|
|
|
17340
|
|
|
|
|
|
|
#undef MEMCOPY |
17341
|
|
|
|
|
|
|
|
17342
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
17343
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
17344
|
|
|
|
|
|
|
|
17345
|
|
|
|
|
|
|
|
17346
|
|
|
|
|
|
|
|
17347
|
|
|
|
|
|
|
static forceinline u16 |
17348
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
17349
|
|
|
|
|
|
|
{ |
17350
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17351
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
17352
|
|
|
|
|
|
|
else |
17353
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
17354
|
|
|
|
|
|
|
} |
17355
|
|
|
|
|
|
|
|
17356
|
|
|
|
|
|
|
static forceinline u16 |
17357
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
17358
|
|
|
|
|
|
|
{ |
17359
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17360
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
17361
|
|
|
|
|
|
|
else |
17362
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
17363
|
|
|
|
|
|
|
} |
17364
|
|
|
|
|
|
|
|
17365
|
|
|
|
|
|
|
static forceinline u32 |
17366
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
17367
|
|
|
|
|
|
|
{ |
17368
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17369
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
17370
|
|
|
|
|
|
|
else |
17371
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
17372
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
17373
|
|
|
|
|
|
|
} |
17374
|
|
|
|
|
|
|
|
17375
|
|
|
|
|
|
|
static forceinline u32 |
17376
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
17377
|
|
|
|
|
|
|
{ |
17378
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17379
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
17380
|
|
|
|
|
|
|
else |
17381
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
17382
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
17383
|
|
|
|
|
|
|
} |
17384
|
|
|
|
|
|
|
|
17385
|
|
|
|
|
|
|
static forceinline u64 |
17386
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
17387
|
|
|
|
|
|
|
{ |
17388
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
17389
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
17390
|
|
|
|
|
|
|
else |
17391
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
17392
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
17393
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
17394
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
17395
|
|
|
|
|
|
|
} |
17396
|
|
|
|
|
|
|
|
17397
|
|
|
|
|
|
|
static forceinline machine_word_t |
17398
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
17399
|
|
|
|
|
|
|
{ |
17400
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
17401
|
|
|
|
|
|
|
if (WORDBITS == 32) |
17402
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
17403
|
|
|
|
|
|
|
else |
17404
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
17405
|
|
|
|
|
|
|
} |
17406
|
|
|
|
|
|
|
|
17407
|
|
|
|
|
|
|
|
17408
|
|
|
|
|
|
|
|
17409
|
|
|
|
|
|
|
static forceinline void |
17410
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
17411
|
|
|
|
|
|
|
{ |
17412
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17413
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
17414
|
|
|
|
|
|
|
} else { |
17415
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
17416
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
17417
|
|
|
|
|
|
|
} |
17418
|
|
|
|
|
|
|
} |
17419
|
|
|
|
|
|
|
|
17420
|
|
|
|
|
|
|
static forceinline void |
17421
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
17422
|
|
|
|
|
|
|
{ |
17423
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17424
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
17425
|
|
|
|
|
|
|
} else { |
17426
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
17427
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
17428
|
|
|
|
|
|
|
} |
17429
|
|
|
|
|
|
|
} |
17430
|
|
|
|
|
|
|
|
17431
|
|
|
|
|
|
|
static forceinline void |
17432
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
17433
|
|
|
|
|
|
|
{ |
17434
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17435
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
17436
|
|
|
|
|
|
|
} else { |
17437
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
17438
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
17439
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
17440
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
17441
|
|
|
|
|
|
|
} |
17442
|
|
|
|
|
|
|
} |
17443
|
|
|
|
|
|
|
|
17444
|
|
|
|
|
|
|
static forceinline void |
17445
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
17446
|
|
|
|
|
|
|
{ |
17447
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17448
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
17449
|
|
|
|
|
|
|
} else { |
17450
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
17451
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
17452
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
17453
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
17454
|
|
|
|
|
|
|
} |
17455
|
|
|
|
|
|
|
} |
17456
|
|
|
|
|
|
|
|
17457
|
|
|
|
|
|
|
static forceinline void |
17458
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
17459
|
|
|
|
|
|
|
{ |
17460
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
17461
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
17462
|
|
|
|
|
|
|
} else { |
17463
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
17464
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
17465
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
17466
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
17467
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
17468
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
17469
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
17470
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
17471
|
|
|
|
|
|
|
} |
17472
|
|
|
|
|
|
|
} |
17473
|
|
|
|
|
|
|
|
17474
|
|
|
|
|
|
|
static forceinline void |
17475
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
17476
|
|
|
|
|
|
|
{ |
17477
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
17478
|
|
|
|
|
|
|
if (WORDBITS == 32) |
17479
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
17480
|
|
|
|
|
|
|
else |
17481
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
17482
|
|
|
|
|
|
|
} |
17483
|
|
|
|
|
|
|
|
17484
|
|
|
|
|
|
|
|
17485
|
|
|
|
|
|
|
|
17486
|
|
|
|
|
|
|
|
17487
|
|
|
|
|
|
|
|
17488
|
|
|
|
|
|
|
|
17489
|
|
|
|
|
|
|
|
17490
|
|
|
|
|
|
|
static forceinline unsigned |
17491
|
|
|
|
|
|
|
bsr32(u32 v) |
17492
|
|
|
|
|
|
|
{ |
17493
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
17494
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
17495
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17496
|
|
|
|
|
|
|
unsigned long i; |
17497
|
|
|
|
|
|
|
|
17498
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
17499
|
|
|
|
|
|
|
return i; |
17500
|
|
|
|
|
|
|
#else |
17501
|
|
|
|
|
|
|
unsigned i = 0; |
17502
|
|
|
|
|
|
|
|
17503
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
17504
|
|
|
|
|
|
|
i++; |
17505
|
|
|
|
|
|
|
return i; |
17506
|
|
|
|
|
|
|
#endif |
17507
|
|
|
|
|
|
|
} |
17508
|
|
|
|
|
|
|
|
17509
|
|
|
|
|
|
|
static forceinline unsigned |
17510
|
|
|
|
|
|
|
bsr64(u64 v) |
17511
|
|
|
|
|
|
|
{ |
17512
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
17513
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
17514
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
17515
|
|
|
|
|
|
|
unsigned long i; |
17516
|
|
|
|
|
|
|
|
17517
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
17518
|
|
|
|
|
|
|
return i; |
17519
|
|
|
|
|
|
|
#else |
17520
|
|
|
|
|
|
|
unsigned i = 0; |
17521
|
|
|
|
|
|
|
|
17522
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
17523
|
|
|
|
|
|
|
i++; |
17524
|
|
|
|
|
|
|
return i; |
17525
|
|
|
|
|
|
|
#endif |
17526
|
|
|
|
|
|
|
} |
17527
|
|
|
|
|
|
|
|
17528
|
|
|
|
|
|
|
static forceinline unsigned |
17529
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
17530
|
|
|
|
|
|
|
{ |
17531
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
17532
|
|
|
|
|
|
|
if (WORDBITS == 32) |
17533
|
|
|
|
|
|
|
return bsr32(v); |
17534
|
|
|
|
|
|
|
else |
17535
|
|
|
|
|
|
|
return bsr64(v); |
17536
|
|
|
|
|
|
|
} |
17537
|
|
|
|
|
|
|
|
17538
|
|
|
|
|
|
|
|
17539
|
|
|
|
|
|
|
|
17540
|
|
|
|
|
|
|
static forceinline unsigned |
17541
|
|
|
|
|
|
|
bsf32(u32 v) |
17542
|
|
|
|
|
|
|
{ |
17543
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
17544
|
|
|
|
|
|
|
return __builtin_ctz(v); |
17545
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
17546
|
|
|
|
|
|
|
unsigned long i; |
17547
|
|
|
|
|
|
|
|
17548
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
17549
|
|
|
|
|
|
|
return i; |
17550
|
|
|
|
|
|
|
#else |
17551
|
|
|
|
|
|
|
unsigned i = 0; |
17552
|
|
|
|
|
|
|
|
17553
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
17554
|
|
|
|
|
|
|
i++; |
17555
|
|
|
|
|
|
|
return i; |
17556
|
|
|
|
|
|
|
#endif |
17557
|
|
|
|
|
|
|
} |
17558
|
|
|
|
|
|
|
|
17559
|
|
|
|
|
|
|
static forceinline unsigned |
17560
|
|
|
|
|
|
|
bsf64(u64 v) |
17561
|
|
|
|
|
|
|
{ |
17562
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
17563
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
17564
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
17565
|
|
|
|
|
|
|
unsigned long i; |
17566
|
|
|
|
|
|
|
|
17567
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
17568
|
|
|
|
|
|
|
return i; |
17569
|
|
|
|
|
|
|
#else |
17570
|
|
|
|
|
|
|
unsigned i = 0; |
17571
|
|
|
|
|
|
|
|
17572
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
17573
|
|
|
|
|
|
|
i++; |
17574
|
|
|
|
|
|
|
return i; |
17575
|
|
|
|
|
|
|
#endif |
17576
|
|
|
|
|
|
|
} |
17577
|
|
|
|
|
|
|
|
17578
|
|
|
|
|
|
|
static forceinline unsigned |
17579
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
17580
|
|
|
|
|
|
|
{ |
17581
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
17582
|
|
|
|
|
|
|
if (WORDBITS == 32) |
17583
|
|
|
|
|
|
|
return bsf32(v); |
17584
|
|
|
|
|
|
|
else |
17585
|
|
|
|
|
|
|
return bsf64(v); |
17586
|
|
|
|
|
|
|
} |
17587
|
|
|
|
|
|
|
|
17588
|
|
|
|
|
|
|
|
17589
|
|
|
|
|
|
|
#undef rbit32 |
17590
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
17591
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
17592
|
|
|
|
|
|
|
static forceinline u32 |
17593
|
|
|
|
|
|
|
rbit32(u32 v) |
17594
|
|
|
|
|
|
|
{ |
17595
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
17596
|
|
|
|
|
|
|
return v; |
17597
|
|
|
|
|
|
|
} |
17598
|
|
|
|
|
|
|
#define rbit32 rbit32 |
17599
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
17600
|
|
|
|
|
|
|
static forceinline u32 |
17601
|
|
|
|
|
|
|
rbit32(u32 v) |
17602
|
|
|
|
|
|
|
{ |
17603
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
17604
|
|
|
|
|
|
|
return v; |
17605
|
|
|
|
|
|
|
} |
17606
|
|
|
|
|
|
|
#define rbit32 rbit32 |
17607
|
|
|
|
|
|
|
#endif |
17608
|
|
|
|
|
|
|
|
17609
|
|
|
|
|
|
|
#endif |
17610
|
|
|
|
|
|
|
|
17611
|
|
|
|
|
|
|
|
17612
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
17613
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
17614
|
|
|
|
|
|
|
|
17615
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
17616
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
17617
|
|
|
|
|
|
|
|
17618
|
|
|
|
|
|
|
#ifdef FREESTANDING |
17619
|
|
|
|
|
|
|
|
17620
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
17621
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
17622
|
|
|
|
|
|
|
|
17623
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
17624
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
17625
|
|
|
|
|
|
|
|
17626
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
17627
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
17628
|
|
|
|
|
|
|
|
17629
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
17630
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
17631
|
|
|
|
|
|
|
|
17632
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
17633
|
|
|
|
|
|
|
#else |
17634
|
|
|
|
|
|
|
#include |
17635
|
|
|
|
|
|
|
#endif |
17636
|
|
|
|
|
|
|
|
17637
|
|
|
|
|
|
|
|
17638
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
17639
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
17640
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
17641
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
17642
|
|
|
|
|
|
|
#else |
17643
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
17644
|
|
|
|
|
|
|
#endif |
17645
|
|
|
|
|
|
|
|
17646
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
17647
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
17648
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
17649
|
|
|
|
|
|
|
|
17650
|
|
|
|
|
|
|
#endif |
17651
|
|
|
|
|
|
|
|
17652
|
|
|
|
|
|
|
|
17653
|
|
|
|
|
|
|
#ifndef MATCHFINDER_WINDOW_ORDER |
17654
|
|
|
|
|
|
|
# error "MATCHFINDER_WINDOW_ORDER must be defined!" |
17655
|
|
|
|
|
|
|
#endif |
17656
|
|
|
|
|
|
|
|
17657
|
|
|
|
|
|
|
|
17658
|
|
|
|
|
|
|
static forceinline u32 |
17659
|
|
|
|
|
|
|
loaded_u32_to_u24(u32 v) |
17660
|
|
|
|
|
|
|
{ |
17661
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
17662
|
|
|
|
|
|
|
return v & 0xFFFFFF; |
17663
|
|
|
|
|
|
|
else |
17664
|
|
|
|
|
|
|
return v >> 8; |
17665
|
|
|
|
|
|
|
} |
17666
|
|
|
|
|
|
|
|
17667
|
|
|
|
|
|
|
|
17668
|
|
|
|
|
|
|
static forceinline u32 |
17669
|
|
|
|
|
|
|
load_u24_unaligned(const u8 *p) |
17670
|
|
|
|
|
|
|
{ |
17671
|
|
|
|
|
|
|
#if UNALIGNED_ACCESS_IS_FAST |
17672
|
|
|
|
|
|
|
return loaded_u32_to_u24(load_u32_unaligned(p)); |
17673
|
|
|
|
|
|
|
#else |
17674
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
17675
|
|
|
|
|
|
|
return ((u32)p[0] << 0) | ((u32)p[1] << 8) | ((u32)p[2] << 16); |
17676
|
|
|
|
|
|
|
else |
17677
|
|
|
|
|
|
|
return ((u32)p[2] << 0) | ((u32)p[1] << 8) | ((u32)p[0] << 16); |
17678
|
|
|
|
|
|
|
#endif |
17679
|
|
|
|
|
|
|
} |
17680
|
|
|
|
|
|
|
|
17681
|
|
|
|
|
|
|
#define MATCHFINDER_WINDOW_SIZE (1UL << MATCHFINDER_WINDOW_ORDER) |
17682
|
|
|
|
|
|
|
|
17683
|
|
|
|
|
|
|
typedef s16 mf_pos_t; |
17684
|
|
|
|
|
|
|
|
17685
|
|
|
|
|
|
|
#define MATCHFINDER_INITVAL ((mf_pos_t)-MATCHFINDER_WINDOW_SIZE) |
17686
|
|
|
|
|
|
|
|
17687
|
|
|
|
|
|
|
|
17688
|
|
|
|
|
|
|
#define MATCHFINDER_MEM_ALIGNMENT 32 |
17689
|
|
|
|
|
|
|
#define MATCHFINDER_SIZE_ALIGNMENT 128 |
17690
|
|
|
|
|
|
|
|
17691
|
|
|
|
|
|
|
#undef matchfinder_init |
17692
|
|
|
|
|
|
|
#undef matchfinder_rebase |
17693
|
|
|
|
|
|
|
#ifdef _aligned_attribute |
17694
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED _aligned_attribute(MATCHFINDER_MEM_ALIGNMENT) |
17695
|
|
|
|
|
|
|
# if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
17696
|
|
|
|
|
|
|
/* # include "arm/matchfinder_impl.h" */ |
17697
|
|
|
|
|
|
|
|
17698
|
|
|
|
|
|
|
|
17699
|
|
|
|
|
|
|
#ifndef LIB_ARM_MATCHFINDER_IMPL_H |
17700
|
|
|
|
|
|
|
#define LIB_ARM_MATCHFINDER_IMPL_H |
17701
|
|
|
|
|
|
|
|
17702
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
17703
|
|
|
|
|
|
|
|
17704
|
|
|
|
|
|
|
|
17705
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
17706
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
17707
|
|
|
|
|
|
|
|
17708
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
17709
|
|
|
|
|
|
|
|
17710
|
|
|
|
|
|
|
|
17711
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
17712
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
17713
|
|
|
|
|
|
|
|
17714
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
17715
|
|
|
|
|
|
|
|
17716
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
17717
|
|
|
|
|
|
|
#endif |
17718
|
|
|
|
|
|
|
|
17719
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
17720
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
17721
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
17722
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
17723
|
|
|
|
|
|
|
#else |
17724
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
17725
|
|
|
|
|
|
|
#endif |
17726
|
|
|
|
|
|
|
|
17727
|
|
|
|
|
|
|
|
17728
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
17729
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
17730
|
|
|
|
|
|
|
#else |
17731
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
17732
|
|
|
|
|
|
|
#endif |
17733
|
|
|
|
|
|
|
|
17734
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
17735
|
|
|
|
|
|
|
|
17736
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
17737
|
|
|
|
|
|
|
|
17738
|
|
|
|
|
|
|
|
17739
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
17740
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
17741
|
|
|
|
|
|
|
|
17742
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
17743
|
|
|
|
|
|
|
|
17744
|
|
|
|
|
|
|
|
17745
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
17746
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
17747
|
|
|
|
|
|
|
|
17748
|
|
|
|
|
|
|
#include |
17749
|
|
|
|
|
|
|
#include |
17750
|
|
|
|
|
|
|
|
17751
|
|
|
|
|
|
|
#ifdef __cplusplus |
17752
|
|
|
|
|
|
|
extern "C" { |
17753
|
|
|
|
|
|
|
#endif |
17754
|
|
|
|
|
|
|
|
17755
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
17756
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
17757
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
17758
|
|
|
|
|
|
|
|
17759
|
|
|
|
|
|
|
|
17760
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
17761
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
17762
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
17763
|
|
|
|
|
|
|
# else |
17764
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
17765
|
|
|
|
|
|
|
# endif |
17766
|
|
|
|
|
|
|
#endif |
17767
|
|
|
|
|
|
|
|
17768
|
|
|
|
|
|
|
|
17769
|
|
|
|
|
|
|
|
17770
|
|
|
|
|
|
|
|
17771
|
|
|
|
|
|
|
|
17772
|
|
|
|
|
|
|
struct libdeflate_compressor; |
17773
|
|
|
|
|
|
|
|
17774
|
|
|
|
|
|
|
|
17775
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
17776
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
17777
|
|
|
|
|
|
|
|
17778
|
|
|
|
|
|
|
|
17779
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17780
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
17781
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17782
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
17783
|
|
|
|
|
|
|
|
17784
|
|
|
|
|
|
|
|
17785
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17786
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
17787
|
|
|
|
|
|
|
size_t in_nbytes); |
17788
|
|
|
|
|
|
|
|
17789
|
|
|
|
|
|
|
|
17790
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17791
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
17792
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17793
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
17794
|
|
|
|
|
|
|
|
17795
|
|
|
|
|
|
|
|
17796
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17797
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
17798
|
|
|
|
|
|
|
size_t in_nbytes); |
17799
|
|
|
|
|
|
|
|
17800
|
|
|
|
|
|
|
|
17801
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17802
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
17803
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17804
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
17805
|
|
|
|
|
|
|
|
17806
|
|
|
|
|
|
|
|
17807
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
17808
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
17809
|
|
|
|
|
|
|
size_t in_nbytes); |
17810
|
|
|
|
|
|
|
|
17811
|
|
|
|
|
|
|
|
17812
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
17813
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
17814
|
|
|
|
|
|
|
|
17815
|
|
|
|
|
|
|
|
17816
|
|
|
|
|
|
|
|
17817
|
|
|
|
|
|
|
|
17818
|
|
|
|
|
|
|
|
17819
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
17820
|
|
|
|
|
|
|
|
17821
|
|
|
|
|
|
|
|
17822
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
17823
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
17824
|
|
|
|
|
|
|
|
17825
|
|
|
|
|
|
|
|
17826
|
|
|
|
|
|
|
enum libdeflate_result { |
17827
|
|
|
|
|
|
|
|
17828
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
17829
|
|
|
|
|
|
|
|
17830
|
|
|
|
|
|
|
|
17831
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
17832
|
|
|
|
|
|
|
|
17833
|
|
|
|
|
|
|
|
17834
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
17835
|
|
|
|
|
|
|
|
17836
|
|
|
|
|
|
|
|
17837
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
17838
|
|
|
|
|
|
|
}; |
17839
|
|
|
|
|
|
|
|
17840
|
|
|
|
|
|
|
|
17841
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17842
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
17843
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17844
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17845
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17846
|
|
|
|
|
|
|
|
17847
|
|
|
|
|
|
|
|
17848
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17849
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
17850
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17851
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17852
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
17853
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17854
|
|
|
|
|
|
|
|
17855
|
|
|
|
|
|
|
|
17856
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17857
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
17858
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17859
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17860
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17861
|
|
|
|
|
|
|
|
17862
|
|
|
|
|
|
|
|
17863
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17864
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
17865
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17866
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17867
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
17868
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17869
|
|
|
|
|
|
|
|
17870
|
|
|
|
|
|
|
|
17871
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17872
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
17873
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17874
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17875
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17876
|
|
|
|
|
|
|
|
17877
|
|
|
|
|
|
|
|
17878
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
17879
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
17880
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
17881
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
17882
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
17883
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
17884
|
|
|
|
|
|
|
|
17885
|
|
|
|
|
|
|
|
17886
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
17887
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
17888
|
|
|
|
|
|
|
|
17889
|
|
|
|
|
|
|
|
17890
|
|
|
|
|
|
|
|
17891
|
|
|
|
|
|
|
|
17892
|
|
|
|
|
|
|
|
17893
|
|
|
|
|
|
|
|
17894
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
17895
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
17896
|
|
|
|
|
|
|
|
17897
|
|
|
|
|
|
|
|
17898
|
|
|
|
|
|
|
|
17899
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
17900
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
17901
|
|
|
|
|
|
|
|
17902
|
|
|
|
|
|
|
|
17903
|
|
|
|
|
|
|
|
17904
|
|
|
|
|
|
|
|
17905
|
|
|
|
|
|
|
|
17906
|
|
|
|
|
|
|
|
17907
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
17908
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
17909
|
|
|
|
|
|
|
void (*free_func)(void *)); |
17910
|
|
|
|
|
|
|
|
17911
|
|
|
|
|
|
|
#ifdef __cplusplus |
17912
|
|
|
|
|
|
|
} |
17913
|
|
|
|
|
|
|
#endif |
17914
|
|
|
|
|
|
|
|
17915
|
|
|
|
|
|
|
#endif |
17916
|
|
|
|
|
|
|
|
17917
|
|
|
|
|
|
|
|
17918
|
|
|
|
|
|
|
#include |
17919
|
|
|
|
|
|
|
#include |
17920
|
|
|
|
|
|
|
#include |
17921
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17922
|
|
|
|
|
|
|
# include |
17923
|
|
|
|
|
|
|
# include |
17924
|
|
|
|
|
|
|
|
17925
|
|
|
|
|
|
|
|
17926
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
17927
|
|
|
|
|
|
|
|
17928
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
17929
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
17930
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
17931
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
17932
|
|
|
|
|
|
|
|
17933
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
17934
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
17935
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
17936
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
17937
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
17938
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
17939
|
|
|
|
|
|
|
#endif |
17940
|
|
|
|
|
|
|
#ifndef FREESTANDING |
17941
|
|
|
|
|
|
|
# include |
17942
|
|
|
|
|
|
|
#endif |
17943
|
|
|
|
|
|
|
|
17944
|
|
|
|
|
|
|
|
17945
|
|
|
|
|
|
|
|
17946
|
|
|
|
|
|
|
|
17947
|
|
|
|
|
|
|
|
17948
|
|
|
|
|
|
|
|
17949
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
17950
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
17951
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
17952
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
17953
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17954
|
|
|
|
|
|
|
# if defined(_M_X64) |
17955
|
|
|
|
|
|
|
# define ARCH_X86_64 |
17956
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
17957
|
|
|
|
|
|
|
# define ARCH_X86_32 |
17958
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
17959
|
|
|
|
|
|
|
# define ARCH_ARM64 |
17960
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
17961
|
|
|
|
|
|
|
# define ARCH_ARM32 |
17962
|
|
|
|
|
|
|
# endif |
17963
|
|
|
|
|
|
|
#else |
17964
|
|
|
|
|
|
|
# if defined(__x86_64__) |
17965
|
|
|
|
|
|
|
# define ARCH_X86_64 |
17966
|
|
|
|
|
|
|
# elif defined(__i386__) |
17967
|
|
|
|
|
|
|
# define ARCH_X86_32 |
17968
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
17969
|
|
|
|
|
|
|
# define ARCH_ARM64 |
17970
|
|
|
|
|
|
|
# elif defined(__arm__) |
17971
|
|
|
|
|
|
|
# define ARCH_ARM32 |
17972
|
|
|
|
|
|
|
# endif |
17973
|
|
|
|
|
|
|
#endif |
17974
|
|
|
|
|
|
|
|
17975
|
|
|
|
|
|
|
|
17976
|
|
|
|
|
|
|
|
17977
|
|
|
|
|
|
|
|
17978
|
|
|
|
|
|
|
|
17979
|
|
|
|
|
|
|
|
17980
|
|
|
|
|
|
|
typedef uint8_t u8; |
17981
|
|
|
|
|
|
|
typedef uint16_t u16; |
17982
|
|
|
|
|
|
|
typedef uint32_t u32; |
17983
|
|
|
|
|
|
|
typedef uint64_t u64; |
17984
|
|
|
|
|
|
|
typedef int8_t s8; |
17985
|
|
|
|
|
|
|
typedef int16_t s16; |
17986
|
|
|
|
|
|
|
typedef int32_t s32; |
17987
|
|
|
|
|
|
|
typedef int64_t s64; |
17988
|
|
|
|
|
|
|
|
17989
|
|
|
|
|
|
|
|
17990
|
|
|
|
|
|
|
#ifdef _MSC_VER |
17991
|
|
|
|
|
|
|
# ifdef _WIN64 |
17992
|
|
|
|
|
|
|
typedef long long ssize_t; |
17993
|
|
|
|
|
|
|
# else |
17994
|
|
|
|
|
|
|
typedef long ssize_t; |
17995
|
|
|
|
|
|
|
# endif |
17996
|
|
|
|
|
|
|
#endif |
17997
|
|
|
|
|
|
|
|
17998
|
|
|
|
|
|
|
|
17999
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
18000
|
|
|
|
|
|
|
|
18001
|
|
|
|
|
|
|
|
18002
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
18003
|
|
|
|
|
|
|
|
18004
|
|
|
|
|
|
|
|
18005
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
18006
|
|
|
|
|
|
|
|
18007
|
|
|
|
|
|
|
|
18008
|
|
|
|
|
|
|
|
18009
|
|
|
|
|
|
|
|
18010
|
|
|
|
|
|
|
|
18011
|
|
|
|
|
|
|
|
18012
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
18013
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
18014
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
18015
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
18016
|
|
|
|
|
|
|
#else |
18017
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
18018
|
|
|
|
|
|
|
#endif |
18019
|
|
|
|
|
|
|
#ifdef __clang__ |
18020
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
18021
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
18022
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
18023
|
|
|
|
|
|
|
# else |
18024
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
18025
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
18026
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
18027
|
|
|
|
|
|
|
# endif |
18028
|
|
|
|
|
|
|
#else |
18029
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
18030
|
|
|
|
|
|
|
#endif |
18031
|
|
|
|
|
|
|
|
18032
|
|
|
|
|
|
|
|
18033
|
|
|
|
|
|
|
#ifndef __has_attribute |
18034
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
18035
|
|
|
|
|
|
|
#endif |
18036
|
|
|
|
|
|
|
#ifndef __has_builtin |
18037
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
18038
|
|
|
|
|
|
|
#endif |
18039
|
|
|
|
|
|
|
|
18040
|
|
|
|
|
|
|
|
18041
|
|
|
|
|
|
|
#ifdef _MSC_VER |
18042
|
|
|
|
|
|
|
# define inline __inline |
18043
|
|
|
|
|
|
|
#endif |
18044
|
|
|
|
|
|
|
|
18045
|
|
|
|
|
|
|
|
18046
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
18047
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
18048
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18049
|
|
|
|
|
|
|
# define forceinline __forceinline |
18050
|
|
|
|
|
|
|
#else |
18051
|
|
|
|
|
|
|
# define forceinline inline |
18052
|
|
|
|
|
|
|
#endif |
18053
|
|
|
|
|
|
|
|
18054
|
|
|
|
|
|
|
|
18055
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
18056
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
18057
|
|
|
|
|
|
|
#else |
18058
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
18059
|
|
|
|
|
|
|
#endif |
18060
|
|
|
|
|
|
|
|
18061
|
|
|
|
|
|
|
|
18062
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
18063
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
18064
|
|
|
|
|
|
|
# define restrict __restrict__ |
18065
|
|
|
|
|
|
|
# else |
18066
|
|
|
|
|
|
|
# define restrict |
18067
|
|
|
|
|
|
|
# endif |
18068
|
|
|
|
|
|
|
#endif |
18069
|
|
|
|
|
|
|
|
18070
|
|
|
|
|
|
|
|
18071
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
18072
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
18073
|
|
|
|
|
|
|
#else |
18074
|
|
|
|
|
|
|
# define likely(expr) (expr) |
18075
|
|
|
|
|
|
|
#endif |
18076
|
|
|
|
|
|
|
|
18077
|
|
|
|
|
|
|
|
18078
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
18079
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
18080
|
|
|
|
|
|
|
#else |
18081
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
18082
|
|
|
|
|
|
|
#endif |
18083
|
|
|
|
|
|
|
|
18084
|
|
|
|
|
|
|
|
18085
|
|
|
|
|
|
|
#undef prefetchr |
18086
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
18087
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
18088
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18089
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
18090
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
18091
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
18092
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
18093
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
18094
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
18095
|
|
|
|
|
|
|
# endif |
18096
|
|
|
|
|
|
|
#endif |
18097
|
|
|
|
|
|
|
#ifndef prefetchr |
18098
|
|
|
|
|
|
|
# define prefetchr(addr) |
18099
|
|
|
|
|
|
|
#endif |
18100
|
|
|
|
|
|
|
|
18101
|
|
|
|
|
|
|
|
18102
|
|
|
|
|
|
|
#undef prefetchw |
18103
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
18104
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
18105
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18106
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
18107
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
18108
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
18109
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
18110
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
18111
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
18112
|
|
|
|
|
|
|
# endif |
18113
|
|
|
|
|
|
|
#endif |
18114
|
|
|
|
|
|
|
#ifndef prefetchw |
18115
|
|
|
|
|
|
|
# define prefetchw(addr) |
18116
|
|
|
|
|
|
|
#endif |
18117
|
|
|
|
|
|
|
|
18118
|
|
|
|
|
|
|
|
18119
|
|
|
|
|
|
|
#undef _aligned_attribute |
18120
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
18121
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
18122
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18123
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
18124
|
|
|
|
|
|
|
#endif |
18125
|
|
|
|
|
|
|
|
18126
|
|
|
|
|
|
|
|
18127
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
18128
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
18129
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
18130
|
|
|
|
|
|
|
#else |
18131
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
18132
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
18133
|
|
|
|
|
|
|
#endif |
18134
|
|
|
|
|
|
|
|
18135
|
|
|
|
|
|
|
|
18136
|
|
|
|
|
|
|
|
18137
|
|
|
|
|
|
|
|
18138
|
|
|
|
|
|
|
|
18139
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
18140
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
18141
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
18142
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
18143
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
18144
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
18145
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
18146
|
|
|
|
|
|
|
|
18147
|
|
|
|
|
|
|
|
18148
|
|
|
|
|
|
|
|
18149
|
|
|
|
|
|
|
|
18150
|
|
|
|
|
|
|
|
18151
|
|
|
|
|
|
|
|
18152
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
18153
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
18154
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18155
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
18156
|
|
|
|
|
|
|
#else |
18157
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
18158
|
|
|
|
|
|
|
{ |
18159
|
|
|
|
|
|
|
union { |
18160
|
|
|
|
|
|
|
u32 w; |
18161
|
|
|
|
|
|
|
u8 b; |
18162
|
|
|
|
|
|
|
} u; |
18163
|
|
|
|
|
|
|
|
18164
|
|
|
|
|
|
|
u.w = 1; |
18165
|
|
|
|
|
|
|
return u.b; |
18166
|
|
|
|
|
|
|
} |
18167
|
|
|
|
|
|
|
#endif |
18168
|
|
|
|
|
|
|
|
18169
|
|
|
|
|
|
|
|
18170
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
18171
|
|
|
|
|
|
|
{ |
18172
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
18173
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
18174
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18175
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
18176
|
|
|
|
|
|
|
#else |
18177
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
18178
|
|
|
|
|
|
|
#endif |
18179
|
|
|
|
|
|
|
} |
18180
|
|
|
|
|
|
|
|
18181
|
|
|
|
|
|
|
|
18182
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
18183
|
|
|
|
|
|
|
{ |
18184
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
18185
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
18186
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18187
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
18188
|
|
|
|
|
|
|
#else |
18189
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
18190
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
18191
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
18192
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
18193
|
|
|
|
|
|
|
#endif |
18194
|
|
|
|
|
|
|
} |
18195
|
|
|
|
|
|
|
|
18196
|
|
|
|
|
|
|
|
18197
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
18198
|
|
|
|
|
|
|
{ |
18199
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
18200
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
18201
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18202
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
18203
|
|
|
|
|
|
|
#else |
18204
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
18205
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
18206
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
18207
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
18208
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
18209
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
18210
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
18211
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
18212
|
|
|
|
|
|
|
#endif |
18213
|
|
|
|
|
|
|
} |
18214
|
|
|
|
|
|
|
|
18215
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
18216
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
18217
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
18218
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
18219
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
18220
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
18221
|
|
|
|
|
|
|
|
18222
|
|
|
|
|
|
|
|
18223
|
|
|
|
|
|
|
|
18224
|
|
|
|
|
|
|
|
18225
|
|
|
|
|
|
|
|
18226
|
|
|
|
|
|
|
|
18227
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
18228
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
18229
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
18230
|
|
|
|
|
|
|
defined(__wasm__)) |
18231
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
18232
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18233
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
18234
|
|
|
|
|
|
|
#else |
18235
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
18236
|
|
|
|
|
|
|
#endif |
18237
|
|
|
|
|
|
|
|
18238
|
|
|
|
|
|
|
|
18239
|
|
|
|
|
|
|
|
18240
|
|
|
|
|
|
|
#ifdef FREESTANDING |
18241
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
18242
|
|
|
|
|
|
|
#else |
18243
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
18244
|
|
|
|
|
|
|
#endif |
18245
|
|
|
|
|
|
|
|
18246
|
|
|
|
|
|
|
|
18247
|
|
|
|
|
|
|
|
18248
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
18249
|
|
|
|
|
|
|
static forceinline type \ |
18250
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
18251
|
|
|
|
|
|
|
{ \ |
18252
|
|
|
|
|
|
|
type v; \ |
18253
|
|
|
|
|
|
|
\ |
18254
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
18255
|
|
|
|
|
|
|
return v; \ |
18256
|
|
|
|
|
|
|
} \ |
18257
|
|
|
|
|
|
|
\ |
18258
|
|
|
|
|
|
|
static forceinline void \ |
18259
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
18260
|
|
|
|
|
|
|
{ \ |
18261
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
18262
|
|
|
|
|
|
|
} |
18263
|
|
|
|
|
|
|
|
18264
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
18265
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
18266
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
18267
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
18268
|
|
|
|
|
|
|
|
18269
|
|
|
|
|
|
|
#undef MEMCOPY |
18270
|
|
|
|
|
|
|
|
18271
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
18272
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
18273
|
|
|
|
|
|
|
|
18274
|
|
|
|
|
|
|
|
18275
|
|
|
|
|
|
|
|
18276
|
|
|
|
|
|
|
static forceinline u16 |
18277
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
18278
|
|
|
|
|
|
|
{ |
18279
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18280
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
18281
|
|
|
|
|
|
|
else |
18282
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
18283
|
|
|
|
|
|
|
} |
18284
|
|
|
|
|
|
|
|
18285
|
|
|
|
|
|
|
static forceinline u16 |
18286
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
18287
|
|
|
|
|
|
|
{ |
18288
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18289
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
18290
|
|
|
|
|
|
|
else |
18291
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
18292
|
|
|
|
|
|
|
} |
18293
|
|
|
|
|
|
|
|
18294
|
|
|
|
|
|
|
static forceinline u32 |
18295
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
18296
|
|
|
|
|
|
|
{ |
18297
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18298
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
18299
|
|
|
|
|
|
|
else |
18300
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
18301
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
18302
|
|
|
|
|
|
|
} |
18303
|
|
|
|
|
|
|
|
18304
|
|
|
|
|
|
|
static forceinline u32 |
18305
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
18306
|
|
|
|
|
|
|
{ |
18307
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18308
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
18309
|
|
|
|
|
|
|
else |
18310
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
18311
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
18312
|
|
|
|
|
|
|
} |
18313
|
|
|
|
|
|
|
|
18314
|
|
|
|
|
|
|
static forceinline u64 |
18315
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
18316
|
|
|
|
|
|
|
{ |
18317
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
18318
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
18319
|
|
|
|
|
|
|
else |
18320
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
18321
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
18322
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
18323
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
18324
|
|
|
|
|
|
|
} |
18325
|
|
|
|
|
|
|
|
18326
|
|
|
|
|
|
|
static forceinline machine_word_t |
18327
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
18328
|
|
|
|
|
|
|
{ |
18329
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
18330
|
|
|
|
|
|
|
if (WORDBITS == 32) |
18331
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
18332
|
|
|
|
|
|
|
else |
18333
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
18334
|
|
|
|
|
|
|
} |
18335
|
|
|
|
|
|
|
|
18336
|
|
|
|
|
|
|
|
18337
|
|
|
|
|
|
|
|
18338
|
|
|
|
|
|
|
static forceinline void |
18339
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
18340
|
|
|
|
|
|
|
{ |
18341
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18342
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
18343
|
|
|
|
|
|
|
} else { |
18344
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
18345
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
18346
|
|
|
|
|
|
|
} |
18347
|
|
|
|
|
|
|
} |
18348
|
|
|
|
|
|
|
|
18349
|
|
|
|
|
|
|
static forceinline void |
18350
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
18351
|
|
|
|
|
|
|
{ |
18352
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18353
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
18354
|
|
|
|
|
|
|
} else { |
18355
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
18356
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
18357
|
|
|
|
|
|
|
} |
18358
|
|
|
|
|
|
|
} |
18359
|
|
|
|
|
|
|
|
18360
|
|
|
|
|
|
|
static forceinline void |
18361
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
18362
|
|
|
|
|
|
|
{ |
18363
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18364
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
18365
|
|
|
|
|
|
|
} else { |
18366
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
18367
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
18368
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
18369
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
18370
|
|
|
|
|
|
|
} |
18371
|
|
|
|
|
|
|
} |
18372
|
|
|
|
|
|
|
|
18373
|
|
|
|
|
|
|
static forceinline void |
18374
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
18375
|
|
|
|
|
|
|
{ |
18376
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18377
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
18378
|
|
|
|
|
|
|
} else { |
18379
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
18380
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
18381
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
18382
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
18383
|
|
|
|
|
|
|
} |
18384
|
|
|
|
|
|
|
} |
18385
|
|
|
|
|
|
|
|
18386
|
|
|
|
|
|
|
static forceinline void |
18387
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
18388
|
|
|
|
|
|
|
{ |
18389
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
18390
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
18391
|
|
|
|
|
|
|
} else { |
18392
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
18393
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
18394
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
18395
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
18396
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
18397
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
18398
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
18399
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
18400
|
|
|
|
|
|
|
} |
18401
|
|
|
|
|
|
|
} |
18402
|
|
|
|
|
|
|
|
18403
|
|
|
|
|
|
|
static forceinline void |
18404
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
18405
|
|
|
|
|
|
|
{ |
18406
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
18407
|
|
|
|
|
|
|
if (WORDBITS == 32) |
18408
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
18409
|
|
|
|
|
|
|
else |
18410
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
18411
|
|
|
|
|
|
|
} |
18412
|
|
|
|
|
|
|
|
18413
|
|
|
|
|
|
|
|
18414
|
|
|
|
|
|
|
|
18415
|
|
|
|
|
|
|
|
18416
|
|
|
|
|
|
|
|
18417
|
|
|
|
|
|
|
|
18418
|
|
|
|
|
|
|
|
18419
|
|
|
|
|
|
|
static forceinline unsigned |
18420
|
|
|
|
|
|
|
bsr32(u32 v) |
18421
|
|
|
|
|
|
|
{ |
18422
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
18423
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
18424
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18425
|
|
|
|
|
|
|
unsigned long i; |
18426
|
|
|
|
|
|
|
|
18427
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
18428
|
|
|
|
|
|
|
return i; |
18429
|
|
|
|
|
|
|
#else |
18430
|
|
|
|
|
|
|
unsigned i = 0; |
18431
|
|
|
|
|
|
|
|
18432
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
18433
|
|
|
|
|
|
|
i++; |
18434
|
|
|
|
|
|
|
return i; |
18435
|
|
|
|
|
|
|
#endif |
18436
|
|
|
|
|
|
|
} |
18437
|
|
|
|
|
|
|
|
18438
|
|
|
|
|
|
|
static forceinline unsigned |
18439
|
|
|
|
|
|
|
bsr64(u64 v) |
18440
|
|
|
|
|
|
|
{ |
18441
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
18442
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
18443
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
18444
|
|
|
|
|
|
|
unsigned long i; |
18445
|
|
|
|
|
|
|
|
18446
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
18447
|
|
|
|
|
|
|
return i; |
18448
|
|
|
|
|
|
|
#else |
18449
|
|
|
|
|
|
|
unsigned i = 0; |
18450
|
|
|
|
|
|
|
|
18451
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
18452
|
|
|
|
|
|
|
i++; |
18453
|
|
|
|
|
|
|
return i; |
18454
|
|
|
|
|
|
|
#endif |
18455
|
|
|
|
|
|
|
} |
18456
|
|
|
|
|
|
|
|
18457
|
|
|
|
|
|
|
static forceinline unsigned |
18458
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
18459
|
|
|
|
|
|
|
{ |
18460
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
18461
|
|
|
|
|
|
|
if (WORDBITS == 32) |
18462
|
|
|
|
|
|
|
return bsr32(v); |
18463
|
|
|
|
|
|
|
else |
18464
|
|
|
|
|
|
|
return bsr64(v); |
18465
|
|
|
|
|
|
|
} |
18466
|
|
|
|
|
|
|
|
18467
|
|
|
|
|
|
|
|
18468
|
|
|
|
|
|
|
|
18469
|
|
|
|
|
|
|
static forceinline unsigned |
18470
|
|
|
|
|
|
|
bsf32(u32 v) |
18471
|
|
|
|
|
|
|
{ |
18472
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
18473
|
|
|
|
|
|
|
return __builtin_ctz(v); |
18474
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
18475
|
|
|
|
|
|
|
unsigned long i; |
18476
|
|
|
|
|
|
|
|
18477
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
18478
|
|
|
|
|
|
|
return i; |
18479
|
|
|
|
|
|
|
#else |
18480
|
|
|
|
|
|
|
unsigned i = 0; |
18481
|
|
|
|
|
|
|
|
18482
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
18483
|
|
|
|
|
|
|
i++; |
18484
|
|
|
|
|
|
|
return i; |
18485
|
|
|
|
|
|
|
#endif |
18486
|
|
|
|
|
|
|
} |
18487
|
|
|
|
|
|
|
|
18488
|
|
|
|
|
|
|
static forceinline unsigned |
18489
|
|
|
|
|
|
|
bsf64(u64 v) |
18490
|
|
|
|
|
|
|
{ |
18491
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
18492
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
18493
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
18494
|
|
|
|
|
|
|
unsigned long i; |
18495
|
|
|
|
|
|
|
|
18496
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
18497
|
|
|
|
|
|
|
return i; |
18498
|
|
|
|
|
|
|
#else |
18499
|
|
|
|
|
|
|
unsigned i = 0; |
18500
|
|
|
|
|
|
|
|
18501
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
18502
|
|
|
|
|
|
|
i++; |
18503
|
|
|
|
|
|
|
return i; |
18504
|
|
|
|
|
|
|
#endif |
18505
|
|
|
|
|
|
|
} |
18506
|
|
|
|
|
|
|
|
18507
|
|
|
|
|
|
|
static forceinline unsigned |
18508
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
18509
|
|
|
|
|
|
|
{ |
18510
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
18511
|
|
|
|
|
|
|
if (WORDBITS == 32) |
18512
|
|
|
|
|
|
|
return bsf32(v); |
18513
|
|
|
|
|
|
|
else |
18514
|
|
|
|
|
|
|
return bsf64(v); |
18515
|
|
|
|
|
|
|
} |
18516
|
|
|
|
|
|
|
|
18517
|
|
|
|
|
|
|
|
18518
|
|
|
|
|
|
|
#undef rbit32 |
18519
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
18520
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
18521
|
|
|
|
|
|
|
static forceinline u32 |
18522
|
|
|
|
|
|
|
rbit32(u32 v) |
18523
|
|
|
|
|
|
|
{ |
18524
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
18525
|
|
|
|
|
|
|
return v; |
18526
|
|
|
|
|
|
|
} |
18527
|
|
|
|
|
|
|
#define rbit32 rbit32 |
18528
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
18529
|
|
|
|
|
|
|
static forceinline u32 |
18530
|
|
|
|
|
|
|
rbit32(u32 v) |
18531
|
|
|
|
|
|
|
{ |
18532
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
18533
|
|
|
|
|
|
|
return v; |
18534
|
|
|
|
|
|
|
} |
18535
|
|
|
|
|
|
|
#define rbit32 rbit32 |
18536
|
|
|
|
|
|
|
#endif |
18537
|
|
|
|
|
|
|
|
18538
|
|
|
|
|
|
|
#endif |
18539
|
|
|
|
|
|
|
|
18540
|
|
|
|
|
|
|
|
18541
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
18542
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
18543
|
|
|
|
|
|
|
|
18544
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
18545
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
18546
|
|
|
|
|
|
|
|
18547
|
|
|
|
|
|
|
#ifdef FREESTANDING |
18548
|
|
|
|
|
|
|
|
18549
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
18550
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
18551
|
|
|
|
|
|
|
|
18552
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
18553
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
18554
|
|
|
|
|
|
|
|
18555
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
18556
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
18557
|
|
|
|
|
|
|
|
18558
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
18559
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
18560
|
|
|
|
|
|
|
|
18561
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
18562
|
|
|
|
|
|
|
#else |
18563
|
|
|
|
|
|
|
#include |
18564
|
|
|
|
|
|
|
#endif |
18565
|
|
|
|
|
|
|
|
18566
|
|
|
|
|
|
|
|
18567
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
18568
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
18569
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
18570
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
18571
|
|
|
|
|
|
|
#else |
18572
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
18573
|
|
|
|
|
|
|
#endif |
18574
|
|
|
|
|
|
|
|
18575
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
18576
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
18577
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
18578
|
|
|
|
|
|
|
|
18579
|
|
|
|
|
|
|
#endif |
18580
|
|
|
|
|
|
|
|
18581
|
|
|
|
|
|
|
|
18582
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
18583
|
|
|
|
|
|
|
|
18584
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
18585
|
|
|
|
|
|
|
|
18586
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
18587
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
18588
|
|
|
|
|
|
|
(defined(__linux__) || \ |
18589
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
18590
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
18591
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
18592
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
18593
|
|
|
|
|
|
|
#endif |
18594
|
|
|
|
|
|
|
|
18595
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
18596
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
18597
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
18598
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
18599
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
18600
|
|
|
|
|
|
|
|
18601
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
18602
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
18603
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
18604
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
18605
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
18606
|
|
|
|
|
|
|
|
18607
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
18608
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
18609
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
18610
|
|
|
|
|
|
|
|
18611
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
18612
|
|
|
|
|
|
|
|
18613
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
18614
|
|
|
|
|
|
|
{ |
18615
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
18616
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
18617
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
18618
|
|
|
|
|
|
|
} |
18619
|
|
|
|
|
|
|
#else |
18620
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
18621
|
|
|
|
|
|
|
#endif |
18622
|
|
|
|
|
|
|
|
18623
|
|
|
|
|
|
|
|
18624
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
18625
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
18626
|
|
|
|
|
|
|
#else |
18627
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
18628
|
|
|
|
|
|
|
#endif |
18629
|
|
|
|
|
|
|
|
18630
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
18631
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
18632
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
18633
|
|
|
|
|
|
|
#else |
18634
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
18635
|
|
|
|
|
|
|
#endif |
18636
|
|
|
|
|
|
|
|
18637
|
|
|
|
|
|
|
|
18638
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
18639
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
18640
|
|
|
|
|
|
|
#else |
18641
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
18642
|
|
|
|
|
|
|
#endif |
18643
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
18644
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
18645
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
18646
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
18647
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
18648
|
|
|
|
|
|
|
\ |
18649
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
18650
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
18651
|
|
|
|
|
|
|
|
18652
|
|
|
|
|
|
|
# ifdef _MSC_VER |
18653
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
18654
|
|
|
|
|
|
|
# else |
18655
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
18656
|
|
|
|
|
|
|
# endif |
18657
|
|
|
|
|
|
|
#else |
18658
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
18659
|
|
|
|
|
|
|
#endif |
18660
|
|
|
|
|
|
|
|
18661
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
18662
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
18663
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
18664
|
|
|
|
|
|
|
#else |
18665
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
18666
|
|
|
|
|
|
|
#endif |
18667
|
|
|
|
|
|
|
|
18668
|
|
|
|
|
|
|
|
18669
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
18670
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
18671
|
|
|
|
|
|
|
#else |
18672
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
18673
|
|
|
|
|
|
|
#endif |
18674
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
18675
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
18676
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
18677
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
18678
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
18679
|
|
|
|
|
|
|
|
18680
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
18681
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
18682
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
18683
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
18684
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
18685
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
18686
|
|
|
|
|
|
|
# endif |
18687
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
18688
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
18689
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
18690
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
18691
|
|
|
|
|
|
|
# endif |
18692
|
|
|
|
|
|
|
#endif |
18693
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
18694
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
18695
|
|
|
|
|
|
|
#endif |
18696
|
|
|
|
|
|
|
|
18697
|
|
|
|
|
|
|
|
18698
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
18699
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
18700
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
18701
|
|
|
|
|
|
|
# else |
18702
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
18703
|
|
|
|
|
|
|
# endif |
18704
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
18705
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
18706
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
18707
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
18708
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
18709
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
18710
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
18711
|
|
|
|
|
|
|
#else |
18712
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
18713
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
18714
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
18715
|
|
|
|
|
|
|
#endif |
18716
|
|
|
|
|
|
|
|
18717
|
|
|
|
|
|
|
|
18718
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
18719
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
18720
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
18721
|
|
|
|
|
|
|
# else |
18722
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
18723
|
|
|
|
|
|
|
# endif |
18724
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
18725
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
18726
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
18727
|
|
|
|
|
|
|
defined(_MSC_VER))) |
18728
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
18729
|
|
|
|
|
|
|
# else |
18730
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
18731
|
|
|
|
|
|
|
# endif |
18732
|
|
|
|
|
|
|
#else |
18733
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
18734
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
18735
|
|
|
|
|
|
|
#endif |
18736
|
|
|
|
|
|
|
|
18737
|
|
|
|
|
|
|
|
18738
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
18739
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
18740
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
18741
|
|
|
|
|
|
|
#endif |
18742
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
18743
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
18744
|
|
|
|
|
|
|
#endif |
18745
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
18746
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
18747
|
|
|
|
|
|
|
#endif |
18748
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
18749
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
18750
|
|
|
|
|
|
|
# include |
18751
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
18752
|
|
|
|
|
|
|
#endif |
18753
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
18754
|
|
|
|
|
|
|
# include |
18755
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
18756
|
|
|
|
|
|
|
#endif |
18757
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
18758
|
|
|
|
|
|
|
# include |
18759
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
18760
|
|
|
|
|
|
|
#endif |
18761
|
|
|
|
|
|
|
|
18762
|
|
|
|
|
|
|
#endif |
18763
|
|
|
|
|
|
|
|
18764
|
|
|
|
|
|
|
#endif |
18765
|
|
|
|
|
|
|
|
18766
|
|
|
|
|
|
|
|
18767
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE |
18768
|
|
|
|
|
|
|
# include |
18769
|
|
|
|
|
|
|
static forceinline void |
18770
|
|
|
|
|
|
|
matchfinder_init_neon(mf_pos_t *data, size_t size) |
18771
|
|
|
|
|
|
|
{ |
18772
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
18773
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16(MATCHFINDER_INITVAL); |
18774
|
|
|
|
|
|
|
|
18775
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
18776
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
18777
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
18778
|
|
|
|
|
|
|
|
18779
|
|
|
|
|
|
|
do { |
18780
|
|
|
|
|
|
|
p[0] = v; |
18781
|
|
|
|
|
|
|
p[1] = v; |
18782
|
|
|
|
|
|
|
p[2] = v; |
18783
|
|
|
|
|
|
|
p[3] = v; |
18784
|
|
|
|
|
|
|
p += 4; |
18785
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
18786
|
|
|
|
|
|
|
} while (size != 0); |
18787
|
|
|
|
|
|
|
} |
18788
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_neon |
18789
|
|
|
|
|
|
|
|
18790
|
|
|
|
|
|
|
static forceinline void |
18791
|
|
|
|
|
|
|
matchfinder_rebase_neon(mf_pos_t *data, size_t size) |
18792
|
|
|
|
|
|
|
{ |
18793
|
|
|
|
|
|
|
int16x8_t *p = (int16x8_t *)data; |
18794
|
|
|
|
|
|
|
int16x8_t v = vdupq_n_s16((u16)-MATCHFINDER_WINDOW_SIZE); |
18795
|
|
|
|
|
|
|
|
18796
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
18797
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
18798
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
18799
|
|
|
|
|
|
|
|
18800
|
|
|
|
|
|
|
do { |
18801
|
|
|
|
|
|
|
p[0] = vqaddq_s16(p[0], v); |
18802
|
|
|
|
|
|
|
p[1] = vqaddq_s16(p[1], v); |
18803
|
|
|
|
|
|
|
p[2] = vqaddq_s16(p[2], v); |
18804
|
|
|
|
|
|
|
p[3] = vqaddq_s16(p[3], v); |
18805
|
|
|
|
|
|
|
p += 4; |
18806
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
18807
|
|
|
|
|
|
|
} while (size != 0); |
18808
|
|
|
|
|
|
|
} |
18809
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_neon |
18810
|
|
|
|
|
|
|
|
18811
|
|
|
|
|
|
|
#endif |
18812
|
|
|
|
|
|
|
|
18813
|
|
|
|
|
|
|
#endif |
18814
|
|
|
|
|
|
|
|
18815
|
|
|
|
|
|
|
# elif defined(ARCH_X86_32) || defined(ARCH_X86_64) |
18816
|
|
|
|
|
|
|
/* # include "x86/matchfinder_impl.h" */ |
18817
|
|
|
|
|
|
|
|
18818
|
|
|
|
|
|
|
|
18819
|
|
|
|
|
|
|
#ifndef LIB_X86_MATCHFINDER_IMPL_H |
18820
|
|
|
|
|
|
|
#define LIB_X86_MATCHFINDER_IMPL_H |
18821
|
|
|
|
|
|
|
|
18822
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
18823
|
|
|
|
|
|
|
|
18824
|
|
|
|
|
|
|
|
18825
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
18826
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
18827
|
|
|
|
|
|
|
|
18828
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
18829
|
|
|
|
|
|
|
|
18830
|
|
|
|
|
|
|
|
18831
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
18832
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
18833
|
|
|
|
|
|
|
|
18834
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
18835
|
|
|
|
|
|
|
|
18836
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
18837
|
|
|
|
|
|
|
#endif |
18838
|
|
|
|
|
|
|
|
18839
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
18840
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
18841
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
18842
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
18843
|
|
|
|
|
|
|
#else |
18844
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
18845
|
|
|
|
|
|
|
#endif |
18846
|
|
|
|
|
|
|
|
18847
|
|
|
|
|
|
|
|
18848
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
18849
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
18850
|
|
|
|
|
|
|
#else |
18851
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
18852
|
|
|
|
|
|
|
#endif |
18853
|
|
|
|
|
|
|
|
18854
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
18855
|
|
|
|
|
|
|
|
18856
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
18857
|
|
|
|
|
|
|
|
18858
|
|
|
|
|
|
|
|
18859
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
18860
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
18861
|
|
|
|
|
|
|
|
18862
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
18863
|
|
|
|
|
|
|
|
18864
|
|
|
|
|
|
|
|
18865
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
18866
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
18867
|
|
|
|
|
|
|
|
18868
|
|
|
|
|
|
|
#include |
18869
|
|
|
|
|
|
|
#include |
18870
|
|
|
|
|
|
|
|
18871
|
|
|
|
|
|
|
#ifdef __cplusplus |
18872
|
|
|
|
|
|
|
extern "C" { |
18873
|
|
|
|
|
|
|
#endif |
18874
|
|
|
|
|
|
|
|
18875
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
18876
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
18877
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
18878
|
|
|
|
|
|
|
|
18879
|
|
|
|
|
|
|
|
18880
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
18881
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
18882
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
18883
|
|
|
|
|
|
|
# else |
18884
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
18885
|
|
|
|
|
|
|
# endif |
18886
|
|
|
|
|
|
|
#endif |
18887
|
|
|
|
|
|
|
|
18888
|
|
|
|
|
|
|
|
18889
|
|
|
|
|
|
|
|
18890
|
|
|
|
|
|
|
|
18891
|
|
|
|
|
|
|
|
18892
|
|
|
|
|
|
|
struct libdeflate_compressor; |
18893
|
|
|
|
|
|
|
|
18894
|
|
|
|
|
|
|
|
18895
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
18896
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
18897
|
|
|
|
|
|
|
|
18898
|
|
|
|
|
|
|
|
18899
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18900
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
18901
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18902
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
18903
|
|
|
|
|
|
|
|
18904
|
|
|
|
|
|
|
|
18905
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18906
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
18907
|
|
|
|
|
|
|
size_t in_nbytes); |
18908
|
|
|
|
|
|
|
|
18909
|
|
|
|
|
|
|
|
18910
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18911
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
18912
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18913
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
18914
|
|
|
|
|
|
|
|
18915
|
|
|
|
|
|
|
|
18916
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18917
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
18918
|
|
|
|
|
|
|
size_t in_nbytes); |
18919
|
|
|
|
|
|
|
|
18920
|
|
|
|
|
|
|
|
18921
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18922
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
18923
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18924
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
18925
|
|
|
|
|
|
|
|
18926
|
|
|
|
|
|
|
|
18927
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
18928
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
18929
|
|
|
|
|
|
|
size_t in_nbytes); |
18930
|
|
|
|
|
|
|
|
18931
|
|
|
|
|
|
|
|
18932
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
18933
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
18934
|
|
|
|
|
|
|
|
18935
|
|
|
|
|
|
|
|
18936
|
|
|
|
|
|
|
|
18937
|
|
|
|
|
|
|
|
18938
|
|
|
|
|
|
|
|
18939
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
18940
|
|
|
|
|
|
|
|
18941
|
|
|
|
|
|
|
|
18942
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
18943
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
18944
|
|
|
|
|
|
|
|
18945
|
|
|
|
|
|
|
|
18946
|
|
|
|
|
|
|
enum libdeflate_result { |
18947
|
|
|
|
|
|
|
|
18948
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
18949
|
|
|
|
|
|
|
|
18950
|
|
|
|
|
|
|
|
18951
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
18952
|
|
|
|
|
|
|
|
18953
|
|
|
|
|
|
|
|
18954
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
18955
|
|
|
|
|
|
|
|
18956
|
|
|
|
|
|
|
|
18957
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
18958
|
|
|
|
|
|
|
}; |
18959
|
|
|
|
|
|
|
|
18960
|
|
|
|
|
|
|
|
18961
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18962
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
18963
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18964
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18965
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18966
|
|
|
|
|
|
|
|
18967
|
|
|
|
|
|
|
|
18968
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18969
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
18970
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18971
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18972
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
18973
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18974
|
|
|
|
|
|
|
|
18975
|
|
|
|
|
|
|
|
18976
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18977
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
18978
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18979
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18980
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18981
|
|
|
|
|
|
|
|
18982
|
|
|
|
|
|
|
|
18983
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18984
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
18985
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18986
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18987
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
18988
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18989
|
|
|
|
|
|
|
|
18990
|
|
|
|
|
|
|
|
18991
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18992
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
18993
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
18994
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
18995
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
18996
|
|
|
|
|
|
|
|
18997
|
|
|
|
|
|
|
|
18998
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
18999
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
19000
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
19001
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
19002
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
19003
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
19004
|
|
|
|
|
|
|
|
19005
|
|
|
|
|
|
|
|
19006
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
19007
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
19008
|
|
|
|
|
|
|
|
19009
|
|
|
|
|
|
|
|
19010
|
|
|
|
|
|
|
|
19011
|
|
|
|
|
|
|
|
19012
|
|
|
|
|
|
|
|
19013
|
|
|
|
|
|
|
|
19014
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
19015
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
19016
|
|
|
|
|
|
|
|
19017
|
|
|
|
|
|
|
|
19018
|
|
|
|
|
|
|
|
19019
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
19020
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
19021
|
|
|
|
|
|
|
|
19022
|
|
|
|
|
|
|
|
19023
|
|
|
|
|
|
|
|
19024
|
|
|
|
|
|
|
|
19025
|
|
|
|
|
|
|
|
19026
|
|
|
|
|
|
|
|
19027
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
19028
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
19029
|
|
|
|
|
|
|
void (*free_func)(void *)); |
19030
|
|
|
|
|
|
|
|
19031
|
|
|
|
|
|
|
#ifdef __cplusplus |
19032
|
|
|
|
|
|
|
} |
19033
|
|
|
|
|
|
|
#endif |
19034
|
|
|
|
|
|
|
|
19035
|
|
|
|
|
|
|
#endif |
19036
|
|
|
|
|
|
|
|
19037
|
|
|
|
|
|
|
|
19038
|
|
|
|
|
|
|
#include |
19039
|
|
|
|
|
|
|
#include |
19040
|
|
|
|
|
|
|
#include |
19041
|
|
|
|
|
|
|
#ifdef _MSC_VER |
19042
|
|
|
|
|
|
|
# include |
19043
|
|
|
|
|
|
|
# include |
19044
|
|
|
|
|
|
|
|
19045
|
|
|
|
|
|
|
|
19046
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
19047
|
|
|
|
|
|
|
|
19048
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
19049
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
19050
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
19051
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
19052
|
|
|
|
|
|
|
|
19053
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
19054
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
19055
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
19056
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
19057
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
19058
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
19059
|
|
|
|
|
|
|
#endif |
19060
|
|
|
|
|
|
|
#ifndef FREESTANDING |
19061
|
|
|
|
|
|
|
# include |
19062
|
|
|
|
|
|
|
#endif |
19063
|
|
|
|
|
|
|
|
19064
|
|
|
|
|
|
|
|
19065
|
|
|
|
|
|
|
|
19066
|
|
|
|
|
|
|
|
19067
|
|
|
|
|
|
|
|
19068
|
|
|
|
|
|
|
|
19069
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
19070
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
19071
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
19072
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
19073
|
|
|
|
|
|
|
#ifdef _MSC_VER |
19074
|
|
|
|
|
|
|
# if defined(_M_X64) |
19075
|
|
|
|
|
|
|
# define ARCH_X86_64 |
19076
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
19077
|
|
|
|
|
|
|
# define ARCH_X86_32 |
19078
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
19079
|
|
|
|
|
|
|
# define ARCH_ARM64 |
19080
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
19081
|
|
|
|
|
|
|
# define ARCH_ARM32 |
19082
|
|
|
|
|
|
|
# endif |
19083
|
|
|
|
|
|
|
#else |
19084
|
|
|
|
|
|
|
# if defined(__x86_64__) |
19085
|
|
|
|
|
|
|
# define ARCH_X86_64 |
19086
|
|
|
|
|
|
|
# elif defined(__i386__) |
19087
|
|
|
|
|
|
|
# define ARCH_X86_32 |
19088
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
19089
|
|
|
|
|
|
|
# define ARCH_ARM64 |
19090
|
|
|
|
|
|
|
# elif defined(__arm__) |
19091
|
|
|
|
|
|
|
# define ARCH_ARM32 |
19092
|
|
|
|
|
|
|
# endif |
19093
|
|
|
|
|
|
|
#endif |
19094
|
|
|
|
|
|
|
|
19095
|
|
|
|
|
|
|
|
19096
|
|
|
|
|
|
|
|
19097
|
|
|
|
|
|
|
|
19098
|
|
|
|
|
|
|
|
19099
|
|
|
|
|
|
|
|
19100
|
|
|
|
|
|
|
typedef uint8_t u8; |
19101
|
|
|
|
|
|
|
typedef uint16_t u16; |
19102
|
|
|
|
|
|
|
typedef uint32_t u32; |
19103
|
|
|
|
|
|
|
typedef uint64_t u64; |
19104
|
|
|
|
|
|
|
typedef int8_t s8; |
19105
|
|
|
|
|
|
|
typedef int16_t s16; |
19106
|
|
|
|
|
|
|
typedef int32_t s32; |
19107
|
|
|
|
|
|
|
typedef int64_t s64; |
19108
|
|
|
|
|
|
|
|
19109
|
|
|
|
|
|
|
|
19110
|
|
|
|
|
|
|
#ifdef _MSC_VER |
19111
|
|
|
|
|
|
|
# ifdef _WIN64 |
19112
|
|
|
|
|
|
|
typedef long long ssize_t; |
19113
|
|
|
|
|
|
|
# else |
19114
|
|
|
|
|
|
|
typedef long ssize_t; |
19115
|
|
|
|
|
|
|
# endif |
19116
|
|
|
|
|
|
|
#endif |
19117
|
|
|
|
|
|
|
|
19118
|
|
|
|
|
|
|
|
19119
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
19120
|
|
|
|
|
|
|
|
19121
|
|
|
|
|
|
|
|
19122
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
19123
|
|
|
|
|
|
|
|
19124
|
|
|
|
|
|
|
|
19125
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
19126
|
|
|
|
|
|
|
|
19127
|
|
|
|
|
|
|
|
19128
|
|
|
|
|
|
|
|
19129
|
|
|
|
|
|
|
|
19130
|
|
|
|
|
|
|
|
19131
|
|
|
|
|
|
|
|
19132
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
19133
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
19134
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
19135
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
19136
|
|
|
|
|
|
|
#else |
19137
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
19138
|
|
|
|
|
|
|
#endif |
19139
|
|
|
|
|
|
|
#ifdef __clang__ |
19140
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
19141
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
19142
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
19143
|
|
|
|
|
|
|
# else |
19144
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
19145
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
19146
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
19147
|
|
|
|
|
|
|
# endif |
19148
|
|
|
|
|
|
|
#else |
19149
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
19150
|
|
|
|
|
|
|
#endif |
19151
|
|
|
|
|
|
|
|
19152
|
|
|
|
|
|
|
|
19153
|
|
|
|
|
|
|
#ifndef __has_attribute |
19154
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
19155
|
|
|
|
|
|
|
#endif |
19156
|
|
|
|
|
|
|
#ifndef __has_builtin |
19157
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
19158
|
|
|
|
|
|
|
#endif |
19159
|
|
|
|
|
|
|
|
19160
|
|
|
|
|
|
|
|
19161
|
|
|
|
|
|
|
#ifdef _MSC_VER |
19162
|
|
|
|
|
|
|
# define inline __inline |
19163
|
|
|
|
|
|
|
#endif |
19164
|
|
|
|
|
|
|
|
19165
|
|
|
|
|
|
|
|
19166
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
19167
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
19168
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19169
|
|
|
|
|
|
|
# define forceinline __forceinline |
19170
|
|
|
|
|
|
|
#else |
19171
|
|
|
|
|
|
|
# define forceinline inline |
19172
|
|
|
|
|
|
|
#endif |
19173
|
|
|
|
|
|
|
|
19174
|
|
|
|
|
|
|
|
19175
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
19176
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
19177
|
|
|
|
|
|
|
#else |
19178
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
19179
|
|
|
|
|
|
|
#endif |
19180
|
|
|
|
|
|
|
|
19181
|
|
|
|
|
|
|
|
19182
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
19183
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
19184
|
|
|
|
|
|
|
# define restrict __restrict__ |
19185
|
|
|
|
|
|
|
# else |
19186
|
|
|
|
|
|
|
# define restrict |
19187
|
|
|
|
|
|
|
# endif |
19188
|
|
|
|
|
|
|
#endif |
19189
|
|
|
|
|
|
|
|
19190
|
|
|
|
|
|
|
|
19191
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
19192
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
19193
|
|
|
|
|
|
|
#else |
19194
|
|
|
|
|
|
|
# define likely(expr) (expr) |
19195
|
|
|
|
|
|
|
#endif |
19196
|
|
|
|
|
|
|
|
19197
|
|
|
|
|
|
|
|
19198
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
19199
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
19200
|
|
|
|
|
|
|
#else |
19201
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
19202
|
|
|
|
|
|
|
#endif |
19203
|
|
|
|
|
|
|
|
19204
|
|
|
|
|
|
|
|
19205
|
|
|
|
|
|
|
#undef prefetchr |
19206
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
19207
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
19208
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19209
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
19210
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
19211
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
19212
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
19213
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
19214
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
19215
|
|
|
|
|
|
|
# endif |
19216
|
|
|
|
|
|
|
#endif |
19217
|
|
|
|
|
|
|
#ifndef prefetchr |
19218
|
|
|
|
|
|
|
# define prefetchr(addr) |
19219
|
|
|
|
|
|
|
#endif |
19220
|
|
|
|
|
|
|
|
19221
|
|
|
|
|
|
|
|
19222
|
|
|
|
|
|
|
#undef prefetchw |
19223
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
19224
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
19225
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19226
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
19227
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
19228
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
19229
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
19230
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
19231
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
19232
|
|
|
|
|
|
|
# endif |
19233
|
|
|
|
|
|
|
#endif |
19234
|
|
|
|
|
|
|
#ifndef prefetchw |
19235
|
|
|
|
|
|
|
# define prefetchw(addr) |
19236
|
|
|
|
|
|
|
#endif |
19237
|
|
|
|
|
|
|
|
19238
|
|
|
|
|
|
|
|
19239
|
|
|
|
|
|
|
#undef _aligned_attribute |
19240
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
19241
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
19242
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19243
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
19244
|
|
|
|
|
|
|
#endif |
19245
|
|
|
|
|
|
|
|
19246
|
|
|
|
|
|
|
|
19247
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
19248
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
19249
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
19250
|
|
|
|
|
|
|
#else |
19251
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
19252
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
19253
|
|
|
|
|
|
|
#endif |
19254
|
|
|
|
|
|
|
|
19255
|
|
|
|
|
|
|
|
19256
|
|
|
|
|
|
|
|
19257
|
|
|
|
|
|
|
|
19258
|
|
|
|
|
|
|
|
19259
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
19260
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
19261
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
19262
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
19263
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
19264
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
19265
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
19266
|
|
|
|
|
|
|
|
19267
|
|
|
|
|
|
|
|
19268
|
|
|
|
|
|
|
|
19269
|
|
|
|
|
|
|
|
19270
|
|
|
|
|
|
|
|
19271
|
|
|
|
|
|
|
|
19272
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
19273
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
19274
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19275
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
19276
|
|
|
|
|
|
|
#else |
19277
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
19278
|
|
|
|
|
|
|
{ |
19279
|
|
|
|
|
|
|
union { |
19280
|
|
|
|
|
|
|
u32 w; |
19281
|
|
|
|
|
|
|
u8 b; |
19282
|
|
|
|
|
|
|
} u; |
19283
|
|
|
|
|
|
|
|
19284
|
|
|
|
|
|
|
u.w = 1; |
19285
|
|
|
|
|
|
|
return u.b; |
19286
|
|
|
|
|
|
|
} |
19287
|
|
|
|
|
|
|
#endif |
19288
|
|
|
|
|
|
|
|
19289
|
|
|
|
|
|
|
|
19290
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
19291
|
|
|
|
|
|
|
{ |
19292
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
19293
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
19294
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19295
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
19296
|
|
|
|
|
|
|
#else |
19297
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
19298
|
|
|
|
|
|
|
#endif |
19299
|
|
|
|
|
|
|
} |
19300
|
|
|
|
|
|
|
|
19301
|
|
|
|
|
|
|
|
19302
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
19303
|
|
|
|
|
|
|
{ |
19304
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
19305
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
19306
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19307
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
19308
|
|
|
|
|
|
|
#else |
19309
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
19310
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
19311
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
19312
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
19313
|
|
|
|
|
|
|
#endif |
19314
|
|
|
|
|
|
|
} |
19315
|
|
|
|
|
|
|
|
19316
|
|
|
|
|
|
|
|
19317
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
19318
|
|
|
|
|
|
|
{ |
19319
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
19320
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
19321
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19322
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
19323
|
|
|
|
|
|
|
#else |
19324
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
19325
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
19326
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
19327
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
19328
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
19329
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
19330
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
19331
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
19332
|
|
|
|
|
|
|
#endif |
19333
|
|
|
|
|
|
|
} |
19334
|
|
|
|
|
|
|
|
19335
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
19336
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
19337
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
19338
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
19339
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
19340
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
19341
|
|
|
|
|
|
|
|
19342
|
|
|
|
|
|
|
|
19343
|
|
|
|
|
|
|
|
19344
|
|
|
|
|
|
|
|
19345
|
|
|
|
|
|
|
|
19346
|
|
|
|
|
|
|
|
19347
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
19348
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
19349
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
19350
|
|
|
|
|
|
|
defined(__wasm__)) |
19351
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
19352
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19353
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
19354
|
|
|
|
|
|
|
#else |
19355
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
19356
|
|
|
|
|
|
|
#endif |
19357
|
|
|
|
|
|
|
|
19358
|
|
|
|
|
|
|
|
19359
|
|
|
|
|
|
|
|
19360
|
|
|
|
|
|
|
#ifdef FREESTANDING |
19361
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
19362
|
|
|
|
|
|
|
#else |
19363
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
19364
|
|
|
|
|
|
|
#endif |
19365
|
|
|
|
|
|
|
|
19366
|
|
|
|
|
|
|
|
19367
|
|
|
|
|
|
|
|
19368
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
19369
|
|
|
|
|
|
|
static forceinline type \ |
19370
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
19371
|
|
|
|
|
|
|
{ \ |
19372
|
|
|
|
|
|
|
type v; \ |
19373
|
|
|
|
|
|
|
\ |
19374
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
19375
|
|
|
|
|
|
|
return v; \ |
19376
|
|
|
|
|
|
|
} \ |
19377
|
|
|
|
|
|
|
\ |
19378
|
|
|
|
|
|
|
static forceinline void \ |
19379
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
19380
|
|
|
|
|
|
|
{ \ |
19381
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
19382
|
|
|
|
|
|
|
} |
19383
|
|
|
|
|
|
|
|
19384
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
19385
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
19386
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
19387
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
19388
|
|
|
|
|
|
|
|
19389
|
|
|
|
|
|
|
#undef MEMCOPY |
19390
|
|
|
|
|
|
|
|
19391
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
19392
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
19393
|
|
|
|
|
|
|
|
19394
|
|
|
|
|
|
|
|
19395
|
|
|
|
|
|
|
|
19396
|
|
|
|
|
|
|
static forceinline u16 |
19397
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
19398
|
|
|
|
|
|
|
{ |
19399
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19400
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
19401
|
|
|
|
|
|
|
else |
19402
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
19403
|
|
|
|
|
|
|
} |
19404
|
|
|
|
|
|
|
|
19405
|
|
|
|
|
|
|
static forceinline u16 |
19406
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
19407
|
|
|
|
|
|
|
{ |
19408
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19409
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
19410
|
|
|
|
|
|
|
else |
19411
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
19412
|
|
|
|
|
|
|
} |
19413
|
|
|
|
|
|
|
|
19414
|
|
|
|
|
|
|
static forceinline u32 |
19415
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
19416
|
|
|
|
|
|
|
{ |
19417
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19418
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
19419
|
|
|
|
|
|
|
else |
19420
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
19421
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
19422
|
|
|
|
|
|
|
} |
19423
|
|
|
|
|
|
|
|
19424
|
|
|
|
|
|
|
static forceinline u32 |
19425
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
19426
|
|
|
|
|
|
|
{ |
19427
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19428
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
19429
|
|
|
|
|
|
|
else |
19430
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
19431
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
19432
|
|
|
|
|
|
|
} |
19433
|
|
|
|
|
|
|
|
19434
|
|
|
|
|
|
|
static forceinline u64 |
19435
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
19436
|
|
|
|
|
|
|
{ |
19437
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
19438
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
19439
|
|
|
|
|
|
|
else |
19440
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
19441
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
19442
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
19443
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
19444
|
|
|
|
|
|
|
} |
19445
|
|
|
|
|
|
|
|
19446
|
|
|
|
|
|
|
static forceinline machine_word_t |
19447
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
19448
|
|
|
|
|
|
|
{ |
19449
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
19450
|
|
|
|
|
|
|
if (WORDBITS == 32) |
19451
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
19452
|
|
|
|
|
|
|
else |
19453
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
19454
|
|
|
|
|
|
|
} |
19455
|
|
|
|
|
|
|
|
19456
|
|
|
|
|
|
|
|
19457
|
|
|
|
|
|
|
|
19458
|
|
|
|
|
|
|
static forceinline void |
19459
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
19460
|
|
|
|
|
|
|
{ |
19461
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19462
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
19463
|
|
|
|
|
|
|
} else { |
19464
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
19465
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
19466
|
|
|
|
|
|
|
} |
19467
|
|
|
|
|
|
|
} |
19468
|
|
|
|
|
|
|
|
19469
|
|
|
|
|
|
|
static forceinline void |
19470
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
19471
|
|
|
|
|
|
|
{ |
19472
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19473
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
19474
|
|
|
|
|
|
|
} else { |
19475
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
19476
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
19477
|
|
|
|
|
|
|
} |
19478
|
|
|
|
|
|
|
} |
19479
|
|
|
|
|
|
|
|
19480
|
|
|
|
|
|
|
static forceinline void |
19481
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
19482
|
|
|
|
|
|
|
{ |
19483
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19484
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
19485
|
|
|
|
|
|
|
} else { |
19486
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
19487
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
19488
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
19489
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
19490
|
|
|
|
|
|
|
} |
19491
|
|
|
|
|
|
|
} |
19492
|
|
|
|
|
|
|
|
19493
|
|
|
|
|
|
|
static forceinline void |
19494
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
19495
|
|
|
|
|
|
|
{ |
19496
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19497
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
19498
|
|
|
|
|
|
|
} else { |
19499
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
19500
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
19501
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
19502
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
19503
|
|
|
|
|
|
|
} |
19504
|
|
|
|
|
|
|
} |
19505
|
|
|
|
|
|
|
|
19506
|
|
|
|
|
|
|
static forceinline void |
19507
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
19508
|
|
|
|
|
|
|
{ |
19509
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19510
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
19511
|
|
|
|
|
|
|
} else { |
19512
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
19513
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
19514
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
19515
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
19516
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
19517
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
19518
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
19519
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
19520
|
|
|
|
|
|
|
} |
19521
|
|
|
|
|
|
|
} |
19522
|
|
|
|
|
|
|
|
19523
|
|
|
|
|
|
|
static forceinline void |
19524
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
19525
|
|
|
|
|
|
|
{ |
19526
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
19527
|
|
|
|
|
|
|
if (WORDBITS == 32) |
19528
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
19529
|
|
|
|
|
|
|
else |
19530
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
19531
|
|
|
|
|
|
|
} |
19532
|
|
|
|
|
|
|
|
19533
|
|
|
|
|
|
|
|
19534
|
|
|
|
|
|
|
|
19535
|
|
|
|
|
|
|
|
19536
|
|
|
|
|
|
|
|
19537
|
|
|
|
|
|
|
|
19538
|
|
|
|
|
|
|
|
19539
|
|
|
|
|
|
|
static forceinline unsigned |
19540
|
|
|
|
|
|
|
bsr32(u32 v) |
19541
|
|
|
|
|
|
|
{ |
19542
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
19543
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
19544
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19545
|
|
|
|
|
|
|
unsigned long i; |
19546
|
|
|
|
|
|
|
|
19547
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
19548
|
|
|
|
|
|
|
return i; |
19549
|
|
|
|
|
|
|
#else |
19550
|
|
|
|
|
|
|
unsigned i = 0; |
19551
|
|
|
|
|
|
|
|
19552
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
19553
|
|
|
|
|
|
|
i++; |
19554
|
|
|
|
|
|
|
return i; |
19555
|
|
|
|
|
|
|
#endif |
19556
|
|
|
|
|
|
|
} |
19557
|
|
|
|
|
|
|
|
19558
|
|
|
|
|
|
|
static forceinline unsigned |
19559
|
|
|
|
|
|
|
bsr64(u64 v) |
19560
|
|
|
|
|
|
|
{ |
19561
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
19562
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
19563
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
19564
|
|
|
|
|
|
|
unsigned long i; |
19565
|
|
|
|
|
|
|
|
19566
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
19567
|
|
|
|
|
|
|
return i; |
19568
|
|
|
|
|
|
|
#else |
19569
|
|
|
|
|
|
|
unsigned i = 0; |
19570
|
|
|
|
|
|
|
|
19571
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
19572
|
|
|
|
|
|
|
i++; |
19573
|
|
|
|
|
|
|
return i; |
19574
|
|
|
|
|
|
|
#endif |
19575
|
|
|
|
|
|
|
} |
19576
|
|
|
|
|
|
|
|
19577
|
|
|
|
|
|
|
static forceinline unsigned |
19578
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
19579
|
|
|
|
|
|
|
{ |
19580
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
19581
|
|
|
|
|
|
|
if (WORDBITS == 32) |
19582
|
|
|
|
|
|
|
return bsr32(v); |
19583
|
|
|
|
|
|
|
else |
19584
|
|
|
|
|
|
|
return bsr64(v); |
19585
|
|
|
|
|
|
|
} |
19586
|
|
|
|
|
|
|
|
19587
|
|
|
|
|
|
|
|
19588
|
|
|
|
|
|
|
|
19589
|
|
|
|
|
|
|
static forceinline unsigned |
19590
|
|
|
|
|
|
|
bsf32(u32 v) |
19591
|
|
|
|
|
|
|
{ |
19592
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
19593
|
|
|
|
|
|
|
return __builtin_ctz(v); |
19594
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
19595
|
|
|
|
|
|
|
unsigned long i; |
19596
|
|
|
|
|
|
|
|
19597
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
19598
|
|
|
|
|
|
|
return i; |
19599
|
|
|
|
|
|
|
#else |
19600
|
|
|
|
|
|
|
unsigned i = 0; |
19601
|
|
|
|
|
|
|
|
19602
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
19603
|
|
|
|
|
|
|
i++; |
19604
|
|
|
|
|
|
|
return i; |
19605
|
|
|
|
|
|
|
#endif |
19606
|
|
|
|
|
|
|
} |
19607
|
|
|
|
|
|
|
|
19608
|
|
|
|
|
|
|
static forceinline unsigned |
19609
|
|
|
|
|
|
|
bsf64(u64 v) |
19610
|
|
|
|
|
|
|
{ |
19611
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
19612
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
19613
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
19614
|
|
|
|
|
|
|
unsigned long i; |
19615
|
|
|
|
|
|
|
|
19616
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
19617
|
|
|
|
|
|
|
return i; |
19618
|
|
|
|
|
|
|
#else |
19619
|
|
|
|
|
|
|
unsigned i = 0; |
19620
|
|
|
|
|
|
|
|
19621
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
19622
|
|
|
|
|
|
|
i++; |
19623
|
|
|
|
|
|
|
return i; |
19624
|
|
|
|
|
|
|
#endif |
19625
|
|
|
|
|
|
|
} |
19626
|
|
|
|
|
|
|
|
19627
|
|
|
|
|
|
|
static forceinline unsigned |
19628
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
19629
|
|
|
|
|
|
|
{ |
19630
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
19631
|
|
|
|
|
|
|
if (WORDBITS == 32) |
19632
|
|
|
|
|
|
|
return bsf32(v); |
19633
|
|
|
|
|
|
|
else |
19634
|
|
|
|
|
|
|
return bsf64(v); |
19635
|
|
|
|
|
|
|
} |
19636
|
|
|
|
|
|
|
|
19637
|
|
|
|
|
|
|
|
19638
|
|
|
|
|
|
|
#undef rbit32 |
19639
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
19640
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
19641
|
|
|
|
|
|
|
static forceinline u32 |
19642
|
|
|
|
|
|
|
rbit32(u32 v) |
19643
|
|
|
|
|
|
|
{ |
19644
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
19645
|
|
|
|
|
|
|
return v; |
19646
|
|
|
|
|
|
|
} |
19647
|
|
|
|
|
|
|
#define rbit32 rbit32 |
19648
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
19649
|
|
|
|
|
|
|
static forceinline u32 |
19650
|
|
|
|
|
|
|
rbit32(u32 v) |
19651
|
|
|
|
|
|
|
{ |
19652
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
19653
|
|
|
|
|
|
|
return v; |
19654
|
|
|
|
|
|
|
} |
19655
|
|
|
|
|
|
|
#define rbit32 rbit32 |
19656
|
|
|
|
|
|
|
#endif |
19657
|
|
|
|
|
|
|
|
19658
|
|
|
|
|
|
|
#endif |
19659
|
|
|
|
|
|
|
|
19660
|
|
|
|
|
|
|
|
19661
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
19662
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
19663
|
|
|
|
|
|
|
|
19664
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
19665
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
19666
|
|
|
|
|
|
|
|
19667
|
|
|
|
|
|
|
#ifdef FREESTANDING |
19668
|
|
|
|
|
|
|
|
19669
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
19670
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
19671
|
|
|
|
|
|
|
|
19672
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
19673
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
19674
|
|
|
|
|
|
|
|
19675
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
19676
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
19677
|
|
|
|
|
|
|
|
19678
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
19679
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
19680
|
|
|
|
|
|
|
|
19681
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
19682
|
|
|
|
|
|
|
#else |
19683
|
|
|
|
|
|
|
#include |
19684
|
|
|
|
|
|
|
#endif |
19685
|
|
|
|
|
|
|
|
19686
|
|
|
|
|
|
|
|
19687
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
19688
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
19689
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
19690
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
19691
|
|
|
|
|
|
|
#else |
19692
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
19693
|
|
|
|
|
|
|
#endif |
19694
|
|
|
|
|
|
|
|
19695
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
19696
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
19697
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
19698
|
|
|
|
|
|
|
|
19699
|
|
|
|
|
|
|
#endif |
19700
|
|
|
|
|
|
|
|
19701
|
|
|
|
|
|
|
|
19702
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
19703
|
|
|
|
|
|
|
|
19704
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
19705
|
|
|
|
|
|
|
|
19706
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
19707
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
19708
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
19709
|
|
|
|
|
|
|
#endif |
19710
|
|
|
|
|
|
|
|
19711
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
19712
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
19713
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
19714
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
19715
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
19716
|
|
|
|
|
|
|
|
19717
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
19718
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
19719
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
19720
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
19721
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
19722
|
|
|
|
|
|
|
|
19723
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
19724
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
19725
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
19726
|
|
|
|
|
|
|
|
19727
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
19728
|
|
|
|
|
|
|
|
19729
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
19730
|
|
|
|
|
|
|
{ |
19731
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
19732
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
19733
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
19734
|
|
|
|
|
|
|
} |
19735
|
|
|
|
|
|
|
#else |
19736
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
19737
|
|
|
|
|
|
|
#endif |
19738
|
|
|
|
|
|
|
|
19739
|
|
|
|
|
|
|
|
19740
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
19741
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
19742
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
19743
|
|
|
|
|
|
|
#else |
19744
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
19745
|
|
|
|
|
|
|
#endif |
19746
|
|
|
|
|
|
|
|
19747
|
|
|
|
|
|
|
|
19748
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
19749
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
19750
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
19751
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
19752
|
|
|
|
|
|
|
#else |
19753
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
19754
|
|
|
|
|
|
|
#endif |
19755
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
19756
|
|
|
|
|
|
|
|
19757
|
|
|
|
|
|
|
|
19758
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
19759
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
19760
|
|
|
|
|
|
|
#else |
19761
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
19762
|
|
|
|
|
|
|
#endif |
19763
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
19764
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
19765
|
|
|
|
|
|
|
defined(_MSC_VER))) |
19766
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
19767
|
|
|
|
|
|
|
#else |
19768
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
19769
|
|
|
|
|
|
|
#endif |
19770
|
|
|
|
|
|
|
|
19771
|
|
|
|
|
|
|
|
19772
|
|
|
|
|
|
|
#ifdef __AVX__ |
19773
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
19774
|
|
|
|
|
|
|
#else |
19775
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
19776
|
|
|
|
|
|
|
#endif |
19777
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
19778
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
19779
|
|
|
|
|
|
|
defined(_MSC_VER))) |
19780
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
19781
|
|
|
|
|
|
|
#else |
19782
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
19783
|
|
|
|
|
|
|
#endif |
19784
|
|
|
|
|
|
|
|
19785
|
|
|
|
|
|
|
|
19786
|
|
|
|
|
|
|
#ifdef __AVX2__ |
19787
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
19788
|
|
|
|
|
|
|
#else |
19789
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
19790
|
|
|
|
|
|
|
#endif |
19791
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
19792
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
19793
|
|
|
|
|
|
|
defined(_MSC_VER))) |
19794
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
19795
|
|
|
|
|
|
|
#else |
19796
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
19797
|
|
|
|
|
|
|
#endif |
19798
|
|
|
|
|
|
|
|
19799
|
|
|
|
|
|
|
|
19800
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
19801
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
19802
|
|
|
|
|
|
|
#else |
19803
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
19804
|
|
|
|
|
|
|
#endif |
19805
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
19806
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
19807
|
|
|
|
|
|
|
defined(_MSC_VER))) |
19808
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
19809
|
|
|
|
|
|
|
#else |
19810
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
19811
|
|
|
|
|
|
|
#endif |
19812
|
|
|
|
|
|
|
|
19813
|
|
|
|
|
|
|
#endif |
19814
|
|
|
|
|
|
|
|
19815
|
|
|
|
|
|
|
#endif |
19816
|
|
|
|
|
|
|
|
19817
|
|
|
|
|
|
|
|
19818
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE |
19819
|
|
|
|
|
|
|
# include |
19820
|
|
|
|
|
|
|
static forceinline void |
19821
|
|
|
|
|
|
|
matchfinder_init_avx2(mf_pos_t *data, size_t size) |
19822
|
|
|
|
|
|
|
{ |
19823
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
19824
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16(MATCHFINDER_INITVAL); |
19825
|
|
|
|
|
|
|
|
19826
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
19827
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
19828
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
19829
|
|
|
|
|
|
|
|
19830
|
|
|
|
|
|
|
do { |
19831
|
|
|
|
|
|
|
p[0] = v; |
19832
|
|
|
|
|
|
|
p[1] = v; |
19833
|
|
|
|
|
|
|
p[2] = v; |
19834
|
|
|
|
|
|
|
p[3] = v; |
19835
|
|
|
|
|
|
|
p += 4; |
19836
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
19837
|
|
|
|
|
|
|
} while (size != 0); |
19838
|
|
|
|
|
|
|
} |
19839
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_avx2 |
19840
|
|
|
|
|
|
|
|
19841
|
|
|
|
|
|
|
static forceinline void |
19842
|
|
|
|
|
|
|
matchfinder_rebase_avx2(mf_pos_t *data, size_t size) |
19843
|
|
|
|
|
|
|
{ |
19844
|
|
|
|
|
|
|
__m256i *p = (__m256i *)data; |
19845
|
|
|
|
|
|
|
__m256i v = _mm256_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
19846
|
|
|
|
|
|
|
|
19847
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
19848
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
19849
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
19850
|
|
|
|
|
|
|
|
19851
|
|
|
|
|
|
|
do { |
19852
|
|
|
|
|
|
|
|
19853
|
|
|
|
|
|
|
p[0] = _mm256_adds_epi16(p[0], v); |
19854
|
|
|
|
|
|
|
p[1] = _mm256_adds_epi16(p[1], v); |
19855
|
|
|
|
|
|
|
p[2] = _mm256_adds_epi16(p[2], v); |
19856
|
|
|
|
|
|
|
p[3] = _mm256_adds_epi16(p[3], v); |
19857
|
|
|
|
|
|
|
p += 4; |
19858
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
19859
|
|
|
|
|
|
|
} while (size != 0); |
19860
|
|
|
|
|
|
|
} |
19861
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_avx2 |
19862
|
|
|
|
|
|
|
|
19863
|
|
|
|
|
|
|
#elif HAVE_SSE2_NATIVE |
19864
|
|
|
|
|
|
|
# include |
19865
|
|
|
|
|
|
|
static forceinline void |
19866
|
|
|
|
|
|
|
matchfinder_init_sse2(mf_pos_t *data, size_t size) |
19867
|
|
|
|
|
|
|
{ |
19868
|
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
19869
|
|
|
|
|
|
|
__m128i v = _mm_set1_epi16(MATCHFINDER_INITVAL); |
19870
|
|
|
|
|
|
|
|
19871
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
19872
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
19873
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
19874
|
|
|
|
|
|
|
|
19875
|
|
|
|
|
|
|
do { |
19876
|
|
|
|
|
|
|
p[0] = v; |
19877
|
|
|
|
|
|
|
p[1] = v; |
19878
|
|
|
|
|
|
|
p[2] = v; |
19879
|
|
|
|
|
|
|
p[3] = v; |
19880
|
|
|
|
|
|
|
p += 4; |
19881
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
19882
|
|
|
|
|
|
|
} while (size != 0); |
19883
|
|
|
|
|
|
|
} |
19884
|
|
|
|
|
|
|
#define matchfinder_init matchfinder_init_sse2 |
19885
|
|
|
|
|
|
|
|
19886
|
|
|
|
|
|
|
static forceinline void |
19887
|
|
|
|
|
|
|
matchfinder_rebase_sse2(mf_pos_t *data, size_t size) |
19888
|
|
|
|
|
|
|
{ |
19889
|
|
|
|
|
|
|
__m128i *p = (__m128i *)data; |
19890
|
|
|
|
|
|
|
__m128i v = _mm_set1_epi16((u16)-MATCHFINDER_WINDOW_SIZE); |
19891
|
|
|
|
|
|
|
|
19892
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_MEM_ALIGNMENT % sizeof(*p) == 0); |
19893
|
|
|
|
|
|
|
STATIC_ASSERT(MATCHFINDER_SIZE_ALIGNMENT % (4 * sizeof(*p)) == 0); |
19894
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(mf_pos_t) == 2); |
19895
|
|
|
|
|
|
|
|
19896
|
|
|
|
|
|
|
do { |
19897
|
|
|
|
|
|
|
|
19898
|
|
|
|
|
|
|
p[0] = _mm_adds_epi16(p[0], v); |
19899
|
|
|
|
|
|
|
p[1] = _mm_adds_epi16(p[1], v); |
19900
|
|
|
|
|
|
|
p[2] = _mm_adds_epi16(p[2], v); |
19901
|
|
|
|
|
|
|
p[3] = _mm_adds_epi16(p[3], v); |
19902
|
|
|
|
|
|
|
p += 4; |
19903
|
|
|
|
|
|
|
size -= 4 * sizeof(*p); |
19904
|
|
|
|
|
|
|
} while (size != 0); |
19905
|
|
|
|
|
|
|
} |
19906
|
|
|
|
|
|
|
#define matchfinder_rebase matchfinder_rebase_sse2 |
19907
|
|
|
|
|
|
|
#endif |
19908
|
|
|
|
|
|
|
|
19909
|
|
|
|
|
|
|
#endif |
19910
|
|
|
|
|
|
|
|
19911
|
|
|
|
|
|
|
# endif |
19912
|
|
|
|
|
|
|
#else |
19913
|
|
|
|
|
|
|
# define MATCHFINDER_ALIGNED |
19914
|
|
|
|
|
|
|
#endif |
19915
|
|
|
|
|
|
|
|
19916
|
|
|
|
|
|
|
|
19917
|
|
|
|
|
|
|
#ifndef matchfinder_init |
19918
|
|
|
|
|
|
|
static forceinline void |
19919
|
|
|
|
|
|
|
matchfinder_init(mf_pos_t *data, size_t size) |
19920
|
|
|
|
|
|
|
{ |
19921
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
19922
|
|
|
|
|
|
|
size_t i; |
19923
|
|
|
|
|
|
|
|
19924
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
19925
|
|
|
|
|
|
|
data[i] = MATCHFINDER_INITVAL; |
19926
|
|
|
|
|
|
|
} |
19927
|
|
|
|
|
|
|
#endif |
19928
|
|
|
|
|
|
|
|
19929
|
|
|
|
|
|
|
|
19930
|
|
|
|
|
|
|
#ifndef matchfinder_rebase |
19931
|
|
|
|
|
|
|
static forceinline void |
19932
|
|
|
|
|
|
|
matchfinder_rebase(mf_pos_t *data, size_t size) |
19933
|
|
|
|
|
|
|
{ |
19934
|
|
|
|
|
|
|
size_t num_entries = size / sizeof(*data); |
19935
|
|
|
|
|
|
|
size_t i; |
19936
|
|
|
|
|
|
|
|
19937
|
|
|
|
|
|
|
if (MATCHFINDER_WINDOW_SIZE == 32768) { |
19938
|
|
|
|
|
|
|
|
19939
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) |
19940
|
|
|
|
|
|
|
data[i] = 0x8000 | (data[i] & ~(data[i] >> 15)); |
19941
|
|
|
|
|
|
|
} else { |
19942
|
|
|
|
|
|
|
for (i = 0; i < num_entries; i++) { |
19943
|
|
|
|
|
|
|
if (data[i] >= 0) |
19944
|
|
|
|
|
|
|
data[i] -= (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
19945
|
|
|
|
|
|
|
else |
19946
|
|
|
|
|
|
|
data[i] = (mf_pos_t)-MATCHFINDER_WINDOW_SIZE; |
19947
|
|
|
|
|
|
|
} |
19948
|
|
|
|
|
|
|
} |
19949
|
|
|
|
|
|
|
} |
19950
|
|
|
|
|
|
|
#endif |
19951
|
|
|
|
|
|
|
|
19952
|
|
|
|
|
|
|
|
19953
|
|
|
|
|
|
|
static forceinline u32 |
19954
|
|
|
|
|
|
|
lz_hash(u32 seq, unsigned num_bits) |
19955
|
|
|
|
|
|
|
{ |
19956
|
|
|
|
|
|
|
return (u32)(seq * 0x1E35A7BD) >> (32 - num_bits); |
19957
|
|
|
|
|
|
|
} |
19958
|
|
|
|
|
|
|
|
19959
|
|
|
|
|
|
|
|
19960
|
|
|
|
|
|
|
static forceinline unsigned |
19961
|
|
|
|
|
|
|
lz_extend(const u8 * const strptr, const u8 * const matchptr, |
19962
|
|
|
|
|
|
|
const unsigned start_len, const unsigned max_len) |
19963
|
|
|
|
|
|
|
{ |
19964
|
|
|
|
|
|
|
unsigned len = start_len; |
19965
|
|
|
|
|
|
|
machine_word_t v_word; |
19966
|
|
|
|
|
|
|
|
19967
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
19968
|
|
|
|
|
|
|
|
19969
|
|
|
|
|
|
|
if (likely(max_len - len >= 4 * WORDBYTES)) { |
19970
|
|
|
|
|
|
|
|
19971
|
|
|
|
|
|
|
#define COMPARE_WORD_STEP \ |
19972
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ \ |
19973
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); \ |
19974
|
|
|
|
|
|
|
if (v_word != 0) \ |
19975
|
|
|
|
|
|
|
goto word_differs; \ |
19976
|
|
|
|
|
|
|
len += WORDBYTES; \ |
19977
|
|
|
|
|
|
|
|
19978
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
19979
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
19980
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
19981
|
|
|
|
|
|
|
COMPARE_WORD_STEP |
19982
|
|
|
|
|
|
|
#undef COMPARE_WORD_STEP |
19983
|
|
|
|
|
|
|
} |
19984
|
|
|
|
|
|
|
|
19985
|
|
|
|
|
|
|
while (len + WORDBYTES <= max_len) { |
19986
|
|
|
|
|
|
|
v_word = load_word_unaligned(&matchptr[len]) ^ |
19987
|
|
|
|
|
|
|
load_word_unaligned(&strptr[len]); |
19988
|
|
|
|
|
|
|
if (v_word != 0) |
19989
|
|
|
|
|
|
|
goto word_differs; |
19990
|
|
|
|
|
|
|
len += WORDBYTES; |
19991
|
|
|
|
|
|
|
} |
19992
|
|
|
|
|
|
|
} |
19993
|
|
|
|
|
|
|
|
19994
|
|
|
|
|
|
|
while (len < max_len && matchptr[len] == strptr[len]) |
19995
|
|
|
|
|
|
|
len++; |
19996
|
|
|
|
|
|
|
return len; |
19997
|
|
|
|
|
|
|
|
19998
|
|
|
|
|
|
|
word_differs: |
19999
|
|
|
|
|
|
|
if (CPU_IS_LITTLE_ENDIAN()) |
20000
|
|
|
|
|
|
|
len += (bsfw(v_word) >> 3); |
20001
|
|
|
|
|
|
|
else |
20002
|
|
|
|
|
|
|
len += (WORDBITS - 1 - bsrw(v_word)) >> 3; |
20003
|
|
|
|
|
|
|
return len; |
20004
|
|
|
|
|
|
|
} |
20005
|
|
|
|
|
|
|
|
20006
|
|
|
|
|
|
|
#endif |
20007
|
|
|
|
|
|
|
|
20008
|
|
|
|
|
|
|
|
20009
|
|
|
|
|
|
|
#define BT_MATCHFINDER_HASH3_ORDER 16 |
20010
|
|
|
|
|
|
|
#define BT_MATCHFINDER_HASH3_WAYS 2 |
20011
|
|
|
|
|
|
|
#define BT_MATCHFINDER_HASH4_ORDER 16 |
20012
|
|
|
|
|
|
|
|
20013
|
|
|
|
|
|
|
#define BT_MATCHFINDER_TOTAL_HASH_SIZE \ |
20014
|
|
|
|
|
|
|
(((1UL << BT_MATCHFINDER_HASH3_ORDER) * BT_MATCHFINDER_HASH3_WAYS + \ |
20015
|
|
|
|
|
|
|
(1UL << BT_MATCHFINDER_HASH4_ORDER)) * sizeof(mf_pos_t)) |
20016
|
|
|
|
|
|
|
|
20017
|
|
|
|
|
|
|
|
20018
|
|
|
|
|
|
|
struct lz_match { |
20019
|
|
|
|
|
|
|
|
20020
|
|
|
|
|
|
|
|
20021
|
|
|
|
|
|
|
u16 length; |
20022
|
|
|
|
|
|
|
|
20023
|
|
|
|
|
|
|
|
20024
|
|
|
|
|
|
|
u16 offset; |
20025
|
|
|
|
|
|
|
}; |
20026
|
|
|
|
|
|
|
|
20027
|
|
|
|
|
|
|
struct MATCHFINDER_ALIGNED bt_matchfinder { |
20028
|
|
|
|
|
|
|
|
20029
|
|
|
|
|
|
|
|
20030
|
|
|
|
|
|
|
mf_pos_t hash3_tab[1UL << BT_MATCHFINDER_HASH3_ORDER][BT_MATCHFINDER_HASH3_WAYS]; |
20031
|
|
|
|
|
|
|
|
20032
|
|
|
|
|
|
|
|
20033
|
|
|
|
|
|
|
mf_pos_t hash4_tab[1UL << BT_MATCHFINDER_HASH4_ORDER]; |
20034
|
|
|
|
|
|
|
|
20035
|
|
|
|
|
|
|
|
20036
|
|
|
|
|
|
|
mf_pos_t child_tab[2UL * MATCHFINDER_WINDOW_SIZE]; |
20037
|
|
|
|
|
|
|
}; |
20038
|
|
|
|
|
|
|
|
20039
|
|
|
|
|
|
|
|
20040
|
|
|
|
|
|
|
static forceinline void |
20041
|
|
|
|
|
|
|
bt_matchfinder_init(struct bt_matchfinder *mf) |
20042
|
|
|
|
|
|
|
{ |
20043
|
|
|
|
|
|
|
STATIC_ASSERT(BT_MATCHFINDER_TOTAL_HASH_SIZE % |
20044
|
|
|
|
|
|
|
MATCHFINDER_SIZE_ALIGNMENT == 0); |
20045
|
|
|
|
|
|
|
|
20046
|
|
|
|
|
|
|
matchfinder_init((mf_pos_t *)mf, BT_MATCHFINDER_TOTAL_HASH_SIZE); |
20047
|
|
|
|
|
|
|
} |
20048
|
|
|
|
|
|
|
|
20049
|
|
|
|
|
|
|
static forceinline void |
20050
|
|
|
|
|
|
|
bt_matchfinder_slide_window(struct bt_matchfinder *mf) |
20051
|
|
|
|
|
|
|
{ |
20052
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(*mf) % MATCHFINDER_SIZE_ALIGNMENT == 0); |
20053
|
|
|
|
|
|
|
|
20054
|
|
|
|
|
|
|
matchfinder_rebase((mf_pos_t *)mf, sizeof(*mf)); |
20055
|
|
|
|
|
|
|
} |
20056
|
|
|
|
|
|
|
|
20057
|
|
|
|
|
|
|
static forceinline mf_pos_t * |
20058
|
|
|
|
|
|
|
bt_left_child(struct bt_matchfinder *mf, s32 node) |
20059
|
|
|
|
|
|
|
{ |
20060
|
30366
|
|
|
|
|
|
return &mf->child_tab[2 * (node & (MATCHFINDER_WINDOW_SIZE - 1)) + 0]; |
20061
|
|
|
|
|
|
|
} |
20062
|
|
|
|
|
|
|
|
20063
|
|
|
|
|
|
|
static forceinline mf_pos_t * |
20064
|
|
|
|
|
|
|
bt_right_child(struct bt_matchfinder *mf, s32 node) |
20065
|
|
|
|
|
|
|
{ |
20066
|
30366
|
|
|
|
|
|
return &mf->child_tab[2 * (node & (MATCHFINDER_WINDOW_SIZE - 1)) + 1]; |
20067
|
|
|
|
|
|
|
} |
20068
|
|
|
|
|
|
|
|
20069
|
|
|
|
|
|
|
|
20070
|
|
|
|
|
|
|
#define BT_MATCHFINDER_REQUIRED_NBYTES 5 |
20071
|
|
|
|
|
|
|
|
20072
|
|
|
|
|
|
|
|
20073
|
|
|
|
|
|
|
static forceinline struct lz_match * |
20074
|
|
|
|
|
|
|
bt_matchfinder_advance_one_byte(struct bt_matchfinder * const mf, |
20075
|
|
|
|
|
|
|
const u8 * const in_base, |
20076
|
|
|
|
|
|
|
const ptrdiff_t cur_pos, |
20077
|
|
|
|
|
|
|
const u32 max_len, |
20078
|
|
|
|
|
|
|
const u32 nice_len, |
20079
|
|
|
|
|
|
|
const u32 max_search_depth, |
20080
|
|
|
|
|
|
|
u32 * const next_hashes, |
20081
|
|
|
|
|
|
|
struct lz_match *lz_matchptr, |
20082
|
|
|
|
|
|
|
const bool record_matches) |
20083
|
|
|
|
|
|
|
{ |
20084
|
15264
|
|
|
|
|
|
const u8 *in_next = in_base + cur_pos; |
20085
|
15264
|
|
|
|
|
|
u32 depth_remaining = max_search_depth; |
20086
|
15264
|
|
|
|
|
|
const s32 cutoff = cur_pos - MATCHFINDER_WINDOW_SIZE; |
20087
|
|
|
|
|
|
|
u32 next_hashseq; |
20088
|
|
|
|
|
|
|
u32 hash3; |
20089
|
|
|
|
|
|
|
u32 hash4; |
20090
|
|
|
|
|
|
|
s32 cur_node; |
20091
|
|
|
|
|
|
|
#if BT_MATCHFINDER_HASH3_WAYS >= 2 |
20092
|
|
|
|
|
|
|
s32 cur_node_2; |
20093
|
|
|
|
|
|
|
#endif |
20094
|
|
|
|
|
|
|
const u8 *matchptr; |
20095
|
|
|
|
|
|
|
mf_pos_t *pending_lt_ptr, *pending_gt_ptr; |
20096
|
|
|
|
|
|
|
u32 best_lt_len, best_gt_len; |
20097
|
|
|
|
|
|
|
u32 len; |
20098
|
15264
|
|
|
|
|
|
u32 best_len = 3; |
20099
|
|
|
|
|
|
|
|
20100
|
|
|
|
|
|
|
STATIC_ASSERT(BT_MATCHFINDER_HASH3_WAYS >= 1 && |
20101
|
|
|
|
|
|
|
BT_MATCHFINDER_HASH3_WAYS <= 2); |
20102
|
|
|
|
|
|
|
|
20103
|
30528
|
|
|
|
|
|
next_hashseq = get_unaligned_le32(in_next + 1); |
20104
|
|
|
|
|
|
|
|
20105
|
15264
|
|
|
|
|
|
hash3 = next_hashes[0]; |
20106
|
15264
|
|
|
|
|
|
hash4 = next_hashes[1]; |
20107
|
|
|
|
|
|
|
|
20108
|
30528
|
|
|
|
|
|
next_hashes[0] = lz_hash(next_hashseq & 0xFFFFFF, BT_MATCHFINDER_HASH3_ORDER); |
20109
|
30528
|
|
|
|
|
|
next_hashes[1] = lz_hash(next_hashseq, BT_MATCHFINDER_HASH4_ORDER); |
20110
|
15264
|
|
|
|
|
|
prefetchw(&mf->hash3_tab[next_hashes[0]]); |
20111
|
15264
|
|
|
|
|
|
prefetchw(&mf->hash4_tab[next_hashes[1]]); |
20112
|
|
|
|
|
|
|
|
20113
|
15264
|
|
|
|
|
|
cur_node = mf->hash3_tab[hash3][0]; |
20114
|
15264
|
|
|
|
|
|
mf->hash3_tab[hash3][0] = cur_pos; |
20115
|
|
|
|
|
|
|
#if BT_MATCHFINDER_HASH3_WAYS >= 2 |
20116
|
15264
|
|
|
|
|
|
cur_node_2 = mf->hash3_tab[hash3][1]; |
20117
|
15264
|
|
|
|
|
|
mf->hash3_tab[hash3][1] = cur_node; |
20118
|
|
|
|
|
|
|
#endif |
20119
|
225
|
100
|
|
|
|
|
if (record_matches && cur_node > cutoff) { |
20120
|
63
|
|
|
|
|
|
u32 seq3 = load_u24_unaligned(in_next); |
20121
|
63
|
50
|
|
|
|
|
if (seq3 == load_u24_unaligned(&in_base[cur_node])) { |
20122
|
63
|
|
|
|
|
|
lz_matchptr->length = 3; |
20123
|
63
|
|
|
|
|
|
lz_matchptr->offset = in_next - &in_base[cur_node]; |
20124
|
63
|
|
|
|
|
|
lz_matchptr++; |
20125
|
|
|
|
|
|
|
} |
20126
|
|
|
|
|
|
|
#if BT_MATCHFINDER_HASH3_WAYS >= 2 |
20127
|
0
|
0
|
|
|
|
|
else if (cur_node_2 > cutoff && |
|
|
0
|
|
|
|
|
|
20128
|
0
|
|
|
|
|
|
seq3 == load_u24_unaligned(&in_base[cur_node_2])) |
20129
|
|
|
|
|
|
|
{ |
20130
|
0
|
|
|
|
|
|
lz_matchptr->length = 3; |
20131
|
0
|
|
|
|
|
|
lz_matchptr->offset = in_next - &in_base[cur_node_2]; |
20132
|
0
|
|
|
|
|
|
lz_matchptr++; |
20133
|
|
|
|
|
|
|
} |
20134
|
|
|
|
|
|
|
#endif |
20135
|
|
|
|
|
|
|
} |
20136
|
|
|
|
|
|
|
|
20137
|
15264
|
|
|
|
|
|
cur_node = mf->hash4_tab[hash4]; |
20138
|
15264
|
|
|
|
|
|
mf->hash4_tab[hash4] = cur_pos; |
20139
|
|
|
|
|
|
|
|
20140
|
30528
|
|
|
|
|
|
pending_lt_ptr = bt_left_child(mf, cur_pos); |
20141
|
30528
|
|
|
|
|
|
pending_gt_ptr = bt_right_child(mf, cur_pos); |
20142
|
|
|
|
|
|
|
|
20143
|
15264
|
100
|
|
|
|
|
if (cur_node <= cutoff) { |
|
|
50
|
|
|
|
|
|
20144
|
162
|
|
|
|
|
|
*pending_lt_ptr = MATCHFINDER_INITVAL; |
20145
|
162
|
|
|
|
|
|
*pending_gt_ptr = MATCHFINDER_INITVAL; |
20146
|
162
|
|
|
|
|
|
return lz_matchptr; |
20147
|
|
|
|
|
|
|
} |
20148
|
|
|
|
|
|
|
|
20149
|
15102
|
|
|
|
|
|
best_lt_len = 0; |
20150
|
15102
|
|
|
|
|
|
best_gt_len = 0; |
20151
|
15102
|
|
|
|
|
|
len = 0; |
20152
|
|
|
|
|
|
|
|
20153
|
|
|
|
|
|
|
for (;;) { |
20154
|
15102
|
|
|
|
|
|
matchptr = &in_base[cur_node]; |
20155
|
|
|
|
|
|
|
|
20156
|
15102
|
50
|
|
|
|
|
if (matchptr[len] == in_next[len]) { |
|
|
50
|
|
|
|
|
|
20157
|
30204
|
|
|
|
|
|
len = lz_extend(in_next, matchptr, len + 1, max_len); |
20158
|
15102
|
50
|
|
|
|
|
if (!record_matches || len > best_len) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
20159
|
|
|
|
|
|
|
if (record_matches) { |
20160
|
63
|
|
|
|
|
|
best_len = len; |
20161
|
63
|
|
|
|
|
|
lz_matchptr->length = len; |
20162
|
63
|
|
|
|
|
|
lz_matchptr->offset = in_next - matchptr; |
20163
|
63
|
|
|
|
|
|
lz_matchptr++; |
20164
|
|
|
|
|
|
|
} |
20165
|
15102
|
50
|
|
|
|
|
if (len >= nice_len) { |
|
|
50
|
|
|
|
|
|
20166
|
15102
|
|
|
|
|
|
*pending_lt_ptr = *bt_left_child(mf, cur_node); |
20167
|
15102
|
|
|
|
|
|
*pending_gt_ptr = *bt_right_child(mf, cur_node); |
20168
|
15102
|
|
|
|
|
|
return lz_matchptr; |
20169
|
|
|
|
|
|
|
} |
20170
|
|
|
|
|
|
|
} |
20171
|
|
|
|
|
|
|
} |
20172
|
|
|
|
|
|
|
|
20173
|
0
|
0
|
|
|
|
|
if (matchptr[len] < in_next[len]) { |
|
|
0
|
|
|
|
|
|
20174
|
0
|
|
|
|
|
|
*pending_lt_ptr = cur_node; |
20175
|
0
|
|
|
|
|
|
pending_lt_ptr = bt_right_child(mf, cur_node); |
20176
|
0
|
|
|
|
|
|
cur_node = *pending_lt_ptr; |
20177
|
0
|
|
|
|
|
|
best_lt_len = len; |
20178
|
0
|
0
|
|
|
|
|
if (best_gt_len < len) |
|
|
0
|
|
|
|
|
|
20179
|
0
|
|
|
|
|
|
len = best_gt_len; |
20180
|
|
|
|
|
|
|
} else { |
20181
|
0
|
|
|
|
|
|
*pending_gt_ptr = cur_node; |
20182
|
0
|
|
|
|
|
|
pending_gt_ptr = bt_left_child(mf, cur_node); |
20183
|
0
|
|
|
|
|
|
cur_node = *pending_gt_ptr; |
20184
|
0
|
|
|
|
|
|
best_gt_len = len; |
20185
|
0
|
0
|
|
|
|
|
if (best_lt_len < len) |
|
|
0
|
|
|
|
|
|
20186
|
0
|
|
|
|
|
|
len = best_lt_len; |
20187
|
|
|
|
|
|
|
} |
20188
|
|
|
|
|
|
|
|
20189
|
0
|
0
|
|
|
|
|
if (cur_node <= cutoff || !--depth_remaining) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
20190
|
0
|
|
|
|
|
|
*pending_lt_ptr = MATCHFINDER_INITVAL; |
20191
|
0
|
|
|
|
|
|
*pending_gt_ptr = MATCHFINDER_INITVAL; |
20192
|
15039
|
|
|
|
|
|
return lz_matchptr; |
20193
|
|
|
|
|
|
|
} |
20194
|
|
|
|
|
|
|
} |
20195
|
|
|
|
|
|
|
} |
20196
|
|
|
|
|
|
|
|
20197
|
|
|
|
|
|
|
|
20198
|
|
|
|
|
|
|
static forceinline struct lz_match * |
20199
|
|
|
|
|
|
|
bt_matchfinder_get_matches(struct bt_matchfinder *mf, |
20200
|
|
|
|
|
|
|
const u8 *in_base, |
20201
|
|
|
|
|
|
|
ptrdiff_t cur_pos, |
20202
|
|
|
|
|
|
|
u32 max_len, |
20203
|
|
|
|
|
|
|
u32 nice_len, |
20204
|
|
|
|
|
|
|
u32 max_search_depth, |
20205
|
|
|
|
|
|
|
u32 next_hashes[2], |
20206
|
|
|
|
|
|
|
struct lz_match *lz_matchptr) |
20207
|
|
|
|
|
|
|
{ |
20208
|
225
|
|
|
|
|
|
return bt_matchfinder_advance_one_byte(mf, |
20209
|
|
|
|
|
|
|
in_base, |
20210
|
|
|
|
|
|
|
cur_pos, |
20211
|
|
|
|
|
|
|
max_len, |
20212
|
|
|
|
|
|
|
nice_len, |
20213
|
|
|
|
|
|
|
max_search_depth, |
20214
|
|
|
|
|
|
|
next_hashes, |
20215
|
|
|
|
|
|
|
lz_matchptr, |
20216
|
|
|
|
|
|
|
true); |
20217
|
|
|
|
|
|
|
} |
20218
|
|
|
|
|
|
|
|
20219
|
|
|
|
|
|
|
|
20220
|
|
|
|
|
|
|
static forceinline void |
20221
|
|
|
|
|
|
|
bt_matchfinder_skip_byte(struct bt_matchfinder *mf, |
20222
|
|
|
|
|
|
|
const u8 *in_base, |
20223
|
|
|
|
|
|
|
ptrdiff_t cur_pos, |
20224
|
|
|
|
|
|
|
u32 nice_len, |
20225
|
|
|
|
|
|
|
u32 max_search_depth, |
20226
|
|
|
|
|
|
|
u32 next_hashes[2]) |
20227
|
|
|
|
|
|
|
{ |
20228
|
|
|
|
|
|
|
bt_matchfinder_advance_one_byte(mf, |
20229
|
|
|
|
|
|
|
in_base, |
20230
|
|
|
|
|
|
|
cur_pos, |
20231
|
|
|
|
|
|
|
nice_len, |
20232
|
|
|
|
|
|
|
nice_len, |
20233
|
|
|
|
|
|
|
max_search_depth, |
20234
|
|
|
|
|
|
|
next_hashes, |
20235
|
|
|
|
|
|
|
NULL, |
20236
|
|
|
|
|
|
|
false); |
20237
|
|
|
|
|
|
|
} |
20238
|
|
|
|
|
|
|
|
20239
|
|
|
|
|
|
|
#endif |
20240
|
|
|
|
|
|
|
|
20241
|
|
|
|
|
|
|
|
20242
|
|
|
|
|
|
|
#define MAX_MATCHES_PER_POS \ |
20243
|
|
|
|
|
|
|
(DEFLATE_MAX_MATCH_LEN - DEFLATE_MIN_MATCH_LEN + 1) |
20244
|
|
|
|
|
|
|
#endif |
20245
|
|
|
|
|
|
|
|
20246
|
|
|
|
|
|
|
|
20247
|
|
|
|
|
|
|
#define MAX_BLOCK_LENGTH \ |
20248
|
|
|
|
|
|
|
MAX(SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH - 1, \ |
20249
|
|
|
|
|
|
|
SOFT_MAX_BLOCK_LENGTH + 1 + DEFLATE_MAX_MATCH_LEN) |
20250
|
|
|
|
|
|
|
|
20251
|
|
|
|
|
|
|
static forceinline void |
20252
|
|
|
|
|
|
|
check_buildtime_parameters(void) |
20253
|
|
|
|
|
|
|
{ |
20254
|
|
|
|
|
|
|
|
20255
|
|
|
|
|
|
|
STATIC_ASSERT(SOFT_MAX_BLOCK_LENGTH >= MIN_BLOCK_LENGTH); |
20256
|
|
|
|
|
|
|
STATIC_ASSERT(FAST_SOFT_MAX_BLOCK_LENGTH >= MIN_BLOCK_LENGTH); |
20257
|
|
|
|
|
|
|
STATIC_ASSERT(SEQ_STORE_LENGTH * DEFLATE_MIN_MATCH_LEN >= |
20258
|
|
|
|
|
|
|
MIN_BLOCK_LENGTH); |
20259
|
|
|
|
|
|
|
STATIC_ASSERT(FAST_SEQ_STORE_LENGTH * HT_MATCHFINDER_MIN_MATCH_LEN >= |
20260
|
|
|
|
|
|
|
MIN_BLOCK_LENGTH); |
20261
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
20262
|
|
|
|
|
|
|
STATIC_ASSERT(MIN_BLOCK_LENGTH * MAX_MATCHES_PER_POS <= |
20263
|
|
|
|
|
|
|
MATCH_CACHE_LENGTH); |
20264
|
|
|
|
|
|
|
#endif |
20265
|
|
|
|
|
|
|
|
20266
|
|
|
|
|
|
|
|
20267
|
|
|
|
|
|
|
STATIC_ASSERT(FAST_SOFT_MAX_BLOCK_LENGTH <= SOFT_MAX_BLOCK_LENGTH); |
20268
|
|
|
|
|
|
|
|
20269
|
|
|
|
|
|
|
|
20270
|
|
|
|
|
|
|
STATIC_ASSERT(SEQ_STORE_LENGTH * DEFLATE_MIN_MATCH_LEN <= |
20271
|
|
|
|
|
|
|
SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH); |
20272
|
|
|
|
|
|
|
STATIC_ASSERT(FAST_SEQ_STORE_LENGTH * HT_MATCHFINDER_MIN_MATCH_LEN <= |
20273
|
|
|
|
|
|
|
FAST_SOFT_MAX_BLOCK_LENGTH + MIN_BLOCK_LENGTH); |
20274
|
|
|
|
|
|
|
|
20275
|
|
|
|
|
|
|
|
20276
|
|
|
|
|
|
|
STATIC_ASSERT( |
20277
|
|
|
|
|
|
|
MAX_LITLEN_CODEWORD_LEN <= DEFLATE_MAX_LITLEN_CODEWORD_LEN); |
20278
|
|
|
|
|
|
|
STATIC_ASSERT( |
20279
|
|
|
|
|
|
|
MAX_OFFSET_CODEWORD_LEN <= DEFLATE_MAX_OFFSET_CODEWORD_LEN); |
20280
|
|
|
|
|
|
|
STATIC_ASSERT( |
20281
|
|
|
|
|
|
|
MAX_PRE_CODEWORD_LEN <= DEFLATE_MAX_PRE_CODEWORD_LEN); |
20282
|
|
|
|
|
|
|
STATIC_ASSERT( |
20283
|
|
|
|
|
|
|
(1U << MAX_LITLEN_CODEWORD_LEN) >= DEFLATE_NUM_LITLEN_SYMS); |
20284
|
|
|
|
|
|
|
STATIC_ASSERT( |
20285
|
|
|
|
|
|
|
(1U << MAX_OFFSET_CODEWORD_LEN) >= DEFLATE_NUM_OFFSET_SYMS); |
20286
|
|
|
|
|
|
|
STATIC_ASSERT( |
20287
|
|
|
|
|
|
|
(1U << MAX_PRE_CODEWORD_LEN) >= DEFLATE_NUM_PRECODE_SYMS); |
20288
|
|
|
|
|
|
|
} |
20289
|
|
|
|
|
|
|
|
20290
|
|
|
|
|
|
|
|
20291
|
|
|
|
|
|
|
|
20292
|
|
|
|
|
|
|
|
20293
|
|
|
|
|
|
|
static const unsigned deflate_length_slot_base[] = { |
20294
|
|
|
|
|
|
|
3, 4, 5, 6, 7, 8, 9, 10, |
20295
|
|
|
|
|
|
|
11, 13, 15, 17, 19, 23, 27, 31, |
20296
|
|
|
|
|
|
|
35, 43, 51, 59, 67, 83, 99, 115, |
20297
|
|
|
|
|
|
|
131, 163, 195, 227, 258, |
20298
|
|
|
|
|
|
|
}; |
20299
|
|
|
|
|
|
|
|
20300
|
|
|
|
|
|
|
|
20301
|
|
|
|
|
|
|
static const u8 deflate_extra_length_bits[] = { |
20302
|
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, |
20303
|
|
|
|
|
|
|
1, 1, 1, 1, 2, 2, 2, 2, |
20304
|
|
|
|
|
|
|
3, 3, 3, 3, 4, 4, 4, 4, |
20305
|
|
|
|
|
|
|
5, 5, 5, 5, 0, |
20306
|
|
|
|
|
|
|
}; |
20307
|
|
|
|
|
|
|
|
20308
|
|
|
|
|
|
|
|
20309
|
|
|
|
|
|
|
static const unsigned deflate_offset_slot_base[] = { |
20310
|
|
|
|
|
|
|
1, 2, 3, 4, 5, 7, 9, 13, |
20311
|
|
|
|
|
|
|
17, 25, 33, 49, 65, 97, 129, 193, |
20312
|
|
|
|
|
|
|
257, 385, 513, 769, 1025, 1537, 2049, 3073, |
20313
|
|
|
|
|
|
|
4097, 6145, 8193, 12289, 16385, 24577, |
20314
|
|
|
|
|
|
|
}; |
20315
|
|
|
|
|
|
|
|
20316
|
|
|
|
|
|
|
|
20317
|
|
|
|
|
|
|
static const u8 deflate_extra_offset_bits[] = { |
20318
|
|
|
|
|
|
|
0, 0, 0, 0, 1, 1, 2, 2, |
20319
|
|
|
|
|
|
|
3, 3, 4, 4, 5, 5, 6, 6, |
20320
|
|
|
|
|
|
|
7, 7, 8, 8, 9, 9, 10, 10, |
20321
|
|
|
|
|
|
|
11, 11, 12, 12, 13, 13, |
20322
|
|
|
|
|
|
|
}; |
20323
|
|
|
|
|
|
|
|
20324
|
|
|
|
|
|
|
|
20325
|
|
|
|
|
|
|
static const u8 deflate_length_slot[DEFLATE_MAX_MATCH_LEN + 1] = { |
20326
|
|
|
|
|
|
|
0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, |
20327
|
|
|
|
|
|
|
12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, |
20328
|
|
|
|
|
|
|
16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, |
20329
|
|
|
|
|
|
|
18, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, |
20330
|
|
|
|
|
|
|
20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, |
20331
|
|
|
|
|
|
|
21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, |
20332
|
|
|
|
|
|
|
22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, |
20333
|
|
|
|
|
|
|
23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, |
20334
|
|
|
|
|
|
|
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, |
20335
|
|
|
|
|
|
|
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, |
20336
|
|
|
|
|
|
|
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, |
20337
|
|
|
|
|
|
|
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, |
20338
|
|
|
|
|
|
|
26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
20339
|
|
|
|
|
|
|
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
20340
|
|
|
|
|
|
|
27, 27, 28, |
20341
|
|
|
|
|
|
|
}; |
20342
|
|
|
|
|
|
|
|
20343
|
|
|
|
|
|
|
|
20344
|
|
|
|
|
|
|
static const u8 deflate_offset_slot[512] = { |
20345
|
|
|
|
|
|
|
0, 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, |
20346
|
|
|
|
|
|
|
7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, |
20347
|
|
|
|
|
|
|
9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, |
20348
|
|
|
|
|
|
|
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, |
20349
|
|
|
|
|
|
|
11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, |
20350
|
|
|
|
|
|
|
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, |
20351
|
|
|
|
|
|
|
12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, |
20352
|
|
|
|
|
|
|
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, |
20353
|
|
|
|
|
|
|
13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
20354
|
|
|
|
|
|
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
20355
|
|
|
|
|
|
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
20356
|
|
|
|
|
|
|
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, |
20357
|
|
|
|
|
|
|
14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
20358
|
|
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
20359
|
|
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
20360
|
|
|
|
|
|
|
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, |
20361
|
|
|
|
|
|
|
15, 0, 16, 17, 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, |
20362
|
|
|
|
|
|
|
22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, |
20363
|
|
|
|
|
|
|
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, |
20364
|
|
|
|
|
|
|
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, |
20365
|
|
|
|
|
|
|
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, |
20366
|
|
|
|
|
|
|
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, |
20367
|
|
|
|
|
|
|
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
20368
|
|
|
|
|
|
|
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, |
20369
|
|
|
|
|
|
|
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
20370
|
|
|
|
|
|
|
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
20371
|
|
|
|
|
|
|
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
20372
|
|
|
|
|
|
|
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, |
20373
|
|
|
|
|
|
|
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, |
20374
|
|
|
|
|
|
|
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, |
20375
|
|
|
|
|
|
|
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, |
20376
|
|
|
|
|
|
|
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, |
20377
|
|
|
|
|
|
|
}; |
20378
|
|
|
|
|
|
|
|
20379
|
|
|
|
|
|
|
|
20380
|
|
|
|
|
|
|
static const u8 deflate_precode_lens_permutation[DEFLATE_NUM_PRECODE_SYMS] = { |
20381
|
|
|
|
|
|
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
20382
|
|
|
|
|
|
|
}; |
20383
|
|
|
|
|
|
|
|
20384
|
|
|
|
|
|
|
|
20385
|
|
|
|
|
|
|
static const u8 deflate_extra_precode_bits[DEFLATE_NUM_PRECODE_SYMS] = { |
20386
|
|
|
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 |
20387
|
|
|
|
|
|
|
}; |
20388
|
|
|
|
|
|
|
|
20389
|
|
|
|
|
|
|
|
20390
|
|
|
|
|
|
|
struct deflate_codewords { |
20391
|
|
|
|
|
|
|
u32 litlen[DEFLATE_NUM_LITLEN_SYMS]; |
20392
|
|
|
|
|
|
|
u32 offset[DEFLATE_NUM_OFFSET_SYMS]; |
20393
|
|
|
|
|
|
|
}; |
20394
|
|
|
|
|
|
|
|
20395
|
|
|
|
|
|
|
|
20396
|
|
|
|
|
|
|
struct deflate_lens { |
20397
|
|
|
|
|
|
|
u8 litlen[DEFLATE_NUM_LITLEN_SYMS]; |
20398
|
|
|
|
|
|
|
u8 offset[DEFLATE_NUM_OFFSET_SYMS]; |
20399
|
|
|
|
|
|
|
}; |
20400
|
|
|
|
|
|
|
|
20401
|
|
|
|
|
|
|
|
20402
|
|
|
|
|
|
|
struct deflate_codes { |
20403
|
|
|
|
|
|
|
struct deflate_codewords codewords; |
20404
|
|
|
|
|
|
|
struct deflate_lens lens; |
20405
|
|
|
|
|
|
|
}; |
20406
|
|
|
|
|
|
|
|
20407
|
|
|
|
|
|
|
|
20408
|
|
|
|
|
|
|
struct deflate_freqs { |
20409
|
|
|
|
|
|
|
u32 litlen[DEFLATE_NUM_LITLEN_SYMS]; |
20410
|
|
|
|
|
|
|
u32 offset[DEFLATE_NUM_OFFSET_SYMS]; |
20411
|
|
|
|
|
|
|
}; |
20412
|
|
|
|
|
|
|
|
20413
|
|
|
|
|
|
|
|
20414
|
|
|
|
|
|
|
struct deflate_sequence { |
20415
|
|
|
|
|
|
|
|
20416
|
|
|
|
|
|
|
|
20417
|
|
|
|
|
|
|
#define SEQ_LENGTH_SHIFT 23 |
20418
|
|
|
|
|
|
|
#define SEQ_LITRUNLEN_MASK (((u32)1 << SEQ_LENGTH_SHIFT) - 1) |
20419
|
|
|
|
|
|
|
u32 litrunlen_and_length; |
20420
|
|
|
|
|
|
|
|
20421
|
|
|
|
|
|
|
|
20422
|
|
|
|
|
|
|
u16 offset; |
20423
|
|
|
|
|
|
|
|
20424
|
|
|
|
|
|
|
|
20425
|
|
|
|
|
|
|
u16 offset_slot; |
20426
|
|
|
|
|
|
|
}; |
20427
|
|
|
|
|
|
|
|
20428
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
20429
|
|
|
|
|
|
|
|
20430
|
|
|
|
|
|
|
|
20431
|
|
|
|
|
|
|
struct deflate_costs { |
20432
|
|
|
|
|
|
|
|
20433
|
|
|
|
|
|
|
|
20434
|
|
|
|
|
|
|
u32 literal[DEFLATE_NUM_LITERALS]; |
20435
|
|
|
|
|
|
|
|
20436
|
|
|
|
|
|
|
|
20437
|
|
|
|
|
|
|
u32 length[DEFLATE_MAX_MATCH_LEN + 1]; |
20438
|
|
|
|
|
|
|
|
20439
|
|
|
|
|
|
|
|
20440
|
|
|
|
|
|
|
u32 offset_slot[DEFLATE_NUM_OFFSET_SYMS]; |
20441
|
|
|
|
|
|
|
}; |
20442
|
|
|
|
|
|
|
|
20443
|
|
|
|
|
|
|
|
20444
|
|
|
|
|
|
|
struct deflate_optimum_node { |
20445
|
|
|
|
|
|
|
|
20446
|
|
|
|
|
|
|
u32 cost_to_end; |
20447
|
|
|
|
|
|
|
|
20448
|
|
|
|
|
|
|
|
20449
|
|
|
|
|
|
|
#define OPTIMUM_OFFSET_SHIFT 9 |
20450
|
|
|
|
|
|
|
#define OPTIMUM_LEN_MASK (((u32)1 << OPTIMUM_OFFSET_SHIFT) - 1) |
20451
|
|
|
|
|
|
|
u32 item; |
20452
|
|
|
|
|
|
|
|
20453
|
|
|
|
|
|
|
}; |
20454
|
|
|
|
|
|
|
|
20455
|
|
|
|
|
|
|
#endif |
20456
|
|
|
|
|
|
|
|
20457
|
|
|
|
|
|
|
|
20458
|
|
|
|
|
|
|
#define NUM_LITERAL_OBSERVATION_TYPES 8 |
20459
|
|
|
|
|
|
|
#define NUM_MATCH_OBSERVATION_TYPES 2 |
20460
|
|
|
|
|
|
|
#define NUM_OBSERVATION_TYPES (NUM_LITERAL_OBSERVATION_TYPES + \ |
20461
|
|
|
|
|
|
|
NUM_MATCH_OBSERVATION_TYPES) |
20462
|
|
|
|
|
|
|
#define NUM_OBSERVATIONS_PER_BLOCK_CHECK 512 |
20463
|
|
|
|
|
|
|
struct block_split_stats { |
20464
|
|
|
|
|
|
|
u32 new_observations[NUM_OBSERVATION_TYPES]; |
20465
|
|
|
|
|
|
|
u32 observations[NUM_OBSERVATION_TYPES]; |
20466
|
|
|
|
|
|
|
u32 num_new_observations; |
20467
|
|
|
|
|
|
|
u32 num_observations; |
20468
|
|
|
|
|
|
|
}; |
20469
|
|
|
|
|
|
|
|
20470
|
|
|
|
|
|
|
struct deflate_output_bitstream; |
20471
|
|
|
|
|
|
|
|
20472
|
|
|
|
|
|
|
|
20473
|
|
|
|
|
|
|
struct libdeflate_compressor { |
20474
|
|
|
|
|
|
|
|
20475
|
|
|
|
|
|
|
|
20476
|
|
|
|
|
|
|
void (*impl)(struct libdeflate_compressor *restrict c, const u8 *in, |
20477
|
|
|
|
|
|
|
size_t in_nbytes, struct deflate_output_bitstream *os); |
20478
|
|
|
|
|
|
|
|
20479
|
|
|
|
|
|
|
|
20480
|
|
|
|
|
|
|
unsigned compression_level; |
20481
|
|
|
|
|
|
|
|
20482
|
|
|
|
|
|
|
|
20483
|
|
|
|
|
|
|
size_t max_passthrough_size; |
20484
|
|
|
|
|
|
|
|
20485
|
|
|
|
|
|
|
|
20486
|
|
|
|
|
|
|
unsigned max_search_depth; |
20487
|
|
|
|
|
|
|
|
20488
|
|
|
|
|
|
|
|
20489
|
|
|
|
|
|
|
unsigned nice_match_length; |
20490
|
|
|
|
|
|
|
|
20491
|
|
|
|
|
|
|
|
20492
|
|
|
|
|
|
|
struct deflate_freqs freqs; |
20493
|
|
|
|
|
|
|
|
20494
|
|
|
|
|
|
|
|
20495
|
|
|
|
|
|
|
struct block_split_stats split_stats; |
20496
|
|
|
|
|
|
|
|
20497
|
|
|
|
|
|
|
|
20498
|
|
|
|
|
|
|
struct deflate_codes codes; |
20499
|
|
|
|
|
|
|
|
20500
|
|
|
|
|
|
|
|
20501
|
|
|
|
|
|
|
struct deflate_codes static_codes; |
20502
|
|
|
|
|
|
|
|
20503
|
|
|
|
|
|
|
|
20504
|
|
|
|
|
|
|
union { |
20505
|
|
|
|
|
|
|
|
20506
|
|
|
|
|
|
|
struct { |
20507
|
|
|
|
|
|
|
u32 freqs[DEFLATE_NUM_PRECODE_SYMS]; |
20508
|
|
|
|
|
|
|
u32 codewords[DEFLATE_NUM_PRECODE_SYMS]; |
20509
|
|
|
|
|
|
|
u8 lens[DEFLATE_NUM_PRECODE_SYMS]; |
20510
|
|
|
|
|
|
|
unsigned items[DEFLATE_NUM_LITLEN_SYMS + |
20511
|
|
|
|
|
|
|
DEFLATE_NUM_OFFSET_SYMS]; |
20512
|
|
|
|
|
|
|
unsigned num_litlen_syms; |
20513
|
|
|
|
|
|
|
unsigned num_offset_syms; |
20514
|
|
|
|
|
|
|
unsigned num_explicit_lens; |
20515
|
|
|
|
|
|
|
unsigned num_items; |
20516
|
|
|
|
|
|
|
} precode; |
20517
|
|
|
|
|
|
|
|
20518
|
|
|
|
|
|
|
struct { |
20519
|
|
|
|
|
|
|
u32 codewords[DEFLATE_MAX_MATCH_LEN + 1]; |
20520
|
|
|
|
|
|
|
u8 lens[DEFLATE_MAX_MATCH_LEN + 1]; |
20521
|
|
|
|
|
|
|
} length; |
20522
|
|
|
|
|
|
|
} o; |
20523
|
|
|
|
|
|
|
|
20524
|
|
|
|
|
|
|
union { |
20525
|
|
|
|
|
|
|
|
20526
|
|
|
|
|
|
|
struct { |
20527
|
|
|
|
|
|
|
|
20528
|
|
|
|
|
|
|
struct hc_matchfinder hc_mf; |
20529
|
|
|
|
|
|
|
|
20530
|
|
|
|
|
|
|
|
20531
|
|
|
|
|
|
|
struct deflate_sequence sequences[SEQ_STORE_LENGTH + 1]; |
20532
|
|
|
|
|
|
|
|
20533
|
|
|
|
|
|
|
} g; |
20534
|
|
|
|
|
|
|
|
20535
|
|
|
|
|
|
|
|
20536
|
|
|
|
|
|
|
struct { |
20537
|
|
|
|
|
|
|
|
20538
|
|
|
|
|
|
|
struct ht_matchfinder ht_mf; |
20539
|
|
|
|
|
|
|
|
20540
|
|
|
|
|
|
|
|
20541
|
|
|
|
|
|
|
struct deflate_sequence sequences[ |
20542
|
|
|
|
|
|
|
FAST_SEQ_STORE_LENGTH + 1]; |
20543
|
|
|
|
|
|
|
|
20544
|
|
|
|
|
|
|
} f; |
20545
|
|
|
|
|
|
|
|
20546
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
20547
|
|
|
|
|
|
|
|
20548
|
|
|
|
|
|
|
struct { |
20549
|
|
|
|
|
|
|
|
20550
|
|
|
|
|
|
|
|
20551
|
|
|
|
|
|
|
struct bt_matchfinder bt_mf; |
20552
|
|
|
|
|
|
|
|
20553
|
|
|
|
|
|
|
|
20554
|
|
|
|
|
|
|
struct lz_match match_cache[MATCH_CACHE_LENGTH + |
20555
|
|
|
|
|
|
|
MAX_MATCHES_PER_POS + |
20556
|
|
|
|
|
|
|
DEFLATE_MAX_MATCH_LEN - 1]; |
20557
|
|
|
|
|
|
|
|
20558
|
|
|
|
|
|
|
|
20559
|
|
|
|
|
|
|
struct deflate_optimum_node optimum_nodes[ |
20560
|
|
|
|
|
|
|
MAX_BLOCK_LENGTH + 1]; |
20561
|
|
|
|
|
|
|
|
20562
|
|
|
|
|
|
|
|
20563
|
|
|
|
|
|
|
struct deflate_costs costs; |
20564
|
|
|
|
|
|
|
|
20565
|
|
|
|
|
|
|
struct deflate_costs costs_producing_best_true_cost; |
20566
|
|
|
|
|
|
|
|
20567
|
|
|
|
|
|
|
|
20568
|
|
|
|
|
|
|
u8 offset_slot_full[DEFLATE_MAX_MATCH_OFFSET + 1]; |
20569
|
|
|
|
|
|
|
|
20570
|
|
|
|
|
|
|
|
20571
|
|
|
|
|
|
|
u32 prev_observations[NUM_OBSERVATION_TYPES]; |
20572
|
|
|
|
|
|
|
u32 prev_num_observations; |
20573
|
|
|
|
|
|
|
|
20574
|
|
|
|
|
|
|
|
20575
|
|
|
|
|
|
|
u32 new_match_len_freqs[DEFLATE_MAX_MATCH_LEN + 1]; |
20576
|
|
|
|
|
|
|
u32 match_len_freqs[DEFLATE_MAX_MATCH_LEN + 1]; |
20577
|
|
|
|
|
|
|
|
20578
|
|
|
|
|
|
|
|
20579
|
|
|
|
|
|
|
unsigned max_optim_passes; |
20580
|
|
|
|
|
|
|
|
20581
|
|
|
|
|
|
|
|
20582
|
|
|
|
|
|
|
unsigned min_improvement_to_continue; |
20583
|
|
|
|
|
|
|
|
20584
|
|
|
|
|
|
|
|
20585
|
|
|
|
|
|
|
unsigned min_bits_to_use_nonfinal_path; |
20586
|
|
|
|
|
|
|
|
20587
|
|
|
|
|
|
|
} n; |
20588
|
|
|
|
|
|
|
#endif |
20589
|
|
|
|
|
|
|
|
20590
|
|
|
|
|
|
|
} p; |
20591
|
|
|
|
|
|
|
}; |
20592
|
|
|
|
|
|
|
|
20593
|
|
|
|
|
|
|
|
20594
|
|
|
|
|
|
|
typedef machine_word_t bitbuf_t; |
20595
|
|
|
|
|
|
|
|
20596
|
|
|
|
|
|
|
|
20597
|
|
|
|
|
|
|
#define COMPRESS_BITBUF_NBITS (8 * sizeof(bitbuf_t) - 1) |
20598
|
|
|
|
|
|
|
|
20599
|
|
|
|
|
|
|
|
20600
|
|
|
|
|
|
|
#define CAN_BUFFER(n) (7 + (n) <= COMPRESS_BITBUF_NBITS) |
20601
|
|
|
|
|
|
|
|
20602
|
|
|
|
|
|
|
|
20603
|
|
|
|
|
|
|
struct deflate_output_bitstream { |
20604
|
|
|
|
|
|
|
|
20605
|
|
|
|
|
|
|
|
20606
|
|
|
|
|
|
|
bitbuf_t bitbuf; |
20607
|
|
|
|
|
|
|
|
20608
|
|
|
|
|
|
|
|
20609
|
|
|
|
|
|
|
unsigned bitcount; |
20610
|
|
|
|
|
|
|
|
20611
|
|
|
|
|
|
|
|
20612
|
|
|
|
|
|
|
u8 *next; |
20613
|
|
|
|
|
|
|
|
20614
|
|
|
|
|
|
|
|
20615
|
|
|
|
|
|
|
u8 *end; |
20616
|
|
|
|
|
|
|
}; |
20617
|
|
|
|
|
|
|
|
20618
|
|
|
|
|
|
|
|
20619
|
|
|
|
|
|
|
#define OUTPUT_END_PADDING 8 |
20620
|
|
|
|
|
|
|
|
20621
|
|
|
|
|
|
|
|
20622
|
|
|
|
|
|
|
#define ADD_BITS(bits, n) \ |
20623
|
|
|
|
|
|
|
do { \ |
20624
|
|
|
|
|
|
|
bitbuf |= (bitbuf_t)(bits) << bitcount; \ |
20625
|
|
|
|
|
|
|
bitcount += (n); \ |
20626
|
|
|
|
|
|
|
ASSERT(bitcount <= COMPRESS_BITBUF_NBITS); \ |
20627
|
|
|
|
|
|
|
} while (0) |
20628
|
|
|
|
|
|
|
|
20629
|
|
|
|
|
|
|
|
20630
|
|
|
|
|
|
|
#define FLUSH_BITS() \ |
20631
|
|
|
|
|
|
|
do { \ |
20632
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { \ |
20633
|
|
|
|
|
|
|
\ |
20634
|
|
|
|
|
|
|
put_unaligned_leword(bitbuf, out_next); \ |
20635
|
|
|
|
|
|
|
bitbuf >>= bitcount & ~7; \ |
20636
|
|
|
|
|
|
|
out_next += MIN(out_end - out_next, bitcount >> 3); \ |
20637
|
|
|
|
|
|
|
bitcount &= 7; \ |
20638
|
|
|
|
|
|
|
} else { \ |
20639
|
|
|
|
|
|
|
\ |
20640
|
|
|
|
|
|
|
while (bitcount >= 8) { \ |
20641
|
|
|
|
|
|
|
*out_next = bitbuf; \ |
20642
|
|
|
|
|
|
|
if (out_next != out_end) \ |
20643
|
|
|
|
|
|
|
out_next++; \ |
20644
|
|
|
|
|
|
|
bitcount -= 8; \ |
20645
|
|
|
|
|
|
|
bitbuf >>= 8; \ |
20646
|
|
|
|
|
|
|
} \ |
20647
|
|
|
|
|
|
|
} \ |
20648
|
|
|
|
|
|
|
} while (0) |
20649
|
|
|
|
|
|
|
|
20650
|
|
|
|
|
|
|
|
20651
|
|
|
|
|
|
|
static void |
20652
|
35
|
|
|
|
|
|
heapify_subtree(u32 A[], unsigned length, unsigned subtree_idx) |
20653
|
|
|
|
|
|
|
{ |
20654
|
|
|
|
|
|
|
unsigned parent_idx; |
20655
|
|
|
|
|
|
|
unsigned child_idx; |
20656
|
|
|
|
|
|
|
u32 v; |
20657
|
|
|
|
|
|
|
|
20658
|
35
|
|
|
|
|
|
v = A[subtree_idx]; |
20659
|
35
|
|
|
|
|
|
parent_idx = subtree_idx; |
20660
|
87
|
100
|
|
|
|
|
while ((child_idx = parent_idx * 2) <= length) { |
20661
|
63
|
100
|
|
|
|
|
if (child_idx < length && A[child_idx + 1] > A[child_idx]) |
|
|
100
|
|
|
|
|
|
20662
|
26
|
|
|
|
|
|
child_idx++; |
20663
|
63
|
100
|
|
|
|
|
if (v >= A[child_idx]) |
20664
|
11
|
|
|
|
|
|
break; |
20665
|
52
|
|
|
|
|
|
A[parent_idx] = A[child_idx]; |
20666
|
52
|
|
|
|
|
|
parent_idx = child_idx; |
20667
|
|
|
|
|
|
|
} |
20668
|
35
|
|
|
|
|
|
A[parent_idx] = v; |
20669
|
35
|
|
|
|
|
|
} |
20670
|
|
|
|
|
|
|
|
20671
|
|
|
|
|
|
|
|
20672
|
|
|
|
|
|
|
static void |
20673
|
251
|
|
|
|
|
|
heapify_array(u32 A[], unsigned length) |
20674
|
|
|
|
|
|
|
{ |
20675
|
|
|
|
|
|
|
unsigned subtree_idx; |
20676
|
|
|
|
|
|
|
|
20677
|
263
|
100
|
|
|
|
|
for (subtree_idx = length / 2; subtree_idx >= 1; subtree_idx--) |
20678
|
12
|
|
|
|
|
|
heapify_subtree(A, length, subtree_idx); |
20679
|
251
|
|
|
|
|
|
} |
20680
|
|
|
|
|
|
|
|
20681
|
|
|
|
|
|
|
|
20682
|
|
|
|
|
|
|
static void |
20683
|
251
|
|
|
|
|
|
heap_sort(u32 A[], unsigned length) |
20684
|
|
|
|
|
|
|
{ |
20685
|
251
|
|
|
|
|
|
A--; |
20686
|
|
|
|
|
|
|
|
20687
|
251
|
|
|
|
|
|
heapify_array(A, length); |
20688
|
|
|
|
|
|
|
|
20689
|
274
|
100
|
|
|
|
|
while (length >= 2) { |
20690
|
23
|
|
|
|
|
|
u32 tmp = A[length]; |
20691
|
|
|
|
|
|
|
|
20692
|
23
|
|
|
|
|
|
A[length] = A[1]; |
20693
|
23
|
|
|
|
|
|
A[1] = tmp; |
20694
|
23
|
|
|
|
|
|
length--; |
20695
|
23
|
|
|
|
|
|
heapify_subtree(A, length, 1); |
20696
|
|
|
|
|
|
|
} |
20697
|
251
|
|
|
|
|
|
} |
20698
|
|
|
|
|
|
|
|
20699
|
|
|
|
|
|
|
#define NUM_SYMBOL_BITS 10 |
20700
|
|
|
|
|
|
|
#define NUM_FREQ_BITS (32 - NUM_SYMBOL_BITS) |
20701
|
|
|
|
|
|
|
#define SYMBOL_MASK ((1 << NUM_SYMBOL_BITS) - 1) |
20702
|
|
|
|
|
|
|
#define FREQ_MASK (~SYMBOL_MASK) |
20703
|
|
|
|
|
|
|
|
20704
|
|
|
|
|
|
|
#define GET_NUM_COUNTERS(num_syms) (num_syms) |
20705
|
|
|
|
|
|
|
|
20706
|
|
|
|
|
|
|
|
20707
|
|
|
|
|
|
|
static unsigned |
20708
|
251
|
|
|
|
|
|
sort_symbols(unsigned num_syms, const u32 freqs[], u8 lens[], u32 symout[]) |
20709
|
|
|
|
|
|
|
{ |
20710
|
|
|
|
|
|
|
unsigned sym; |
20711
|
|
|
|
|
|
|
unsigned i; |
20712
|
|
|
|
|
|
|
unsigned num_used_syms; |
20713
|
|
|
|
|
|
|
unsigned num_counters; |
20714
|
|
|
|
|
|
|
unsigned counters[GET_NUM_COUNTERS(DEFLATE_MAX_NUM_SYMS)]; |
20715
|
|
|
|
|
|
|
|
20716
|
|
|
|
|
|
|
|
20717
|
|
|
|
|
|
|
|
20718
|
251
|
|
|
|
|
|
num_counters = GET_NUM_COUNTERS(num_syms); |
20719
|
|
|
|
|
|
|
|
20720
|
251
|
|
|
|
|
|
memset(counters, 0, num_counters * sizeof(counters[0])); |
20721
|
|
|
|
|
|
|
|
20722
|
|
|
|
|
|
|
|
20723
|
31246
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) |
20724
|
30995
|
|
|
|
|
|
counters[MIN(freqs[sym], num_counters - 1)]++; |
20725
|
|
|
|
|
|
|
|
20726
|
|
|
|
|
|
|
|
20727
|
251
|
|
|
|
|
|
num_used_syms = 0; |
20728
|
30995
|
100
|
|
|
|
|
for (i = 1; i < num_counters; i++) { |
20729
|
30744
|
|
|
|
|
|
unsigned count = counters[i]; |
20730
|
|
|
|
|
|
|
|
20731
|
30744
|
|
|
|
|
|
counters[i] = num_used_syms; |
20732
|
30744
|
|
|
|
|
|
num_used_syms += count; |
20733
|
|
|
|
|
|
|
} |
20734
|
|
|
|
|
|
|
|
20735
|
|
|
|
|
|
|
|
20736
|
31246
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) { |
20737
|
30995
|
|
|
|
|
|
u32 freq = freqs[sym]; |
20738
|
|
|
|
|
|
|
|
20739
|
30995
|
100
|
|
|
|
|
if (freq != 0) { |
20740
|
13394
|
|
|
|
|
|
symout[counters[MIN(freq, num_counters - 1)]++] = |
20741
|
13394
|
|
|
|
|
|
sym | (freq << NUM_SYMBOL_BITS); |
20742
|
|
|
|
|
|
|
} else { |
20743
|
17601
|
|
|
|
|
|
lens[sym] = 0; |
20744
|
|
|
|
|
|
|
} |
20745
|
|
|
|
|
|
|
} |
20746
|
|
|
|
|
|
|
|
20747
|
|
|
|
|
|
|
|
20748
|
251
|
|
|
|
|
|
heap_sort(symout + counters[num_counters - 2], |
20749
|
251
|
|
|
|
|
|
counters[num_counters - 1] - counters[num_counters - 2]); |
20750
|
|
|
|
|
|
|
|
20751
|
251
|
|
|
|
|
|
return num_used_syms; |
20752
|
|
|
|
|
|
|
} |
20753
|
|
|
|
|
|
|
|
20754
|
|
|
|
|
|
|
|
20755
|
|
|
|
|
|
|
static void |
20756
|
197
|
|
|
|
|
|
build_tree(u32 A[], unsigned sym_count) |
20757
|
|
|
|
|
|
|
{ |
20758
|
197
|
|
|
|
|
|
const unsigned last_idx = sym_count - 1; |
20759
|
|
|
|
|
|
|
|
20760
|
|
|
|
|
|
|
|
20761
|
197
|
|
|
|
|
|
unsigned i = 0; |
20762
|
|
|
|
|
|
|
|
20763
|
|
|
|
|
|
|
|
20764
|
197
|
|
|
|
|
|
unsigned b = 0; |
20765
|
|
|
|
|
|
|
|
20766
|
|
|
|
|
|
|
|
20767
|
197
|
|
|
|
|
|
unsigned e = 0; |
20768
|
|
|
|
|
|
|
|
20769
|
|
|
|
|
|
|
do { |
20770
|
|
|
|
|
|
|
u32 new_freq; |
20771
|
|
|
|
|
|
|
|
20772
|
|
|
|
|
|
|
|
20773
|
13152
|
100
|
|
|
|
|
if (i + 1 <= last_idx && |
|
|
100
|
|
|
|
|
|
20774
|
7710
|
100
|
|
|
|
|
(b == e || (A[i + 1] & FREQ_MASK) <= (A[b] & FREQ_MASK))) { |
20775
|
|
|
|
|
|
|
|
20776
|
6487
|
|
|
|
|
|
new_freq = (A[i] & FREQ_MASK) + (A[i + 1] & FREQ_MASK); |
20777
|
6487
|
|
|
|
|
|
i += 2; |
20778
|
6665
|
100
|
|
|
|
|
} else if (b + 2 <= e && |
|
|
100
|
|
|
|
|
|
20779
|
1481
|
100
|
|
|
|
|
(i > last_idx || |
20780
|
1481
|
|
|
|
|
|
(A[b + 1] & FREQ_MASK) < (A[i] & FREQ_MASK))) { |
20781
|
|
|
|
|
|
|
|
20782
|
6290
|
|
|
|
|
|
new_freq = (A[b] & FREQ_MASK) + (A[b + 1] & FREQ_MASK); |
20783
|
6290
|
|
|
|
|
|
A[b] = (e << NUM_SYMBOL_BITS) | (A[b] & SYMBOL_MASK); |
20784
|
12580
|
|
|
|
|
|
A[b + 1] = (e << NUM_SYMBOL_BITS) | |
20785
|
6290
|
|
|
|
|
|
(A[b + 1] & SYMBOL_MASK); |
20786
|
6290
|
|
|
|
|
|
b += 2; |
20787
|
|
|
|
|
|
|
} else { |
20788
|
|
|
|
|
|
|
|
20789
|
375
|
|
|
|
|
|
new_freq = (A[i] & FREQ_MASK) + (A[b] & FREQ_MASK); |
20790
|
375
|
|
|
|
|
|
A[b] = (e << NUM_SYMBOL_BITS) | (A[b] & SYMBOL_MASK); |
20791
|
375
|
|
|
|
|
|
i++; |
20792
|
375
|
|
|
|
|
|
b++; |
20793
|
|
|
|
|
|
|
} |
20794
|
13152
|
|
|
|
|
|
A[e] = new_freq | (A[e] & SYMBOL_MASK); |
20795
|
|
|
|
|
|
|
|
20796
|
13152
|
100
|
|
|
|
|
} while (++e < last_idx); |
20797
|
197
|
|
|
|
|
|
} |
20798
|
|
|
|
|
|
|
|
20799
|
|
|
|
|
|
|
|
20800
|
|
|
|
|
|
|
static void |
20801
|
197
|
|
|
|
|
|
compute_length_counts(u32 A[], unsigned root_idx, unsigned len_counts[], |
20802
|
|
|
|
|
|
|
unsigned max_codeword_len) |
20803
|
|
|
|
|
|
|
{ |
20804
|
|
|
|
|
|
|
unsigned len; |
20805
|
|
|
|
|
|
|
int node; |
20806
|
|
|
|
|
|
|
|
20807
|
|
|
|
|
|
|
|
20808
|
|
|
|
|
|
|
|
20809
|
2736
|
100
|
|
|
|
|
for (len = 0; len <= max_codeword_len; len++) |
20810
|
2539
|
|
|
|
|
|
len_counts[len] = 0; |
20811
|
197
|
|
|
|
|
|
len_counts[1] = 2; |
20812
|
|
|
|
|
|
|
|
20813
|
|
|
|
|
|
|
|
20814
|
197
|
|
|
|
|
|
A[root_idx] &= SYMBOL_MASK; |
20815
|
|
|
|
|
|
|
|
20816
|
13152
|
100
|
|
|
|
|
for (node = root_idx - 1; node >= 0; node--) { |
20817
|
|
|
|
|
|
|
|
20818
|
|
|
|
|
|
|
|
20819
|
|
|
|
|
|
|
|
20820
|
12955
|
|
|
|
|
|
unsigned parent = A[node] >> NUM_SYMBOL_BITS; |
20821
|
12955
|
|
|
|
|
|
unsigned parent_depth = A[parent] >> NUM_SYMBOL_BITS; |
20822
|
12955
|
|
|
|
|
|
unsigned depth = parent_depth + 1; |
20823
|
|
|
|
|
|
|
|
20824
|
|
|
|
|
|
|
|
20825
|
12955
|
|
|
|
|
|
A[node] = (A[node] & SYMBOL_MASK) | (depth << NUM_SYMBOL_BITS); |
20826
|
|
|
|
|
|
|
|
20827
|
|
|
|
|
|
|
|
20828
|
12955
|
50
|
|
|
|
|
if (depth >= max_codeword_len) { |
20829
|
0
|
|
|
|
|
|
depth = max_codeword_len; |
20830
|
|
|
|
|
|
|
do { |
20831
|
0
|
|
|
|
|
|
depth--; |
20832
|
0
|
0
|
|
|
|
|
} while (len_counts[depth] == 0); |
20833
|
|
|
|
|
|
|
} |
20834
|
|
|
|
|
|
|
|
20835
|
|
|
|
|
|
|
|
20836
|
12955
|
|
|
|
|
|
len_counts[depth]--; |
20837
|
12955
|
|
|
|
|
|
len_counts[depth + 1] += 2; |
20838
|
|
|
|
|
|
|
} |
20839
|
197
|
|
|
|
|
|
} |
20840
|
|
|
|
|
|
|
|
20841
|
|
|
|
|
|
|
|
20842
|
|
|
|
|
|
|
|
20843
|
|
|
|
|
|
|
#ifdef rbit32 |
20844
|
|
|
|
|
|
|
static forceinline u32 reverse_codeword(u32 codeword, u8 len) |
20845
|
|
|
|
|
|
|
{ |
20846
|
|
|
|
|
|
|
return rbit32(codeword) >> ((32 - len) & 31); |
20847
|
|
|
|
|
|
|
} |
20848
|
|
|
|
|
|
|
#else |
20849
|
|
|
|
|
|
|
|
20850
|
|
|
|
|
|
|
static const u8 bitreverse_tab[256] = { |
20851
|
|
|
|
|
|
|
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, |
20852
|
|
|
|
|
|
|
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, |
20853
|
|
|
|
|
|
|
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, |
20854
|
|
|
|
|
|
|
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, |
20855
|
|
|
|
|
|
|
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, |
20856
|
|
|
|
|
|
|
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, |
20857
|
|
|
|
|
|
|
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, |
20858
|
|
|
|
|
|
|
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, |
20859
|
|
|
|
|
|
|
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, |
20860
|
|
|
|
|
|
|
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, |
20861
|
|
|
|
|
|
|
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, |
20862
|
|
|
|
|
|
|
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, |
20863
|
|
|
|
|
|
|
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, |
20864
|
|
|
|
|
|
|
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, |
20865
|
|
|
|
|
|
|
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, |
20866
|
|
|
|
|
|
|
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, |
20867
|
|
|
|
|
|
|
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, |
20868
|
|
|
|
|
|
|
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, |
20869
|
|
|
|
|
|
|
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, |
20870
|
|
|
|
|
|
|
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, |
20871
|
|
|
|
|
|
|
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, |
20872
|
|
|
|
|
|
|
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, |
20873
|
|
|
|
|
|
|
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, |
20874
|
|
|
|
|
|
|
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, |
20875
|
|
|
|
|
|
|
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, |
20876
|
|
|
|
|
|
|
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, |
20877
|
|
|
|
|
|
|
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, |
20878
|
|
|
|
|
|
|
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, |
20879
|
|
|
|
|
|
|
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, |
20880
|
|
|
|
|
|
|
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, |
20881
|
|
|
|
|
|
|
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, |
20882
|
|
|
|
|
|
|
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, |
20883
|
|
|
|
|
|
|
}; |
20884
|
|
|
|
|
|
|
|
20885
|
|
|
|
|
|
|
static forceinline u32 reverse_codeword(u32 codeword, u8 len) |
20886
|
|
|
|
|
|
|
{ |
20887
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_CODEWORD_LEN <= 16); |
20888
|
58534
|
|
|
|
|
|
codeword = ((u32)bitreverse_tab[codeword & 0xff] << 8) | |
20889
|
29267
|
|
|
|
|
|
bitreverse_tab[codeword >> 8]; |
20890
|
29267
|
|
|
|
|
|
return codeword >> (16 - len); |
20891
|
|
|
|
|
|
|
} |
20892
|
|
|
|
|
|
|
#endif |
20893
|
|
|
|
|
|
|
|
20894
|
|
|
|
|
|
|
|
20895
|
|
|
|
|
|
|
static void |
20896
|
197
|
|
|
|
|
|
gen_codewords(u32 A[], u8 lens[], const unsigned len_counts[], |
20897
|
|
|
|
|
|
|
unsigned max_codeword_len, unsigned num_syms) |
20898
|
|
|
|
|
|
|
{ |
20899
|
|
|
|
|
|
|
u32 next_codewords[DEFLATE_MAX_CODEWORD_LEN + 1]; |
20900
|
|
|
|
|
|
|
unsigned i; |
20901
|
|
|
|
|
|
|
unsigned len; |
20902
|
|
|
|
|
|
|
unsigned sym; |
20903
|
|
|
|
|
|
|
|
20904
|
|
|
|
|
|
|
|
20905
|
2539
|
100
|
|
|
|
|
for (i = 0, len = max_codeword_len; len >= 1; len--) { |
20906
|
2342
|
|
|
|
|
|
unsigned count = len_counts[len]; |
20907
|
|
|
|
|
|
|
|
20908
|
15691
|
100
|
|
|
|
|
while (count--) |
20909
|
13349
|
|
|
|
|
|
lens[A[i++] & SYMBOL_MASK] = len; |
20910
|
|
|
|
|
|
|
} |
20911
|
|
|
|
|
|
|
|
20912
|
|
|
|
|
|
|
|
20913
|
197
|
|
|
|
|
|
next_codewords[0] = 0; |
20914
|
197
|
|
|
|
|
|
next_codewords[1] = 0; |
20915
|
2342
|
100
|
|
|
|
|
for (len = 2; len <= max_codeword_len; len++) |
20916
|
2145
|
|
|
|
|
|
next_codewords[len] = |
20917
|
2145
|
|
|
|
|
|
(next_codewords[len - 1] + len_counts[len - 1]) << 1; |
20918
|
|
|
|
|
|
|
|
20919
|
29464
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) { |
20920
|
|
|
|
|
|
|
|
20921
|
87801
|
|
|
|
|
|
A[sym] = reverse_codeword(next_codewords[lens[sym]]++, |
20922
|
29267
|
|
|
|
|
|
lens[sym]); |
20923
|
|
|
|
|
|
|
} |
20924
|
197
|
|
|
|
|
|
} |
20925
|
|
|
|
|
|
|
|
20926
|
|
|
|
|
|
|
|
20927
|
|
|
|
|
|
|
static void |
20928
|
251
|
|
|
|
|
|
deflate_make_huffman_code(unsigned num_syms, unsigned max_codeword_len, |
20929
|
|
|
|
|
|
|
const u32 freqs[], u8 lens[], u32 codewords[]) |
20930
|
|
|
|
|
|
|
{ |
20931
|
251
|
|
|
|
|
|
u32 *A = codewords; |
20932
|
|
|
|
|
|
|
unsigned num_used_syms; |
20933
|
|
|
|
|
|
|
|
20934
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_NUM_SYMS <= 1 << NUM_SYMBOL_BITS); |
20935
|
|
|
|
|
|
|
STATIC_ASSERT(MAX_BLOCK_LENGTH <= ((u32)1 << NUM_FREQ_BITS) - 1); |
20936
|
|
|
|
|
|
|
|
20937
|
|
|
|
|
|
|
|
20938
|
251
|
|
|
|
|
|
num_used_syms = sort_symbols(num_syms, freqs, lens, A); |
20939
|
|
|
|
|
|
|
|
20940
|
|
|
|
|
|
|
|
20941
|
|
|
|
|
|
|
|
20942
|
|
|
|
|
|
|
|
20943
|
|
|
|
|
|
|
|
20944
|
251
|
100
|
|
|
|
|
if (unlikely(num_used_syms == 0)) { |
20945
|
|
|
|
|
|
|
|
20946
|
9
|
|
|
|
|
|
return; |
20947
|
|
|
|
|
|
|
} |
20948
|
|
|
|
|
|
|
|
20949
|
242
|
100
|
|
|
|
|
if (unlikely(num_used_syms == 1)) { |
20950
|
|
|
|
|
|
|
|
20951
|
|
|
|
|
|
|
|
20952
|
45
|
|
|
|
|
|
unsigned sym = A[0] & SYMBOL_MASK; |
20953
|
45
|
50
|
|
|
|
|
unsigned nonzero_idx = sym ? sym : 1; |
20954
|
|
|
|
|
|
|
|
20955
|
45
|
|
|
|
|
|
codewords[0] = 0; |
20956
|
45
|
|
|
|
|
|
lens[0] = 1; |
20957
|
45
|
|
|
|
|
|
codewords[nonzero_idx] = 1; |
20958
|
45
|
|
|
|
|
|
lens[nonzero_idx] = 1; |
20959
|
45
|
|
|
|
|
|
return; |
20960
|
|
|
|
|
|
|
} |
20961
|
|
|
|
|
|
|
|
20962
|
|
|
|
|
|
|
|
20963
|
|
|
|
|
|
|
|
20964
|
197
|
|
|
|
|
|
build_tree(A, num_used_syms); |
20965
|
|
|
|
|
|
|
|
20966
|
|
|
|
|
|
|
{ |
20967
|
|
|
|
|
|
|
unsigned len_counts[DEFLATE_MAX_CODEWORD_LEN + 1]; |
20968
|
|
|
|
|
|
|
|
20969
|
197
|
|
|
|
|
|
compute_length_counts(A, num_used_syms - 2, |
20970
|
|
|
|
|
|
|
len_counts, max_codeword_len); |
20971
|
|
|
|
|
|
|
|
20972
|
197
|
|
|
|
|
|
gen_codewords(A, lens, len_counts, max_codeword_len, num_syms); |
20973
|
|
|
|
|
|
|
} |
20974
|
|
|
|
|
|
|
} |
20975
|
|
|
|
|
|
|
|
20976
|
|
|
|
|
|
|
|
20977
|
|
|
|
|
|
|
static void |
20978
|
56
|
|
|
|
|
|
deflate_reset_symbol_frequencies(struct libdeflate_compressor *c) |
20979
|
|
|
|
|
|
|
{ |
20980
|
56
|
|
|
|
|
|
memset(&c->freqs, 0, sizeof(c->freqs)); |
20981
|
56
|
|
|
|
|
|
} |
20982
|
|
|
|
|
|
|
|
20983
|
|
|
|
|
|
|
|
20984
|
|
|
|
|
|
|
static void |
20985
|
93
|
|
|
|
|
|
deflate_make_huffman_codes(const struct deflate_freqs *freqs, |
20986
|
|
|
|
|
|
|
struct deflate_codes *codes) |
20987
|
|
|
|
|
|
|
{ |
20988
|
93
|
|
|
|
|
|
deflate_make_huffman_code(DEFLATE_NUM_LITLEN_SYMS, |
20989
|
|
|
|
|
|
|
MAX_LITLEN_CODEWORD_LEN, |
20990
|
93
|
|
|
|
|
|
freqs->litlen, |
20991
|
93
|
|
|
|
|
|
codes->lens.litlen, |
20992
|
93
|
|
|
|
|
|
codes->codewords.litlen); |
20993
|
|
|
|
|
|
|
|
20994
|
93
|
|
|
|
|
|
deflate_make_huffman_code(DEFLATE_NUM_OFFSET_SYMS, |
20995
|
|
|
|
|
|
|
MAX_OFFSET_CODEWORD_LEN, |
20996
|
93
|
|
|
|
|
|
freqs->offset, |
20997
|
93
|
|
|
|
|
|
codes->lens.offset, |
20998
|
93
|
|
|
|
|
|
codes->codewords.offset); |
20999
|
93
|
|
|
|
|
|
} |
21000
|
|
|
|
|
|
|
|
21001
|
|
|
|
|
|
|
|
21002
|
|
|
|
|
|
|
static void |
21003
|
37
|
|
|
|
|
|
deflate_init_static_codes(struct libdeflate_compressor *c) |
21004
|
|
|
|
|
|
|
{ |
21005
|
|
|
|
|
|
|
unsigned i; |
21006
|
|
|
|
|
|
|
|
21007
|
5365
|
100
|
|
|
|
|
for (i = 0; i < 144; i++) |
21008
|
5328
|
|
|
|
|
|
c->freqs.litlen[i] = 1 << (9 - 8); |
21009
|
4181
|
100
|
|
|
|
|
for (; i < 256; i++) |
21010
|
4144
|
|
|
|
|
|
c->freqs.litlen[i] = 1 << (9 - 9); |
21011
|
925
|
100
|
|
|
|
|
for (; i < 280; i++) |
21012
|
888
|
|
|
|
|
|
c->freqs.litlen[i] = 1 << (9 - 7); |
21013
|
333
|
100
|
|
|
|
|
for (; i < 288; i++) |
21014
|
296
|
|
|
|
|
|
c->freqs.litlen[i] = 1 << (9 - 8); |
21015
|
|
|
|
|
|
|
|
21016
|
1221
|
100
|
|
|
|
|
for (i = 0; i < 32; i++) |
21017
|
1184
|
|
|
|
|
|
c->freqs.offset[i] = 1 << (5 - 5); |
21018
|
|
|
|
|
|
|
|
21019
|
37
|
|
|
|
|
|
deflate_make_huffman_codes(&c->freqs, &c->static_codes); |
21020
|
37
|
|
|
|
|
|
} |
21021
|
|
|
|
|
|
|
|
21022
|
|
|
|
|
|
|
|
21023
|
|
|
|
|
|
|
static forceinline unsigned |
21024
|
|
|
|
|
|
|
deflate_get_offset_slot(unsigned offset) |
21025
|
|
|
|
|
|
|
{ |
21026
|
|
|
|
|
|
|
#if 1 |
21027
|
2091
|
50
|
|
|
|
|
if (offset <= 256) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
21028
|
1114
|
|
|
|
|
|
return deflate_offset_slot[offset]; |
21029
|
|
|
|
|
|
|
else |
21030
|
977
|
|
|
|
|
|
return deflate_offset_slot[256 + ((offset - 1) >> 7)]; |
21031
|
|
|
|
|
|
|
#else |
21032
|
|
|
|
|
|
|
u32 i1 = offset; |
21033
|
|
|
|
|
|
|
u32 i2 = 256 + ((offset - 1) >> 7); |
21034
|
|
|
|
|
|
|
u32 is_small = (s32)(offset - 257) >> 31; |
21035
|
|
|
|
|
|
|
|
21036
|
|
|
|
|
|
|
return deflate_offset_slot[(i1 & is_small) ^ (i2 & ~is_small)]; |
21037
|
|
|
|
|
|
|
#endif |
21038
|
|
|
|
|
|
|
} |
21039
|
|
|
|
|
|
|
|
21040
|
|
|
|
|
|
|
static unsigned |
21041
|
65
|
|
|
|
|
|
deflate_compute_precode_items(const u8 lens[], const unsigned num_lens, |
21042
|
|
|
|
|
|
|
u32 precode_freqs[], unsigned precode_items[]) |
21043
|
|
|
|
|
|
|
{ |
21044
|
|
|
|
|
|
|
unsigned *itemptr; |
21045
|
|
|
|
|
|
|
unsigned run_start; |
21046
|
|
|
|
|
|
|
unsigned run_end; |
21047
|
|
|
|
|
|
|
unsigned extra_bits; |
21048
|
|
|
|
|
|
|
u8 len; |
21049
|
|
|
|
|
|
|
|
21050
|
65
|
|
|
|
|
|
memset(precode_freqs, 0, |
21051
|
|
|
|
|
|
|
DEFLATE_NUM_PRECODE_SYMS * sizeof(precode_freqs[0])); |
21052
|
|
|
|
|
|
|
|
21053
|
65
|
|
|
|
|
|
itemptr = precode_items; |
21054
|
65
|
|
|
|
|
|
run_start = 0; |
21055
|
|
|
|
|
|
|
do { |
21056
|
|
|
|
|
|
|
|
21057
|
|
|
|
|
|
|
|
21058
|
|
|
|
|
|
|
|
21059
|
1973
|
|
|
|
|
|
len = lens[run_start]; |
21060
|
|
|
|
|
|
|
|
21061
|
|
|
|
|
|
|
|
21062
|
1973
|
|
|
|
|
|
run_end = run_start; |
21063
|
|
|
|
|
|
|
do { |
21064
|
18864
|
|
|
|
|
|
run_end++; |
21065
|
18864
|
100
|
|
|
|
|
} while (run_end != num_lens && len == lens[run_end]); |
|
|
100
|
|
|
|
|
|
21066
|
|
|
|
|
|
|
|
21067
|
1973
|
100
|
|
|
|
|
if (len == 0) { |
21068
|
|
|
|
|
|
|
|
21069
|
|
|
|
|
|
|
|
21070
|
|
|
|
|
|
|
|
21071
|
1092
|
100
|
|
|
|
|
while ((run_end - run_start) >= 11) { |
21072
|
249
|
|
|
|
|
|
extra_bits = MIN((run_end - run_start) - 11, |
21073
|
|
|
|
|
|
|
0x7F); |
21074
|
249
|
|
|
|
|
|
precode_freqs[18]++; |
21075
|
249
|
|
|
|
|
|
*itemptr++ = 18 | (extra_bits << 5); |
21076
|
249
|
|
|
|
|
|
run_start += 11 + extra_bits; |
21077
|
|
|
|
|
|
|
} |
21078
|
|
|
|
|
|
|
|
21079
|
|
|
|
|
|
|
|
21080
|
843
|
100
|
|
|
|
|
if ((run_end - run_start) >= 3) { |
21081
|
309
|
|
|
|
|
|
extra_bits = MIN((run_end - run_start) - 3, |
21082
|
|
|
|
|
|
|
0x7); |
21083
|
309
|
|
|
|
|
|
precode_freqs[17]++; |
21084
|
309
|
|
|
|
|
|
*itemptr++ = 17 | (extra_bits << 5); |
21085
|
843
|
|
|
|
|
|
run_start += 3 + extra_bits; |
21086
|
|
|
|
|
|
|
} |
21087
|
|
|
|
|
|
|
} else { |
21088
|
|
|
|
|
|
|
|
21089
|
|
|
|
|
|
|
|
21090
|
|
|
|
|
|
|
|
21091
|
|
|
|
|
|
|
|
21092
|
1130
|
100
|
|
|
|
|
if ((run_end - run_start) >= 4) { |
21093
|
6
|
|
|
|
|
|
precode_freqs[len]++; |
21094
|
6
|
|
|
|
|
|
*itemptr++ = len; |
21095
|
6
|
|
|
|
|
|
run_start++; |
21096
|
|
|
|
|
|
|
do { |
21097
|
6
|
|
|
|
|
|
extra_bits = MIN((run_end - run_start) - |
21098
|
|
|
|
|
|
|
3, 0x3); |
21099
|
6
|
|
|
|
|
|
precode_freqs[16]++; |
21100
|
6
|
|
|
|
|
|
*itemptr++ = 16 | (extra_bits << 5); |
21101
|
6
|
|
|
|
|
|
run_start += 3 + extra_bits; |
21102
|
6
|
50
|
|
|
|
|
} while ((run_end - run_start) >= 3); |
21103
|
|
|
|
|
|
|
} |
21104
|
|
|
|
|
|
|
} |
21105
|
|
|
|
|
|
|
|
21106
|
|
|
|
|
|
|
|
21107
|
3535
|
100
|
|
|
|
|
while (run_start != run_end) { |
21108
|
1562
|
|
|
|
|
|
precode_freqs[len]++; |
21109
|
1562
|
|
|
|
|
|
*itemptr++ = len; |
21110
|
1562
|
|
|
|
|
|
run_start++; |
21111
|
|
|
|
|
|
|
} |
21112
|
1973
|
100
|
|
|
|
|
} while (run_start != num_lens); |
21113
|
|
|
|
|
|
|
|
21114
|
65
|
|
|
|
|
|
return itemptr - precode_items; |
21115
|
|
|
|
|
|
|
} |
21116
|
|
|
|
|
|
|
|
21117
|
|
|
|
|
|
|
|
21118
|
|
|
|
|
|
|
|
21119
|
|
|
|
|
|
|
|
21120
|
|
|
|
|
|
|
static void |
21121
|
65
|
|
|
|
|
|
deflate_precompute_huffman_header(struct libdeflate_compressor *c) |
21122
|
|
|
|
|
|
|
{ |
21123
|
|
|
|
|
|
|
|
21124
|
|
|
|
|
|
|
|
21125
|
475
|
100
|
|
|
|
|
for (c->o.precode.num_litlen_syms = DEFLATE_NUM_LITLEN_SYMS; |
21126
|
475
|
|
|
|
|
|
c->o.precode.num_litlen_syms > 257; |
21127
|
410
|
|
|
|
|
|
c->o.precode.num_litlen_syms--) |
21128
|
466
|
100
|
|
|
|
|
if (c->codes.lens.litlen[c->o.precode.num_litlen_syms - 1] != 0) |
21129
|
56
|
|
|
|
|
|
break; |
21130
|
|
|
|
|
|
|
|
21131
|
1591
|
100
|
|
|
|
|
for (c->o.precode.num_offset_syms = DEFLATE_NUM_OFFSET_SYMS; |
21132
|
1591
|
|
|
|
|
|
c->o.precode.num_offset_syms > 1; |
21133
|
1526
|
|
|
|
|
|
c->o.precode.num_offset_syms--) |
21134
|
1582
|
100
|
|
|
|
|
if (c->codes.lens.offset[c->o.precode.num_offset_syms - 1] != 0) |
21135
|
56
|
|
|
|
|
|
break; |
21136
|
|
|
|
|
|
|
|
21137
|
|
|
|
|
|
|
|
21138
|
|
|
|
|
|
|
STATIC_ASSERT(offsetof(struct deflate_lens, offset) == |
21139
|
|
|
|
|
|
|
DEFLATE_NUM_LITLEN_SYMS); |
21140
|
65
|
50
|
|
|
|
|
if (c->o.precode.num_litlen_syms != DEFLATE_NUM_LITLEN_SYMS) { |
21141
|
65
|
|
|
|
|
|
memmove((u8 *)&c->codes.lens + c->o.precode.num_litlen_syms, |
21142
|
65
|
|
|
|
|
|
(u8 *)&c->codes.lens + DEFLATE_NUM_LITLEN_SYMS, |
21143
|
65
|
|
|
|
|
|
c->o.precode.num_offset_syms); |
21144
|
|
|
|
|
|
|
} |
21145
|
|
|
|
|
|
|
|
21146
|
|
|
|
|
|
|
|
21147
|
65
|
|
|
|
|
|
c->o.precode.num_items = |
21148
|
65
|
|
|
|
|
|
deflate_compute_precode_items((u8 *)&c->codes.lens, |
21149
|
65
|
|
|
|
|
|
c->o.precode.num_litlen_syms + |
21150
|
65
|
|
|
|
|
|
c->o.precode.num_offset_syms, |
21151
|
65
|
|
|
|
|
|
c->o.precode.freqs, |
21152
|
65
|
|
|
|
|
|
c->o.precode.items); |
21153
|
|
|
|
|
|
|
|
21154
|
|
|
|
|
|
|
|
21155
|
65
|
|
|
|
|
|
deflate_make_huffman_code(DEFLATE_NUM_PRECODE_SYMS, |
21156
|
|
|
|
|
|
|
MAX_PRE_CODEWORD_LEN, |
21157
|
65
|
|
|
|
|
|
c->o.precode.freqs, c->o.precode.lens, |
21158
|
65
|
|
|
|
|
|
c->o.precode.codewords); |
21159
|
|
|
|
|
|
|
|
21160
|
|
|
|
|
|
|
|
21161
|
174
|
50
|
|
|
|
|
for (c->o.precode.num_explicit_lens = DEFLATE_NUM_PRECODE_SYMS; |
21162
|
174
|
|
|
|
|
|
c->o.precode.num_explicit_lens > 4; |
21163
|
109
|
|
|
|
|
|
c->o.precode.num_explicit_lens--) |
21164
|
174
|
100
|
|
|
|
|
if (c->o.precode.lens[deflate_precode_lens_permutation[ |
21165
|
174
|
|
|
|
|
|
c->o.precode.num_explicit_lens - 1]] != 0) |
21166
|
65
|
|
|
|
|
|
break; |
21167
|
|
|
|
|
|
|
|
21168
|
|
|
|
|
|
|
|
21169
|
65
|
50
|
|
|
|
|
if (c->o.precode.num_litlen_syms != DEFLATE_NUM_LITLEN_SYMS) { |
21170
|
65
|
|
|
|
|
|
memmove((u8 *)&c->codes.lens + DEFLATE_NUM_LITLEN_SYMS, |
21171
|
65
|
|
|
|
|
|
(u8 *)&c->codes.lens + c->o.precode.num_litlen_syms, |
21172
|
65
|
|
|
|
|
|
c->o.precode.num_offset_syms); |
21173
|
|
|
|
|
|
|
} |
21174
|
65
|
|
|
|
|
|
} |
21175
|
|
|
|
|
|
|
|
21176
|
|
|
|
|
|
|
|
21177
|
|
|
|
|
|
|
static void |
21178
|
38
|
|
|
|
|
|
deflate_compute_full_len_codewords(struct libdeflate_compressor *c, |
21179
|
|
|
|
|
|
|
const struct deflate_codes *codes) |
21180
|
|
|
|
|
|
|
{ |
21181
|
|
|
|
|
|
|
unsigned len; |
21182
|
|
|
|
|
|
|
|
21183
|
|
|
|
|
|
|
STATIC_ASSERT(MAX_LITLEN_CODEWORD_LEN + |
21184
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS <= 32); |
21185
|
|
|
|
|
|
|
|
21186
|
9766
|
100
|
|
|
|
|
for (len = DEFLATE_MIN_MATCH_LEN; len <= DEFLATE_MAX_MATCH_LEN; len++) { |
21187
|
9728
|
|
|
|
|
|
unsigned slot = deflate_length_slot[len]; |
21188
|
9728
|
|
|
|
|
|
unsigned litlen_sym = DEFLATE_FIRST_LEN_SYM + slot; |
21189
|
9728
|
|
|
|
|
|
u32 extra_bits = len - deflate_length_slot_base[slot]; |
21190
|
|
|
|
|
|
|
|
21191
|
9728
|
|
|
|
|
|
c->o.length.codewords[len] = |
21192
|
19456
|
|
|
|
|
|
codes->codewords.litlen[litlen_sym] | |
21193
|
9728
|
|
|
|
|
|
(extra_bits << codes->lens.litlen[litlen_sym]); |
21194
|
19456
|
|
|
|
|
|
c->o.length.lens[len] = codes->lens.litlen[litlen_sym] + |
21195
|
9728
|
|
|
|
|
|
deflate_extra_length_bits[slot]; |
21196
|
|
|
|
|
|
|
} |
21197
|
38
|
|
|
|
|
|
} |
21198
|
|
|
|
|
|
|
|
21199
|
|
|
|
|
|
|
|
21200
|
|
|
|
|
|
|
#define WRITE_MATCH(c_, codes_, length_, offset_, offset_slot_) \ |
21201
|
|
|
|
|
|
|
do { \ |
21202
|
|
|
|
|
|
|
const struct libdeflate_compressor *c__ = (c_); \ |
21203
|
|
|
|
|
|
|
const struct deflate_codes *codes__ = (codes_); \ |
21204
|
|
|
|
|
|
|
unsigned length__ = (length_); \ |
21205
|
|
|
|
|
|
|
unsigned offset__ = (offset_); \ |
21206
|
|
|
|
|
|
|
unsigned offset_slot__ = (offset_slot_); \ |
21207
|
|
|
|
|
|
|
\ |
21208
|
|
|
|
|
|
|
\ |
21209
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_BUFFER(MAX_LITLEN_CODEWORD_LEN + \ |
21210
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS)); \ |
21211
|
|
|
|
|
|
|
ADD_BITS(c__->o.length.codewords[length__], \ |
21212
|
|
|
|
|
|
|
c__->o.length.lens[length__]); \ |
21213
|
|
|
|
|
|
|
\ |
21214
|
|
|
|
|
|
|
if (!CAN_BUFFER(MAX_LITLEN_CODEWORD_LEN + \ |
21215
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS + \ |
21216
|
|
|
|
|
|
|
MAX_OFFSET_CODEWORD_LEN + \ |
21217
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_OFFSET_BITS)) \ |
21218
|
|
|
|
|
|
|
FLUSH_BITS(); \ |
21219
|
|
|
|
|
|
|
\ |
21220
|
|
|
|
|
|
|
\ |
21221
|
|
|
|
|
|
|
ADD_BITS(codes__->codewords.offset[offset_slot__], \ |
21222
|
|
|
|
|
|
|
codes__->lens.offset[offset_slot__]); \ |
21223
|
|
|
|
|
|
|
\ |
21224
|
|
|
|
|
|
|
if (!CAN_BUFFER(MAX_OFFSET_CODEWORD_LEN + \ |
21225
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_OFFSET_BITS)) \ |
21226
|
|
|
|
|
|
|
FLUSH_BITS(); \ |
21227
|
|
|
|
|
|
|
\ |
21228
|
|
|
|
|
|
|
\ |
21229
|
|
|
|
|
|
|
ADD_BITS(offset__ - deflate_offset_slot_base[offset_slot__], \ |
21230
|
|
|
|
|
|
|
deflate_extra_offset_bits[offset_slot__]); \ |
21231
|
|
|
|
|
|
|
\ |
21232
|
|
|
|
|
|
|
FLUSH_BITS(); \ |
21233
|
|
|
|
|
|
|
} while (0) |
21234
|
|
|
|
|
|
|
|
21235
|
|
|
|
|
|
|
|
21236
|
|
|
|
|
|
|
static void |
21237
|
38
|
|
|
|
|
|
deflate_flush_block(struct libdeflate_compressor *c, |
21238
|
|
|
|
|
|
|
struct deflate_output_bitstream *os, |
21239
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
21240
|
|
|
|
|
|
|
const struct deflate_sequence *sequences, |
21241
|
|
|
|
|
|
|
bool is_final_block) |
21242
|
|
|
|
|
|
|
{ |
21243
|
|
|
|
|
|
|
|
21244
|
38
|
|
|
|
|
|
const u8 *in_next = block_begin; |
21245
|
38
|
|
|
|
|
|
const u8 * const in_end = block_begin + block_length; |
21246
|
38
|
|
|
|
|
|
bitbuf_t bitbuf = os->bitbuf; |
21247
|
38
|
|
|
|
|
|
unsigned bitcount = os->bitcount; |
21248
|
38
|
|
|
|
|
|
u8 *out_next = os->next; |
21249
|
38
|
|
|
|
|
|
u8 * const out_end = os->end; |
21250
|
|
|
|
|
|
|
|
21251
|
38
|
|
|
|
|
|
u32 dynamic_cost = 0; |
21252
|
38
|
|
|
|
|
|
u32 static_cost = 0; |
21253
|
38
|
|
|
|
|
|
u32 uncompressed_cost = 0; |
21254
|
|
|
|
|
|
|
u32 best_cost; |
21255
|
|
|
|
|
|
|
struct deflate_codes *codes; |
21256
|
|
|
|
|
|
|
unsigned sym; |
21257
|
|
|
|
|
|
|
|
21258
|
38
|
100
|
|
|
|
|
ASSERT(block_length >= MIN_BLOCK_LENGTH || is_final_block); |
|
|
50
|
|
|
|
|
|
21259
|
|
|
|
|
|
|
ASSERT(block_length <= MAX_BLOCK_LENGTH); |
21260
|
|
|
|
|
|
|
ASSERT(bitcount <= 7); |
21261
|
38
|
|
|
|
|
|
ASSERT((bitbuf & ~(((bitbuf_t)1 << bitcount) - 1)) == 0); |
21262
|
|
|
|
|
|
|
ASSERT(out_next <= out_end); |
21263
|
|
|
|
|
|
|
|
21264
|
|
|
|
|
|
|
|
21265
|
38
|
|
|
|
|
|
deflate_precompute_huffman_header(c); |
21266
|
|
|
|
|
|
|
|
21267
|
|
|
|
|
|
|
|
21268
|
38
|
|
|
|
|
|
dynamic_cost += 5 + 5 + 4 + (3 * c->o.precode.num_explicit_lens); |
21269
|
760
|
100
|
|
|
|
|
for (sym = 0; sym < DEFLATE_NUM_PRECODE_SYMS; sym++) { |
21270
|
722
|
|
|
|
|
|
u32 extra = deflate_extra_precode_bits[sym]; |
21271
|
|
|
|
|
|
|
|
21272
|
1444
|
|
|
|
|
|
dynamic_cost += c->o.precode.freqs[sym] * |
21273
|
722
|
|
|
|
|
|
(extra + c->o.precode.lens[sym]); |
21274
|
|
|
|
|
|
|
} |
21275
|
|
|
|
|
|
|
|
21276
|
|
|
|
|
|
|
|
21277
|
5510
|
100
|
|
|
|
|
for (sym = 0; sym < 144; sym++) { |
21278
|
10944
|
|
|
|
|
|
dynamic_cost += c->freqs.litlen[sym] * |
21279
|
5472
|
|
|
|
|
|
c->codes.lens.litlen[sym]; |
21280
|
5472
|
|
|
|
|
|
static_cost += c->freqs.litlen[sym] * 8; |
21281
|
|
|
|
|
|
|
} |
21282
|
4294
|
100
|
|
|
|
|
for (; sym < 256; sym++) { |
21283
|
8512
|
|
|
|
|
|
dynamic_cost += c->freqs.litlen[sym] * |
21284
|
4256
|
|
|
|
|
|
c->codes.lens.litlen[sym]; |
21285
|
4256
|
|
|
|
|
|
static_cost += c->freqs.litlen[sym] * 9; |
21286
|
|
|
|
|
|
|
} |
21287
|
|
|
|
|
|
|
|
21288
|
|
|
|
|
|
|
|
21289
|
38
|
|
|
|
|
|
dynamic_cost += c->codes.lens.litlen[DEFLATE_END_OF_BLOCK]; |
21290
|
38
|
|
|
|
|
|
static_cost += 7; |
21291
|
|
|
|
|
|
|
|
21292
|
|
|
|
|
|
|
|
21293
|
1140
|
100
|
|
|
|
|
for (sym = DEFLATE_FIRST_LEN_SYM; |
21294
|
|
|
|
|
|
|
sym < DEFLATE_FIRST_LEN_SYM + ARRAY_LEN(deflate_extra_length_bits); |
21295
|
1102
|
|
|
|
|
|
sym++) { |
21296
|
1102
|
|
|
|
|
|
u32 extra = deflate_extra_length_bits[ |
21297
|
1102
|
|
|
|
|
|
sym - DEFLATE_FIRST_LEN_SYM]; |
21298
|
|
|
|
|
|
|
|
21299
|
2204
|
|
|
|
|
|
dynamic_cost += c->freqs.litlen[sym] * |
21300
|
1102
|
|
|
|
|
|
(extra + c->codes.lens.litlen[sym]); |
21301
|
2204
|
|
|
|
|
|
static_cost += c->freqs.litlen[sym] * |
21302
|
1102
|
|
|
|
|
|
(extra + c->static_codes.lens.litlen[sym]); |
21303
|
|
|
|
|
|
|
} |
21304
|
|
|
|
|
|
|
|
21305
|
|
|
|
|
|
|
|
21306
|
1178
|
100
|
|
|
|
|
for (sym = 0; sym < ARRAY_LEN(deflate_extra_offset_bits); sym++) { |
21307
|
1140
|
|
|
|
|
|
u32 extra = deflate_extra_offset_bits[sym]; |
21308
|
|
|
|
|
|
|
|
21309
|
2280
|
|
|
|
|
|
dynamic_cost += c->freqs.offset[sym] * |
21310
|
1140
|
|
|
|
|
|
(extra + c->codes.lens.offset[sym]); |
21311
|
1140
|
|
|
|
|
|
static_cost += c->freqs.offset[sym] * (extra + 5); |
21312
|
|
|
|
|
|
|
} |
21313
|
|
|
|
|
|
|
|
21314
|
|
|
|
|
|
|
|
21315
|
114
|
|
|
|
|
|
uncompressed_cost += (-(bitcount + 3) & 7) + 32 + |
21316
|
38
|
|
|
|
|
|
(40 * (DIV_ROUND_UP(block_length, |
21317
|
38
|
|
|
|
|
|
UINT16_MAX) - 1)) + |
21318
|
38
|
|
|
|
|
|
(8 * block_length); |
21319
|
|
|
|
|
|
|
|
21320
|
|
|
|
|
|
|
|
21321
|
38
|
|
|
|
|
|
best_cost = MIN(static_cost, uncompressed_cost); |
21322
|
38
|
100
|
|
|
|
|
if (dynamic_cost < best_cost) { |
21323
|
2
|
|
|
|
|
|
const unsigned num_explicit_lens = c->o.precode.num_explicit_lens; |
21324
|
2
|
|
|
|
|
|
const unsigned num_precode_items = c->o.precode.num_items; |
21325
|
|
|
|
|
|
|
unsigned precode_sym, precode_item; |
21326
|
|
|
|
|
|
|
unsigned i; |
21327
|
|
|
|
|
|
|
|
21328
|
|
|
|
|
|
|
|
21329
|
|
|
|
|
|
|
|
21330
|
2
|
|
|
|
|
|
best_cost = dynamic_cost; |
21331
|
2
|
|
|
|
|
|
codes = &c->codes; |
21332
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_BUFFER(1 + 2 + 5 + 5 + 4 + 3)); |
21333
|
2
|
|
|
|
|
|
ADD_BITS(is_final_block, 1); |
21334
|
2
|
|
|
|
|
|
ADD_BITS(DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN, 2); |
21335
|
2
|
|
|
|
|
|
ADD_BITS(c->o.precode.num_litlen_syms - 257, 5); |
21336
|
2
|
|
|
|
|
|
ADD_BITS(c->o.precode.num_offset_syms - 1, 5); |
21337
|
2
|
|
|
|
|
|
ADD_BITS(num_explicit_lens - 4, 4); |
21338
|
|
|
|
|
|
|
|
21339
|
|
|
|
|
|
|
|
21340
|
|
|
|
|
|
|
if (CAN_BUFFER(3 * (DEFLATE_NUM_PRECODE_SYMS - 1))) { |
21341
|
|
|
|
|
|
|
|
21342
|
2
|
|
|
|
|
|
precode_sym = deflate_precode_lens_permutation[0]; |
21343
|
2
|
|
|
|
|
|
ADD_BITS(c->o.precode.lens[precode_sym], 3); |
21344
|
2
|
50
|
|
|
|
|
FLUSH_BITS(); |
21345
|
2
|
|
|
|
|
|
i = 1; |
21346
|
|
|
|
|
|
|
do { |
21347
|
26
|
|
|
|
|
|
precode_sym = |
21348
|
26
|
|
|
|
|
|
deflate_precode_lens_permutation[i]; |
21349
|
26
|
|
|
|
|
|
ADD_BITS(c->o.precode.lens[precode_sym], 3); |
21350
|
26
|
100
|
|
|
|
|
} while (++i < num_explicit_lens); |
21351
|
2
|
50
|
|
|
|
|
FLUSH_BITS(); |
21352
|
|
|
|
|
|
|
} else { |
21353
|
|
|
|
|
|
|
FLUSH_BITS(); |
21354
|
|
|
|
|
|
|
i = 0; |
21355
|
|
|
|
|
|
|
do { |
21356
|
|
|
|
|
|
|
precode_sym = |
21357
|
|
|
|
|
|
|
deflate_precode_lens_permutation[i]; |
21358
|
|
|
|
|
|
|
ADD_BITS(c->o.precode.lens[precode_sym], 3); |
21359
|
|
|
|
|
|
|
FLUSH_BITS(); |
21360
|
|
|
|
|
|
|
} while (++i < num_explicit_lens); |
21361
|
|
|
|
|
|
|
} |
21362
|
|
|
|
|
|
|
|
21363
|
|
|
|
|
|
|
|
21364
|
2
|
|
|
|
|
|
i = 0; |
21365
|
|
|
|
|
|
|
do { |
21366
|
233
|
|
|
|
|
|
precode_item = c->o.precode.items[i]; |
21367
|
233
|
|
|
|
|
|
precode_sym = precode_item & 0x1F; |
21368
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_BUFFER(MAX_PRE_CODEWORD_LEN + 7)); |
21369
|
233
|
|
|
|
|
|
ADD_BITS(c->o.precode.codewords[precode_sym], |
21370
|
|
|
|
|
|
|
c->o.precode.lens[precode_sym]); |
21371
|
233
|
|
|
|
|
|
ADD_BITS(precode_item >> 5, |
21372
|
|
|
|
|
|
|
deflate_extra_precode_bits[precode_sym]); |
21373
|
233
|
50
|
|
|
|
|
FLUSH_BITS(); |
21374
|
233
|
100
|
|
|
|
|
} while (++i < num_precode_items); |
21375
|
36
|
50
|
|
|
|
|
} else if (static_cost < uncompressed_cost) { |
21376
|
|
|
|
|
|
|
|
21377
|
36
|
|
|
|
|
|
codes = &c->static_codes; |
21378
|
36
|
|
|
|
|
|
ADD_BITS(is_final_block, 1); |
21379
|
36
|
|
|
|
|
|
ADD_BITS(DEFLATE_BLOCKTYPE_STATIC_HUFFMAN, 2); |
21380
|
36
|
50
|
|
|
|
|
FLUSH_BITS(); |
21381
|
|
|
|
|
|
|
} else { |
21382
|
|
|
|
|
|
|
|
21383
|
|
|
|
|
|
|
do { |
21384
|
0
|
|
|
|
|
|
u8 bfinal = 0; |
21385
|
0
|
|
|
|
|
|
size_t len = UINT16_MAX; |
21386
|
|
|
|
|
|
|
|
21387
|
0
|
0
|
|
|
|
|
if (in_end - in_next <= UINT16_MAX) { |
21388
|
0
|
|
|
|
|
|
bfinal = is_final_block; |
21389
|
0
|
|
|
|
|
|
len = in_end - in_next; |
21390
|
|
|
|
|
|
|
} |
21391
|
0
|
0
|
|
|
|
|
if (out_end - out_next < |
21392
|
0
|
|
|
|
|
|
(bitcount + 3 + 7) / 8 + 4 + len) { |
21393
|
|
|
|
|
|
|
|
21394
|
0
|
|
|
|
|
|
out_next = out_end; |
21395
|
0
|
|
|
|
|
|
goto out; |
21396
|
|
|
|
|
|
|
} |
21397
|
|
|
|
|
|
|
|
21398
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_BLOCKTYPE_UNCOMPRESSED == 0); |
21399
|
0
|
|
|
|
|
|
*out_next++ = (bfinal << bitcount) | bitbuf; |
21400
|
0
|
0
|
|
|
|
|
if (bitcount > 5) |
21401
|
0
|
|
|
|
|
|
*out_next++ = 0; |
21402
|
0
|
|
|
|
|
|
bitbuf = 0; |
21403
|
0
|
|
|
|
|
|
bitcount = 0; |
21404
|
|
|
|
|
|
|
|
21405
|
0
|
|
|
|
|
|
put_unaligned_le16(len, out_next); |
21406
|
0
|
|
|
|
|
|
out_next += 2; |
21407
|
0
|
|
|
|
|
|
put_unaligned_le16(~len, out_next); |
21408
|
0
|
|
|
|
|
|
out_next += 2; |
21409
|
0
|
|
|
|
|
|
memcpy(out_next, in_next, len); |
21410
|
0
|
|
|
|
|
|
out_next += len; |
21411
|
0
|
|
|
|
|
|
in_next += len; |
21412
|
0
|
0
|
|
|
|
|
} while (in_next != in_end); |
21413
|
|
|
|
|
|
|
|
21414
|
0
|
|
|
|
|
|
goto out; |
21415
|
|
|
|
|
|
|
} |
21416
|
|
|
|
|
|
|
|
21417
|
|
|
|
|
|
|
|
21418
|
|
|
|
|
|
|
ASSERT(bitcount <= 7); |
21419
|
38
|
|
|
|
|
|
deflate_compute_full_len_codewords(c, codes); |
21420
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
21421
|
38
|
100
|
|
|
|
|
if (sequences == NULL) { |
21422
|
|
|
|
|
|
|
|
21423
|
9
|
|
|
|
|
|
struct deflate_optimum_node *cur_node = |
21424
|
|
|
|
|
|
|
&c->p.n.optimum_nodes[0]; |
21425
|
9
|
|
|
|
|
|
struct deflate_optimum_node * const end_node = |
21426
|
|
|
|
|
|
|
&c->p.n.optimum_nodes[block_length]; |
21427
|
|
|
|
|
|
|
do { |
21428
|
225
|
|
|
|
|
|
unsigned length = cur_node->item & OPTIMUM_LEN_MASK; |
21429
|
225
|
|
|
|
|
|
unsigned offset = cur_node->item >> |
21430
|
|
|
|
|
|
|
OPTIMUM_OFFSET_SHIFT; |
21431
|
225
|
100
|
|
|
|
|
if (length == 1) { |
21432
|
|
|
|
|
|
|
|
21433
|
162
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[offset], |
21434
|
|
|
|
|
|
|
codes->lens.litlen[offset]); |
21435
|
162
|
50
|
|
|
|
|
FLUSH_BITS(); |
21436
|
|
|
|
|
|
|
} else { |
21437
|
|
|
|
|
|
|
|
21438
|
63
|
50
|
|
|
|
|
WRITE_MATCH(c, codes, length, offset, |
21439
|
|
|
|
|
|
|
c->p.n.offset_slot_full[offset]); |
21440
|
|
|
|
|
|
|
} |
21441
|
225
|
|
|
|
|
|
cur_node += length; |
21442
|
225
|
100
|
|
|
|
|
} while (cur_node != end_node); |
21443
|
|
|
|
|
|
|
} else |
21444
|
|
|
|
|
|
|
#endif |
21445
|
|
|
|
|
|
|
{ |
21446
|
|
|
|
|
|
|
|
21447
|
|
|
|
|
|
|
const struct deflate_sequence *seq; |
21448
|
|
|
|
|
|
|
|
21449
|
29
|
|
|
|
|
|
for (seq = sequences; ; seq++) { |
21450
|
2120
|
|
|
|
|
|
u32 litrunlen = seq->litrunlen_and_length & |
21451
|
|
|
|
|
|
|
SEQ_LITRUNLEN_MASK; |
21452
|
2120
|
|
|
|
|
|
unsigned length = seq->litrunlen_and_length >> |
21453
|
|
|
|
|
|
|
SEQ_LENGTH_SHIFT; |
21454
|
|
|
|
|
|
|
unsigned lit; |
21455
|
|
|
|
|
|
|
|
21456
|
|
|
|
|
|
|
|
21457
|
|
|
|
|
|
|
if (CAN_BUFFER(4 * MAX_LITLEN_CODEWORD_LEN)) { |
21458
|
2677
|
100
|
|
|
|
|
for (; litrunlen >= 4; litrunlen -= 4) { |
21459
|
557
|
|
|
|
|
|
lit = *in_next++; |
21460
|
557
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21461
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21462
|
557
|
|
|
|
|
|
lit = *in_next++; |
21463
|
557
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21464
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21465
|
557
|
|
|
|
|
|
lit = *in_next++; |
21466
|
557
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21467
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21468
|
557
|
|
|
|
|
|
lit = *in_next++; |
21469
|
557
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21470
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21471
|
557
|
50
|
|
|
|
|
FLUSH_BITS(); |
21472
|
|
|
|
|
|
|
} |
21473
|
2120
|
100
|
|
|
|
|
if (litrunlen-- != 0) { |
21474
|
509
|
|
|
|
|
|
lit = *in_next++; |
21475
|
509
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21476
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21477
|
509
|
100
|
|
|
|
|
if (litrunlen-- != 0) { |
21478
|
280
|
|
|
|
|
|
lit = *in_next++; |
21479
|
280
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21480
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21481
|
280
|
100
|
|
|
|
|
if (litrunlen-- != 0) { |
21482
|
112
|
|
|
|
|
|
lit = *in_next++; |
21483
|
509
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21484
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21485
|
|
|
|
|
|
|
} |
21486
|
|
|
|
|
|
|
} |
21487
|
509
|
50
|
|
|
|
|
FLUSH_BITS(); |
21488
|
|
|
|
|
|
|
} |
21489
|
|
|
|
|
|
|
} else { |
21490
|
|
|
|
|
|
|
while (litrunlen--) { |
21491
|
|
|
|
|
|
|
lit = *in_next++; |
21492
|
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[lit], |
21493
|
|
|
|
|
|
|
codes->lens.litlen[lit]); |
21494
|
|
|
|
|
|
|
FLUSH_BITS(); |
21495
|
|
|
|
|
|
|
} |
21496
|
|
|
|
|
|
|
} |
21497
|
|
|
|
|
|
|
|
21498
|
2120
|
100
|
|
|
|
|
if (length == 0) { |
21499
|
|
|
|
|
|
|
ASSERT(in_next == in_end); |
21500
|
29
|
|
|
|
|
|
break; |
21501
|
|
|
|
|
|
|
} |
21502
|
|
|
|
|
|
|
|
21503
|
|
|
|
|
|
|
|
21504
|
2091
|
50
|
|
|
|
|
WRITE_MATCH(c, codes, length, seq->offset, |
21505
|
|
|
|
|
|
|
seq->offset_slot); |
21506
|
2091
|
|
|
|
|
|
in_next += length; |
21507
|
2091
|
|
|
|
|
|
} |
21508
|
|
|
|
|
|
|
} |
21509
|
|
|
|
|
|
|
|
21510
|
|
|
|
|
|
|
|
21511
|
|
|
|
|
|
|
ASSERT(bitcount <= 7); |
21512
|
38
|
|
|
|
|
|
ADD_BITS(codes->codewords.litlen[DEFLATE_END_OF_BLOCK], |
21513
|
|
|
|
|
|
|
codes->lens.litlen[DEFLATE_END_OF_BLOCK]); |
21514
|
38
|
50
|
|
|
|
|
FLUSH_BITS(); |
21515
|
|
|
|
|
|
|
out: |
21516
|
|
|
|
|
|
|
ASSERT(bitcount <= 7); |
21517
|
|
|
|
|
|
|
|
21518
|
38
|
50
|
|
|
|
|
ASSERT(8 * (out_next - os->next) + bitcount - os->bitcount == |
|
|
0
|
|
|
|
|
|
21519
|
|
|
|
|
|
|
3 + best_cost || out_next == out_end); |
21520
|
|
|
|
|
|
|
|
21521
|
38
|
|
|
|
|
|
os->bitbuf = bitbuf; |
21522
|
38
|
|
|
|
|
|
os->bitcount = bitcount; |
21523
|
38
|
|
|
|
|
|
os->next = out_next; |
21524
|
38
|
|
|
|
|
|
} |
21525
|
|
|
|
|
|
|
|
21526
|
|
|
|
|
|
|
static void |
21527
|
29
|
|
|
|
|
|
deflate_finish_block(struct libdeflate_compressor *c, |
21528
|
|
|
|
|
|
|
struct deflate_output_bitstream *os, |
21529
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
21530
|
|
|
|
|
|
|
const struct deflate_sequence *sequences, |
21531
|
|
|
|
|
|
|
bool is_final_block) |
21532
|
|
|
|
|
|
|
{ |
21533
|
29
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_END_OF_BLOCK]++; |
21534
|
29
|
|
|
|
|
|
deflate_make_huffman_codes(&c->freqs, &c->codes); |
21535
|
29
|
|
|
|
|
|
deflate_flush_block(c, os, block_begin, block_length, sequences, |
21536
|
|
|
|
|
|
|
is_final_block); |
21537
|
29
|
|
|
|
|
|
} |
21538
|
|
|
|
|
|
|
|
21539
|
|
|
|
|
|
|
|
21540
|
|
|
|
|
|
|
|
21541
|
|
|
|
|
|
|
|
21542
|
|
|
|
|
|
|
|
21543
|
|
|
|
|
|
|
|
21544
|
|
|
|
|
|
|
static void |
21545
|
44
|
|
|
|
|
|
init_block_split_stats(struct block_split_stats *stats) |
21546
|
|
|
|
|
|
|
{ |
21547
|
|
|
|
|
|
|
int i; |
21548
|
|
|
|
|
|
|
|
21549
|
484
|
100
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) { |
21550
|
440
|
|
|
|
|
|
stats->new_observations[i] = 0; |
21551
|
440
|
|
|
|
|
|
stats->observations[i] = 0; |
21552
|
|
|
|
|
|
|
} |
21553
|
44
|
|
|
|
|
|
stats->num_new_observations = 0; |
21554
|
44
|
|
|
|
|
|
stats->num_observations = 0; |
21555
|
44
|
|
|
|
|
|
} |
21556
|
|
|
|
|
|
|
|
21557
|
|
|
|
|
|
|
|
21558
|
|
|
|
|
|
|
static forceinline void |
21559
|
|
|
|
|
|
|
observe_literal(struct block_split_stats *stats, u8 lit) |
21560
|
|
|
|
|
|
|
{ |
21561
|
3237
|
|
|
|
|
|
stats->new_observations[((lit >> 5) & 0x6) | (lit & 1)]++; |
21562
|
3075
|
|
|
|
|
|
stats->num_new_observations++; |
21563
|
|
|
|
|
|
|
} |
21564
|
|
|
|
|
|
|
|
21565
|
|
|
|
|
|
|
|
21566
|
|
|
|
|
|
|
static forceinline void |
21567
|
|
|
|
|
|
|
observe_match(struct block_split_stats *stats, unsigned length) |
21568
|
|
|
|
|
|
|
{ |
21569
|
2133
|
50
|
|
|
|
|
stats->new_observations[NUM_LITERAL_OBSERVATION_TYPES + |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
21570
|
2133
|
|
|
|
|
|
(length >= 9)]++; |
21571
|
2070
|
|
|
|
|
|
stats->num_new_observations++; |
21572
|
|
|
|
|
|
|
} |
21573
|
|
|
|
|
|
|
|
21574
|
|
|
|
|
|
|
static void |
21575
|
15
|
|
|
|
|
|
merge_new_observations(struct block_split_stats *stats) |
21576
|
|
|
|
|
|
|
{ |
21577
|
|
|
|
|
|
|
int i; |
21578
|
|
|
|
|
|
|
|
21579
|
165
|
100
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) { |
21580
|
150
|
|
|
|
|
|
stats->observations[i] += stats->new_observations[i]; |
21581
|
150
|
|
|
|
|
|
stats->new_observations[i] = 0; |
21582
|
|
|
|
|
|
|
} |
21583
|
15
|
|
|
|
|
|
stats->num_observations += stats->num_new_observations; |
21584
|
15
|
|
|
|
|
|
stats->num_new_observations = 0; |
21585
|
15
|
|
|
|
|
|
} |
21586
|
|
|
|
|
|
|
|
21587
|
|
|
|
|
|
|
static bool |
21588
|
7
|
|
|
|
|
|
do_end_block_check(struct block_split_stats *stats, u32 block_length) |
21589
|
|
|
|
|
|
|
{ |
21590
|
7
|
100
|
|
|
|
|
if (stats->num_observations > 0) { |
21591
|
|
|
|
|
|
|
|
21592
|
6
|
|
|
|
|
|
u32 total_delta = 0; |
21593
|
|
|
|
|
|
|
u32 num_items; |
21594
|
|
|
|
|
|
|
u32 cutoff; |
21595
|
|
|
|
|
|
|
int i; |
21596
|
|
|
|
|
|
|
|
21597
|
66
|
100
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) { |
21598
|
120
|
|
|
|
|
|
u32 expected = stats->observations[i] * |
21599
|
60
|
|
|
|
|
|
stats->num_new_observations; |
21600
|
120
|
|
|
|
|
|
u32 actual = stats->new_observations[i] * |
21601
|
60
|
|
|
|
|
|
stats->num_observations; |
21602
|
60
|
100
|
|
|
|
|
u32 delta = (actual > expected) ? actual - expected : |
21603
|
|
|
|
|
|
|
expected - actual; |
21604
|
|
|
|
|
|
|
|
21605
|
60
|
|
|
|
|
|
total_delta += delta; |
21606
|
|
|
|
|
|
|
} |
21607
|
|
|
|
|
|
|
|
21608
|
12
|
|
|
|
|
|
num_items = stats->num_observations + |
21609
|
6
|
|
|
|
|
|
stats->num_new_observations; |
21610
|
|
|
|
|
|
|
|
21611
|
12
|
|
|
|
|
|
cutoff = stats->num_new_observations * 200 / 512 * |
21612
|
6
|
|
|
|
|
|
stats->num_observations; |
21613
|
|
|
|
|
|
|
|
21614
|
6
|
100
|
|
|
|
|
if (block_length < 10000 && num_items < 8192) |
|
|
50
|
|
|
|
|
|
21615
|
1
|
|
|
|
|
|
cutoff += (u64)cutoff * (8192 - num_items) / 8192; |
21616
|
|
|
|
|
|
|
|
21617
|
|
|
|
|
|
|
|
21618
|
6
|
100
|
|
|
|
|
if (total_delta + |
21619
|
6
|
|
|
|
|
|
(block_length / 4096) * stats->num_observations >= cutoff) |
21620
|
1
|
|
|
|
|
|
return true; |
21621
|
|
|
|
|
|
|
} |
21622
|
6
|
|
|
|
|
|
merge_new_observations(stats); |
21623
|
6
|
|
|
|
|
|
return false; |
21624
|
|
|
|
|
|
|
} |
21625
|
|
|
|
|
|
|
|
21626
|
|
|
|
|
|
|
static forceinline bool |
21627
|
|
|
|
|
|
|
ready_to_check_block(const struct block_split_stats *stats, |
21628
|
|
|
|
|
|
|
const u8 *in_block_begin, const u8 *in_next, |
21629
|
|
|
|
|
|
|
const u8 *in_end) |
21630
|
|
|
|
|
|
|
{ |
21631
|
5245
|
|
|
|
|
|
return stats->num_new_observations >= NUM_OBSERVATIONS_PER_BLOCK_CHECK |
21632
|
450
|
0
|
|
|
|
|
&& in_next - in_block_begin >= MIN_BLOCK_LENGTH |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
21633
|
5695
|
50
|
|
|
|
|
&& in_end - in_next >= MIN_BLOCK_LENGTH; |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
21634
|
|
|
|
|
|
|
} |
21635
|
|
|
|
|
|
|
|
21636
|
|
|
|
|
|
|
static forceinline bool |
21637
|
|
|
|
|
|
|
should_end_block(struct block_split_stats *stats, |
21638
|
|
|
|
|
|
|
const u8 *in_block_begin, const u8 *in_next, const u8 *in_end) |
21639
|
|
|
|
|
|
|
{ |
21640
|
|
|
|
|
|
|
|
21641
|
5029
|
50
|
|
|
|
|
if (!ready_to_check_block(stats, in_block_begin, in_next, in_end)) |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
21642
|
5022
|
|
|
|
|
|
return false; |
21643
|
|
|
|
|
|
|
|
21644
|
7
|
|
|
|
|
|
return do_end_block_check(stats, in_next - in_block_begin); |
21645
|
|
|
|
|
|
|
} |
21646
|
|
|
|
|
|
|
|
21647
|
|
|
|
|
|
|
|
21648
|
|
|
|
|
|
|
|
21649
|
|
|
|
|
|
|
static void |
21650
|
29
|
|
|
|
|
|
deflate_begin_sequences(struct libdeflate_compressor *c, |
21651
|
|
|
|
|
|
|
struct deflate_sequence *first_seq) |
21652
|
|
|
|
|
|
|
{ |
21653
|
29
|
|
|
|
|
|
deflate_reset_symbol_frequencies(c); |
21654
|
29
|
|
|
|
|
|
first_seq->litrunlen_and_length = 0; |
21655
|
29
|
|
|
|
|
|
} |
21656
|
|
|
|
|
|
|
|
21657
|
|
|
|
|
|
|
static forceinline void |
21658
|
|
|
|
|
|
|
deflate_choose_literal(struct libdeflate_compressor *c, unsigned literal, |
21659
|
|
|
|
|
|
|
bool gather_split_stats, struct deflate_sequence *seq) |
21660
|
|
|
|
|
|
|
{ |
21661
|
3129
|
|
|
|
|
|
c->freqs.litlen[literal]++; |
21662
|
|
|
|
|
|
|
|
21663
|
3129
|
50
|
|
|
|
|
if (gather_split_stats) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
21664
|
3075
|
|
|
|
|
|
observe_literal(&c->split_stats, literal); |
21665
|
|
|
|
|
|
|
|
21666
|
|
|
|
|
|
|
STATIC_ASSERT(MAX_BLOCK_LENGTH <= SEQ_LITRUNLEN_MASK); |
21667
|
216
|
|
|
|
|
|
seq->litrunlen_and_length++; |
21668
|
|
|
|
|
|
|
} |
21669
|
|
|
|
|
|
|
|
21670
|
|
|
|
|
|
|
static forceinline void |
21671
|
|
|
|
|
|
|
deflate_choose_match(struct libdeflate_compressor *c, |
21672
|
|
|
|
|
|
|
unsigned length, unsigned offset, bool gather_split_stats, |
21673
|
|
|
|
|
|
|
struct deflate_sequence **seq_p) |
21674
|
|
|
|
|
|
|
{ |
21675
|
2091
|
|
|
|
|
|
struct deflate_sequence *seq = *seq_p; |
21676
|
2091
|
|
|
|
|
|
unsigned length_slot = deflate_length_slot[length]; |
21677
|
2091
|
|
|
|
|
|
unsigned offset_slot = deflate_get_offset_slot(offset); |
21678
|
|
|
|
|
|
|
|
21679
|
2091
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_FIRST_LEN_SYM + length_slot]++; |
21680
|
2091
|
|
|
|
|
|
c->freqs.offset[offset_slot]++; |
21681
|
2091
|
50
|
|
|
|
|
if (gather_split_stats) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
21682
|
2070
|
|
|
|
|
|
observe_match(&c->split_stats, length); |
21683
|
|
|
|
|
|
|
|
21684
|
2091
|
|
|
|
|
|
seq->litrunlen_and_length |= (u32)length << SEQ_LENGTH_SHIFT; |
21685
|
2091
|
|
|
|
|
|
seq->offset = offset; |
21686
|
2091
|
|
|
|
|
|
seq->offset_slot = offset_slot; |
21687
|
|
|
|
|
|
|
|
21688
|
2091
|
|
|
|
|
|
seq++; |
21689
|
2091
|
|
|
|
|
|
seq->litrunlen_and_length = 0; |
21690
|
2091
|
|
|
|
|
|
*seq_p = seq; |
21691
|
|
|
|
|
|
|
} |
21692
|
|
|
|
|
|
|
|
21693
|
|
|
|
|
|
|
|
21694
|
|
|
|
|
|
|
static forceinline void |
21695
|
|
|
|
|
|
|
adjust_max_and_nice_len(unsigned *max_len, unsigned *nice_len, size_t remaining) |
21696
|
|
|
|
|
|
|
{ |
21697
|
22346
|
100
|
|
|
|
|
if (unlikely(remaining < DEFLATE_MAX_MATCH_LEN)) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
21698
|
2389
|
|
|
|
|
|
*max_len = remaining; |
21699
|
2389
|
|
|
|
|
|
*nice_len = MIN(*nice_len, *max_len); |
21700
|
|
|
|
|
|
|
} |
21701
|
|
|
|
|
|
|
} |
21702
|
|
|
|
|
|
|
|
21703
|
|
|
|
|
|
|
|
21704
|
|
|
|
|
|
|
static unsigned |
21705
|
46
|
|
|
|
|
|
choose_min_match_len(unsigned num_used_literals, unsigned max_search_depth) |
21706
|
|
|
|
|
|
|
{ |
21707
|
|
|
|
|
|
|
|
21708
|
|
|
|
|
|
|
static const u8 min_lens[] = { |
21709
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 8, 8, 7, 7, 6, 6, 6, 6, 6, 6, |
21710
|
|
|
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
21711
|
|
|
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, |
21712
|
|
|
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
21713
|
|
|
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
21714
|
|
|
|
|
|
|
|
21715
|
|
|
|
|
|
|
}; |
21716
|
|
|
|
|
|
|
unsigned min_len; |
21717
|
|
|
|
|
|
|
|
21718
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MIN_MATCH_LEN <= 3); |
21719
|
|
|
|
|
|
|
STATIC_ASSERT(ARRAY_LEN(min_lens) <= DEFLATE_NUM_LITERALS + 1); |
21720
|
|
|
|
|
|
|
|
21721
|
46
|
50
|
|
|
|
|
if (num_used_literals >= ARRAY_LEN(min_lens)) |
21722
|
0
|
|
|
|
|
|
return 3; |
21723
|
46
|
|
|
|
|
|
min_len = min_lens[num_used_literals]; |
21724
|
|
|
|
|
|
|
|
21725
|
46
|
100
|
|
|
|
|
if (max_search_depth < 16) { |
21726
|
6
|
50
|
|
|
|
|
if (max_search_depth < 5) |
21727
|
0
|
|
|
|
|
|
min_len = MIN(min_len, 4); |
21728
|
6
|
100
|
|
|
|
|
else if (max_search_depth < 10) |
21729
|
3
|
|
|
|
|
|
min_len = MIN(min_len, 5); |
21730
|
|
|
|
|
|
|
else |
21731
|
3
|
|
|
|
|
|
min_len = MIN(min_len, 7); |
21732
|
|
|
|
|
|
|
} |
21733
|
46
|
|
|
|
|
|
return min_len; |
21734
|
|
|
|
|
|
|
} |
21735
|
|
|
|
|
|
|
|
21736
|
|
|
|
|
|
|
static unsigned |
21737
|
35
|
|
|
|
|
|
calculate_min_match_len(const u8 *data, size_t data_len, |
21738
|
|
|
|
|
|
|
unsigned max_search_depth) |
21739
|
|
|
|
|
|
|
{ |
21740
|
35
|
|
|
|
|
|
u8 used[256] = { 0 }; |
21741
|
35
|
|
|
|
|
|
unsigned num_used_literals = 0; |
21742
|
|
|
|
|
|
|
size_t i; |
21743
|
|
|
|
|
|
|
|
21744
|
|
|
|
|
|
|
|
21745
|
35
|
|
|
|
|
|
data_len = MIN(data_len, 4096); |
21746
|
64327
|
100
|
|
|
|
|
for (i = 0; i < data_len; i++) |
21747
|
64292
|
|
|
|
|
|
used[data[i]] = 1; |
21748
|
8995
|
100
|
|
|
|
|
for (i = 0; i < 256; i++) |
21749
|
8960
|
|
|
|
|
|
num_used_literals += used[i]; |
21750
|
35
|
|
|
|
|
|
return choose_min_match_len(num_used_literals, max_search_depth); |
21751
|
|
|
|
|
|
|
} |
21752
|
|
|
|
|
|
|
|
21753
|
|
|
|
|
|
|
|
21754
|
|
|
|
|
|
|
static unsigned |
21755
|
2
|
|
|
|
|
|
recalculate_min_match_len(const struct deflate_freqs *freqs, |
21756
|
|
|
|
|
|
|
unsigned max_search_depth) |
21757
|
|
|
|
|
|
|
{ |
21758
|
2
|
|
|
|
|
|
u32 literal_freq = 0; |
21759
|
|
|
|
|
|
|
u32 cutoff; |
21760
|
2
|
|
|
|
|
|
unsigned num_used_literals = 0; |
21761
|
|
|
|
|
|
|
int i; |
21762
|
|
|
|
|
|
|
|
21763
|
514
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) |
21764
|
512
|
|
|
|
|
|
literal_freq += freqs->litlen[i]; |
21765
|
|
|
|
|
|
|
|
21766
|
2
|
|
|
|
|
|
cutoff = literal_freq >> 10; |
21767
|
|
|
|
|
|
|
|
21768
|
514
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) { |
21769
|
512
|
100
|
|
|
|
|
if (freqs->litlen[i] > cutoff) |
21770
|
119
|
|
|
|
|
|
num_used_literals++; |
21771
|
|
|
|
|
|
|
} |
21772
|
2
|
|
|
|
|
|
return choose_min_match_len(num_used_literals, max_search_depth); |
21773
|
|
|
|
|
|
|
} |
21774
|
|
|
|
|
|
|
|
21775
|
|
|
|
|
|
|
static forceinline const u8 * |
21776
|
|
|
|
|
|
|
choose_max_block_end(const u8 *in_block_begin, const u8 *in_end, |
21777
|
|
|
|
|
|
|
size_t soft_max_len) |
21778
|
|
|
|
|
|
|
{ |
21779
|
38
|
50
|
|
|
|
|
if (in_end - in_block_begin < soft_max_len + MIN_BLOCK_LENGTH) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
21780
|
38
|
|
|
|
|
|
return in_end; |
21781
|
0
|
|
|
|
|
|
return in_block_begin + soft_max_len; |
21782
|
|
|
|
|
|
|
} |
21783
|
|
|
|
|
|
|
|
21784
|
|
|
|
|
|
|
|
21785
|
|
|
|
|
|
|
static size_t |
21786
|
0
|
|
|
|
|
|
deflate_compress_none(const u8 *in, size_t in_nbytes, |
21787
|
|
|
|
|
|
|
u8 *out, size_t out_nbytes_avail) |
21788
|
|
|
|
|
|
|
{ |
21789
|
0
|
|
|
|
|
|
const u8 *in_next = in; |
21790
|
0
|
|
|
|
|
|
const u8 * const in_end = in + in_nbytes; |
21791
|
0
|
|
|
|
|
|
u8 *out_next = out; |
21792
|
0
|
|
|
|
|
|
u8 * const out_end = out + out_nbytes_avail; |
21793
|
|
|
|
|
|
|
|
21794
|
|
|
|
|
|
|
|
21795
|
0
|
0
|
|
|
|
|
if (unlikely(in_nbytes == 0)) { |
21796
|
0
|
0
|
|
|
|
|
if (out_nbytes_avail < 5) |
21797
|
0
|
|
|
|
|
|
return 0; |
21798
|
|
|
|
|
|
|
|
21799
|
0
|
|
|
|
|
|
*out_next++ = 1 | (DEFLATE_BLOCKTYPE_UNCOMPRESSED << 1); |
21800
|
|
|
|
|
|
|
|
21801
|
|
|
|
|
|
|
put_unaligned_le32(0xFFFF0000, out_next); |
21802
|
0
|
|
|
|
|
|
return 5; |
21803
|
|
|
|
|
|
|
} |
21804
|
|
|
|
|
|
|
|
21805
|
|
|
|
|
|
|
do { |
21806
|
0
|
|
|
|
|
|
u8 bfinal = 0; |
21807
|
0
|
|
|
|
|
|
size_t len = UINT16_MAX; |
21808
|
|
|
|
|
|
|
|
21809
|
0
|
0
|
|
|
|
|
if (in_end - in_next <= UINT16_MAX) { |
21810
|
0
|
|
|
|
|
|
bfinal = 1; |
21811
|
0
|
|
|
|
|
|
len = in_end - in_next; |
21812
|
|
|
|
|
|
|
} |
21813
|
0
|
0
|
|
|
|
|
if (out_end - out_next < 5 + len) |
21814
|
0
|
|
|
|
|
|
return 0; |
21815
|
|
|
|
|
|
|
|
21816
|
0
|
|
|
|
|
|
*out_next++ = bfinal | (DEFLATE_BLOCKTYPE_UNCOMPRESSED << 1); |
21817
|
|
|
|
|
|
|
|
21818
|
|
|
|
|
|
|
|
21819
|
0
|
|
|
|
|
|
put_unaligned_le16(len, out_next); |
21820
|
0
|
|
|
|
|
|
out_next += 2; |
21821
|
0
|
|
|
|
|
|
put_unaligned_le16(~len, out_next); |
21822
|
0
|
|
|
|
|
|
out_next += 2; |
21823
|
0
|
|
|
|
|
|
memcpy(out_next, in_next, len); |
21824
|
0
|
|
|
|
|
|
out_next += len; |
21825
|
0
|
|
|
|
|
|
in_next += len; |
21826
|
0
|
0
|
|
|
|
|
} while (in_next != in_end); |
21827
|
|
|
|
|
|
|
|
21828
|
0
|
|
|
|
|
|
return out_next - out; |
21829
|
|
|
|
|
|
|
} |
21830
|
|
|
|
|
|
|
|
21831
|
|
|
|
|
|
|
|
21832
|
|
|
|
|
|
|
static void |
21833
|
3
|
|
|
|
|
|
deflate_compress_fastest(struct libdeflate_compressor * restrict c, |
21834
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
21835
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
21836
|
|
|
|
|
|
|
{ |
21837
|
3
|
|
|
|
|
|
const u8 *in_next = in; |
21838
|
3
|
|
|
|
|
|
const u8 *in_end = in_next + in_nbytes; |
21839
|
3
|
|
|
|
|
|
const u8 *in_cur_base = in_next; |
21840
|
3
|
|
|
|
|
|
unsigned max_len = DEFLATE_MAX_MATCH_LEN; |
21841
|
3
|
|
|
|
|
|
unsigned nice_len = MIN(c->nice_match_length, max_len); |
21842
|
3
|
|
|
|
|
|
u32 next_hash = 0; |
21843
|
|
|
|
|
|
|
|
21844
|
3
|
|
|
|
|
|
ht_matchfinder_init(&c->p.f.ht_mf); |
21845
|
|
|
|
|
|
|
|
21846
|
|
|
|
|
|
|
do { |
21847
|
|
|
|
|
|
|
|
21848
|
|
|
|
|
|
|
|
21849
|
3
|
|
|
|
|
|
const u8 * const in_block_begin = in_next; |
21850
|
3
|
|
|
|
|
|
const u8 * const in_max_block_end = choose_max_block_end( |
21851
|
|
|
|
|
|
|
in_next, in_end, FAST_SOFT_MAX_BLOCK_LENGTH); |
21852
|
3
|
|
|
|
|
|
struct deflate_sequence *seq = c->p.f.sequences; |
21853
|
|
|
|
|
|
|
|
21854
|
3
|
|
|
|
|
|
deflate_begin_sequences(c, seq); |
21855
|
|
|
|
|
|
|
|
21856
|
|
|
|
|
|
|
do { |
21857
|
|
|
|
|
|
|
u32 length; |
21858
|
|
|
|
|
|
|
u32 offset; |
21859
|
75
|
|
|
|
|
|
size_t remaining = in_end - in_next; |
21860
|
|
|
|
|
|
|
|
21861
|
75
|
100
|
|
|
|
|
if (unlikely(remaining < DEFLATE_MAX_MATCH_LEN)) { |
21862
|
3
|
|
|
|
|
|
max_len = remaining; |
21863
|
3
|
50
|
|
|
|
|
if (max_len < HT_MATCHFINDER_REQUIRED_NBYTES) { |
21864
|
|
|
|
|
|
|
do { |
21865
|
0
|
|
|
|
|
|
deflate_choose_literal(c, |
21866
|
0
|
|
|
|
|
|
*in_next++, false, seq); |
21867
|
0
|
0
|
|
|
|
|
} while (--max_len); |
21868
|
0
|
|
|
|
|
|
break; |
21869
|
|
|
|
|
|
|
} |
21870
|
3
|
|
|
|
|
|
nice_len = MIN(nice_len, max_len); |
21871
|
|
|
|
|
|
|
} |
21872
|
150
|
|
|
|
|
|
length = ht_matchfinder_longest_match(&c->p.f.ht_mf, |
21873
|
|
|
|
|
|
|
&in_cur_base, |
21874
|
|
|
|
|
|
|
in_next, |
21875
|
|
|
|
|
|
|
max_len, |
21876
|
|
|
|
|
|
|
nice_len, |
21877
|
|
|
|
|
|
|
&next_hash, |
21878
|
|
|
|
|
|
|
&offset); |
21879
|
75
|
100
|
|
|
|
|
if (length) { |
21880
|
|
|
|
|
|
|
|
21881
|
21
|
|
|
|
|
|
deflate_choose_match(c, length, offset, false, |
21882
|
|
|
|
|
|
|
&seq); |
21883
|
21
|
|
|
|
|
|
ht_matchfinder_skip_bytes(&c->p.f.ht_mf, |
21884
|
|
|
|
|
|
|
&in_cur_base, |
21885
|
|
|
|
|
|
|
in_next + 1, |
21886
|
|
|
|
|
|
|
in_end, |
21887
|
|
|
|
|
|
|
length - 1, |
21888
|
|
|
|
|
|
|
&next_hash); |
21889
|
21
|
|
|
|
|
|
in_next += length; |
21890
|
|
|
|
|
|
|
} else { |
21891
|
|
|
|
|
|
|
|
21892
|
54
|
|
|
|
|
|
deflate_choose_literal(c, *in_next++, false, |
21893
|
|
|
|
|
|
|
seq); |
21894
|
|
|
|
|
|
|
} |
21895
|
|
|
|
|
|
|
|
21896
|
|
|
|
|
|
|
|
21897
|
72
|
50
|
|
|
|
|
} while (in_next < in_max_block_end && |
21898
|
75
|
100
|
|
|
|
|
seq < &c->p.f.sequences[FAST_SEQ_STORE_LENGTH]); |
21899
|
|
|
|
|
|
|
|
21900
|
3
|
|
|
|
|
|
deflate_finish_block(c, os, in_block_begin, |
21901
|
3
|
|
|
|
|
|
in_next - in_block_begin, |
21902
|
3
|
|
|
|
|
|
c->p.f.sequences, in_next == in_end); |
21903
|
3
|
50
|
|
|
|
|
} while (in_next != in_end); |
21904
|
3
|
|
|
|
|
|
} |
21905
|
|
|
|
|
|
|
|
21906
|
|
|
|
|
|
|
|
21907
|
|
|
|
|
|
|
static void |
21908
|
9
|
|
|
|
|
|
deflate_compress_greedy(struct libdeflate_compressor * restrict c, |
21909
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
21910
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
21911
|
|
|
|
|
|
|
{ |
21912
|
9
|
|
|
|
|
|
const u8 *in_next = in; |
21913
|
9
|
|
|
|
|
|
const u8 *in_end = in_next + in_nbytes; |
21914
|
9
|
|
|
|
|
|
const u8 *in_cur_base = in_next; |
21915
|
9
|
|
|
|
|
|
unsigned max_len = DEFLATE_MAX_MATCH_LEN; |
21916
|
9
|
|
|
|
|
|
unsigned nice_len = MIN(c->nice_match_length, max_len); |
21917
|
9
|
|
|
|
|
|
u32 next_hashes[2] = {0, 0}; |
21918
|
|
|
|
|
|
|
|
21919
|
9
|
|
|
|
|
|
hc_matchfinder_init(&c->p.g.hc_mf); |
21920
|
|
|
|
|
|
|
|
21921
|
|
|
|
|
|
|
do { |
21922
|
|
|
|
|
|
|
|
21923
|
|
|
|
|
|
|
|
21924
|
9
|
|
|
|
|
|
const u8 * const in_block_begin = in_next; |
21925
|
9
|
|
|
|
|
|
const u8 * const in_max_block_end = choose_max_block_end( |
21926
|
|
|
|
|
|
|
in_next, in_end, SOFT_MAX_BLOCK_LENGTH); |
21927
|
9
|
|
|
|
|
|
struct deflate_sequence *seq = c->p.g.sequences; |
21928
|
|
|
|
|
|
|
unsigned min_len; |
21929
|
|
|
|
|
|
|
|
21930
|
9
|
|
|
|
|
|
init_block_split_stats(&c->split_stats); |
21931
|
9
|
|
|
|
|
|
deflate_begin_sequences(c, seq); |
21932
|
9
|
|
|
|
|
|
min_len = calculate_min_match_len(in_next, |
21933
|
9
|
|
|
|
|
|
in_max_block_end - in_next, |
21934
|
|
|
|
|
|
|
c->max_search_depth); |
21935
|
|
|
|
|
|
|
do { |
21936
|
|
|
|
|
|
|
u32 length; |
21937
|
|
|
|
|
|
|
u32 offset; |
21938
|
|
|
|
|
|
|
|
21939
|
225
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, |
21940
|
225
|
|
|
|
|
|
in_end - in_next); |
21941
|
450
|
|
|
|
|
|
length = hc_matchfinder_longest_match( |
21942
|
|
|
|
|
|
|
&c->p.g.hc_mf, |
21943
|
|
|
|
|
|
|
&in_cur_base, |
21944
|
|
|
|
|
|
|
in_next, |
21945
|
|
|
|
|
|
|
min_len - 1, |
21946
|
|
|
|
|
|
|
max_len, |
21947
|
|
|
|
|
|
|
nice_len, |
21948
|
|
|
|
|
|
|
c->max_search_depth, |
21949
|
|
|
|
|
|
|
next_hashes, |
21950
|
|
|
|
|
|
|
&offset); |
21951
|
|
|
|
|
|
|
|
21952
|
225
|
100
|
|
|
|
|
if (length >= min_len && |
|
|
50
|
|
|
|
|
|
21953
|
0
|
0
|
|
|
|
|
(length > DEFLATE_MIN_MATCH_LEN || |
21954
|
0
|
|
|
|
|
|
offset <= 4096)) { |
21955
|
|
|
|
|
|
|
|
21956
|
63
|
|
|
|
|
|
deflate_choose_match(c, length, offset, true, |
21957
|
|
|
|
|
|
|
&seq); |
21958
|
63
|
|
|
|
|
|
hc_matchfinder_skip_bytes(&c->p.g.hc_mf, |
21959
|
|
|
|
|
|
|
&in_cur_base, |
21960
|
|
|
|
|
|
|
in_next + 1, |
21961
|
|
|
|
|
|
|
in_end, |
21962
|
|
|
|
|
|
|
length - 1, |
21963
|
|
|
|
|
|
|
next_hashes); |
21964
|
63
|
|
|
|
|
|
in_next += length; |
21965
|
|
|
|
|
|
|
} else { |
21966
|
|
|
|
|
|
|
|
21967
|
162
|
|
|
|
|
|
deflate_choose_literal(c, *in_next++, true, |
21968
|
|
|
|
|
|
|
seq); |
21969
|
|
|
|
|
|
|
} |
21970
|
|
|
|
|
|
|
|
21971
|
|
|
|
|
|
|
|
21972
|
216
|
50
|
|
|
|
|
} while (in_next < in_max_block_end && |
21973
|
216
|
50
|
|
|
|
|
seq < &c->p.g.sequences[SEQ_STORE_LENGTH] && |
21974
|
432
|
|
|
|
|
|
!should_end_block(&c->split_stats, |
21975
|
225
|
100
|
|
|
|
|
in_block_begin, in_next, in_end)); |
21976
|
|
|
|
|
|
|
|
21977
|
9
|
|
|
|
|
|
deflate_finish_block(c, os, in_block_begin, |
21978
|
9
|
|
|
|
|
|
in_next - in_block_begin, |
21979
|
9
|
|
|
|
|
|
c->p.g.sequences, in_next == in_end); |
21980
|
9
|
50
|
|
|
|
|
} while (in_next != in_end); |
21981
|
9
|
|
|
|
|
|
} |
21982
|
|
|
|
|
|
|
|
21983
|
|
|
|
|
|
|
static forceinline void |
21984
|
|
|
|
|
|
|
deflate_compress_lazy_generic(struct libdeflate_compressor * restrict c, |
21985
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
21986
|
|
|
|
|
|
|
struct deflate_output_bitstream *os, bool lazy2) |
21987
|
|
|
|
|
|
|
{ |
21988
|
16
|
|
|
|
|
|
const u8 *in_next = in; |
21989
|
16
|
|
|
|
|
|
const u8 *in_end = in_next + in_nbytes; |
21990
|
16
|
|
|
|
|
|
const u8 *in_cur_base = in_next; |
21991
|
16
|
|
|
|
|
|
unsigned max_len = DEFLATE_MAX_MATCH_LEN; |
21992
|
16
|
|
|
|
|
|
unsigned nice_len = MIN(c->nice_match_length, max_len); |
21993
|
16
|
|
|
|
|
|
u32 next_hashes[2] = {0, 0}; |
21994
|
|
|
|
|
|
|
|
21995
|
16
|
|
|
|
|
|
hc_matchfinder_init(&c->p.g.hc_mf); |
21996
|
|
|
|
|
|
|
|
21997
|
|
|
|
|
|
|
do { |
21998
|
|
|
|
|
|
|
|
21999
|
|
|
|
|
|
|
|
22000
|
17
|
|
|
|
|
|
const u8 * const in_block_begin = in_next; |
22001
|
17
|
|
|
|
|
|
const u8 * const in_max_block_end = choose_max_block_end( |
22002
|
|
|
|
|
|
|
in_next, in_end, SOFT_MAX_BLOCK_LENGTH); |
22003
|
17
|
|
|
|
|
|
const u8 *next_recalc_min_len = |
22004
|
17
|
|
|
|
|
|
in_next + MIN(in_end - in_next, 10000); |
22005
|
17
|
|
|
|
|
|
struct deflate_sequence *seq = c->p.g.sequences; |
22006
|
|
|
|
|
|
|
unsigned min_len; |
22007
|
|
|
|
|
|
|
|
22008
|
17
|
|
|
|
|
|
init_block_split_stats(&c->split_stats); |
22009
|
17
|
|
|
|
|
|
deflate_begin_sequences(c, seq); |
22010
|
17
|
|
|
|
|
|
min_len = calculate_min_match_len(in_next, |
22011
|
17
|
|
|
|
|
|
in_max_block_end - in_next, |
22012
|
|
|
|
|
|
|
c->max_search_depth); |
22013
|
|
|
|
|
|
|
do { |
22014
|
|
|
|
|
|
|
unsigned cur_len; |
22015
|
|
|
|
|
|
|
unsigned cur_offset; |
22016
|
|
|
|
|
|
|
unsigned next_len; |
22017
|
|
|
|
|
|
|
unsigned next_offset; |
22018
|
|
|
|
|
|
|
|
22019
|
|
|
|
|
|
|
|
22020
|
4829
|
50
|
|
|
|
|
if (in_next >= next_recalc_min_len) { |
|
|
100
|
|
|
|
|
|
22021
|
2
|
|
|
|
|
|
min_len = recalculate_min_match_len( |
22022
|
2
|
|
|
|
|
|
&c->freqs, |
22023
|
|
|
|
|
|
|
c->max_search_depth); |
22024
|
2
|
|
|
|
|
|
next_recalc_min_len += |
22025
|
2
|
|
|
|
|
|
MIN(in_end - next_recalc_min_len, |
22026
|
|
|
|
|
|
|
in_next - in_block_begin); |
22027
|
|
|
|
|
|
|
} |
22028
|
|
|
|
|
|
|
|
22029
|
|
|
|
|
|
|
|
22030
|
4829
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, |
22031
|
4829
|
|
|
|
|
|
in_end - in_next); |
22032
|
9658
|
|
|
|
|
|
cur_len = hc_matchfinder_longest_match( |
22033
|
|
|
|
|
|
|
&c->p.g.hc_mf, |
22034
|
|
|
|
|
|
|
&in_cur_base, |
22035
|
|
|
|
|
|
|
in_next, |
22036
|
|
|
|
|
|
|
min_len - 1, |
22037
|
|
|
|
|
|
|
max_len, |
22038
|
|
|
|
|
|
|
nice_len, |
22039
|
|
|
|
|
|
|
c->max_search_depth, |
22040
|
|
|
|
|
|
|
next_hashes, |
22041
|
|
|
|
|
|
|
&cur_offset); |
22042
|
4829
|
100
|
|
|
|
|
if (cur_len < min_len || |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
22043
|
0
|
0
|
|
|
|
|
(cur_len == DEFLATE_MIN_MATCH_LEN && |
|
|
0
|
|
|
|
|
|
22044
|
0
|
|
|
|
|
|
cur_offset > 8192)) { |
22045
|
|
|
|
|
|
|
|
22046
|
2822
|
|
|
|
|
|
deflate_choose_literal(c, *in_next++, true, |
22047
|
|
|
|
|
|
|
seq); |
22048
|
2928
|
|
|
|
|
|
continue; |
22049
|
|
|
|
|
|
|
} |
22050
|
2007
|
|
|
|
|
|
in_next++; |
22051
|
|
|
|
|
|
|
|
22052
|
|
|
|
|
|
|
have_cur_match: |
22053
|
|
|
|
|
|
|
|
22054
|
2098
|
50
|
|
|
|
|
if (cur_len >= nice_len) { |
|
|
100
|
|
|
|
|
|
22055
|
106
|
|
|
|
|
|
deflate_choose_match(c, cur_len, cur_offset, |
22056
|
|
|
|
|
|
|
true, &seq); |
22057
|
106
|
|
|
|
|
|
hc_matchfinder_skip_bytes(&c->p.g.hc_mf, |
22058
|
|
|
|
|
|
|
&in_cur_base, |
22059
|
|
|
|
|
|
|
in_next, |
22060
|
|
|
|
|
|
|
in_end, |
22061
|
|
|
|
|
|
|
cur_len - 1, |
22062
|
|
|
|
|
|
|
next_hashes); |
22063
|
106
|
|
|
|
|
|
in_next += cur_len - 1; |
22064
|
106
|
|
|
|
|
|
continue; |
22065
|
|
|
|
|
|
|
} |
22066
|
|
|
|
|
|
|
|
22067
|
|
|
|
|
|
|
|
22068
|
1992
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, |
22069
|
1992
|
|
|
|
|
|
in_end - in_next); |
22070
|
3984
|
|
|
|
|
|
next_len = hc_matchfinder_longest_match( |
22071
|
|
|
|
|
|
|
&c->p.g.hc_mf, |
22072
|
|
|
|
|
|
|
&in_cur_base, |
22073
|
|
|
|
|
|
|
in_next++, |
22074
|
|
|
|
|
|
|
cur_len - 1, |
22075
|
|
|
|
|
|
|
max_len, |
22076
|
|
|
|
|
|
|
nice_len, |
22077
|
1992
|
|
|
|
|
|
c->max_search_depth >> 1, |
22078
|
|
|
|
|
|
|
next_hashes, |
22079
|
|
|
|
|
|
|
&next_offset); |
22080
|
2130
|
0
|
|
|
|
|
if (next_len >= cur_len && |
|
|
0
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
22081
|
276
|
|
|
|
|
|
4 * (int)(next_len - cur_len) + |
22082
|
414
|
|
|
|
|
|
((int)bsr32(cur_offset) - |
22083
|
276
|
|
|
|
|
|
(int)bsr32(next_offset)) > 2) { |
22084
|
|
|
|
|
|
|
|
22085
|
91
|
|
|
|
|
|
deflate_choose_literal(c, *(in_next - 2), true, |
22086
|
|
|
|
|
|
|
seq); |
22087
|
91
|
|
|
|
|
|
cur_len = next_len; |
22088
|
91
|
|
|
|
|
|
cur_offset = next_offset; |
22089
|
|
|
|
|
|
|
goto have_cur_match; |
22090
|
|
|
|
|
|
|
} |
22091
|
|
|
|
|
|
|
|
22092
|
1901
|
0
|
|
|
|
|
if (lazy2) { |
|
|
50
|
|
|
|
|
|
22093
|
|
|
|
|
|
|
|
22094
|
0
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, |
22095
|
0
|
|
|
|
|
|
in_end - in_next); |
22096
|
0
|
|
|
|
|
|
next_len = hc_matchfinder_longest_match( |
22097
|
|
|
|
|
|
|
&c->p.g.hc_mf, |
22098
|
|
|
|
|
|
|
&in_cur_base, |
22099
|
|
|
|
|
|
|
in_next++, |
22100
|
|
|
|
|
|
|
cur_len - 1, |
22101
|
|
|
|
|
|
|
max_len, |
22102
|
|
|
|
|
|
|
nice_len, |
22103
|
0
|
|
|
|
|
|
c->max_search_depth >> 2, |
22104
|
|
|
|
|
|
|
next_hashes, |
22105
|
|
|
|
|
|
|
&next_offset); |
22106
|
0
|
0
|
|
|
|
|
if (next_len >= cur_len && |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22107
|
0
|
|
|
|
|
|
4 * (int)(next_len - cur_len) + |
22108
|
0
|
|
|
|
|
|
((int)bsr32(cur_offset) - |
22109
|
0
|
|
|
|
|
|
(int)bsr32(next_offset)) > 6) { |
22110
|
|
|
|
|
|
|
|
22111
|
0
|
|
|
|
|
|
deflate_choose_literal( |
22112
|
0
|
|
|
|
|
|
c, *(in_next - 3), true, seq); |
22113
|
0
|
|
|
|
|
|
deflate_choose_literal( |
22114
|
0
|
|
|
|
|
|
c, *(in_next - 2), true, seq); |
22115
|
0
|
|
|
|
|
|
cur_len = next_len; |
22116
|
0
|
|
|
|
|
|
cur_offset = next_offset; |
22117
|
|
|
|
|
|
|
goto have_cur_match; |
22118
|
|
|
|
|
|
|
} |
22119
|
|
|
|
|
|
|
|
22120
|
0
|
|
|
|
|
|
deflate_choose_match(c, cur_len, cur_offset, |
22121
|
|
|
|
|
|
|
true, &seq); |
22122
|
0
|
0
|
|
|
|
|
if (cur_len > 3) { |
|
|
0
|
|
|
|
|
|
22123
|
0
|
|
|
|
|
|
hc_matchfinder_skip_bytes(&c->p.g.hc_mf, |
22124
|
|
|
|
|
|
|
&in_cur_base, |
22125
|
|
|
|
|
|
|
in_next, |
22126
|
|
|
|
|
|
|
in_end, |
22127
|
|
|
|
|
|
|
cur_len - 3, |
22128
|
|
|
|
|
|
|
next_hashes); |
22129
|
0
|
|
|
|
|
|
in_next += cur_len - 3; |
22130
|
|
|
|
|
|
|
} |
22131
|
|
|
|
|
|
|
} else { |
22132
|
|
|
|
|
|
|
|
22133
|
1901
|
|
|
|
|
|
deflate_choose_match(c, cur_len, cur_offset, |
22134
|
|
|
|
|
|
|
true, &seq); |
22135
|
1901
|
|
|
|
|
|
hc_matchfinder_skip_bytes(&c->p.g.hc_mf, |
22136
|
|
|
|
|
|
|
&in_cur_base, |
22137
|
|
|
|
|
|
|
in_next, |
22138
|
|
|
|
|
|
|
in_end, |
22139
|
|
|
|
|
|
|
cur_len - 2, |
22140
|
|
|
|
|
|
|
next_hashes); |
22141
|
1901
|
|
|
|
|
|
in_next += cur_len - 2; |
22142
|
|
|
|
|
|
|
} |
22143
|
|
|
|
|
|
|
|
22144
|
4813
|
50
|
|
|
|
|
} while (in_next < in_max_block_end && |
|
|
50
|
|
|
|
|
|
22145
|
4813
|
50
|
|
|
|
|
seq < &c->p.g.sequences[SEQ_STORE_LENGTH] && |
|
|
100
|
|
|
|
|
|
22146
|
9626
|
|
|
|
|
|
!should_end_block(&c->split_stats, |
22147
|
4829
|
100
|
|
|
|
|
in_block_begin, in_next, in_end)); |
|
|
100
|
|
|
|
|
|
22148
|
|
|
|
|
|
|
|
22149
|
17
|
|
|
|
|
|
deflate_finish_block(c, os, in_block_begin, |
22150
|
17
|
|
|
|
|
|
in_next - in_block_begin, |
22151
|
17
|
|
|
|
|
|
c->p.g.sequences, in_next == in_end); |
22152
|
17
|
|
|
|
|
|
} while (in_next != in_end); |
22153
|
|
|
|
|
|
|
} |
22154
|
|
|
|
|
|
|
|
22155
|
|
|
|
|
|
|
|
22156
|
|
|
|
|
|
|
static void |
22157
|
10
|
|
|
|
|
|
deflate_compress_lazy(struct libdeflate_compressor * restrict c, |
22158
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
22159
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
22160
|
|
|
|
|
|
|
{ |
22161
|
|
|
|
|
|
|
deflate_compress_lazy_generic(c, in, in_nbytes, os, false); |
22162
|
10
|
|
|
|
|
|
} |
22163
|
|
|
|
|
|
|
|
22164
|
|
|
|
|
|
|
|
22165
|
|
|
|
|
|
|
static void |
22166
|
6
|
|
|
|
|
|
deflate_compress_lazy2(struct libdeflate_compressor * restrict c, |
22167
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
22168
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
22169
|
|
|
|
|
|
|
{ |
22170
|
|
|
|
|
|
|
deflate_compress_lazy_generic(c, in, in_nbytes, os, true); |
22171
|
6
|
|
|
|
|
|
} |
22172
|
|
|
|
|
|
|
|
22173
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
22174
|
|
|
|
|
|
|
|
22175
|
|
|
|
|
|
|
|
22176
|
|
|
|
|
|
|
static void |
22177
|
18
|
|
|
|
|
|
deflate_tally_item_list(struct libdeflate_compressor *c, u32 block_length) |
22178
|
|
|
|
|
|
|
{ |
22179
|
18
|
|
|
|
|
|
struct deflate_optimum_node *cur_node = &c->p.n.optimum_nodes[0]; |
22180
|
18
|
|
|
|
|
|
struct deflate_optimum_node *end_node = |
22181
|
|
|
|
|
|
|
&c->p.n.optimum_nodes[block_length]; |
22182
|
|
|
|
|
|
|
|
22183
|
|
|
|
|
|
|
do { |
22184
|
450
|
|
|
|
|
|
unsigned length = cur_node->item & OPTIMUM_LEN_MASK; |
22185
|
450
|
|
|
|
|
|
unsigned offset = cur_node->item >> OPTIMUM_OFFSET_SHIFT; |
22186
|
|
|
|
|
|
|
|
22187
|
450
|
100
|
|
|
|
|
if (length == 1) { |
22188
|
|
|
|
|
|
|
|
22189
|
324
|
|
|
|
|
|
c->freqs.litlen[offset]++; |
22190
|
|
|
|
|
|
|
} else { |
22191
|
|
|
|
|
|
|
|
22192
|
126
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_FIRST_LEN_SYM + |
22193
|
252
|
|
|
|
|
|
deflate_length_slot[length]]++; |
22194
|
126
|
|
|
|
|
|
c->freqs.offset[c->p.n.offset_slot_full[offset]]++; |
22195
|
|
|
|
|
|
|
} |
22196
|
450
|
|
|
|
|
|
cur_node += length; |
22197
|
450
|
100
|
|
|
|
|
} while (cur_node != end_node); |
22198
|
|
|
|
|
|
|
|
22199
|
|
|
|
|
|
|
|
22200
|
18
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_END_OF_BLOCK]++; |
22201
|
18
|
|
|
|
|
|
} |
22202
|
|
|
|
|
|
|
|
22203
|
|
|
|
|
|
|
static void |
22204
|
9
|
|
|
|
|
|
deflate_choose_all_literals(struct libdeflate_compressor *c, |
22205
|
|
|
|
|
|
|
const u8 *block, u32 block_length) |
22206
|
|
|
|
|
|
|
{ |
22207
|
|
|
|
|
|
|
u32 i; |
22208
|
|
|
|
|
|
|
|
22209
|
9
|
|
|
|
|
|
deflate_reset_symbol_frequencies(c); |
22210
|
15309
|
100
|
|
|
|
|
for (i = 0; i < block_length; i++) |
22211
|
15300
|
|
|
|
|
|
c->freqs.litlen[block[i]]++; |
22212
|
9
|
|
|
|
|
|
c->freqs.litlen[DEFLATE_END_OF_BLOCK]++; |
22213
|
|
|
|
|
|
|
|
22214
|
9
|
|
|
|
|
|
deflate_make_huffman_codes(&c->freqs, &c->codes); |
22215
|
9
|
|
|
|
|
|
} |
22216
|
|
|
|
|
|
|
|
22217
|
|
|
|
|
|
|
|
22218
|
|
|
|
|
|
|
static u32 |
22219
|
27
|
|
|
|
|
|
deflate_compute_true_cost(struct libdeflate_compressor *c) |
22220
|
|
|
|
|
|
|
{ |
22221
|
27
|
|
|
|
|
|
u32 cost = 0; |
22222
|
|
|
|
|
|
|
unsigned sym; |
22223
|
|
|
|
|
|
|
|
22224
|
27
|
|
|
|
|
|
deflate_precompute_huffman_header(c); |
22225
|
|
|
|
|
|
|
|
22226
|
27
|
|
|
|
|
|
memset(&c->codes.lens.litlen[c->o.precode.num_litlen_syms], 0, |
22227
|
27
|
|
|
|
|
|
DEFLATE_NUM_LITLEN_SYMS - c->o.precode.num_litlen_syms); |
22228
|
|
|
|
|
|
|
|
22229
|
27
|
|
|
|
|
|
cost += 5 + 5 + 4 + (3 * c->o.precode.num_explicit_lens); |
22230
|
540
|
100
|
|
|
|
|
for (sym = 0; sym < DEFLATE_NUM_PRECODE_SYMS; sym++) { |
22231
|
1026
|
|
|
|
|
|
cost += c->o.precode.freqs[sym] * |
22232
|
1026
|
|
|
|
|
|
(c->o.precode.lens[sym] + |
22233
|
513
|
|
|
|
|
|
deflate_extra_precode_bits[sym]); |
22234
|
|
|
|
|
|
|
} |
22235
|
|
|
|
|
|
|
|
22236
|
6966
|
100
|
|
|
|
|
for (sym = 0; sym < DEFLATE_FIRST_LEN_SYM; sym++) |
22237
|
6939
|
|
|
|
|
|
cost += c->freqs.litlen[sym] * c->codes.lens.litlen[sym]; |
22238
|
|
|
|
|
|
|
|
22239
|
810
|
100
|
|
|
|
|
for (; sym < DEFLATE_FIRST_LEN_SYM + |
22240
|
783
|
|
|
|
|
|
ARRAY_LEN(deflate_extra_length_bits); sym++) |
22241
|
1566
|
|
|
|
|
|
cost += c->freqs.litlen[sym] * |
22242
|
1566
|
|
|
|
|
|
(c->codes.lens.litlen[sym] + |
22243
|
783
|
|
|
|
|
|
deflate_extra_length_bits[sym - DEFLATE_FIRST_LEN_SYM]); |
22244
|
|
|
|
|
|
|
|
22245
|
837
|
100
|
|
|
|
|
for (sym = 0; sym < ARRAY_LEN(deflate_extra_offset_bits); sym++) |
22246
|
1620
|
|
|
|
|
|
cost += c->freqs.offset[sym] * |
22247
|
1620
|
|
|
|
|
|
(c->codes.lens.offset[sym] + |
22248
|
810
|
|
|
|
|
|
deflate_extra_offset_bits[sym]); |
22249
|
27
|
|
|
|
|
|
return cost; |
22250
|
|
|
|
|
|
|
} |
22251
|
|
|
|
|
|
|
|
22252
|
|
|
|
|
|
|
|
22253
|
|
|
|
|
|
|
static void |
22254
|
9
|
|
|
|
|
|
deflate_set_costs_from_codes(struct libdeflate_compressor *c, |
22255
|
|
|
|
|
|
|
const struct deflate_lens *lens) |
22256
|
|
|
|
|
|
|
{ |
22257
|
|
|
|
|
|
|
unsigned i; |
22258
|
|
|
|
|
|
|
|
22259
|
|
|
|
|
|
|
|
22260
|
2313
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) { |
22261
|
2304
|
100
|
|
|
|
|
u32 bits = (lens->litlen[i] ? |
22262
|
108
|
|
|
|
|
|
lens->litlen[i] : LITERAL_NOSTAT_BITS); |
22263
|
|
|
|
|
|
|
|
22264
|
2304
|
|
|
|
|
|
c->p.n.costs.literal[i] = bits * BIT_COST; |
22265
|
|
|
|
|
|
|
} |
22266
|
|
|
|
|
|
|
|
22267
|
|
|
|
|
|
|
|
22268
|
2313
|
100
|
|
|
|
|
for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++) { |
22269
|
2304
|
|
|
|
|
|
unsigned length_slot = deflate_length_slot[i]; |
22270
|
2304
|
|
|
|
|
|
unsigned litlen_sym = DEFLATE_FIRST_LEN_SYM + length_slot; |
22271
|
2304
|
100
|
|
|
|
|
u32 bits = (lens->litlen[litlen_sym] ? |
22272
|
297
|
|
|
|
|
|
lens->litlen[litlen_sym] : LENGTH_NOSTAT_BITS); |
22273
|
|
|
|
|
|
|
|
22274
|
2304
|
|
|
|
|
|
bits += deflate_extra_length_bits[length_slot]; |
22275
|
2304
|
|
|
|
|
|
c->p.n.costs.length[i] = bits * BIT_COST; |
22276
|
|
|
|
|
|
|
} |
22277
|
|
|
|
|
|
|
|
22278
|
|
|
|
|
|
|
|
22279
|
279
|
100
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++) { |
22280
|
270
|
100
|
|
|
|
|
u32 bits = (lens->offset[i] ? |
22281
|
18
|
|
|
|
|
|
lens->offset[i] : OFFSET_NOSTAT_BITS); |
22282
|
|
|
|
|
|
|
|
22283
|
270
|
|
|
|
|
|
bits += deflate_extra_offset_bits[i]; |
22284
|
270
|
|
|
|
|
|
c->p.n.costs.offset_slot[i] = bits * BIT_COST; |
22285
|
|
|
|
|
|
|
} |
22286
|
9
|
|
|
|
|
|
} |
22287
|
|
|
|
|
|
|
|
22288
|
|
|
|
|
|
|
|
22289
|
|
|
|
|
|
|
static const struct { |
22290
|
|
|
|
|
|
|
u8 used_lits_to_lit_cost[257]; |
22291
|
|
|
|
|
|
|
u8 len_sym_cost; |
22292
|
|
|
|
|
|
|
} default_litlen_costs[] = { |
22293
|
|
|
|
|
|
|
{ |
22294
|
|
|
|
|
|
|
.used_lits_to_lit_cost = { |
22295
|
|
|
|
|
|
|
6, 6, 22, 32, 38, 43, 48, 51, |
22296
|
|
|
|
|
|
|
54, 57, 59, 61, 64, 65, 67, 69, |
22297
|
|
|
|
|
|
|
70, 72, 73, 74, 75, 76, 77, 79, |
22298
|
|
|
|
|
|
|
80, 80, 81, 82, 83, 84, 85, 85, |
22299
|
|
|
|
|
|
|
86, 87, 88, 88, 89, 89, 90, 91, |
22300
|
|
|
|
|
|
|
91, 92, 92, 93, 93, 94, 95, 95, |
22301
|
|
|
|
|
|
|
96, 96, 96, 97, 97, 98, 98, 99, |
22302
|
|
|
|
|
|
|
99, 99, 100, 100, 101, 101, 101, 102, |
22303
|
|
|
|
|
|
|
102, 102, 103, 103, 104, 104, 104, 105, |
22304
|
|
|
|
|
|
|
105, 105, 105, 106, 106, 106, 107, 107, |
22305
|
|
|
|
|
|
|
107, 108, 108, 108, 108, 109, 109, 109, |
22306
|
|
|
|
|
|
|
109, 110, 110, 110, 111, 111, 111, 111, |
22307
|
|
|
|
|
|
|
112, 112, 112, 112, 112, 113, 113, 113, |
22308
|
|
|
|
|
|
|
113, 114, 114, 114, 114, 114, 115, 115, |
22309
|
|
|
|
|
|
|
115, 115, 115, 116, 116, 116, 116, 116, |
22310
|
|
|
|
|
|
|
117, 117, 117, 117, 117, 118, 118, 118, |
22311
|
|
|
|
|
|
|
118, 118, 118, 119, 119, 119, 119, 119, |
22312
|
|
|
|
|
|
|
120, 120, 120, 120, 120, 120, 121, 121, |
22313
|
|
|
|
|
|
|
121, 121, 121, 121, 121, 122, 122, 122, |
22314
|
|
|
|
|
|
|
122, 122, 122, 123, 123, 123, 123, 123, |
22315
|
|
|
|
|
|
|
123, 123, 124, 124, 124, 124, 124, 124, |
22316
|
|
|
|
|
|
|
124, 125, 125, 125, 125, 125, 125, 125, |
22317
|
|
|
|
|
|
|
125, 126, 126, 126, 126, 126, 126, 126, |
22318
|
|
|
|
|
|
|
127, 127, 127, 127, 127, 127, 127, 127, |
22319
|
|
|
|
|
|
|
128, 128, 128, 128, 128, 128, 128, 128, |
22320
|
|
|
|
|
|
|
128, 129, 129, 129, 129, 129, 129, 129, |
22321
|
|
|
|
|
|
|
129, 129, 130, 130, 130, 130, 130, 130, |
22322
|
|
|
|
|
|
|
130, 130, 130, 131, 131, 131, 131, 131, |
22323
|
|
|
|
|
|
|
131, 131, 131, 131, 131, 132, 132, 132, |
22324
|
|
|
|
|
|
|
132, 132, 132, 132, 132, 132, 132, 133, |
22325
|
|
|
|
|
|
|
133, 133, 133, 133, 133, 133, 133, 133, |
22326
|
|
|
|
|
|
|
133, 134, 134, 134, 134, 134, 134, 134, |
22327
|
|
|
|
|
|
|
134, |
22328
|
|
|
|
|
|
|
}, |
22329
|
|
|
|
|
|
|
.len_sym_cost = 109, |
22330
|
|
|
|
|
|
|
}, { |
22331
|
|
|
|
|
|
|
.used_lits_to_lit_cost = { |
22332
|
|
|
|
|
|
|
16, 16, 32, 41, 48, 53, 57, 60, |
22333
|
|
|
|
|
|
|
64, 66, 69, 71, 73, 75, 76, 78, |
22334
|
|
|
|
|
|
|
80, 81, 82, 83, 85, 86, 87, 88, |
22335
|
|
|
|
|
|
|
89, 90, 91, 92, 92, 93, 94, 95, |
22336
|
|
|
|
|
|
|
96, 96, 97, 98, 98, 99, 99, 100, |
22337
|
|
|
|
|
|
|
101, 101, 102, 102, 103, 103, 104, 104, |
22338
|
|
|
|
|
|
|
105, 105, 106, 106, 107, 107, 108, 108, |
22339
|
|
|
|
|
|
|
108, 109, 109, 110, 110, 110, 111, 111, |
22340
|
|
|
|
|
|
|
112, 112, 112, 113, 113, 113, 114, 114, |
22341
|
|
|
|
|
|
|
114, 115, 115, 115, 115, 116, 116, 116, |
22342
|
|
|
|
|
|
|
117, 117, 117, 118, 118, 118, 118, 119, |
22343
|
|
|
|
|
|
|
119, 119, 119, 120, 120, 120, 120, 121, |
22344
|
|
|
|
|
|
|
121, 121, 121, 122, 122, 122, 122, 122, |
22345
|
|
|
|
|
|
|
123, 123, 123, 123, 124, 124, 124, 124, |
22346
|
|
|
|
|
|
|
124, 125, 125, 125, 125, 125, 126, 126, |
22347
|
|
|
|
|
|
|
126, 126, 126, 127, 127, 127, 127, 127, |
22348
|
|
|
|
|
|
|
128, 128, 128, 128, 128, 128, 129, 129, |
22349
|
|
|
|
|
|
|
129, 129, 129, 129, 130, 130, 130, 130, |
22350
|
|
|
|
|
|
|
130, 130, 131, 131, 131, 131, 131, 131, |
22351
|
|
|
|
|
|
|
131, 132, 132, 132, 132, 132, 132, 133, |
22352
|
|
|
|
|
|
|
133, 133, 133, 133, 133, 133, 134, 134, |
22353
|
|
|
|
|
|
|
134, 134, 134, 134, 134, 134, 135, 135, |
22354
|
|
|
|
|
|
|
135, 135, 135, 135, 135, 135, 136, 136, |
22355
|
|
|
|
|
|
|
136, 136, 136, 136, 136, 136, 137, 137, |
22356
|
|
|
|
|
|
|
137, 137, 137, 137, 137, 137, 138, 138, |
22357
|
|
|
|
|
|
|
138, 138, 138, 138, 138, 138, 138, 139, |
22358
|
|
|
|
|
|
|
139, 139, 139, 139, 139, 139, 139, 139, |
22359
|
|
|
|
|
|
|
140, 140, 140, 140, 140, 140, 140, 140, |
22360
|
|
|
|
|
|
|
140, 141, 141, 141, 141, 141, 141, 141, |
22361
|
|
|
|
|
|
|
141, 141, 141, 142, 142, 142, 142, 142, |
22362
|
|
|
|
|
|
|
142, 142, 142, 142, 142, 142, 143, 143, |
22363
|
|
|
|
|
|
|
143, 143, 143, 143, 143, 143, 143, 143, |
22364
|
|
|
|
|
|
|
144, |
22365
|
|
|
|
|
|
|
}, |
22366
|
|
|
|
|
|
|
.len_sym_cost = 93, |
22367
|
|
|
|
|
|
|
}, { |
22368
|
|
|
|
|
|
|
.used_lits_to_lit_cost = { |
22369
|
|
|
|
|
|
|
32, 32, 48, 57, 64, 69, 73, 76, |
22370
|
|
|
|
|
|
|
80, 82, 85, 87, 89, 91, 92, 94, |
22371
|
|
|
|
|
|
|
96, 97, 98, 99, 101, 102, 103, 104, |
22372
|
|
|
|
|
|
|
105, 106, 107, 108, 108, 109, 110, 111, |
22373
|
|
|
|
|
|
|
112, 112, 113, 114, 114, 115, 115, 116, |
22374
|
|
|
|
|
|
|
117, 117, 118, 118, 119, 119, 120, 120, |
22375
|
|
|
|
|
|
|
121, 121, 122, 122, 123, 123, 124, 124, |
22376
|
|
|
|
|
|
|
124, 125, 125, 126, 126, 126, 127, 127, |
22377
|
|
|
|
|
|
|
128, 128, 128, 129, 129, 129, 130, 130, |
22378
|
|
|
|
|
|
|
130, 131, 131, 131, 131, 132, 132, 132, |
22379
|
|
|
|
|
|
|
133, 133, 133, 134, 134, 134, 134, 135, |
22380
|
|
|
|
|
|
|
135, 135, 135, 136, 136, 136, 136, 137, |
22381
|
|
|
|
|
|
|
137, 137, 137, 138, 138, 138, 138, 138, |
22382
|
|
|
|
|
|
|
139, 139, 139, 139, 140, 140, 140, 140, |
22383
|
|
|
|
|
|
|
140, 141, 141, 141, 141, 141, 142, 142, |
22384
|
|
|
|
|
|
|
142, 142, 142, 143, 143, 143, 143, 143, |
22385
|
|
|
|
|
|
|
144, 144, 144, 144, 144, 144, 145, 145, |
22386
|
|
|
|
|
|
|
145, 145, 145, 145, 146, 146, 146, 146, |
22387
|
|
|
|
|
|
|
146, 146, 147, 147, 147, 147, 147, 147, |
22388
|
|
|
|
|
|
|
147, 148, 148, 148, 148, 148, 148, 149, |
22389
|
|
|
|
|
|
|
149, 149, 149, 149, 149, 149, 150, 150, |
22390
|
|
|
|
|
|
|
150, 150, 150, 150, 150, 150, 151, 151, |
22391
|
|
|
|
|
|
|
151, 151, 151, 151, 151, 151, 152, 152, |
22392
|
|
|
|
|
|
|
152, 152, 152, 152, 152, 152, 153, 153, |
22393
|
|
|
|
|
|
|
153, 153, 153, 153, 153, 153, 154, 154, |
22394
|
|
|
|
|
|
|
154, 154, 154, 154, 154, 154, 154, 155, |
22395
|
|
|
|
|
|
|
155, 155, 155, 155, 155, 155, 155, 155, |
22396
|
|
|
|
|
|
|
156, 156, 156, 156, 156, 156, 156, 156, |
22397
|
|
|
|
|
|
|
156, 157, 157, 157, 157, 157, 157, 157, |
22398
|
|
|
|
|
|
|
157, 157, 157, 158, 158, 158, 158, 158, |
22399
|
|
|
|
|
|
|
158, 158, 158, 158, 158, 158, 159, 159, |
22400
|
|
|
|
|
|
|
159, 159, 159, 159, 159, 159, 159, 159, |
22401
|
|
|
|
|
|
|
160, |
22402
|
|
|
|
|
|
|
}, |
22403
|
|
|
|
|
|
|
.len_sym_cost = 84, |
22404
|
|
|
|
|
|
|
}, |
22405
|
|
|
|
|
|
|
}; |
22406
|
|
|
|
|
|
|
|
22407
|
|
|
|
|
|
|
|
22408
|
|
|
|
|
|
|
static void |
22409
|
9
|
|
|
|
|
|
deflate_choose_default_litlen_costs(struct libdeflate_compressor *c, |
22410
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
22411
|
|
|
|
|
|
|
u32 *lit_cost, u32 *len_sym_cost) |
22412
|
|
|
|
|
|
|
{ |
22413
|
9
|
|
|
|
|
|
unsigned num_used_literals = 0; |
22414
|
9
|
|
|
|
|
|
u32 literal_freq = block_length; |
22415
|
9
|
|
|
|
|
|
u32 match_freq = 0; |
22416
|
|
|
|
|
|
|
u32 cutoff; |
22417
|
|
|
|
|
|
|
u32 i; |
22418
|
|
|
|
|
|
|
|
22419
|
|
|
|
|
|
|
|
22420
|
9
|
|
|
|
|
|
memset(c->freqs.litlen, 0, |
22421
|
|
|
|
|
|
|
DEFLATE_NUM_LITERALS * sizeof(c->freqs.litlen[0])); |
22422
|
9
|
|
|
|
|
|
cutoff = literal_freq >> 11; |
22423
|
15309
|
100
|
|
|
|
|
for (i = 0; i < block_length; i++) |
22424
|
15300
|
|
|
|
|
|
c->freqs.litlen[block_begin[i]]++; |
22425
|
2313
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) { |
22426
|
2304
|
100
|
|
|
|
|
if (c->freqs.litlen[i] > cutoff) |
22427
|
108
|
|
|
|
|
|
num_used_literals++; |
22428
|
|
|
|
|
|
|
} |
22429
|
9
|
50
|
|
|
|
|
if (num_used_literals == 0) |
22430
|
0
|
|
|
|
|
|
num_used_literals = 1; |
22431
|
|
|
|
|
|
|
|
22432
|
|
|
|
|
|
|
|
22433
|
9
|
|
|
|
|
|
match_freq = 0; |
22434
|
9
|
|
|
|
|
|
i = choose_min_match_len(num_used_literals, c->max_search_depth); |
22435
|
2286
|
100
|
|
|
|
|
for (; i < ARRAY_LEN(c->p.n.match_len_freqs); i++) { |
22436
|
2277
|
|
|
|
|
|
match_freq += c->p.n.match_len_freqs[i]; |
22437
|
2277
|
|
|
|
|
|
literal_freq -= i * c->p.n.match_len_freqs[i]; |
22438
|
|
|
|
|
|
|
} |
22439
|
9
|
50
|
|
|
|
|
if ((s32)literal_freq < 0) |
22440
|
0
|
|
|
|
|
|
literal_freq = 0; |
22441
|
|
|
|
|
|
|
|
22442
|
9
|
50
|
|
|
|
|
if (match_freq > literal_freq) |
22443
|
0
|
|
|
|
|
|
i = 2; |
22444
|
9
|
50
|
|
|
|
|
else if (match_freq * 4 > literal_freq) |
22445
|
9
|
|
|
|
|
|
i = 1; |
22446
|
|
|
|
|
|
|
else |
22447
|
0
|
|
|
|
|
|
i = 0; |
22448
|
|
|
|
|
|
|
|
22449
|
|
|
|
|
|
|
STATIC_ASSERT(BIT_COST == 16); |
22450
|
9
|
|
|
|
|
|
*lit_cost = default_litlen_costs[i].used_lits_to_lit_cost[ |
22451
|
|
|
|
|
|
|
num_used_literals]; |
22452
|
9
|
|
|
|
|
|
*len_sym_cost = default_litlen_costs[i].len_sym_cost; |
22453
|
9
|
|
|
|
|
|
} |
22454
|
|
|
|
|
|
|
|
22455
|
|
|
|
|
|
|
static forceinline u32 |
22456
|
|
|
|
|
|
|
deflate_default_length_cost(unsigned len, u32 len_sym_cost) |
22457
|
|
|
|
|
|
|
{ |
22458
|
2304
|
|
|
|
|
|
unsigned slot = deflate_length_slot[len]; |
22459
|
2304
|
|
|
|
|
|
u32 num_extra_bits = deflate_extra_length_bits[slot]; |
22460
|
|
|
|
|
|
|
|
22461
|
2304
|
|
|
|
|
|
return len_sym_cost + (num_extra_bits * BIT_COST); |
22462
|
|
|
|
|
|
|
} |
22463
|
|
|
|
|
|
|
|
22464
|
|
|
|
|
|
|
static forceinline u32 |
22465
|
|
|
|
|
|
|
deflate_default_offset_slot_cost(unsigned slot) |
22466
|
|
|
|
|
|
|
{ |
22467
|
270
|
|
|
|
|
|
u32 num_extra_bits = deflate_extra_offset_bits[slot]; |
22468
|
|
|
|
|
|
|
|
22469
|
270
|
|
|
|
|
|
u32 offset_sym_cost = 4*BIT_COST + (907*BIT_COST)/1000; |
22470
|
|
|
|
|
|
|
|
22471
|
270
|
|
|
|
|
|
return offset_sym_cost + (num_extra_bits * BIT_COST); |
22472
|
|
|
|
|
|
|
} |
22473
|
|
|
|
|
|
|
|
22474
|
|
|
|
|
|
|
|
22475
|
|
|
|
|
|
|
static void |
22476
|
9
|
|
|
|
|
|
deflate_set_default_costs(struct libdeflate_compressor *c, |
22477
|
|
|
|
|
|
|
u32 lit_cost, u32 len_sym_cost) |
22478
|
|
|
|
|
|
|
{ |
22479
|
|
|
|
|
|
|
unsigned i; |
22480
|
|
|
|
|
|
|
|
22481
|
|
|
|
|
|
|
|
22482
|
2313
|
100
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) |
22483
|
2304
|
|
|
|
|
|
c->p.n.costs.literal[i] = lit_cost; |
22484
|
|
|
|
|
|
|
|
22485
|
|
|
|
|
|
|
|
22486
|
2313
|
100
|
|
|
|
|
for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++) |
22487
|
2304
|
|
|
|
|
|
c->p.n.costs.length[i] = |
22488
|
2304
|
|
|
|
|
|
deflate_default_length_cost(i, len_sym_cost); |
22489
|
|
|
|
|
|
|
|
22490
|
|
|
|
|
|
|
|
22491
|
279
|
100
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++) |
22492
|
270
|
|
|
|
|
|
c->p.n.costs.offset_slot[i] = |
22493
|
270
|
|
|
|
|
|
deflate_default_offset_slot_cost(i); |
22494
|
9
|
|
|
|
|
|
} |
22495
|
|
|
|
|
|
|
|
22496
|
|
|
|
|
|
|
static forceinline void |
22497
|
|
|
|
|
|
|
deflate_adjust_cost(u32 *cost_p, u32 default_cost, int change_amount) |
22498
|
|
|
|
|
|
|
{ |
22499
|
0
|
0
|
|
|
|
|
if (change_amount == 0) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22500
|
|
|
|
|
|
|
|
22501
|
0
|
|
|
|
|
|
*cost_p = (default_cost + 3 * *cost_p) / 4; |
22502
|
0
|
0
|
|
|
|
|
else if (change_amount == 1) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22503
|
0
|
|
|
|
|
|
*cost_p = (default_cost + *cost_p) / 2; |
22504
|
0
|
0
|
|
|
|
|
else if (change_amount == 2) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22505
|
0
|
|
|
|
|
|
*cost_p = (5 * default_cost + 3 * *cost_p) / 8; |
22506
|
|
|
|
|
|
|
else |
22507
|
|
|
|
|
|
|
|
22508
|
0
|
|
|
|
|
|
*cost_p = (3 * default_cost + *cost_p) / 4; |
22509
|
|
|
|
|
|
|
} |
22510
|
|
|
|
|
|
|
|
22511
|
|
|
|
|
|
|
static forceinline void |
22512
|
|
|
|
|
|
|
deflate_adjust_costs_impl(struct libdeflate_compressor *c, |
22513
|
|
|
|
|
|
|
u32 lit_cost, u32 len_sym_cost, int change_amount) |
22514
|
|
|
|
|
|
|
{ |
22515
|
|
|
|
|
|
|
unsigned i; |
22516
|
|
|
|
|
|
|
|
22517
|
|
|
|
|
|
|
|
22518
|
0
|
0
|
|
|
|
|
for (i = 0; i < DEFLATE_NUM_LITERALS; i++) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22519
|
0
|
|
|
|
|
|
deflate_adjust_cost(&c->p.n.costs.literal[i], lit_cost, |
22520
|
|
|
|
|
|
|
change_amount); |
22521
|
|
|
|
|
|
|
|
22522
|
|
|
|
|
|
|
|
22523
|
0
|
0
|
|
|
|
|
for (i = DEFLATE_MIN_MATCH_LEN; i <= DEFLATE_MAX_MATCH_LEN; i++) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22524
|
0
|
|
|
|
|
|
deflate_adjust_cost(&c->p.n.costs.length[i], |
22525
|
|
|
|
|
|
|
deflate_default_length_cost(i, |
22526
|
|
|
|
|
|
|
len_sym_cost), |
22527
|
|
|
|
|
|
|
change_amount); |
22528
|
|
|
|
|
|
|
|
22529
|
|
|
|
|
|
|
|
22530
|
0
|
0
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(deflate_offset_slot_base); i++) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
22531
|
0
|
|
|
|
|
|
deflate_adjust_cost(&c->p.n.costs.offset_slot[i], |
22532
|
|
|
|
|
|
|
deflate_default_offset_slot_cost(i), |
22533
|
|
|
|
|
|
|
change_amount); |
22534
|
|
|
|
|
|
|
} |
22535
|
|
|
|
|
|
|
|
22536
|
|
|
|
|
|
|
|
22537
|
|
|
|
|
|
|
static void |
22538
|
0
|
|
|
|
|
|
deflate_adjust_costs(struct libdeflate_compressor *c, |
22539
|
|
|
|
|
|
|
u32 lit_cost, u32 len_sym_cost) |
22540
|
|
|
|
|
|
|
{ |
22541
|
0
|
|
|
|
|
|
u64 total_delta = 0; |
22542
|
|
|
|
|
|
|
u64 cutoff; |
22543
|
|
|
|
|
|
|
int i; |
22544
|
|
|
|
|
|
|
|
22545
|
|
|
|
|
|
|
|
22546
|
0
|
0
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) { |
22547
|
0
|
|
|
|
|
|
u64 prev = (u64)c->p.n.prev_observations[i] * |
22548
|
0
|
|
|
|
|
|
c->split_stats.num_observations; |
22549
|
0
|
|
|
|
|
|
u64 cur = (u64)c->split_stats.observations[i] * |
22550
|
0
|
|
|
|
|
|
c->p.n.prev_num_observations; |
22551
|
|
|
|
|
|
|
|
22552
|
0
|
0
|
|
|
|
|
total_delta += prev > cur ? prev - cur : cur - prev; |
22553
|
|
|
|
|
|
|
} |
22554
|
0
|
|
|
|
|
|
cutoff = ((u64)c->p.n.prev_num_observations * |
22555
|
0
|
|
|
|
|
|
c->split_stats.num_observations * 200) / 512; |
22556
|
|
|
|
|
|
|
|
22557
|
0
|
0
|
|
|
|
|
if (total_delta > 3 * cutoff) |
22558
|
|
|
|
|
|
|
|
22559
|
0
|
|
|
|
|
|
deflate_set_default_costs(c, lit_cost, len_sym_cost); |
22560
|
0
|
0
|
|
|
|
|
else if (4 * total_delta > 9 * cutoff) |
22561
|
|
|
|
|
|
|
deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 3); |
22562
|
0
|
0
|
|
|
|
|
else if (2 * total_delta > 3 * cutoff) |
22563
|
|
|
|
|
|
|
deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 2); |
22564
|
0
|
0
|
|
|
|
|
else if (2 * total_delta > cutoff) |
22565
|
|
|
|
|
|
|
deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 1); |
22566
|
|
|
|
|
|
|
else |
22567
|
|
|
|
|
|
|
deflate_adjust_costs_impl(c, lit_cost, len_sym_cost, 0); |
22568
|
0
|
|
|
|
|
|
} |
22569
|
|
|
|
|
|
|
|
22570
|
|
|
|
|
|
|
static void |
22571
|
9
|
|
|
|
|
|
deflate_set_initial_costs(struct libdeflate_compressor *c, |
22572
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
22573
|
|
|
|
|
|
|
bool is_first_block) |
22574
|
|
|
|
|
|
|
{ |
22575
|
|
|
|
|
|
|
u32 lit_cost, len_sym_cost; |
22576
|
|
|
|
|
|
|
|
22577
|
9
|
|
|
|
|
|
deflate_choose_default_litlen_costs(c, block_begin, block_length, |
22578
|
|
|
|
|
|
|
&lit_cost, &len_sym_cost); |
22579
|
9
|
50
|
|
|
|
|
if (is_first_block) |
22580
|
9
|
|
|
|
|
|
deflate_set_default_costs(c, lit_cost, len_sym_cost); |
22581
|
|
|
|
|
|
|
else |
22582
|
0
|
|
|
|
|
|
deflate_adjust_costs(c, lit_cost, len_sym_cost); |
22583
|
9
|
|
|
|
|
|
} |
22584
|
|
|
|
|
|
|
|
22585
|
|
|
|
|
|
|
|
22586
|
|
|
|
|
|
|
static void |
22587
|
18
|
|
|
|
|
|
deflate_find_min_cost_path(struct libdeflate_compressor *c, |
22588
|
|
|
|
|
|
|
const u32 block_length, |
22589
|
|
|
|
|
|
|
const struct lz_match *cache_ptr) |
22590
|
|
|
|
|
|
|
{ |
22591
|
18
|
|
|
|
|
|
struct deflate_optimum_node *end_node = |
22592
|
|
|
|
|
|
|
&c->p.n.optimum_nodes[block_length]; |
22593
|
18
|
|
|
|
|
|
struct deflate_optimum_node *cur_node = end_node; |
22594
|
|
|
|
|
|
|
|
22595
|
18
|
|
|
|
|
|
cur_node->cost_to_end = 0; |
22596
|
|
|
|
|
|
|
do { |
22597
|
|
|
|
|
|
|
unsigned num_matches; |
22598
|
|
|
|
|
|
|
unsigned literal; |
22599
|
|
|
|
|
|
|
u32 best_cost_to_end; |
22600
|
|
|
|
|
|
|
|
22601
|
30600
|
|
|
|
|
|
cur_node--; |
22602
|
30600
|
|
|
|
|
|
cache_ptr--; |
22603
|
|
|
|
|
|
|
|
22604
|
30600
|
|
|
|
|
|
num_matches = cache_ptr->length; |
22605
|
30600
|
|
|
|
|
|
literal = cache_ptr->offset; |
22606
|
|
|
|
|
|
|
|
22607
|
|
|
|
|
|
|
|
22608
|
61200
|
|
|
|
|
|
best_cost_to_end = c->p.n.costs.literal[literal] + |
22609
|
30600
|
|
|
|
|
|
(cur_node + 1)->cost_to_end; |
22610
|
30600
|
|
|
|
|
|
cur_node->item = ((u32)literal << OPTIMUM_OFFSET_SHIFT) | 1; |
22611
|
|
|
|
|
|
|
|
22612
|
|
|
|
|
|
|
|
22613
|
30600
|
100
|
|
|
|
|
if (num_matches) { |
22614
|
|
|
|
|
|
|
const struct lz_match *match; |
22615
|
|
|
|
|
|
|
unsigned len; |
22616
|
|
|
|
|
|
|
unsigned offset; |
22617
|
|
|
|
|
|
|
unsigned offset_slot; |
22618
|
|
|
|
|
|
|
u32 offset_cost; |
22619
|
|
|
|
|
|
|
u32 cost_to_end; |
22620
|
|
|
|
|
|
|
|
22621
|
|
|
|
|
|
|
|
22622
|
126
|
|
|
|
|
|
match = cache_ptr - num_matches; |
22623
|
126
|
|
|
|
|
|
len = DEFLATE_MIN_MATCH_LEN; |
22624
|
|
|
|
|
|
|
do { |
22625
|
252
|
|
|
|
|
|
offset = match->offset; |
22626
|
252
|
|
|
|
|
|
offset_slot = c->p.n.offset_slot_full[offset]; |
22627
|
252
|
|
|
|
|
|
offset_cost = |
22628
|
|
|
|
|
|
|
c->p.n.costs.offset_slot[offset_slot]; |
22629
|
|
|
|
|
|
|
do { |
22630
|
60048
|
|
|
|
|
|
cost_to_end = offset_cost + |
22631
|
30024
|
|
|
|
|
|
c->p.n.costs.length[len] + |
22632
|
30024
|
|
|
|
|
|
(cur_node + len)->cost_to_end; |
22633
|
30024
|
100
|
|
|
|
|
if (cost_to_end < best_cost_to_end) { |
22634
|
29745
|
|
|
|
|
|
best_cost_to_end = cost_to_end; |
22635
|
29745
|
|
|
|
|
|
cur_node->item = len | |
22636
|
29745
|
|
|
|
|
|
((u32)offset << |
22637
|
|
|
|
|
|
|
OPTIMUM_OFFSET_SHIFT); |
22638
|
|
|
|
|
|
|
} |
22639
|
30024
|
100
|
|
|
|
|
} while (++len <= match->length); |
22640
|
252
|
100
|
|
|
|
|
} while (++match != cache_ptr); |
22641
|
126
|
|
|
|
|
|
cache_ptr -= num_matches; |
22642
|
|
|
|
|
|
|
} |
22643
|
30600
|
|
|
|
|
|
cur_node->cost_to_end = best_cost_to_end; |
22644
|
30600
|
100
|
|
|
|
|
} while (cur_node != &c->p.n.optimum_nodes[0]); |
22645
|
|
|
|
|
|
|
|
22646
|
18
|
|
|
|
|
|
deflate_reset_symbol_frequencies(c); |
22647
|
18
|
|
|
|
|
|
deflate_tally_item_list(c, block_length); |
22648
|
18
|
|
|
|
|
|
deflate_make_huffman_codes(&c->freqs, &c->codes); |
22649
|
18
|
|
|
|
|
|
} |
22650
|
|
|
|
|
|
|
|
22651
|
|
|
|
|
|
|
|
22652
|
|
|
|
|
|
|
static void |
22653
|
9
|
|
|
|
|
|
deflate_optimize_and_flush_block(struct libdeflate_compressor *c, |
22654
|
|
|
|
|
|
|
struct deflate_output_bitstream *os, |
22655
|
|
|
|
|
|
|
const u8 *block_begin, u32 block_length, |
22656
|
|
|
|
|
|
|
const struct lz_match *cache_ptr, |
22657
|
|
|
|
|
|
|
bool is_first_block, bool is_final_block, |
22658
|
|
|
|
|
|
|
bool *used_only_literals) |
22659
|
|
|
|
|
|
|
{ |
22660
|
9
|
|
|
|
|
|
unsigned num_passes_remaining = c->p.n.max_optim_passes; |
22661
|
9
|
|
|
|
|
|
u32 best_true_cost = UINT32_MAX; |
22662
|
|
|
|
|
|
|
u32 true_cost; |
22663
|
|
|
|
|
|
|
u32 only_lits_cost; |
22664
|
|
|
|
|
|
|
struct deflate_sequence seq_; |
22665
|
9
|
|
|
|
|
|
struct deflate_sequence *seq = NULL; |
22666
|
|
|
|
|
|
|
u32 i; |
22667
|
|
|
|
|
|
|
|
22668
|
|
|
|
|
|
|
|
22669
|
9
|
|
|
|
|
|
deflate_choose_all_literals(c, block_begin, block_length); |
22670
|
9
|
|
|
|
|
|
only_lits_cost = deflate_compute_true_cost(c); |
22671
|
|
|
|
|
|
|
|
22672
|
|
|
|
|
|
|
|
22673
|
2340
|
100
|
|
|
|
|
for (i = block_length; |
22674
|
2331
|
50
|
|
|
|
|
i <= MIN(block_length - 1 + DEFLATE_MAX_MATCH_LEN, |
22675
|
2322
|
|
|
|
|
|
ARRAY_LEN(c->p.n.optimum_nodes) - 1); i++) |
22676
|
2322
|
|
|
|
|
|
c->p.n.optimum_nodes[i].cost_to_end = 0x80000000; |
22677
|
|
|
|
|
|
|
|
22678
|
|
|
|
|
|
|
|
22679
|
9
|
|
|
|
|
|
deflate_set_initial_costs(c, block_begin, block_length, is_first_block); |
22680
|
|
|
|
|
|
|
|
22681
|
|
|
|
|
|
|
do { |
22682
|
|
|
|
|
|
|
|
22683
|
18
|
|
|
|
|
|
deflate_find_min_cost_path(c, block_length, cache_ptr); |
22684
|
|
|
|
|
|
|
|
22685
|
|
|
|
|
|
|
|
22686
|
18
|
|
|
|
|
|
true_cost = deflate_compute_true_cost(c); |
22687
|
|
|
|
|
|
|
|
22688
|
|
|
|
|
|
|
|
22689
|
18
|
100
|
|
|
|
|
if (true_cost + c->p.n.min_improvement_to_continue > |
22690
|
|
|
|
|
|
|
best_true_cost) |
22691
|
9
|
|
|
|
|
|
break; |
22692
|
|
|
|
|
|
|
|
22693
|
9
|
|
|
|
|
|
best_true_cost = true_cost; |
22694
|
9
|
|
|
|
|
|
c->p.n.costs_producing_best_true_cost = c->p.n.costs; |
22695
|
|
|
|
|
|
|
|
22696
|
|
|
|
|
|
|
|
22697
|
9
|
|
|
|
|
|
deflate_set_costs_from_codes(c, &c->codes.lens); |
22698
|
|
|
|
|
|
|
|
22699
|
9
|
50
|
|
|
|
|
} while (--num_passes_remaining); |
22700
|
|
|
|
|
|
|
|
22701
|
9
|
|
|
|
|
|
*used_only_literals = false; |
22702
|
9
|
50
|
|
|
|
|
if (only_lits_cost < best_true_cost) { |
22703
|
|
|
|
|
|
|
|
22704
|
0
|
|
|
|
|
|
deflate_choose_all_literals(c, block_begin, block_length); |
22705
|
0
|
|
|
|
|
|
deflate_set_costs_from_codes(c, &c->codes.lens); |
22706
|
0
|
|
|
|
|
|
seq_.litrunlen_and_length = block_length; |
22707
|
0
|
|
|
|
|
|
seq = &seq_; |
22708
|
0
|
|
|
|
|
|
*used_only_literals = true; |
22709
|
9
|
50
|
|
|
|
|
} else if (true_cost >= |
22710
|
9
|
|
|
|
|
|
best_true_cost + c->p.n.min_bits_to_use_nonfinal_path) { |
22711
|
|
|
|
|
|
|
|
22712
|
0
|
|
|
|
|
|
c->p.n.costs = c->p.n.costs_producing_best_true_cost; |
22713
|
0
|
|
|
|
|
|
deflate_find_min_cost_path(c, block_length, cache_ptr); |
22714
|
0
|
|
|
|
|
|
deflate_set_costs_from_codes(c, &c->codes.lens); |
22715
|
|
|
|
|
|
|
} |
22716
|
9
|
|
|
|
|
|
deflate_flush_block(c, os, block_begin, block_length, seq, |
22717
|
|
|
|
|
|
|
is_final_block); |
22718
|
9
|
|
|
|
|
|
} |
22719
|
|
|
|
|
|
|
|
22720
|
|
|
|
|
|
|
static void |
22721
|
18
|
|
|
|
|
|
deflate_near_optimal_init_stats(struct libdeflate_compressor *c) |
22722
|
|
|
|
|
|
|
{ |
22723
|
18
|
|
|
|
|
|
init_block_split_stats(&c->split_stats); |
22724
|
18
|
|
|
|
|
|
memset(c->p.n.new_match_len_freqs, 0, |
22725
|
|
|
|
|
|
|
sizeof(c->p.n.new_match_len_freqs)); |
22726
|
18
|
|
|
|
|
|
memset(c->p.n.match_len_freqs, 0, sizeof(c->p.n.match_len_freqs)); |
22727
|
18
|
|
|
|
|
|
} |
22728
|
|
|
|
|
|
|
|
22729
|
|
|
|
|
|
|
static void |
22730
|
9
|
|
|
|
|
|
deflate_near_optimal_merge_stats(struct libdeflate_compressor *c) |
22731
|
|
|
|
|
|
|
{ |
22732
|
|
|
|
|
|
|
unsigned i; |
22733
|
|
|
|
|
|
|
|
22734
|
9
|
|
|
|
|
|
merge_new_observations(&c->split_stats); |
22735
|
2340
|
100
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(c->p.n.match_len_freqs); i++) { |
22736
|
2331
|
|
|
|
|
|
c->p.n.match_len_freqs[i] += c->p.n.new_match_len_freqs[i]; |
22737
|
2331
|
|
|
|
|
|
c->p.n.new_match_len_freqs[i] = 0; |
22738
|
|
|
|
|
|
|
} |
22739
|
9
|
|
|
|
|
|
} |
22740
|
|
|
|
|
|
|
|
22741
|
|
|
|
|
|
|
|
22742
|
|
|
|
|
|
|
static void |
22743
|
9
|
|
|
|
|
|
deflate_near_optimal_save_stats(struct libdeflate_compressor *c) |
22744
|
|
|
|
|
|
|
{ |
22745
|
|
|
|
|
|
|
int i; |
22746
|
|
|
|
|
|
|
|
22747
|
99
|
100
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) |
22748
|
90
|
|
|
|
|
|
c->p.n.prev_observations[i] = c->split_stats.observations[i]; |
22749
|
9
|
|
|
|
|
|
c->p.n.prev_num_observations = c->split_stats.num_observations; |
22750
|
9
|
|
|
|
|
|
} |
22751
|
|
|
|
|
|
|
|
22752
|
|
|
|
|
|
|
static void |
22753
|
0
|
|
|
|
|
|
deflate_near_optimal_clear_old_stats(struct libdeflate_compressor *c) |
22754
|
|
|
|
|
|
|
{ |
22755
|
|
|
|
|
|
|
int i; |
22756
|
|
|
|
|
|
|
|
22757
|
0
|
0
|
|
|
|
|
for (i = 0; i < NUM_OBSERVATION_TYPES; i++) |
22758
|
0
|
|
|
|
|
|
c->split_stats.observations[i] = 0; |
22759
|
0
|
|
|
|
|
|
c->split_stats.num_observations = 0; |
22760
|
0
|
|
|
|
|
|
memset(c->p.n.match_len_freqs, 0, sizeof(c->p.n.match_len_freqs)); |
22761
|
0
|
|
|
|
|
|
} |
22762
|
|
|
|
|
|
|
|
22763
|
|
|
|
|
|
|
|
22764
|
|
|
|
|
|
|
static void |
22765
|
9
|
|
|
|
|
|
deflate_compress_near_optimal(struct libdeflate_compressor * restrict c, |
22766
|
|
|
|
|
|
|
const u8 *in, size_t in_nbytes, |
22767
|
|
|
|
|
|
|
struct deflate_output_bitstream *os) |
22768
|
|
|
|
|
|
|
{ |
22769
|
9
|
|
|
|
|
|
const u8 *in_next = in; |
22770
|
9
|
|
|
|
|
|
const u8 *in_block_begin = in_next; |
22771
|
9
|
|
|
|
|
|
const u8 *in_end = in_next + in_nbytes; |
22772
|
9
|
|
|
|
|
|
const u8 *in_cur_base = in_next; |
22773
|
9
|
|
|
|
|
|
const u8 *in_next_slide = |
22774
|
9
|
|
|
|
|
|
in_next + MIN(in_end - in_next, MATCHFINDER_WINDOW_SIZE); |
22775
|
9
|
|
|
|
|
|
unsigned max_len = DEFLATE_MAX_MATCH_LEN; |
22776
|
9
|
|
|
|
|
|
unsigned nice_len = MIN(c->nice_match_length, max_len); |
22777
|
9
|
|
|
|
|
|
struct lz_match *cache_ptr = c->p.n.match_cache; |
22778
|
9
|
|
|
|
|
|
u32 next_hashes[2] = {0, 0}; |
22779
|
9
|
|
|
|
|
|
bool prev_block_used_only_literals = false; |
22780
|
|
|
|
|
|
|
|
22781
|
9
|
|
|
|
|
|
bt_matchfinder_init(&c->p.n.bt_mf); |
22782
|
9
|
|
|
|
|
|
deflate_near_optimal_init_stats(c); |
22783
|
|
|
|
|
|
|
|
22784
|
|
|
|
|
|
|
do { |
22785
|
|
|
|
|
|
|
|
22786
|
9
|
|
|
|
|
|
const u8 * const in_max_block_end = choose_max_block_end( |
22787
|
|
|
|
|
|
|
in_block_begin, in_end, SOFT_MAX_BLOCK_LENGTH); |
22788
|
9
|
|
|
|
|
|
const u8 *prev_end_block_check = NULL; |
22789
|
9
|
|
|
|
|
|
bool change_detected = false; |
22790
|
9
|
|
|
|
|
|
const u8 *next_observation = in_next; |
22791
|
|
|
|
|
|
|
unsigned min_len; |
22792
|
|
|
|
|
|
|
|
22793
|
|
|
|
|
|
|
|
22794
|
9
|
50
|
|
|
|
|
if (prev_block_used_only_literals) |
22795
|
0
|
|
|
|
|
|
min_len = DEFLATE_MAX_MATCH_LEN + 1; |
22796
|
|
|
|
|
|
|
else |
22797
|
9
|
|
|
|
|
|
min_len = calculate_min_match_len( |
22798
|
|
|
|
|
|
|
in_block_begin, |
22799
|
9
|
|
|
|
|
|
in_max_block_end - in_block_begin, |
22800
|
|
|
|
|
|
|
c->max_search_depth); |
22801
|
|
|
|
|
|
|
|
22802
|
|
|
|
|
|
|
|
22803
|
|
|
|
|
|
|
for (;;) { |
22804
|
|
|
|
|
|
|
struct lz_match *matches; |
22805
|
|
|
|
|
|
|
unsigned best_len; |
22806
|
225
|
|
|
|
|
|
size_t remaining = in_end - in_next; |
22807
|
|
|
|
|
|
|
|
22808
|
|
|
|
|
|
|
|
22809
|
225
|
50
|
|
|
|
|
if (in_next == in_next_slide) { |
22810
|
0
|
|
|
|
|
|
bt_matchfinder_slide_window(&c->p.n.bt_mf); |
22811
|
0
|
|
|
|
|
|
in_cur_base = in_next; |
22812
|
0
|
|
|
|
|
|
in_next_slide = in_next + |
22813
|
|
|
|
|
|
|
MIN(remaining, MATCHFINDER_WINDOW_SIZE); |
22814
|
|
|
|
|
|
|
} |
22815
|
|
|
|
|
|
|
|
22816
|
|
|
|
|
|
|
|
22817
|
225
|
|
|
|
|
|
matches = cache_ptr; |
22818
|
225
|
|
|
|
|
|
best_len = 0; |
22819
|
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, &nice_len, remaining); |
22820
|
225
|
50
|
|
|
|
|
if (likely(max_len >= BT_MATCHFINDER_REQUIRED_NBYTES)) { |
22821
|
450
|
|
|
|
|
|
cache_ptr = bt_matchfinder_get_matches( |
22822
|
|
|
|
|
|
|
&c->p.n.bt_mf, |
22823
|
|
|
|
|
|
|
in_cur_base, |
22824
|
|
|
|
|
|
|
in_next - in_cur_base, |
22825
|
|
|
|
|
|
|
max_len, |
22826
|
|
|
|
|
|
|
nice_len, |
22827
|
|
|
|
|
|
|
c->max_search_depth, |
22828
|
|
|
|
|
|
|
next_hashes, |
22829
|
|
|
|
|
|
|
matches); |
22830
|
225
|
100
|
|
|
|
|
if (cache_ptr > matches) |
22831
|
63
|
|
|
|
|
|
best_len = cache_ptr[-1].length; |
22832
|
|
|
|
|
|
|
} |
22833
|
225
|
50
|
|
|
|
|
if (in_next >= next_observation) { |
22834
|
225
|
100
|
|
|
|
|
if (best_len >= min_len) { |
22835
|
63
|
|
|
|
|
|
observe_match(&c->split_stats, |
22836
|
|
|
|
|
|
|
best_len); |
22837
|
63
|
|
|
|
|
|
next_observation = in_next + best_len; |
22838
|
63
|
|
|
|
|
|
c->p.n.new_match_len_freqs[best_len]++; |
22839
|
|
|
|
|
|
|
} else { |
22840
|
162
|
|
|
|
|
|
observe_literal(&c->split_stats, |
22841
|
162
|
|
|
|
|
|
*in_next); |
22842
|
162
|
|
|
|
|
|
next_observation = in_next + 1; |
22843
|
|
|
|
|
|
|
} |
22844
|
|
|
|
|
|
|
} |
22845
|
|
|
|
|
|
|
|
22846
|
225
|
|
|
|
|
|
cache_ptr->length = cache_ptr - matches; |
22847
|
225
|
|
|
|
|
|
cache_ptr->offset = *in_next; |
22848
|
225
|
|
|
|
|
|
in_next++; |
22849
|
225
|
|
|
|
|
|
cache_ptr++; |
22850
|
|
|
|
|
|
|
|
22851
|
|
|
|
|
|
|
|
22852
|
225
|
100
|
|
|
|
|
if (best_len >= DEFLATE_MIN_MATCH_LEN && |
|
|
50
|
|
|
|
|
|
22853
|
63
|
|
|
|
|
|
best_len >= nice_len) { |
22854
|
63
|
|
|
|
|
|
--best_len; |
22855
|
|
|
|
|
|
|
do { |
22856
|
15075
|
|
|
|
|
|
remaining = in_end - in_next; |
22857
|
15075
|
50
|
|
|
|
|
if (in_next == in_next_slide) { |
22858
|
0
|
|
|
|
|
|
bt_matchfinder_slide_window( |
22859
|
|
|
|
|
|
|
&c->p.n.bt_mf); |
22860
|
0
|
|
|
|
|
|
in_cur_base = in_next; |
22861
|
0
|
|
|
|
|
|
in_next_slide = in_next + |
22862
|
|
|
|
|
|
|
MIN(remaining, |
22863
|
|
|
|
|
|
|
MATCHFINDER_WINDOW_SIZE); |
22864
|
|
|
|
|
|
|
} |
22865
|
|
|
|
|
|
|
adjust_max_and_nice_len(&max_len, |
22866
|
|
|
|
|
|
|
&nice_len, |
22867
|
|
|
|
|
|
|
remaining); |
22868
|
15075
|
100
|
|
|
|
|
if (max_len >= |
22869
|
|
|
|
|
|
|
BT_MATCHFINDER_REQUIRED_NBYTES) { |
22870
|
15039
|
|
|
|
|
|
bt_matchfinder_skip_byte( |
22871
|
|
|
|
|
|
|
&c->p.n.bt_mf, |
22872
|
|
|
|
|
|
|
in_cur_base, |
22873
|
|
|
|
|
|
|
in_next - in_cur_base, |
22874
|
|
|
|
|
|
|
nice_len, |
22875
|
|
|
|
|
|
|
c->max_search_depth, |
22876
|
|
|
|
|
|
|
next_hashes); |
22877
|
|
|
|
|
|
|
} |
22878
|
15075
|
|
|
|
|
|
cache_ptr->length = 0; |
22879
|
15075
|
|
|
|
|
|
cache_ptr->offset = *in_next; |
22880
|
15075
|
|
|
|
|
|
in_next++; |
22881
|
15075
|
|
|
|
|
|
cache_ptr++; |
22882
|
15075
|
100
|
|
|
|
|
} while (--best_len); |
22883
|
|
|
|
|
|
|
} |
22884
|
|
|
|
|
|
|
|
22885
|
225
|
100
|
|
|
|
|
if (in_next >= in_max_block_end) |
22886
|
9
|
|
|
|
|
|
break; |
22887
|
|
|
|
|
|
|
|
22888
|
216
|
50
|
|
|
|
|
if (cache_ptr >= |
22889
|
216
|
|
|
|
|
|
&c->p.n.match_cache[MATCH_CACHE_LENGTH]) |
22890
|
0
|
|
|
|
|
|
break; |
22891
|
|
|
|
|
|
|
|
22892
|
216
|
50
|
|
|
|
|
if (!ready_to_check_block(&c->split_stats, |
22893
|
|
|
|
|
|
|
in_block_begin, in_next, |
22894
|
|
|
|
|
|
|
in_end)) |
22895
|
216
|
|
|
|
|
|
continue; |
22896
|
|
|
|
|
|
|
|
22897
|
0
|
0
|
|
|
|
|
if (do_end_block_check(&c->split_stats, |
22898
|
0
|
|
|
|
|
|
in_next - in_block_begin)) { |
22899
|
0
|
|
|
|
|
|
change_detected = true; |
22900
|
0
|
|
|
|
|
|
break; |
22901
|
|
|
|
|
|
|
} |
22902
|
|
|
|
|
|
|
|
22903
|
0
|
|
|
|
|
|
deflate_near_optimal_merge_stats(c); |
22904
|
0
|
|
|
|
|
|
prev_end_block_check = in_next; |
22905
|
216
|
|
|
|
|
|
} |
22906
|
|
|
|
|
|
|
|
22907
|
9
|
50
|
|
|
|
|
if (change_detected && prev_end_block_check != NULL) { |
|
|
0
|
|
|
|
|
|
22908
|
|
|
|
|
|
|
|
22909
|
0
|
|
|
|
|
|
struct lz_match *orig_cache_ptr = cache_ptr; |
22910
|
0
|
|
|
|
|
|
const u8 *in_block_end = prev_end_block_check; |
22911
|
0
|
|
|
|
|
|
u32 block_length = in_block_end - in_block_begin; |
22912
|
0
|
|
|
|
|
|
bool is_first = (in_block_begin == in); |
22913
|
0
|
|
|
|
|
|
bool is_final = false; |
22914
|
0
|
|
|
|
|
|
u32 num_bytes_to_rewind = in_next - in_block_end; |
22915
|
|
|
|
|
|
|
size_t cache_len_rewound; |
22916
|
|
|
|
|
|
|
|
22917
|
|
|
|
|
|
|
|
22918
|
|
|
|
|
|
|
do { |
22919
|
0
|
|
|
|
|
|
cache_ptr--; |
22920
|
0
|
|
|
|
|
|
cache_ptr -= cache_ptr->length; |
22921
|
0
|
0
|
|
|
|
|
} while (--num_bytes_to_rewind); |
22922
|
0
|
|
|
|
|
|
cache_len_rewound = orig_cache_ptr - cache_ptr; |
22923
|
|
|
|
|
|
|
|
22924
|
0
|
|
|
|
|
|
deflate_optimize_and_flush_block( |
22925
|
|
|
|
|
|
|
c, os, in_block_begin, |
22926
|
|
|
|
|
|
|
block_length, cache_ptr, |
22927
|
|
|
|
|
|
|
is_first, is_final, |
22928
|
|
|
|
|
|
|
&prev_block_used_only_literals); |
22929
|
0
|
|
|
|
|
|
memmove(c->p.n.match_cache, cache_ptr, |
22930
|
|
|
|
|
|
|
cache_len_rewound * sizeof(*cache_ptr)); |
22931
|
0
|
|
|
|
|
|
cache_ptr = &c->p.n.match_cache[cache_len_rewound]; |
22932
|
0
|
|
|
|
|
|
deflate_near_optimal_save_stats(c); |
22933
|
|
|
|
|
|
|
|
22934
|
0
|
|
|
|
|
|
deflate_near_optimal_clear_old_stats(c); |
22935
|
0
|
|
|
|
|
|
in_block_begin = in_block_end; |
22936
|
|
|
|
|
|
|
} else { |
22937
|
|
|
|
|
|
|
|
22938
|
9
|
|
|
|
|
|
u32 block_length = in_next - in_block_begin; |
22939
|
9
|
|
|
|
|
|
bool is_first = (in_block_begin == in); |
22940
|
9
|
|
|
|
|
|
bool is_final = (in_next == in_end); |
22941
|
|
|
|
|
|
|
|
22942
|
9
|
|
|
|
|
|
deflate_near_optimal_merge_stats(c); |
22943
|
9
|
|
|
|
|
|
deflate_optimize_and_flush_block( |
22944
|
|
|
|
|
|
|
c, os, in_block_begin, |
22945
|
|
|
|
|
|
|
block_length, cache_ptr, |
22946
|
|
|
|
|
|
|
is_first, is_final, |
22947
|
|
|
|
|
|
|
&prev_block_used_only_literals); |
22948
|
9
|
|
|
|
|
|
cache_ptr = &c->p.n.match_cache[0]; |
22949
|
9
|
|
|
|
|
|
deflate_near_optimal_save_stats(c); |
22950
|
9
|
|
|
|
|
|
deflate_near_optimal_init_stats(c); |
22951
|
9
|
|
|
|
|
|
in_block_begin = in_next; |
22952
|
|
|
|
|
|
|
} |
22953
|
9
|
50
|
|
|
|
|
} while (in_next != in_end); |
22954
|
9
|
|
|
|
|
|
} |
22955
|
|
|
|
|
|
|
|
22956
|
|
|
|
|
|
|
|
22957
|
|
|
|
|
|
|
static void |
22958
|
9
|
|
|
|
|
|
deflate_init_offset_slot_full(struct libdeflate_compressor *c) |
22959
|
|
|
|
|
|
|
{ |
22960
|
|
|
|
|
|
|
unsigned offset_slot; |
22961
|
|
|
|
|
|
|
unsigned offset; |
22962
|
|
|
|
|
|
|
unsigned offset_end; |
22963
|
|
|
|
|
|
|
|
22964
|
279
|
100
|
|
|
|
|
for (offset_slot = 0; offset_slot < ARRAY_LEN(deflate_offset_slot_base); |
22965
|
270
|
|
|
|
|
|
offset_slot++) { |
22966
|
270
|
|
|
|
|
|
offset = deflate_offset_slot_base[offset_slot]; |
22967
|
270
|
|
|
|
|
|
offset_end = offset + |
22968
|
270
|
|
|
|
|
|
(1 << deflate_extra_offset_bits[offset_slot]); |
22969
|
|
|
|
|
|
|
do { |
22970
|
294912
|
|
|
|
|
|
c->p.n.offset_slot_full[offset] = offset_slot; |
22971
|
294912
|
100
|
|
|
|
|
} while (++offset != offset_end); |
22972
|
|
|
|
|
|
|
} |
22973
|
9
|
|
|
|
|
|
} |
22974
|
|
|
|
|
|
|
|
22975
|
|
|
|
|
|
|
#endif |
22976
|
|
|
|
|
|
|
|
22977
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
22978
|
37
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level) |
22979
|
|
|
|
|
|
|
{ |
22980
|
|
|
|
|
|
|
struct libdeflate_compressor *c; |
22981
|
37
|
|
|
|
|
|
size_t size = offsetof(struct libdeflate_compressor, p); |
22982
|
|
|
|
|
|
|
|
22983
|
|
|
|
|
|
|
check_buildtime_parameters(); |
22984
|
|
|
|
|
|
|
|
22985
|
37
|
50
|
|
|
|
|
if (compression_level < 0 || compression_level > 12) |
|
|
50
|
|
|
|
|
|
22986
|
0
|
|
|
|
|
|
return NULL; |
22987
|
|
|
|
|
|
|
|
22988
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
22989
|
37
|
100
|
|
|
|
|
if (compression_level >= 10) |
22990
|
9
|
|
|
|
|
|
size += sizeof(c->p.n); |
22991
|
|
|
|
|
|
|
else |
22992
|
|
|
|
|
|
|
#endif |
22993
|
|
|
|
|
|
|
{ |
22994
|
28
|
100
|
|
|
|
|
if (compression_level >= 2) |
22995
|
25
|
|
|
|
|
|
size += sizeof(c->p.g); |
22996
|
3
|
50
|
|
|
|
|
else if (compression_level == 1) |
22997
|
3
|
|
|
|
|
|
size += sizeof(c->p.f); |
22998
|
|
|
|
|
|
|
} |
22999
|
|
|
|
|
|
|
|
23000
|
37
|
|
|
|
|
|
c = libdeflate_aligned_malloc(MATCHFINDER_MEM_ALIGNMENT, size); |
23001
|
37
|
50
|
|
|
|
|
if (!c) |
23002
|
0
|
|
|
|
|
|
return NULL; |
23003
|
|
|
|
|
|
|
|
23004
|
37
|
|
|
|
|
|
c->compression_level = compression_level; |
23005
|
|
|
|
|
|
|
|
23006
|
|
|
|
|
|
|
|
23007
|
37
|
|
|
|
|
|
c->max_passthrough_size = 55 - (compression_level * 4); |
23008
|
|
|
|
|
|
|
|
23009
|
37
|
|
|
|
|
|
switch (compression_level) { |
23010
|
|
|
|
|
|
|
case 0: |
23011
|
0
|
|
|
|
|
|
c->max_passthrough_size = SIZE_MAX; |
23012
|
0
|
|
|
|
|
|
c->impl = NULL; |
23013
|
0
|
|
|
|
|
|
break; |
23014
|
|
|
|
|
|
|
case 1: |
23015
|
3
|
|
|
|
|
|
c->impl = deflate_compress_fastest; |
23016
|
|
|
|
|
|
|
|
23017
|
3
|
|
|
|
|
|
c->nice_match_length = 32; |
23018
|
3
|
|
|
|
|
|
break; |
23019
|
|
|
|
|
|
|
case 2: |
23020
|
3
|
|
|
|
|
|
c->impl = deflate_compress_greedy; |
23021
|
3
|
|
|
|
|
|
c->max_search_depth = 6; |
23022
|
3
|
|
|
|
|
|
c->nice_match_length = 10; |
23023
|
3
|
|
|
|
|
|
break; |
23024
|
|
|
|
|
|
|
case 3: |
23025
|
3
|
|
|
|
|
|
c->impl = deflate_compress_greedy; |
23026
|
3
|
|
|
|
|
|
c->max_search_depth = 12; |
23027
|
3
|
|
|
|
|
|
c->nice_match_length = 14; |
23028
|
3
|
|
|
|
|
|
break; |
23029
|
|
|
|
|
|
|
case 4: |
23030
|
3
|
|
|
|
|
|
c->impl = deflate_compress_greedy; |
23031
|
3
|
|
|
|
|
|
c->max_search_depth = 16; |
23032
|
3
|
|
|
|
|
|
c->nice_match_length = 30; |
23033
|
3
|
|
|
|
|
|
break; |
23034
|
|
|
|
|
|
|
case 5: |
23035
|
3
|
|
|
|
|
|
c->impl = deflate_compress_lazy; |
23036
|
3
|
|
|
|
|
|
c->max_search_depth = 16; |
23037
|
3
|
|
|
|
|
|
c->nice_match_length = 30; |
23038
|
3
|
|
|
|
|
|
break; |
23039
|
|
|
|
|
|
|
case 6: |
23040
|
4
|
|
|
|
|
|
c->impl = deflate_compress_lazy; |
23041
|
4
|
|
|
|
|
|
c->max_search_depth = 35; |
23042
|
4
|
|
|
|
|
|
c->nice_match_length = 65; |
23043
|
4
|
|
|
|
|
|
break; |
23044
|
|
|
|
|
|
|
case 7: |
23045
|
3
|
|
|
|
|
|
c->impl = deflate_compress_lazy; |
23046
|
3
|
|
|
|
|
|
c->max_search_depth = 100; |
23047
|
3
|
|
|
|
|
|
c->nice_match_length = 130; |
23048
|
3
|
|
|
|
|
|
break; |
23049
|
|
|
|
|
|
|
case 8: |
23050
|
3
|
|
|
|
|
|
c->impl = deflate_compress_lazy2; |
23051
|
3
|
|
|
|
|
|
c->max_search_depth = 300; |
23052
|
3
|
|
|
|
|
|
c->nice_match_length = DEFLATE_MAX_MATCH_LEN; |
23053
|
3
|
|
|
|
|
|
break; |
23054
|
|
|
|
|
|
|
case 9: |
23055
|
|
|
|
|
|
|
#if !SUPPORT_NEAR_OPTIMAL_PARSING |
23056
|
|
|
|
|
|
|
default: |
23057
|
|
|
|
|
|
|
#endif |
23058
|
3
|
|
|
|
|
|
c->impl = deflate_compress_lazy2; |
23059
|
3
|
|
|
|
|
|
c->max_search_depth = 600; |
23060
|
3
|
|
|
|
|
|
c->nice_match_length = DEFLATE_MAX_MATCH_LEN; |
23061
|
3
|
|
|
|
|
|
break; |
23062
|
|
|
|
|
|
|
#if SUPPORT_NEAR_OPTIMAL_PARSING |
23063
|
|
|
|
|
|
|
case 10: |
23064
|
3
|
|
|
|
|
|
c->impl = deflate_compress_near_optimal; |
23065
|
3
|
|
|
|
|
|
c->max_search_depth = 35; |
23066
|
3
|
|
|
|
|
|
c->nice_match_length = 75; |
23067
|
3
|
|
|
|
|
|
c->p.n.max_optim_passes = 2; |
23068
|
3
|
|
|
|
|
|
c->p.n.min_improvement_to_continue = 32; |
23069
|
3
|
|
|
|
|
|
c->p.n.min_bits_to_use_nonfinal_path = 32; |
23070
|
3
|
|
|
|
|
|
deflate_init_offset_slot_full(c); |
23071
|
3
|
|
|
|
|
|
break; |
23072
|
|
|
|
|
|
|
case 11: |
23073
|
3
|
|
|
|
|
|
c->impl = deflate_compress_near_optimal; |
23074
|
3
|
|
|
|
|
|
c->max_search_depth = 100; |
23075
|
3
|
|
|
|
|
|
c->nice_match_length = 150; |
23076
|
3
|
|
|
|
|
|
c->p.n.max_optim_passes = 4; |
23077
|
3
|
|
|
|
|
|
c->p.n.min_improvement_to_continue = 16; |
23078
|
3
|
|
|
|
|
|
c->p.n.min_bits_to_use_nonfinal_path = 16; |
23079
|
3
|
|
|
|
|
|
deflate_init_offset_slot_full(c); |
23080
|
3
|
|
|
|
|
|
break; |
23081
|
|
|
|
|
|
|
case 12: |
23082
|
|
|
|
|
|
|
default: |
23083
|
3
|
|
|
|
|
|
c->impl = deflate_compress_near_optimal; |
23084
|
3
|
|
|
|
|
|
c->max_search_depth = 300; |
23085
|
3
|
|
|
|
|
|
c->nice_match_length = DEFLATE_MAX_MATCH_LEN; |
23086
|
3
|
|
|
|
|
|
c->p.n.max_optim_passes = 10; |
23087
|
3
|
|
|
|
|
|
c->p.n.min_improvement_to_continue = 1; |
23088
|
3
|
|
|
|
|
|
c->p.n.min_bits_to_use_nonfinal_path = 1; |
23089
|
3
|
|
|
|
|
|
deflate_init_offset_slot_full(c); |
23090
|
3
|
|
|
|
|
|
break; |
23091
|
|
|
|
|
|
|
#endif |
23092
|
|
|
|
|
|
|
} |
23093
|
|
|
|
|
|
|
|
23094
|
37
|
|
|
|
|
|
deflate_init_static_codes(c); |
23095
|
|
|
|
|
|
|
|
23096
|
37
|
|
|
|
|
|
return c; |
23097
|
|
|
|
|
|
|
} |
23098
|
|
|
|
|
|
|
|
23099
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23100
|
37
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *c, |
23101
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23102
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail) |
23103
|
|
|
|
|
|
|
{ |
23104
|
|
|
|
|
|
|
struct deflate_output_bitstream os; |
23105
|
|
|
|
|
|
|
|
23106
|
|
|
|
|
|
|
|
23107
|
37
|
50
|
|
|
|
|
if (unlikely(in_nbytes <= c->max_passthrough_size)) |
23108
|
0
|
|
|
|
|
|
return deflate_compress_none(in, in_nbytes, |
23109
|
|
|
|
|
|
|
out, out_nbytes_avail); |
23110
|
|
|
|
|
|
|
|
23111
|
|
|
|
|
|
|
|
23112
|
37
|
50
|
|
|
|
|
if (unlikely(out_nbytes_avail <= OUTPUT_END_PADDING)) |
23113
|
0
|
|
|
|
|
|
return 0; |
23114
|
37
|
|
|
|
|
|
os.bitbuf = 0; |
23115
|
37
|
|
|
|
|
|
os.bitcount = 0; |
23116
|
37
|
|
|
|
|
|
os.next = out; |
23117
|
37
|
|
|
|
|
|
os.end = os.next + out_nbytes_avail - OUTPUT_END_PADDING; |
23118
|
37
|
|
|
|
|
|
(*c->impl)(c, in, in_nbytes, &os); |
23119
|
|
|
|
|
|
|
|
23120
|
37
|
50
|
|
|
|
|
if (os.next >= os.end) |
23121
|
0
|
|
|
|
|
|
return 0; |
23122
|
37
|
|
|
|
|
|
ASSERT(os.bitcount <= 7); |
23123
|
37
|
50
|
|
|
|
|
if (os.bitcount) |
23124
|
37
|
|
|
|
|
|
*os.next++ = os.bitbuf; |
23125
|
37
|
|
|
|
|
|
return os.next - (u8 *)out; |
23126
|
|
|
|
|
|
|
} |
23127
|
|
|
|
|
|
|
|
23128
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
23129
|
37
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *c) |
23130
|
|
|
|
|
|
|
{ |
23131
|
37
|
|
|
|
|
|
libdeflate_aligned_free(c); |
23132
|
37
|
|
|
|
|
|
} |
23133
|
|
|
|
|
|
|
|
23134
|
|
|
|
|
|
|
unsigned int |
23135
|
25
|
|
|
|
|
|
libdeflate_get_compression_level(struct libdeflate_compressor *c) |
23136
|
|
|
|
|
|
|
{ |
23137
|
25
|
|
|
|
|
|
return c->compression_level; |
23138
|
|
|
|
|
|
|
} |
23139
|
|
|
|
|
|
|
|
23140
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23141
|
37
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *c, |
23142
|
|
|
|
|
|
|
size_t in_nbytes) |
23143
|
|
|
|
|
|
|
{ |
23144
|
37
|
|
|
|
|
|
size_t bound = 0; |
23145
|
|
|
|
|
|
|
size_t max_blocks; |
23146
|
|
|
|
|
|
|
|
23147
|
|
|
|
|
|
|
|
23148
|
|
|
|
|
|
|
|
23149
|
|
|
|
|
|
|
|
23150
|
|
|
|
|
|
|
STATIC_ASSERT(2 * MIN_BLOCK_LENGTH <= UINT16_MAX); |
23151
|
37
|
50
|
|
|
|
|
max_blocks = MAX(DIV_ROUND_UP(in_nbytes, MIN_BLOCK_LENGTH), 1); |
23152
|
|
|
|
|
|
|
|
23153
|
|
|
|
|
|
|
|
23154
|
37
|
|
|
|
|
|
bound += 5 * max_blocks; |
23155
|
|
|
|
|
|
|
|
23156
|
|
|
|
|
|
|
|
23157
|
37
|
|
|
|
|
|
bound += in_nbytes; |
23158
|
|
|
|
|
|
|
|
23159
|
|
|
|
|
|
|
|
23160
|
37
|
|
|
|
|
|
bound += 1 + OUTPUT_END_PADDING; |
23161
|
|
|
|
|
|
|
|
23162
|
37
|
|
|
|
|
|
return bound; |
23163
|
|
|
|
|
|
|
} |
23164
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/deflate_decompress.c */ |
23165
|
|
|
|
|
|
|
|
23166
|
|
|
|
|
|
|
|
23167
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
23168
|
|
|
|
|
|
|
|
23169
|
|
|
|
|
|
|
|
23170
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
23171
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
23172
|
|
|
|
|
|
|
|
23173
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
23174
|
|
|
|
|
|
|
|
23175
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
23176
|
|
|
|
|
|
|
#endif |
23177
|
|
|
|
|
|
|
|
23178
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
23179
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
23180
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
23181
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
23182
|
|
|
|
|
|
|
#else |
23183
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
23184
|
|
|
|
|
|
|
#endif |
23185
|
|
|
|
|
|
|
|
23186
|
|
|
|
|
|
|
|
23187
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
23188
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
23189
|
|
|
|
|
|
|
#else |
23190
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
23191
|
|
|
|
|
|
|
#endif |
23192
|
|
|
|
|
|
|
|
23193
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
23194
|
|
|
|
|
|
|
|
23195
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
23196
|
|
|
|
|
|
|
|
23197
|
|
|
|
|
|
|
|
23198
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
23199
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
23200
|
|
|
|
|
|
|
|
23201
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
23202
|
|
|
|
|
|
|
|
23203
|
|
|
|
|
|
|
|
23204
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
23205
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
23206
|
|
|
|
|
|
|
|
23207
|
|
|
|
|
|
|
#include |
23208
|
|
|
|
|
|
|
#include |
23209
|
|
|
|
|
|
|
|
23210
|
|
|
|
|
|
|
#ifdef __cplusplus |
23211
|
|
|
|
|
|
|
extern "C" { |
23212
|
|
|
|
|
|
|
#endif |
23213
|
|
|
|
|
|
|
|
23214
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
23215
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
23216
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
23217
|
|
|
|
|
|
|
|
23218
|
|
|
|
|
|
|
|
23219
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
23220
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
23221
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
23222
|
|
|
|
|
|
|
# else |
23223
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
23224
|
|
|
|
|
|
|
# endif |
23225
|
|
|
|
|
|
|
#endif |
23226
|
|
|
|
|
|
|
|
23227
|
|
|
|
|
|
|
|
23228
|
|
|
|
|
|
|
|
23229
|
|
|
|
|
|
|
|
23230
|
|
|
|
|
|
|
|
23231
|
|
|
|
|
|
|
struct libdeflate_compressor; |
23232
|
|
|
|
|
|
|
|
23233
|
|
|
|
|
|
|
|
23234
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
23235
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
23236
|
|
|
|
|
|
|
|
23237
|
|
|
|
|
|
|
|
23238
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23239
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
23240
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23241
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
23242
|
|
|
|
|
|
|
|
23243
|
|
|
|
|
|
|
|
23244
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23245
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
23246
|
|
|
|
|
|
|
size_t in_nbytes); |
23247
|
|
|
|
|
|
|
|
23248
|
|
|
|
|
|
|
|
23249
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23250
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
23251
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23252
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
23253
|
|
|
|
|
|
|
|
23254
|
|
|
|
|
|
|
|
23255
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23256
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
23257
|
|
|
|
|
|
|
size_t in_nbytes); |
23258
|
|
|
|
|
|
|
|
23259
|
|
|
|
|
|
|
|
23260
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23261
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
23262
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23263
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
23264
|
|
|
|
|
|
|
|
23265
|
|
|
|
|
|
|
|
23266
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
23267
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
23268
|
|
|
|
|
|
|
size_t in_nbytes); |
23269
|
|
|
|
|
|
|
|
23270
|
|
|
|
|
|
|
|
23271
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
23272
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
23273
|
|
|
|
|
|
|
|
23274
|
|
|
|
|
|
|
|
23275
|
|
|
|
|
|
|
|
23276
|
|
|
|
|
|
|
|
23277
|
|
|
|
|
|
|
|
23278
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
23279
|
|
|
|
|
|
|
|
23280
|
|
|
|
|
|
|
|
23281
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
23282
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
23283
|
|
|
|
|
|
|
|
23284
|
|
|
|
|
|
|
|
23285
|
|
|
|
|
|
|
enum libdeflate_result { |
23286
|
|
|
|
|
|
|
|
23287
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
23288
|
|
|
|
|
|
|
|
23289
|
|
|
|
|
|
|
|
23290
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
23291
|
|
|
|
|
|
|
|
23292
|
|
|
|
|
|
|
|
23293
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
23294
|
|
|
|
|
|
|
|
23295
|
|
|
|
|
|
|
|
23296
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
23297
|
|
|
|
|
|
|
}; |
23298
|
|
|
|
|
|
|
|
23299
|
|
|
|
|
|
|
|
23300
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23301
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
23302
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23303
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23304
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23305
|
|
|
|
|
|
|
|
23306
|
|
|
|
|
|
|
|
23307
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23308
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
23309
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23310
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23311
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
23312
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23313
|
|
|
|
|
|
|
|
23314
|
|
|
|
|
|
|
|
23315
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23316
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
23317
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23318
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23319
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23320
|
|
|
|
|
|
|
|
23321
|
|
|
|
|
|
|
|
23322
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23323
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
23324
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23325
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23326
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
23327
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23328
|
|
|
|
|
|
|
|
23329
|
|
|
|
|
|
|
|
23330
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23331
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
23332
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23333
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23334
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23335
|
|
|
|
|
|
|
|
23336
|
|
|
|
|
|
|
|
23337
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
23338
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
23339
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
23340
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
23341
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
23342
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
23343
|
|
|
|
|
|
|
|
23344
|
|
|
|
|
|
|
|
23345
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
23346
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
23347
|
|
|
|
|
|
|
|
23348
|
|
|
|
|
|
|
|
23349
|
|
|
|
|
|
|
|
23350
|
|
|
|
|
|
|
|
23351
|
|
|
|
|
|
|
|
23352
|
|
|
|
|
|
|
|
23353
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
23354
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
23355
|
|
|
|
|
|
|
|
23356
|
|
|
|
|
|
|
|
23357
|
|
|
|
|
|
|
|
23358
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
23359
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
23360
|
|
|
|
|
|
|
|
23361
|
|
|
|
|
|
|
|
23362
|
|
|
|
|
|
|
|
23363
|
|
|
|
|
|
|
|
23364
|
|
|
|
|
|
|
|
23365
|
|
|
|
|
|
|
|
23366
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
23367
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
23368
|
|
|
|
|
|
|
void (*free_func)(void *)); |
23369
|
|
|
|
|
|
|
|
23370
|
|
|
|
|
|
|
#ifdef __cplusplus |
23371
|
|
|
|
|
|
|
} |
23372
|
|
|
|
|
|
|
#endif |
23373
|
|
|
|
|
|
|
|
23374
|
|
|
|
|
|
|
#endif |
23375
|
|
|
|
|
|
|
|
23376
|
|
|
|
|
|
|
|
23377
|
|
|
|
|
|
|
#include |
23378
|
|
|
|
|
|
|
#include |
23379
|
|
|
|
|
|
|
#include |
23380
|
|
|
|
|
|
|
#ifdef _MSC_VER |
23381
|
|
|
|
|
|
|
# include |
23382
|
|
|
|
|
|
|
# include |
23383
|
|
|
|
|
|
|
|
23384
|
|
|
|
|
|
|
|
23385
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
23386
|
|
|
|
|
|
|
|
23387
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
23388
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
23389
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
23390
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
23391
|
|
|
|
|
|
|
|
23392
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
23393
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
23394
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
23395
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
23396
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
23397
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
23398
|
|
|
|
|
|
|
#endif |
23399
|
|
|
|
|
|
|
#ifndef FREESTANDING |
23400
|
|
|
|
|
|
|
# include |
23401
|
|
|
|
|
|
|
#endif |
23402
|
|
|
|
|
|
|
|
23403
|
|
|
|
|
|
|
|
23404
|
|
|
|
|
|
|
|
23405
|
|
|
|
|
|
|
|
23406
|
|
|
|
|
|
|
|
23407
|
|
|
|
|
|
|
|
23408
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
23409
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
23410
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
23411
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
23412
|
|
|
|
|
|
|
#ifdef _MSC_VER |
23413
|
|
|
|
|
|
|
# if defined(_M_X64) |
23414
|
|
|
|
|
|
|
# define ARCH_X86_64 |
23415
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
23416
|
|
|
|
|
|
|
# define ARCH_X86_32 |
23417
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
23418
|
|
|
|
|
|
|
# define ARCH_ARM64 |
23419
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
23420
|
|
|
|
|
|
|
# define ARCH_ARM32 |
23421
|
|
|
|
|
|
|
# endif |
23422
|
|
|
|
|
|
|
#else |
23423
|
|
|
|
|
|
|
# if defined(__x86_64__) |
23424
|
|
|
|
|
|
|
# define ARCH_X86_64 |
23425
|
|
|
|
|
|
|
# elif defined(__i386__) |
23426
|
|
|
|
|
|
|
# define ARCH_X86_32 |
23427
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
23428
|
|
|
|
|
|
|
# define ARCH_ARM64 |
23429
|
|
|
|
|
|
|
# elif defined(__arm__) |
23430
|
|
|
|
|
|
|
# define ARCH_ARM32 |
23431
|
|
|
|
|
|
|
# endif |
23432
|
|
|
|
|
|
|
#endif |
23433
|
|
|
|
|
|
|
|
23434
|
|
|
|
|
|
|
|
23435
|
|
|
|
|
|
|
|
23436
|
|
|
|
|
|
|
|
23437
|
|
|
|
|
|
|
|
23438
|
|
|
|
|
|
|
|
23439
|
|
|
|
|
|
|
typedef uint8_t u8; |
23440
|
|
|
|
|
|
|
typedef uint16_t u16; |
23441
|
|
|
|
|
|
|
typedef uint32_t u32; |
23442
|
|
|
|
|
|
|
typedef uint64_t u64; |
23443
|
|
|
|
|
|
|
typedef int8_t s8; |
23444
|
|
|
|
|
|
|
typedef int16_t s16; |
23445
|
|
|
|
|
|
|
typedef int32_t s32; |
23446
|
|
|
|
|
|
|
typedef int64_t s64; |
23447
|
|
|
|
|
|
|
|
23448
|
|
|
|
|
|
|
|
23449
|
|
|
|
|
|
|
#ifdef _MSC_VER |
23450
|
|
|
|
|
|
|
# ifdef _WIN64 |
23451
|
|
|
|
|
|
|
typedef long long ssize_t; |
23452
|
|
|
|
|
|
|
# else |
23453
|
|
|
|
|
|
|
typedef long ssize_t; |
23454
|
|
|
|
|
|
|
# endif |
23455
|
|
|
|
|
|
|
#endif |
23456
|
|
|
|
|
|
|
|
23457
|
|
|
|
|
|
|
|
23458
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
23459
|
|
|
|
|
|
|
|
23460
|
|
|
|
|
|
|
|
23461
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
23462
|
|
|
|
|
|
|
|
23463
|
|
|
|
|
|
|
|
23464
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
23465
|
|
|
|
|
|
|
|
23466
|
|
|
|
|
|
|
|
23467
|
|
|
|
|
|
|
|
23468
|
|
|
|
|
|
|
|
23469
|
|
|
|
|
|
|
|
23470
|
|
|
|
|
|
|
|
23471
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
23472
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
23473
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
23474
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
23475
|
|
|
|
|
|
|
#else |
23476
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
23477
|
|
|
|
|
|
|
#endif |
23478
|
|
|
|
|
|
|
#ifdef __clang__ |
23479
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
23480
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
23481
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
23482
|
|
|
|
|
|
|
# else |
23483
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
23484
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
23485
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
23486
|
|
|
|
|
|
|
# endif |
23487
|
|
|
|
|
|
|
#else |
23488
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
23489
|
|
|
|
|
|
|
#endif |
23490
|
|
|
|
|
|
|
|
23491
|
|
|
|
|
|
|
|
23492
|
|
|
|
|
|
|
#ifndef __has_attribute |
23493
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
23494
|
|
|
|
|
|
|
#endif |
23495
|
|
|
|
|
|
|
#ifndef __has_builtin |
23496
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
23497
|
|
|
|
|
|
|
#endif |
23498
|
|
|
|
|
|
|
|
23499
|
|
|
|
|
|
|
|
23500
|
|
|
|
|
|
|
#ifdef _MSC_VER |
23501
|
|
|
|
|
|
|
# define inline __inline |
23502
|
|
|
|
|
|
|
#endif |
23503
|
|
|
|
|
|
|
|
23504
|
|
|
|
|
|
|
|
23505
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
23506
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
23507
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23508
|
|
|
|
|
|
|
# define forceinline __forceinline |
23509
|
|
|
|
|
|
|
#else |
23510
|
|
|
|
|
|
|
# define forceinline inline |
23511
|
|
|
|
|
|
|
#endif |
23512
|
|
|
|
|
|
|
|
23513
|
|
|
|
|
|
|
|
23514
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
23515
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
23516
|
|
|
|
|
|
|
#else |
23517
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
23518
|
|
|
|
|
|
|
#endif |
23519
|
|
|
|
|
|
|
|
23520
|
|
|
|
|
|
|
|
23521
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
23522
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
23523
|
|
|
|
|
|
|
# define restrict __restrict__ |
23524
|
|
|
|
|
|
|
# else |
23525
|
|
|
|
|
|
|
# define restrict |
23526
|
|
|
|
|
|
|
# endif |
23527
|
|
|
|
|
|
|
#endif |
23528
|
|
|
|
|
|
|
|
23529
|
|
|
|
|
|
|
|
23530
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
23531
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
23532
|
|
|
|
|
|
|
#else |
23533
|
|
|
|
|
|
|
# define likely(expr) (expr) |
23534
|
|
|
|
|
|
|
#endif |
23535
|
|
|
|
|
|
|
|
23536
|
|
|
|
|
|
|
|
23537
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
23538
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
23539
|
|
|
|
|
|
|
#else |
23540
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
23541
|
|
|
|
|
|
|
#endif |
23542
|
|
|
|
|
|
|
|
23543
|
|
|
|
|
|
|
|
23544
|
|
|
|
|
|
|
#undef prefetchr |
23545
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
23546
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
23547
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23548
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
23549
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
23550
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
23551
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
23552
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
23553
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
23554
|
|
|
|
|
|
|
# endif |
23555
|
|
|
|
|
|
|
#endif |
23556
|
|
|
|
|
|
|
#ifndef prefetchr |
23557
|
|
|
|
|
|
|
# define prefetchr(addr) |
23558
|
|
|
|
|
|
|
#endif |
23559
|
|
|
|
|
|
|
|
23560
|
|
|
|
|
|
|
|
23561
|
|
|
|
|
|
|
#undef prefetchw |
23562
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
23563
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
23564
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23565
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
23566
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
23567
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
23568
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
23569
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
23570
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
23571
|
|
|
|
|
|
|
# endif |
23572
|
|
|
|
|
|
|
#endif |
23573
|
|
|
|
|
|
|
#ifndef prefetchw |
23574
|
|
|
|
|
|
|
# define prefetchw(addr) |
23575
|
|
|
|
|
|
|
#endif |
23576
|
|
|
|
|
|
|
|
23577
|
|
|
|
|
|
|
|
23578
|
|
|
|
|
|
|
#undef _aligned_attribute |
23579
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
23580
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
23581
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23582
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
23583
|
|
|
|
|
|
|
#endif |
23584
|
|
|
|
|
|
|
|
23585
|
|
|
|
|
|
|
|
23586
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
23587
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
23588
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
23589
|
|
|
|
|
|
|
#else |
23590
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
23591
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
23592
|
|
|
|
|
|
|
#endif |
23593
|
|
|
|
|
|
|
|
23594
|
|
|
|
|
|
|
|
23595
|
|
|
|
|
|
|
|
23596
|
|
|
|
|
|
|
|
23597
|
|
|
|
|
|
|
|
23598
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
23599
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
23600
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
23601
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
23602
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
23603
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
23604
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
23605
|
|
|
|
|
|
|
|
23606
|
|
|
|
|
|
|
|
23607
|
|
|
|
|
|
|
|
23608
|
|
|
|
|
|
|
|
23609
|
|
|
|
|
|
|
|
23610
|
|
|
|
|
|
|
|
23611
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
23612
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
23613
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23614
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
23615
|
|
|
|
|
|
|
#else |
23616
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
23617
|
|
|
|
|
|
|
{ |
23618
|
|
|
|
|
|
|
union { |
23619
|
|
|
|
|
|
|
u32 w; |
23620
|
|
|
|
|
|
|
u8 b; |
23621
|
|
|
|
|
|
|
} u; |
23622
|
|
|
|
|
|
|
|
23623
|
|
|
|
|
|
|
u.w = 1; |
23624
|
|
|
|
|
|
|
return u.b; |
23625
|
|
|
|
|
|
|
} |
23626
|
|
|
|
|
|
|
#endif |
23627
|
|
|
|
|
|
|
|
23628
|
|
|
|
|
|
|
|
23629
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
23630
|
|
|
|
|
|
|
{ |
23631
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
23632
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
23633
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23634
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
23635
|
|
|
|
|
|
|
#else |
23636
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
23637
|
|
|
|
|
|
|
#endif |
23638
|
|
|
|
|
|
|
} |
23639
|
|
|
|
|
|
|
|
23640
|
|
|
|
|
|
|
|
23641
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
23642
|
|
|
|
|
|
|
{ |
23643
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
23644
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
23645
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23646
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
23647
|
|
|
|
|
|
|
#else |
23648
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
23649
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
23650
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
23651
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
23652
|
|
|
|
|
|
|
#endif |
23653
|
|
|
|
|
|
|
} |
23654
|
|
|
|
|
|
|
|
23655
|
|
|
|
|
|
|
|
23656
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
23657
|
|
|
|
|
|
|
{ |
23658
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
23659
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
23660
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23661
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
23662
|
|
|
|
|
|
|
#else |
23663
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
23664
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
23665
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
23666
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
23667
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
23668
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
23669
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
23670
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
23671
|
|
|
|
|
|
|
#endif |
23672
|
|
|
|
|
|
|
} |
23673
|
|
|
|
|
|
|
|
23674
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
23675
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
23676
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
23677
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
23678
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
23679
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
23680
|
|
|
|
|
|
|
|
23681
|
|
|
|
|
|
|
|
23682
|
|
|
|
|
|
|
|
23683
|
|
|
|
|
|
|
|
23684
|
|
|
|
|
|
|
|
23685
|
|
|
|
|
|
|
|
23686
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
23687
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
23688
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
23689
|
|
|
|
|
|
|
defined(__wasm__)) |
23690
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
23691
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23692
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
23693
|
|
|
|
|
|
|
#else |
23694
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
23695
|
|
|
|
|
|
|
#endif |
23696
|
|
|
|
|
|
|
|
23697
|
|
|
|
|
|
|
|
23698
|
|
|
|
|
|
|
|
23699
|
|
|
|
|
|
|
#ifdef FREESTANDING |
23700
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
23701
|
|
|
|
|
|
|
#else |
23702
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
23703
|
|
|
|
|
|
|
#endif |
23704
|
|
|
|
|
|
|
|
23705
|
|
|
|
|
|
|
|
23706
|
|
|
|
|
|
|
|
23707
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
23708
|
|
|
|
|
|
|
static forceinline type \ |
23709
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
23710
|
|
|
|
|
|
|
{ \ |
23711
|
|
|
|
|
|
|
type v; \ |
23712
|
|
|
|
|
|
|
\ |
23713
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
23714
|
|
|
|
|
|
|
return v; \ |
23715
|
|
|
|
|
|
|
} \ |
23716
|
|
|
|
|
|
|
\ |
23717
|
|
|
|
|
|
|
static forceinline void \ |
23718
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
23719
|
|
|
|
|
|
|
{ \ |
23720
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
23721
|
|
|
|
|
|
|
} |
23722
|
|
|
|
|
|
|
|
23723
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
23724
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
23725
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
23726
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
23727
|
|
|
|
|
|
|
|
23728
|
|
|
|
|
|
|
#undef MEMCOPY |
23729
|
|
|
|
|
|
|
|
23730
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
23731
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
23732
|
|
|
|
|
|
|
|
23733
|
|
|
|
|
|
|
|
23734
|
|
|
|
|
|
|
|
23735
|
|
|
|
|
|
|
static forceinline u16 |
23736
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
23737
|
|
|
|
|
|
|
{ |
23738
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
23739
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
23740
|
|
|
|
|
|
|
else |
23741
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
23742
|
|
|
|
|
|
|
} |
23743
|
|
|
|
|
|
|
|
23744
|
|
|
|
|
|
|
static forceinline u16 |
23745
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
23746
|
|
|
|
|
|
|
{ |
23747
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
23748
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
23749
|
|
|
|
|
|
|
else |
23750
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
23751
|
|
|
|
|
|
|
} |
23752
|
|
|
|
|
|
|
|
23753
|
|
|
|
|
|
|
static forceinline u32 |
23754
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
23755
|
|
|
|
|
|
|
{ |
23756
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
23757
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
23758
|
|
|
|
|
|
|
else |
23759
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
23760
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
23761
|
|
|
|
|
|
|
} |
23762
|
|
|
|
|
|
|
|
23763
|
|
|
|
|
|
|
static forceinline u32 |
23764
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
23765
|
|
|
|
|
|
|
{ |
23766
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
23767
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
23768
|
|
|
|
|
|
|
else |
23769
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
23770
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
23771
|
|
|
|
|
|
|
} |
23772
|
|
|
|
|
|
|
|
23773
|
|
|
|
|
|
|
static forceinline u64 |
23774
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
23775
|
|
|
|
|
|
|
{ |
23776
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
23777
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
23778
|
|
|
|
|
|
|
else |
23779
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
23780
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
23781
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
23782
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
23783
|
|
|
|
|
|
|
} |
23784
|
|
|
|
|
|
|
|
23785
|
|
|
|
|
|
|
static forceinline machine_word_t |
23786
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
23787
|
|
|
|
|
|
|
{ |
23788
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
23789
|
|
|
|
|
|
|
if (WORDBITS == 32) |
23790
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
23791
|
|
|
|
|
|
|
else |
23792
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
23793
|
|
|
|
|
|
|
} |
23794
|
|
|
|
|
|
|
|
23795
|
|
|
|
|
|
|
|
23796
|
|
|
|
|
|
|
|
23797
|
|
|
|
|
|
|
static forceinline void |
23798
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
23799
|
|
|
|
|
|
|
{ |
23800
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
23801
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
23802
|
|
|
|
|
|
|
} else { |
23803
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
23804
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
23805
|
|
|
|
|
|
|
} |
23806
|
|
|
|
|
|
|
} |
23807
|
|
|
|
|
|
|
|
23808
|
|
|
|
|
|
|
static forceinline void |
23809
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
23810
|
|
|
|
|
|
|
{ |
23811
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
23812
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
23813
|
|
|
|
|
|
|
} else { |
23814
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
23815
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
23816
|
|
|
|
|
|
|
} |
23817
|
|
|
|
|
|
|
} |
23818
|
|
|
|
|
|
|
|
23819
|
|
|
|
|
|
|
static forceinline void |
23820
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
23821
|
|
|
|
|
|
|
{ |
23822
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
23823
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
23824
|
|
|
|
|
|
|
} else { |
23825
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
23826
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
23827
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
23828
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
23829
|
|
|
|
|
|
|
} |
23830
|
|
|
|
|
|
|
} |
23831
|
|
|
|
|
|
|
|
23832
|
|
|
|
|
|
|
static forceinline void |
23833
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
23834
|
|
|
|
|
|
|
{ |
23835
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
23836
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
23837
|
|
|
|
|
|
|
} else { |
23838
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
23839
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
23840
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
23841
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
23842
|
|
|
|
|
|
|
} |
23843
|
|
|
|
|
|
|
} |
23844
|
|
|
|
|
|
|
|
23845
|
|
|
|
|
|
|
static forceinline void |
23846
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
23847
|
|
|
|
|
|
|
{ |
23848
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
23849
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
23850
|
|
|
|
|
|
|
} else { |
23851
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
23852
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
23853
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
23854
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
23855
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
23856
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
23857
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
23858
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
23859
|
|
|
|
|
|
|
} |
23860
|
|
|
|
|
|
|
} |
23861
|
|
|
|
|
|
|
|
23862
|
|
|
|
|
|
|
static forceinline void |
23863
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
23864
|
|
|
|
|
|
|
{ |
23865
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
23866
|
|
|
|
|
|
|
if (WORDBITS == 32) |
23867
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
23868
|
|
|
|
|
|
|
else |
23869
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
23870
|
|
|
|
|
|
|
} |
23871
|
|
|
|
|
|
|
|
23872
|
|
|
|
|
|
|
|
23873
|
|
|
|
|
|
|
|
23874
|
|
|
|
|
|
|
|
23875
|
|
|
|
|
|
|
|
23876
|
|
|
|
|
|
|
|
23877
|
|
|
|
|
|
|
|
23878
|
|
|
|
|
|
|
static forceinline unsigned |
23879
|
|
|
|
|
|
|
bsr32(u32 v) |
23880
|
|
|
|
|
|
|
{ |
23881
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
23882
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
23883
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23884
|
|
|
|
|
|
|
unsigned long i; |
23885
|
|
|
|
|
|
|
|
23886
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
23887
|
|
|
|
|
|
|
return i; |
23888
|
|
|
|
|
|
|
#else |
23889
|
|
|
|
|
|
|
unsigned i = 0; |
23890
|
|
|
|
|
|
|
|
23891
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
23892
|
|
|
|
|
|
|
i++; |
23893
|
|
|
|
|
|
|
return i; |
23894
|
|
|
|
|
|
|
#endif |
23895
|
|
|
|
|
|
|
} |
23896
|
|
|
|
|
|
|
|
23897
|
|
|
|
|
|
|
static forceinline unsigned |
23898
|
|
|
|
|
|
|
bsr64(u64 v) |
23899
|
|
|
|
|
|
|
{ |
23900
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
23901
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
23902
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
23903
|
|
|
|
|
|
|
unsigned long i; |
23904
|
|
|
|
|
|
|
|
23905
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
23906
|
|
|
|
|
|
|
return i; |
23907
|
|
|
|
|
|
|
#else |
23908
|
|
|
|
|
|
|
unsigned i = 0; |
23909
|
|
|
|
|
|
|
|
23910
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
23911
|
|
|
|
|
|
|
i++; |
23912
|
|
|
|
|
|
|
return i; |
23913
|
|
|
|
|
|
|
#endif |
23914
|
|
|
|
|
|
|
} |
23915
|
|
|
|
|
|
|
|
23916
|
|
|
|
|
|
|
static forceinline unsigned |
23917
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
23918
|
|
|
|
|
|
|
{ |
23919
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
23920
|
|
|
|
|
|
|
if (WORDBITS == 32) |
23921
|
|
|
|
|
|
|
return bsr32(v); |
23922
|
|
|
|
|
|
|
else |
23923
|
|
|
|
|
|
|
return bsr64(v); |
23924
|
|
|
|
|
|
|
} |
23925
|
|
|
|
|
|
|
|
23926
|
|
|
|
|
|
|
|
23927
|
|
|
|
|
|
|
|
23928
|
|
|
|
|
|
|
static forceinline unsigned |
23929
|
|
|
|
|
|
|
bsf32(u32 v) |
23930
|
|
|
|
|
|
|
{ |
23931
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
23932
|
|
|
|
|
|
|
return __builtin_ctz(v); |
23933
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
23934
|
|
|
|
|
|
|
unsigned long i; |
23935
|
|
|
|
|
|
|
|
23936
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
23937
|
|
|
|
|
|
|
return i; |
23938
|
|
|
|
|
|
|
#else |
23939
|
|
|
|
|
|
|
unsigned i = 0; |
23940
|
|
|
|
|
|
|
|
23941
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
23942
|
|
|
|
|
|
|
i++; |
23943
|
|
|
|
|
|
|
return i; |
23944
|
|
|
|
|
|
|
#endif |
23945
|
|
|
|
|
|
|
} |
23946
|
|
|
|
|
|
|
|
23947
|
|
|
|
|
|
|
static forceinline unsigned |
23948
|
|
|
|
|
|
|
bsf64(u64 v) |
23949
|
|
|
|
|
|
|
{ |
23950
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
23951
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
23952
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
23953
|
|
|
|
|
|
|
unsigned long i; |
23954
|
|
|
|
|
|
|
|
23955
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
23956
|
|
|
|
|
|
|
return i; |
23957
|
|
|
|
|
|
|
#else |
23958
|
|
|
|
|
|
|
unsigned i = 0; |
23959
|
|
|
|
|
|
|
|
23960
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
23961
|
|
|
|
|
|
|
i++; |
23962
|
|
|
|
|
|
|
return i; |
23963
|
|
|
|
|
|
|
#endif |
23964
|
|
|
|
|
|
|
} |
23965
|
|
|
|
|
|
|
|
23966
|
|
|
|
|
|
|
static forceinline unsigned |
23967
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
23968
|
|
|
|
|
|
|
{ |
23969
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
23970
|
|
|
|
|
|
|
if (WORDBITS == 32) |
23971
|
|
|
|
|
|
|
return bsf32(v); |
23972
|
|
|
|
|
|
|
else |
23973
|
|
|
|
|
|
|
return bsf64(v); |
23974
|
|
|
|
|
|
|
} |
23975
|
|
|
|
|
|
|
|
23976
|
|
|
|
|
|
|
|
23977
|
|
|
|
|
|
|
#undef rbit32 |
23978
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
23979
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
23980
|
|
|
|
|
|
|
static forceinline u32 |
23981
|
|
|
|
|
|
|
rbit32(u32 v) |
23982
|
|
|
|
|
|
|
{ |
23983
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
23984
|
|
|
|
|
|
|
return v; |
23985
|
|
|
|
|
|
|
} |
23986
|
|
|
|
|
|
|
#define rbit32 rbit32 |
23987
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
23988
|
|
|
|
|
|
|
static forceinline u32 |
23989
|
|
|
|
|
|
|
rbit32(u32 v) |
23990
|
|
|
|
|
|
|
{ |
23991
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
23992
|
|
|
|
|
|
|
return v; |
23993
|
|
|
|
|
|
|
} |
23994
|
|
|
|
|
|
|
#define rbit32 rbit32 |
23995
|
|
|
|
|
|
|
#endif |
23996
|
|
|
|
|
|
|
|
23997
|
|
|
|
|
|
|
#endif |
23998
|
|
|
|
|
|
|
|
23999
|
|
|
|
|
|
|
|
24000
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
24001
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
24002
|
|
|
|
|
|
|
|
24003
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
24004
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
24005
|
|
|
|
|
|
|
|
24006
|
|
|
|
|
|
|
#ifdef FREESTANDING |
24007
|
|
|
|
|
|
|
|
24008
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
24009
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
24010
|
|
|
|
|
|
|
|
24011
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
24012
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
24013
|
|
|
|
|
|
|
|
24014
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
24015
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
24016
|
|
|
|
|
|
|
|
24017
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
24018
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
24019
|
|
|
|
|
|
|
|
24020
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
24021
|
|
|
|
|
|
|
#else |
24022
|
|
|
|
|
|
|
#include |
24023
|
|
|
|
|
|
|
#endif |
24024
|
|
|
|
|
|
|
|
24025
|
|
|
|
|
|
|
|
24026
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
24027
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
24028
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
24029
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
24030
|
|
|
|
|
|
|
#else |
24031
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
24032
|
|
|
|
|
|
|
#endif |
24033
|
|
|
|
|
|
|
|
24034
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
24035
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
24036
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
24037
|
|
|
|
|
|
|
|
24038
|
|
|
|
|
|
|
#endif |
24039
|
|
|
|
|
|
|
|
24040
|
|
|
|
|
|
|
/* #include "deflate_constants.h" */ |
24041
|
|
|
|
|
|
|
|
24042
|
|
|
|
|
|
|
|
24043
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_CONSTANTS_H |
24044
|
|
|
|
|
|
|
#define LIB_DEFLATE_CONSTANTS_H |
24045
|
|
|
|
|
|
|
|
24046
|
|
|
|
|
|
|
|
24047
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_UNCOMPRESSED 0 |
24048
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_STATIC_HUFFMAN 1 |
24049
|
|
|
|
|
|
|
#define DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN 2 |
24050
|
|
|
|
|
|
|
|
24051
|
|
|
|
|
|
|
|
24052
|
|
|
|
|
|
|
#define DEFLATE_MIN_MATCH_LEN 3 |
24053
|
|
|
|
|
|
|
#define DEFLATE_MAX_MATCH_LEN 258 |
24054
|
|
|
|
|
|
|
|
24055
|
|
|
|
|
|
|
|
24056
|
|
|
|
|
|
|
#define DEFLATE_MAX_MATCH_OFFSET 32768 |
24057
|
|
|
|
|
|
|
|
24058
|
|
|
|
|
|
|
|
24059
|
|
|
|
|
|
|
#define DEFLATE_WINDOW_ORDER 15 |
24060
|
|
|
|
|
|
|
|
24061
|
|
|
|
|
|
|
|
24062
|
|
|
|
|
|
|
#define DEFLATE_NUM_PRECODE_SYMS 19 |
24063
|
|
|
|
|
|
|
#define DEFLATE_NUM_LITLEN_SYMS 288 |
24064
|
|
|
|
|
|
|
#define DEFLATE_NUM_OFFSET_SYMS 32 |
24065
|
|
|
|
|
|
|
|
24066
|
|
|
|
|
|
|
|
24067
|
|
|
|
|
|
|
#define DEFLATE_MAX_NUM_SYMS 288 |
24068
|
|
|
|
|
|
|
|
24069
|
|
|
|
|
|
|
|
24070
|
|
|
|
|
|
|
#define DEFLATE_NUM_LITERALS 256 |
24071
|
|
|
|
|
|
|
#define DEFLATE_END_OF_BLOCK 256 |
24072
|
|
|
|
|
|
|
#define DEFLATE_FIRST_LEN_SYM 257 |
24073
|
|
|
|
|
|
|
|
24074
|
|
|
|
|
|
|
|
24075
|
|
|
|
|
|
|
#define DEFLATE_MAX_PRE_CODEWORD_LEN 7 |
24076
|
|
|
|
|
|
|
#define DEFLATE_MAX_LITLEN_CODEWORD_LEN 15 |
24077
|
|
|
|
|
|
|
#define DEFLATE_MAX_OFFSET_CODEWORD_LEN 15 |
24078
|
|
|
|
|
|
|
|
24079
|
|
|
|
|
|
|
|
24080
|
|
|
|
|
|
|
#define DEFLATE_MAX_CODEWORD_LEN 15 |
24081
|
|
|
|
|
|
|
|
24082
|
|
|
|
|
|
|
|
24083
|
|
|
|
|
|
|
#define DEFLATE_MAX_LENS_OVERRUN 137 |
24084
|
|
|
|
|
|
|
|
24085
|
|
|
|
|
|
|
|
24086
|
|
|
|
|
|
|
#define DEFLATE_MAX_EXTRA_LENGTH_BITS 5 |
24087
|
|
|
|
|
|
|
#define DEFLATE_MAX_EXTRA_OFFSET_BITS 13 |
24088
|
|
|
|
|
|
|
|
24089
|
|
|
|
|
|
|
#endif |
24090
|
|
|
|
|
|
|
|
24091
|
|
|
|
|
|
|
|
24092
|
|
|
|
|
|
|
|
24093
|
|
|
|
|
|
|
#if 0 |
24094
|
|
|
|
|
|
|
# pragma message("UNSAFE DECOMPRESSION IS ENABLED. THIS MUST ONLY BE USED IF THE DECOMPRESSOR INPUT WILL ALWAYS BE TRUSTED!") |
24095
|
|
|
|
|
|
|
# define SAFETY_CHECK(expr) (void)(expr) |
24096
|
|
|
|
|
|
|
#else |
24097
|
|
|
|
|
|
|
# define SAFETY_CHECK(expr) if (unlikely(!(expr))) return LIBDEFLATE_BAD_DATA |
24098
|
|
|
|
|
|
|
#endif |
24099
|
|
|
|
|
|
|
|
24100
|
|
|
|
|
|
|
|
24101
|
|
|
|
|
|
|
|
24102
|
|
|
|
|
|
|
|
24103
|
|
|
|
|
|
|
|
24104
|
|
|
|
|
|
|
|
24105
|
|
|
|
|
|
|
/* typedef machine_word_t bitbuf_t; */ |
24106
|
|
|
|
|
|
|
#define DECOMPRESS_BITBUF_NBITS (8 * (int)sizeof(bitbuf_t)) |
24107
|
|
|
|
|
|
|
|
24108
|
|
|
|
|
|
|
|
24109
|
|
|
|
|
|
|
#define BITMASK(n) (((bitbuf_t)1 << (n)) - 1) |
24110
|
|
|
|
|
|
|
|
24111
|
|
|
|
|
|
|
|
24112
|
|
|
|
|
|
|
#define MAX_BITSLEFT \ |
24113
|
|
|
|
|
|
|
(UNALIGNED_ACCESS_IS_FAST ? DECOMPRESS_BITBUF_NBITS - 1 : DECOMPRESS_BITBUF_NBITS) |
24114
|
|
|
|
|
|
|
|
24115
|
|
|
|
|
|
|
|
24116
|
|
|
|
|
|
|
#define CONSUMABLE_NBITS (MAX_BITSLEFT - 7) |
24117
|
|
|
|
|
|
|
|
24118
|
|
|
|
|
|
|
|
24119
|
|
|
|
|
|
|
#define FASTLOOP_PRELOADABLE_NBITS \ |
24120
|
|
|
|
|
|
|
(UNALIGNED_ACCESS_IS_FAST ? DECOMPRESS_BITBUF_NBITS : CONSUMABLE_NBITS) |
24121
|
|
|
|
|
|
|
|
24122
|
|
|
|
|
|
|
|
24123
|
|
|
|
|
|
|
#define PRELOAD_SLACK MAX(0, FASTLOOP_PRELOADABLE_NBITS - MAX_BITSLEFT) |
24124
|
|
|
|
|
|
|
|
24125
|
|
|
|
|
|
|
|
24126
|
|
|
|
|
|
|
#define CAN_CONSUME(n) (CONSUMABLE_NBITS >= (n)) |
24127
|
|
|
|
|
|
|
|
24128
|
|
|
|
|
|
|
|
24129
|
|
|
|
|
|
|
#define CAN_CONSUME_AND_THEN_PRELOAD(consume_nbits, preload_nbits) \ |
24130
|
|
|
|
|
|
|
(CONSUMABLE_NBITS >= (consume_nbits) && \ |
24131
|
|
|
|
|
|
|
FASTLOOP_PRELOADABLE_NBITS >= (consume_nbits) + (preload_nbits)) |
24132
|
|
|
|
|
|
|
|
24133
|
|
|
|
|
|
|
|
24134
|
|
|
|
|
|
|
#define REFILL_BITS_BRANCHLESS() \ |
24135
|
|
|
|
|
|
|
do { \ |
24136
|
|
|
|
|
|
|
bitbuf |= get_unaligned_leword(in_next) << (u8)bitsleft; \ |
24137
|
|
|
|
|
|
|
in_next += sizeof(bitbuf_t) - 1; \ |
24138
|
|
|
|
|
|
|
in_next -= (bitsleft >> 3) & 0x7; \ |
24139
|
|
|
|
|
|
|
bitsleft |= MAX_BITSLEFT & ~7; \ |
24140
|
|
|
|
|
|
|
} while (0) |
24141
|
|
|
|
|
|
|
|
24142
|
|
|
|
|
|
|
|
24143
|
|
|
|
|
|
|
#define REFILL_BITS() \ |
24144
|
|
|
|
|
|
|
do { \ |
24145
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST && \ |
24146
|
|
|
|
|
|
|
likely(in_end - in_next >= sizeof(bitbuf_t))) { \ |
24147
|
|
|
|
|
|
|
REFILL_BITS_BRANCHLESS(); \ |
24148
|
|
|
|
|
|
|
} else { \ |
24149
|
|
|
|
|
|
|
while ((u8)bitsleft < CONSUMABLE_NBITS) { \ |
24150
|
|
|
|
|
|
|
if (likely(in_next != in_end)) { \ |
24151
|
|
|
|
|
|
|
bitbuf |= (bitbuf_t)*in_next++ << \ |
24152
|
|
|
|
|
|
|
(u8)bitsleft; \ |
24153
|
|
|
|
|
|
|
} else { \ |
24154
|
|
|
|
|
|
|
overread_count++; \ |
24155
|
|
|
|
|
|
|
SAFETY_CHECK(overread_count <= \ |
24156
|
|
|
|
|
|
|
sizeof(bitbuf_t)); \ |
24157
|
|
|
|
|
|
|
} \ |
24158
|
|
|
|
|
|
|
bitsleft += 8; \ |
24159
|
|
|
|
|
|
|
} \ |
24160
|
|
|
|
|
|
|
} \ |
24161
|
|
|
|
|
|
|
} while (0) |
24162
|
|
|
|
|
|
|
|
24163
|
|
|
|
|
|
|
|
24164
|
|
|
|
|
|
|
#define REFILL_BITS_IN_FASTLOOP() \ |
24165
|
|
|
|
|
|
|
do { \ |
24166
|
|
|
|
|
|
|
STATIC_ASSERT(UNALIGNED_ACCESS_IS_FAST || \ |
24167
|
|
|
|
|
|
|
FASTLOOP_PRELOADABLE_NBITS == CONSUMABLE_NBITS); \ |
24168
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { \ |
24169
|
|
|
|
|
|
|
REFILL_BITS_BRANCHLESS(); \ |
24170
|
|
|
|
|
|
|
} else { \ |
24171
|
|
|
|
|
|
|
while ((u8)bitsleft < CONSUMABLE_NBITS) { \ |
24172
|
|
|
|
|
|
|
bitbuf |= (bitbuf_t)*in_next++ << (u8)bitsleft; \ |
24173
|
|
|
|
|
|
|
bitsleft += 8; \ |
24174
|
|
|
|
|
|
|
} \ |
24175
|
|
|
|
|
|
|
} \ |
24176
|
|
|
|
|
|
|
} while (0) |
24177
|
|
|
|
|
|
|
|
24178
|
|
|
|
|
|
|
|
24179
|
|
|
|
|
|
|
#define FASTLOOP_MAX_BYTES_WRITTEN \ |
24180
|
|
|
|
|
|
|
(2 + DEFLATE_MAX_MATCH_LEN + (5 * WORDBYTES) - 1) |
24181
|
|
|
|
|
|
|
|
24182
|
|
|
|
|
|
|
|
24183
|
|
|
|
|
|
|
#define FASTLOOP_MAX_BYTES_READ \ |
24184
|
|
|
|
|
|
|
(DIV_ROUND_UP(MAX_BITSLEFT + (2 * LITLEN_TABLEBITS) + \ |
24185
|
|
|
|
|
|
|
LENGTH_MAXBITS + OFFSET_MAXBITS, 8) + \ |
24186
|
|
|
|
|
|
|
sizeof(bitbuf_t)) |
24187
|
|
|
|
|
|
|
|
24188
|
|
|
|
|
|
|
|
24189
|
|
|
|
|
|
|
|
24190
|
|
|
|
|
|
|
|
24191
|
|
|
|
|
|
|
|
24192
|
|
|
|
|
|
|
|
24193
|
|
|
|
|
|
|
|
24194
|
|
|
|
|
|
|
#define PRECODE_TABLEBITS 7 |
24195
|
|
|
|
|
|
|
#define PRECODE_ENOUGH 128 |
24196
|
|
|
|
|
|
|
#define LITLEN_TABLEBITS 11 |
24197
|
|
|
|
|
|
|
#define LITLEN_ENOUGH 2342 |
24198
|
|
|
|
|
|
|
#define OFFSET_TABLEBITS 8 |
24199
|
|
|
|
|
|
|
#define OFFSET_ENOUGH 402 |
24200
|
|
|
|
|
|
|
|
24201
|
|
|
|
|
|
|
|
24202
|
|
|
|
|
|
|
static forceinline u32 |
24203
|
|
|
|
|
|
|
make_decode_table_entry(const u32 decode_results[], u32 sym, u32 len) |
24204
|
|
|
|
|
|
|
{ |
24205
|
12198
|
|
|
|
|
|
return decode_results[sym] + (len << 8) + len; |
24206
|
|
|
|
|
|
|
} |
24207
|
|
|
|
|
|
|
|
24208
|
|
|
|
|
|
|
|
24209
|
|
|
|
|
|
|
static const u32 precode_decode_results[] = { |
24210
|
|
|
|
|
|
|
#define ENTRY(presym) ((u32)presym << 16) |
24211
|
|
|
|
|
|
|
ENTRY(0) , ENTRY(1) , ENTRY(2) , ENTRY(3) , |
24212
|
|
|
|
|
|
|
ENTRY(4) , ENTRY(5) , ENTRY(6) , ENTRY(7) , |
24213
|
|
|
|
|
|
|
ENTRY(8) , ENTRY(9) , ENTRY(10) , ENTRY(11) , |
24214
|
|
|
|
|
|
|
ENTRY(12) , ENTRY(13) , ENTRY(14) , ENTRY(15) , |
24215
|
|
|
|
|
|
|
ENTRY(16) , ENTRY(17) , ENTRY(18) , |
24216
|
|
|
|
|
|
|
#undef ENTRY |
24217
|
|
|
|
|
|
|
}; |
24218
|
|
|
|
|
|
|
|
24219
|
|
|
|
|
|
|
|
24220
|
|
|
|
|
|
|
|
24221
|
|
|
|
|
|
|
|
24222
|
|
|
|
|
|
|
#define HUFFDEC_LITERAL 0x80000000 |
24223
|
|
|
|
|
|
|
|
24224
|
|
|
|
|
|
|
|
24225
|
|
|
|
|
|
|
#define HUFFDEC_EXCEPTIONAL 0x00008000 |
24226
|
|
|
|
|
|
|
|
24227
|
|
|
|
|
|
|
|
24228
|
|
|
|
|
|
|
#define HUFFDEC_SUBTABLE_POINTER 0x00004000 |
24229
|
|
|
|
|
|
|
|
24230
|
|
|
|
|
|
|
|
24231
|
|
|
|
|
|
|
#define HUFFDEC_END_OF_BLOCK 0x00002000 |
24232
|
|
|
|
|
|
|
|
24233
|
|
|
|
|
|
|
|
24234
|
|
|
|
|
|
|
#define LENGTH_MAXBITS (DEFLATE_MAX_LITLEN_CODEWORD_LEN + \ |
24235
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS) |
24236
|
|
|
|
|
|
|
#define LENGTH_MAXFASTBITS (LITLEN_TABLEBITS + \ |
24237
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_LENGTH_BITS) |
24238
|
|
|
|
|
|
|
|
24239
|
|
|
|
|
|
|
|
24240
|
|
|
|
|
|
|
static const u32 litlen_decode_results[] = { |
24241
|
|
|
|
|
|
|
|
24242
|
|
|
|
|
|
|
|
24243
|
|
|
|
|
|
|
#define ENTRY(literal) (HUFFDEC_LITERAL | ((u32)literal << 16)) |
24244
|
|
|
|
|
|
|
ENTRY(0) , ENTRY(1) , ENTRY(2) , ENTRY(3) , |
24245
|
|
|
|
|
|
|
ENTRY(4) , ENTRY(5) , ENTRY(6) , ENTRY(7) , |
24246
|
|
|
|
|
|
|
ENTRY(8) , ENTRY(9) , ENTRY(10) , ENTRY(11) , |
24247
|
|
|
|
|
|
|
ENTRY(12) , ENTRY(13) , ENTRY(14) , ENTRY(15) , |
24248
|
|
|
|
|
|
|
ENTRY(16) , ENTRY(17) , ENTRY(18) , ENTRY(19) , |
24249
|
|
|
|
|
|
|
ENTRY(20) , ENTRY(21) , ENTRY(22) , ENTRY(23) , |
24250
|
|
|
|
|
|
|
ENTRY(24) , ENTRY(25) , ENTRY(26) , ENTRY(27) , |
24251
|
|
|
|
|
|
|
ENTRY(28) , ENTRY(29) , ENTRY(30) , ENTRY(31) , |
24252
|
|
|
|
|
|
|
ENTRY(32) , ENTRY(33) , ENTRY(34) , ENTRY(35) , |
24253
|
|
|
|
|
|
|
ENTRY(36) , ENTRY(37) , ENTRY(38) , ENTRY(39) , |
24254
|
|
|
|
|
|
|
ENTRY(40) , ENTRY(41) , ENTRY(42) , ENTRY(43) , |
24255
|
|
|
|
|
|
|
ENTRY(44) , ENTRY(45) , ENTRY(46) , ENTRY(47) , |
24256
|
|
|
|
|
|
|
ENTRY(48) , ENTRY(49) , ENTRY(50) , ENTRY(51) , |
24257
|
|
|
|
|
|
|
ENTRY(52) , ENTRY(53) , ENTRY(54) , ENTRY(55) , |
24258
|
|
|
|
|
|
|
ENTRY(56) , ENTRY(57) , ENTRY(58) , ENTRY(59) , |
24259
|
|
|
|
|
|
|
ENTRY(60) , ENTRY(61) , ENTRY(62) , ENTRY(63) , |
24260
|
|
|
|
|
|
|
ENTRY(64) , ENTRY(65) , ENTRY(66) , ENTRY(67) , |
24261
|
|
|
|
|
|
|
ENTRY(68) , ENTRY(69) , ENTRY(70) , ENTRY(71) , |
24262
|
|
|
|
|
|
|
ENTRY(72) , ENTRY(73) , ENTRY(74) , ENTRY(75) , |
24263
|
|
|
|
|
|
|
ENTRY(76) , ENTRY(77) , ENTRY(78) , ENTRY(79) , |
24264
|
|
|
|
|
|
|
ENTRY(80) , ENTRY(81) , ENTRY(82) , ENTRY(83) , |
24265
|
|
|
|
|
|
|
ENTRY(84) , ENTRY(85) , ENTRY(86) , ENTRY(87) , |
24266
|
|
|
|
|
|
|
ENTRY(88) , ENTRY(89) , ENTRY(90) , ENTRY(91) , |
24267
|
|
|
|
|
|
|
ENTRY(92) , ENTRY(93) , ENTRY(94) , ENTRY(95) , |
24268
|
|
|
|
|
|
|
ENTRY(96) , ENTRY(97) , ENTRY(98) , ENTRY(99) , |
24269
|
|
|
|
|
|
|
ENTRY(100) , ENTRY(101) , ENTRY(102) , ENTRY(103) , |
24270
|
|
|
|
|
|
|
ENTRY(104) , ENTRY(105) , ENTRY(106) , ENTRY(107) , |
24271
|
|
|
|
|
|
|
ENTRY(108) , ENTRY(109) , ENTRY(110) , ENTRY(111) , |
24272
|
|
|
|
|
|
|
ENTRY(112) , ENTRY(113) , ENTRY(114) , ENTRY(115) , |
24273
|
|
|
|
|
|
|
ENTRY(116) , ENTRY(117) , ENTRY(118) , ENTRY(119) , |
24274
|
|
|
|
|
|
|
ENTRY(120) , ENTRY(121) , ENTRY(122) , ENTRY(123) , |
24275
|
|
|
|
|
|
|
ENTRY(124) , ENTRY(125) , ENTRY(126) , ENTRY(127) , |
24276
|
|
|
|
|
|
|
ENTRY(128) , ENTRY(129) , ENTRY(130) , ENTRY(131) , |
24277
|
|
|
|
|
|
|
ENTRY(132) , ENTRY(133) , ENTRY(134) , ENTRY(135) , |
24278
|
|
|
|
|
|
|
ENTRY(136) , ENTRY(137) , ENTRY(138) , ENTRY(139) , |
24279
|
|
|
|
|
|
|
ENTRY(140) , ENTRY(141) , ENTRY(142) , ENTRY(143) , |
24280
|
|
|
|
|
|
|
ENTRY(144) , ENTRY(145) , ENTRY(146) , ENTRY(147) , |
24281
|
|
|
|
|
|
|
ENTRY(148) , ENTRY(149) , ENTRY(150) , ENTRY(151) , |
24282
|
|
|
|
|
|
|
ENTRY(152) , ENTRY(153) , ENTRY(154) , ENTRY(155) , |
24283
|
|
|
|
|
|
|
ENTRY(156) , ENTRY(157) , ENTRY(158) , ENTRY(159) , |
24284
|
|
|
|
|
|
|
ENTRY(160) , ENTRY(161) , ENTRY(162) , ENTRY(163) , |
24285
|
|
|
|
|
|
|
ENTRY(164) , ENTRY(165) , ENTRY(166) , ENTRY(167) , |
24286
|
|
|
|
|
|
|
ENTRY(168) , ENTRY(169) , ENTRY(170) , ENTRY(171) , |
24287
|
|
|
|
|
|
|
ENTRY(172) , ENTRY(173) , ENTRY(174) , ENTRY(175) , |
24288
|
|
|
|
|
|
|
ENTRY(176) , ENTRY(177) , ENTRY(178) , ENTRY(179) , |
24289
|
|
|
|
|
|
|
ENTRY(180) , ENTRY(181) , ENTRY(182) , ENTRY(183) , |
24290
|
|
|
|
|
|
|
ENTRY(184) , ENTRY(185) , ENTRY(186) , ENTRY(187) , |
24291
|
|
|
|
|
|
|
ENTRY(188) , ENTRY(189) , ENTRY(190) , ENTRY(191) , |
24292
|
|
|
|
|
|
|
ENTRY(192) , ENTRY(193) , ENTRY(194) , ENTRY(195) , |
24293
|
|
|
|
|
|
|
ENTRY(196) , ENTRY(197) , ENTRY(198) , ENTRY(199) , |
24294
|
|
|
|
|
|
|
ENTRY(200) , ENTRY(201) , ENTRY(202) , ENTRY(203) , |
24295
|
|
|
|
|
|
|
ENTRY(204) , ENTRY(205) , ENTRY(206) , ENTRY(207) , |
24296
|
|
|
|
|
|
|
ENTRY(208) , ENTRY(209) , ENTRY(210) , ENTRY(211) , |
24297
|
|
|
|
|
|
|
ENTRY(212) , ENTRY(213) , ENTRY(214) , ENTRY(215) , |
24298
|
|
|
|
|
|
|
ENTRY(216) , ENTRY(217) , ENTRY(218) , ENTRY(219) , |
24299
|
|
|
|
|
|
|
ENTRY(220) , ENTRY(221) , ENTRY(222) , ENTRY(223) , |
24300
|
|
|
|
|
|
|
ENTRY(224) , ENTRY(225) , ENTRY(226) , ENTRY(227) , |
24301
|
|
|
|
|
|
|
ENTRY(228) , ENTRY(229) , ENTRY(230) , ENTRY(231) , |
24302
|
|
|
|
|
|
|
ENTRY(232) , ENTRY(233) , ENTRY(234) , ENTRY(235) , |
24303
|
|
|
|
|
|
|
ENTRY(236) , ENTRY(237) , ENTRY(238) , ENTRY(239) , |
24304
|
|
|
|
|
|
|
ENTRY(240) , ENTRY(241) , ENTRY(242) , ENTRY(243) , |
24305
|
|
|
|
|
|
|
ENTRY(244) , ENTRY(245) , ENTRY(246) , ENTRY(247) , |
24306
|
|
|
|
|
|
|
ENTRY(248) , ENTRY(249) , ENTRY(250) , ENTRY(251) , |
24307
|
|
|
|
|
|
|
ENTRY(252) , ENTRY(253) , ENTRY(254) , ENTRY(255) , |
24308
|
|
|
|
|
|
|
#undef ENTRY |
24309
|
|
|
|
|
|
|
|
24310
|
|
|
|
|
|
|
|
24311
|
|
|
|
|
|
|
HUFFDEC_EXCEPTIONAL | HUFFDEC_END_OF_BLOCK, |
24312
|
|
|
|
|
|
|
|
24313
|
|
|
|
|
|
|
|
24314
|
|
|
|
|
|
|
#define ENTRY(length_base, num_extra_bits) \ |
24315
|
|
|
|
|
|
|
(((u32)(length_base) << 16) | (num_extra_bits)) |
24316
|
|
|
|
|
|
|
ENTRY(3 , 0) , ENTRY(4 , 0) , ENTRY(5 , 0) , ENTRY(6 , 0), |
24317
|
|
|
|
|
|
|
ENTRY(7 , 0) , ENTRY(8 , 0) , ENTRY(9 , 0) , ENTRY(10 , 0), |
24318
|
|
|
|
|
|
|
ENTRY(11 , 1) , ENTRY(13 , 1) , ENTRY(15 , 1) , ENTRY(17 , 1), |
24319
|
|
|
|
|
|
|
ENTRY(19 , 2) , ENTRY(23 , 2) , ENTRY(27 , 2) , ENTRY(31 , 2), |
24320
|
|
|
|
|
|
|
ENTRY(35 , 3) , ENTRY(43 , 3) , ENTRY(51 , 3) , ENTRY(59 , 3), |
24321
|
|
|
|
|
|
|
ENTRY(67 , 4) , ENTRY(83 , 4) , ENTRY(99 , 4) , ENTRY(115, 4), |
24322
|
|
|
|
|
|
|
ENTRY(131, 5) , ENTRY(163, 5) , ENTRY(195, 5) , ENTRY(227, 5), |
24323
|
|
|
|
|
|
|
ENTRY(258, 0) , ENTRY(258, 0) , ENTRY(258, 0) , |
24324
|
|
|
|
|
|
|
#undef ENTRY |
24325
|
|
|
|
|
|
|
}; |
24326
|
|
|
|
|
|
|
|
24327
|
|
|
|
|
|
|
|
24328
|
|
|
|
|
|
|
#define OFFSET_MAXBITS (DEFLATE_MAX_OFFSET_CODEWORD_LEN + \ |
24329
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_OFFSET_BITS) |
24330
|
|
|
|
|
|
|
#define OFFSET_MAXFASTBITS (OFFSET_TABLEBITS + \ |
24331
|
|
|
|
|
|
|
DEFLATE_MAX_EXTRA_OFFSET_BITS) |
24332
|
|
|
|
|
|
|
|
24333
|
|
|
|
|
|
|
|
24334
|
|
|
|
|
|
|
static const u32 offset_decode_results[] = { |
24335
|
|
|
|
|
|
|
#define ENTRY(offset_base, num_extra_bits) \ |
24336
|
|
|
|
|
|
|
(((u32)(offset_base) << 16) | (num_extra_bits)) |
24337
|
|
|
|
|
|
|
ENTRY(1 , 0) , ENTRY(2 , 0) , ENTRY(3 , 0) , ENTRY(4 , 0) , |
24338
|
|
|
|
|
|
|
ENTRY(5 , 1) , ENTRY(7 , 1) , ENTRY(9 , 2) , ENTRY(13 , 2) , |
24339
|
|
|
|
|
|
|
ENTRY(17 , 3) , ENTRY(25 , 3) , ENTRY(33 , 4) , ENTRY(49 , 4) , |
24340
|
|
|
|
|
|
|
ENTRY(65 , 5) , ENTRY(97 , 5) , ENTRY(129 , 6) , ENTRY(193 , 6) , |
24341
|
|
|
|
|
|
|
ENTRY(257 , 7) , ENTRY(385 , 7) , ENTRY(513 , 8) , ENTRY(769 , 8) , |
24342
|
|
|
|
|
|
|
ENTRY(1025 , 9) , ENTRY(1537 , 9) , ENTRY(2049 , 10) , ENTRY(3073 , 10) , |
24343
|
|
|
|
|
|
|
ENTRY(4097 , 11) , ENTRY(6145 , 11) , ENTRY(8193 , 12) , ENTRY(12289 , 12) , |
24344
|
|
|
|
|
|
|
ENTRY(16385 , 13) , ENTRY(24577 , 13) , ENTRY(24577 , 13) , ENTRY(24577 , 13) , |
24345
|
|
|
|
|
|
|
#undef ENTRY |
24346
|
|
|
|
|
|
|
}; |
24347
|
|
|
|
|
|
|
|
24348
|
|
|
|
|
|
|
|
24349
|
|
|
|
|
|
|
struct libdeflate_decompressor { |
24350
|
|
|
|
|
|
|
|
24351
|
|
|
|
|
|
|
|
24352
|
|
|
|
|
|
|
|
24353
|
|
|
|
|
|
|
union { |
24354
|
|
|
|
|
|
|
u8 precode_lens[DEFLATE_NUM_PRECODE_SYMS]; |
24355
|
|
|
|
|
|
|
|
24356
|
|
|
|
|
|
|
struct { |
24357
|
|
|
|
|
|
|
u8 lens[DEFLATE_NUM_LITLEN_SYMS + |
24358
|
|
|
|
|
|
|
DEFLATE_NUM_OFFSET_SYMS + |
24359
|
|
|
|
|
|
|
DEFLATE_MAX_LENS_OVERRUN]; |
24360
|
|
|
|
|
|
|
|
24361
|
|
|
|
|
|
|
u32 precode_decode_table[PRECODE_ENOUGH]; |
24362
|
|
|
|
|
|
|
} l; |
24363
|
|
|
|
|
|
|
|
24364
|
|
|
|
|
|
|
u32 litlen_decode_table[LITLEN_ENOUGH]; |
24365
|
|
|
|
|
|
|
} u; |
24366
|
|
|
|
|
|
|
|
24367
|
|
|
|
|
|
|
u32 offset_decode_table[OFFSET_ENOUGH]; |
24368
|
|
|
|
|
|
|
|
24369
|
|
|
|
|
|
|
|
24370
|
|
|
|
|
|
|
u16 sorted_syms[DEFLATE_MAX_NUM_SYMS]; |
24371
|
|
|
|
|
|
|
|
24372
|
|
|
|
|
|
|
bool static_codes_loaded; |
24373
|
|
|
|
|
|
|
unsigned litlen_tablebits; |
24374
|
|
|
|
|
|
|
}; |
24375
|
|
|
|
|
|
|
|
24376
|
|
|
|
|
|
|
|
24377
|
|
|
|
|
|
|
static bool |
24378
|
87
|
|
|
|
|
|
build_decode_table(u32 decode_table[], |
24379
|
|
|
|
|
|
|
const u8 lens[], |
24380
|
|
|
|
|
|
|
const unsigned num_syms, |
24381
|
|
|
|
|
|
|
const u32 decode_results[], |
24382
|
|
|
|
|
|
|
unsigned table_bits, |
24383
|
|
|
|
|
|
|
unsigned max_codeword_len, |
24384
|
|
|
|
|
|
|
u16 *sorted_syms, |
24385
|
|
|
|
|
|
|
unsigned *table_bits_ret) |
24386
|
|
|
|
|
|
|
{ |
24387
|
|
|
|
|
|
|
unsigned len_counts[DEFLATE_MAX_CODEWORD_LEN + 1]; |
24388
|
|
|
|
|
|
|
unsigned offsets[DEFLATE_MAX_CODEWORD_LEN + 1]; |
24389
|
|
|
|
|
|
|
unsigned sym; |
24390
|
|
|
|
|
|
|
unsigned codeword; |
24391
|
|
|
|
|
|
|
unsigned len; |
24392
|
|
|
|
|
|
|
unsigned count; |
24393
|
|
|
|
|
|
|
u32 codespace_used; |
24394
|
|
|
|
|
|
|
unsigned cur_table_end; |
24395
|
|
|
|
|
|
|
unsigned subtable_prefix; |
24396
|
|
|
|
|
|
|
unsigned subtable_start; |
24397
|
|
|
|
|
|
|
unsigned subtable_bits; |
24398
|
|
|
|
|
|
|
|
24399
|
|
|
|
|
|
|
|
24400
|
1439
|
100
|
|
|
|
|
for (len = 0; len <= max_codeword_len; len++) |
24401
|
1352
|
|
|
|
|
|
len_counts[len] = 0; |
24402
|
13235
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) |
24403
|
13148
|
|
|
|
|
|
len_counts[lens[sym]]++; |
24404
|
|
|
|
|
|
|
|
24405
|
|
|
|
|
|
|
|
24406
|
715
|
50
|
|
|
|
|
while (max_codeword_len > 1 && len_counts[max_codeword_len] == 0) |
|
|
100
|
|
|
|
|
|
24407
|
628
|
|
|
|
|
|
max_codeword_len--; |
24408
|
87
|
100
|
|
|
|
|
if (table_bits_ret != NULL) { |
24409
|
41
|
|
|
|
|
|
table_bits = MIN(table_bits, max_codeword_len); |
24410
|
41
|
|
|
|
|
|
*table_bits_ret = table_bits; |
24411
|
|
|
|
|
|
|
} |
24412
|
|
|
|
|
|
|
|
24413
|
|
|
|
|
|
|
|
24414
|
|
|
|
|
|
|
|
24415
|
|
|
|
|
|
|
|
24416
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(codespace_used) == 4); |
24417
|
|
|
|
|
|
|
STATIC_ASSERT(UINT32_MAX / (1U << (DEFLATE_MAX_CODEWORD_LEN - 1)) >= |
24418
|
|
|
|
|
|
|
DEFLATE_MAX_NUM_SYMS); |
24419
|
|
|
|
|
|
|
|
24420
|
87
|
|
|
|
|
|
offsets[0] = 0; |
24421
|
87
|
|
|
|
|
|
offsets[1] = len_counts[0]; |
24422
|
87
|
|
|
|
|
|
codespace_used = 0; |
24423
|
637
|
100
|
|
|
|
|
for (len = 1; len < max_codeword_len; len++) { |
24424
|
550
|
|
|
|
|
|
offsets[len + 1] = offsets[len] + len_counts[len]; |
24425
|
550
|
|
|
|
|
|
codespace_used = (codespace_used << 1) + len_counts[len]; |
24426
|
|
|
|
|
|
|
} |
24427
|
87
|
|
|
|
|
|
codespace_used = (codespace_used << 1) + len_counts[len]; |
24428
|
|
|
|
|
|
|
|
24429
|
13235
|
100
|
|
|
|
|
for (sym = 0; sym < num_syms; sym++) |
24430
|
13148
|
|
|
|
|
|
sorted_syms[offsets[lens[sym]]++] = sym; |
24431
|
|
|
|
|
|
|
|
24432
|
87
|
|
|
|
|
|
sorted_syms += offsets[0]; |
24433
|
|
|
|
|
|
|
|
24434
|
|
|
|
|
|
|
|
24435
|
|
|
|
|
|
|
|
24436
|
|
|
|
|
|
|
|
24437
|
|
|
|
|
|
|
|
24438
|
|
|
|
|
|
|
|
24439
|
87
|
50
|
|
|
|
|
if (unlikely(codespace_used > (1U << max_codeword_len))) |
24440
|
0
|
|
|
|
|
|
return false; |
24441
|
|
|
|
|
|
|
|
24442
|
|
|
|
|
|
|
|
24443
|
87
|
50
|
|
|
|
|
if (unlikely(codespace_used < (1U << max_codeword_len))) { |
24444
|
|
|
|
|
|
|
u32 entry; |
24445
|
|
|
|
|
|
|
unsigned i; |
24446
|
|
|
|
|
|
|
|
24447
|
0
|
0
|
|
|
|
|
if (codespace_used == 0) { |
24448
|
|
|
|
|
|
|
|
24449
|
|
|
|
|
|
|
|
24450
|
|
|
|
|
|
|
|
24451
|
0
|
|
|
|
|
|
entry = make_decode_table_entry(decode_results, 0, 1); |
24452
|
|
|
|
|
|
|
} else { |
24453
|
|
|
|
|
|
|
|
24454
|
0
|
0
|
|
|
|
|
if (codespace_used != (1U << (max_codeword_len - 1)) || |
|
|
0
|
|
|
|
|
|
24455
|
0
|
|
|
|
|
|
len_counts[1] != 1) |
24456
|
0
|
|
|
|
|
|
return false; |
24457
|
0
|
|
|
|
|
|
entry = make_decode_table_entry(decode_results, |
24458
|
0
|
|
|
|
|
|
*sorted_syms, 1); |
24459
|
|
|
|
|
|
|
} |
24460
|
|
|
|
|
|
|
|
24461
|
0
|
0
|
|
|
|
|
for (i = 0; i < (1U << table_bits); i++) |
24462
|
0
|
|
|
|
|
|
decode_table[i] = entry; |
24463
|
0
|
|
|
|
|
|
return true; |
24464
|
|
|
|
|
|
|
} |
24465
|
|
|
|
|
|
|
|
24466
|
|
|
|
|
|
|
|
24467
|
87
|
|
|
|
|
|
codeword = 0; |
24468
|
87
|
|
|
|
|
|
len = 1; |
24469
|
480
|
100
|
|
|
|
|
while ((count = len_counts[len]) == 0) |
24470
|
393
|
|
|
|
|
|
len++; |
24471
|
87
|
|
|
|
|
|
cur_table_end = 1U << len; |
24472
|
241
|
100
|
|
|
|
|
while (len <= table_bits) { |
24473
|
|
|
|
|
|
|
|
24474
|
|
|
|
|
|
|
do { |
24475
|
|
|
|
|
|
|
unsigned bit; |
24476
|
|
|
|
|
|
|
|
24477
|
|
|
|
|
|
|
|
24478
|
24320
|
|
|
|
|
|
decode_table[codeword] = |
24479
|
24320
|
|
|
|
|
|
make_decode_table_entry(decode_results, |
24480
|
12160
|
|
|
|
|
|
*sorted_syms++, len); |
24481
|
|
|
|
|
|
|
|
24482
|
12160
|
100
|
|
|
|
|
if (codeword == cur_table_end - 1) { |
24483
|
|
|
|
|
|
|
|
24484
|
190
|
100
|
|
|
|
|
for (; len < table_bits; len++) { |
24485
|
111
|
|
|
|
|
|
memcpy(&decode_table[cur_table_end], |
24486
|
|
|
|
|
|
|
decode_table, |
24487
|
|
|
|
|
|
|
cur_table_end * |
24488
|
|
|
|
|
|
|
sizeof(decode_table[0])); |
24489
|
111
|
|
|
|
|
|
cur_table_end <<= 1; |
24490
|
|
|
|
|
|
|
} |
24491
|
79
|
|
|
|
|
|
return true; |
24492
|
|
|
|
|
|
|
} |
24493
|
|
|
|
|
|
|
|
24494
|
24162
|
|
|
|
|
|
bit = 1U << bsr32(codeword ^ (cur_table_end - 1)); |
24495
|
12081
|
|
|
|
|
|
codeword &= bit - 1; |
24496
|
12081
|
|
|
|
|
|
codeword |= bit; |
24497
|
12081
|
100
|
|
|
|
|
} while (--count); |
24498
|
|
|
|
|
|
|
|
24499
|
|
|
|
|
|
|
|
24500
|
|
|
|
|
|
|
do { |
24501
|
157
|
100
|
|
|
|
|
if (++len <= table_bits) { |
24502
|
149
|
|
|
|
|
|
memcpy(&decode_table[cur_table_end], |
24503
|
|
|
|
|
|
|
decode_table, |
24504
|
|
|
|
|
|
|
cur_table_end * sizeof(decode_table[0])); |
24505
|
149
|
|
|
|
|
|
cur_table_end <<= 1; |
24506
|
|
|
|
|
|
|
} |
24507
|
157
|
100
|
|
|
|
|
} while ((count = len_counts[len]) == 0); |
24508
|
|
|
|
|
|
|
} |
24509
|
|
|
|
|
|
|
|
24510
|
|
|
|
|
|
|
|
24511
|
8
|
|
|
|
|
|
cur_table_end = 1U << table_bits; |
24512
|
8
|
|
|
|
|
|
subtable_prefix = -1; |
24513
|
8
|
|
|
|
|
|
subtable_start = 0; |
24514
|
|
|
|
|
|
|
for (;;) { |
24515
|
|
|
|
|
|
|
u32 entry; |
24516
|
|
|
|
|
|
|
unsigned i; |
24517
|
|
|
|
|
|
|
unsigned stride; |
24518
|
|
|
|
|
|
|
unsigned bit; |
24519
|
|
|
|
|
|
|
|
24520
|
|
|
|
|
|
|
|
24521
|
38
|
100
|
|
|
|
|
if ((codeword & ((1U << table_bits) - 1)) != subtable_prefix) { |
24522
|
19
|
|
|
|
|
|
subtable_prefix = (codeword & ((1U << table_bits) - 1)); |
24523
|
19
|
|
|
|
|
|
subtable_start = cur_table_end; |
24524
|
|
|
|
|
|
|
|
24525
|
19
|
|
|
|
|
|
subtable_bits = len - table_bits; |
24526
|
19
|
|
|
|
|
|
codespace_used = count; |
24527
|
19
|
50
|
|
|
|
|
while (codespace_used < (1U << subtable_bits)) { |
24528
|
0
|
|
|
|
|
|
subtable_bits++; |
24529
|
0
|
|
|
|
|
|
codespace_used = (codespace_used << 1) + |
24530
|
0
|
|
|
|
|
|
len_counts[table_bits + subtable_bits]; |
24531
|
|
|
|
|
|
|
} |
24532
|
19
|
|
|
|
|
|
cur_table_end = subtable_start + (1U << subtable_bits); |
24533
|
|
|
|
|
|
|
|
24534
|
|
|
|
|
|
|
|
24535
|
19
|
|
|
|
|
|
decode_table[subtable_prefix] = |
24536
|
19
|
|
|
|
|
|
((u32)subtable_start << 16) | |
24537
|
|
|
|
|
|
|
HUFFDEC_EXCEPTIONAL | |
24538
|
19
|
|
|
|
|
|
HUFFDEC_SUBTABLE_POINTER | |
24539
|
38
|
|
|
|
|
|
(subtable_bits << 8) | table_bits; |
24540
|
|
|
|
|
|
|
} |
24541
|
|
|
|
|
|
|
|
24542
|
|
|
|
|
|
|
|
24543
|
76
|
|
|
|
|
|
entry = make_decode_table_entry(decode_results, *sorted_syms++, |
24544
|
|
|
|
|
|
|
len - table_bits); |
24545
|
38
|
|
|
|
|
|
i = subtable_start + (codeword >> table_bits); |
24546
|
38
|
|
|
|
|
|
stride = 1U << (len - table_bits); |
24547
|
|
|
|
|
|
|
do { |
24548
|
38
|
|
|
|
|
|
decode_table[i] = entry; |
24549
|
38
|
|
|
|
|
|
i += stride; |
24550
|
38
|
50
|
|
|
|
|
} while (i < cur_table_end); |
24551
|
|
|
|
|
|
|
|
24552
|
|
|
|
|
|
|
|
24553
|
38
|
100
|
|
|
|
|
if (codeword == (1U << len) - 1) |
24554
|
8
|
|
|
|
|
|
return true; |
24555
|
60
|
|
|
|
|
|
bit = 1U << bsr32(codeword ^ ((1U << len) - 1)); |
24556
|
30
|
|
|
|
|
|
codeword &= bit - 1; |
24557
|
30
|
|
|
|
|
|
codeword |= bit; |
24558
|
30
|
|
|
|
|
|
count--; |
24559
|
30
|
50
|
|
|
|
|
while (count == 0) |
24560
|
0
|
|
|
|
|
|
count = len_counts[++len]; |
24561
|
117
|
|
|
|
|
|
} |
24562
|
|
|
|
|
|
|
} |
24563
|
|
|
|
|
|
|
|
24564
|
|
|
|
|
|
|
|
24565
|
|
|
|
|
|
|
static bool |
24566
|
5
|
|
|
|
|
|
build_precode_decode_table(struct libdeflate_decompressor *d) |
24567
|
|
|
|
|
|
|
{ |
24568
|
|
|
|
|
|
|
|
24569
|
|
|
|
|
|
|
STATIC_ASSERT(PRECODE_TABLEBITS == 7 && PRECODE_ENOUGH == 128); |
24570
|
|
|
|
|
|
|
|
24571
|
|
|
|
|
|
|
STATIC_ASSERT(ARRAY_LEN(precode_decode_results) == |
24572
|
|
|
|
|
|
|
DEFLATE_NUM_PRECODE_SYMS); |
24573
|
|
|
|
|
|
|
|
24574
|
5
|
|
|
|
|
|
return build_decode_table(d->u.l.precode_decode_table, |
24575
|
5
|
|
|
|
|
|
d->u.precode_lens, |
24576
|
|
|
|
|
|
|
DEFLATE_NUM_PRECODE_SYMS, |
24577
|
|
|
|
|
|
|
precode_decode_results, |
24578
|
|
|
|
|
|
|
PRECODE_TABLEBITS, |
24579
|
|
|
|
|
|
|
DEFLATE_MAX_PRE_CODEWORD_LEN, |
24580
|
5
|
|
|
|
|
|
d->sorted_syms, |
24581
|
|
|
|
|
|
|
NULL); |
24582
|
|
|
|
|
|
|
} |
24583
|
|
|
|
|
|
|
|
24584
|
|
|
|
|
|
|
|
24585
|
|
|
|
|
|
|
static bool |
24586
|
41
|
|
|
|
|
|
build_litlen_decode_table(struct libdeflate_decompressor *d, |
24587
|
|
|
|
|
|
|
unsigned num_litlen_syms, unsigned num_offset_syms) |
24588
|
|
|
|
|
|
|
{ |
24589
|
|
|
|
|
|
|
|
24590
|
|
|
|
|
|
|
STATIC_ASSERT(LITLEN_TABLEBITS == 11 && LITLEN_ENOUGH == 2342); |
24591
|
|
|
|
|
|
|
|
24592
|
|
|
|
|
|
|
STATIC_ASSERT(ARRAY_LEN(litlen_decode_results) == |
24593
|
|
|
|
|
|
|
DEFLATE_NUM_LITLEN_SYMS); |
24594
|
|
|
|
|
|
|
|
24595
|
41
|
|
|
|
|
|
return build_decode_table(d->u.litlen_decode_table, |
24596
|
41
|
|
|
|
|
|
d->u.l.lens, |
24597
|
|
|
|
|
|
|
num_litlen_syms, |
24598
|
|
|
|
|
|
|
litlen_decode_results, |
24599
|
|
|
|
|
|
|
LITLEN_TABLEBITS, |
24600
|
|
|
|
|
|
|
DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
24601
|
41
|
|
|
|
|
|
d->sorted_syms, |
24602
|
|
|
|
|
|
|
&d->litlen_tablebits); |
24603
|
|
|
|
|
|
|
} |
24604
|
|
|
|
|
|
|
|
24605
|
|
|
|
|
|
|
|
24606
|
|
|
|
|
|
|
static bool |
24607
|
41
|
|
|
|
|
|
build_offset_decode_table(struct libdeflate_decompressor *d, |
24608
|
|
|
|
|
|
|
unsigned num_litlen_syms, unsigned num_offset_syms) |
24609
|
|
|
|
|
|
|
{ |
24610
|
|
|
|
|
|
|
|
24611
|
|
|
|
|
|
|
STATIC_ASSERT(OFFSET_TABLEBITS == 8 && OFFSET_ENOUGH == 402); |
24612
|
|
|
|
|
|
|
|
24613
|
|
|
|
|
|
|
STATIC_ASSERT(ARRAY_LEN(offset_decode_results) == |
24614
|
|
|
|
|
|
|
DEFLATE_NUM_OFFSET_SYMS); |
24615
|
|
|
|
|
|
|
|
24616
|
41
|
|
|
|
|
|
return build_decode_table(d->offset_decode_table, |
24617
|
41
|
|
|
|
|
|
d->u.l.lens + num_litlen_syms, |
24618
|
|
|
|
|
|
|
num_offset_syms, |
24619
|
|
|
|
|
|
|
offset_decode_results, |
24620
|
|
|
|
|
|
|
OFFSET_TABLEBITS, |
24621
|
|
|
|
|
|
|
DEFLATE_MAX_OFFSET_CODEWORD_LEN, |
24622
|
41
|
|
|
|
|
|
d->sorted_syms, |
24623
|
|
|
|
|
|
|
NULL); |
24624
|
|
|
|
|
|
|
} |
24625
|
|
|
|
|
|
|
|
24626
|
|
|
|
|
|
|
|
24627
|
|
|
|
|
|
|
|
24628
|
|
|
|
|
|
|
typedef enum libdeflate_result (*decompress_func_t) |
24629
|
|
|
|
|
|
|
(struct libdeflate_decompressor * restrict d, |
24630
|
|
|
|
|
|
|
const void * restrict in, size_t in_nbytes, |
24631
|
|
|
|
|
|
|
void * restrict out, size_t out_nbytes_avail, |
24632
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret); |
24633
|
|
|
|
|
|
|
|
24634
|
|
|
|
|
|
|
#define FUNCNAME deflate_decompress_default |
24635
|
|
|
|
|
|
|
#undef ATTRIBUTES |
24636
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS |
24637
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS8 |
24638
|
|
|
|
|
|
|
/* #include "decompress_template.h" */ |
24639
|
|
|
|
|
|
|
|
24640
|
|
|
|
|
|
|
|
24641
|
|
|
|
|
|
|
|
24642
|
|
|
|
|
|
|
|
24643
|
|
|
|
|
|
|
#ifndef ATTRIBUTES |
24644
|
|
|
|
|
|
|
# define ATTRIBUTES |
24645
|
|
|
|
|
|
|
#endif |
24646
|
|
|
|
|
|
|
#ifndef EXTRACT_VARBITS |
24647
|
|
|
|
|
|
|
# define EXTRACT_VARBITS(word, count) ((word) & BITMASK(count)) |
24648
|
|
|
|
|
|
|
#endif |
24649
|
|
|
|
|
|
|
#ifndef EXTRACT_VARBITS8 |
24650
|
|
|
|
|
|
|
# define EXTRACT_VARBITS8(word, count) ((word) & BITMASK((u8)(count))) |
24651
|
|
|
|
|
|
|
#endif |
24652
|
|
|
|
|
|
|
|
24653
|
|
|
|
|
|
|
static enum libdeflate_result ATTRIBUTES MAYBE_UNUSED |
24654
|
40
|
|
|
|
|
|
FUNCNAME(struct libdeflate_decompressor * restrict d, |
24655
|
|
|
|
|
|
|
const void * restrict in, size_t in_nbytes, |
24656
|
|
|
|
|
|
|
void * restrict out, size_t out_nbytes_avail, |
24657
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret) |
24658
|
|
|
|
|
|
|
{ |
24659
|
40
|
|
|
|
|
|
u8 *out_next = out; |
24660
|
40
|
|
|
|
|
|
u8 * const out_end = out_next + out_nbytes_avail; |
24661
|
40
|
|
|
|
|
|
u8 * const out_fastloop_end = |
24662
|
40
|
|
|
|
|
|
out_end - MIN(out_nbytes_avail, FASTLOOP_MAX_BYTES_WRITTEN); |
24663
|
|
|
|
|
|
|
|
24664
|
|
|
|
|
|
|
|
24665
|
40
|
|
|
|
|
|
const u8 *in_next = in; |
24666
|
40
|
|
|
|
|
|
const u8 * const in_end = in_next + in_nbytes; |
24667
|
40
|
|
|
|
|
|
const u8 * const in_fastloop_end = |
24668
|
40
|
|
|
|
|
|
in_end - MIN(in_nbytes, FASTLOOP_MAX_BYTES_READ); |
24669
|
40
|
|
|
|
|
|
bitbuf_t bitbuf = 0; |
24670
|
|
|
|
|
|
|
bitbuf_t saved_bitbuf; |
24671
|
40
|
|
|
|
|
|
u32 bitsleft = 0; |
24672
|
40
|
|
|
|
|
|
size_t overread_count = 0; |
24673
|
|
|
|
|
|
|
|
24674
|
|
|
|
|
|
|
bool is_final_block; |
24675
|
|
|
|
|
|
|
unsigned block_type; |
24676
|
|
|
|
|
|
|
unsigned num_litlen_syms; |
24677
|
|
|
|
|
|
|
unsigned num_offset_syms; |
24678
|
|
|
|
|
|
|
bitbuf_t litlen_tablemask; |
24679
|
|
|
|
|
|
|
u32 entry; |
24680
|
|
|
|
|
|
|
|
24681
|
|
|
|
|
|
|
next_block: |
24682
|
|
|
|
|
|
|
|
24683
|
|
|
|
|
|
|
; |
24684
|
|
|
|
|
|
|
|
24685
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME(1 + 2 + 5 + 5 + 4 + 3)); |
24686
|
82
|
50
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
24687
|
|
|
|
|
|
|
|
24688
|
|
|
|
|
|
|
|
24689
|
41
|
|
|
|
|
|
is_final_block = bitbuf & BITMASK(1); |
24690
|
|
|
|
|
|
|
|
24691
|
|
|
|
|
|
|
|
24692
|
41
|
|
|
|
|
|
block_type = (bitbuf >> 1) & BITMASK(2); |
24693
|
|
|
|
|
|
|
|
24694
|
41
|
100
|
|
|
|
|
if (block_type == DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN) { |
24695
|
|
|
|
|
|
|
|
24696
|
|
|
|
|
|
|
|
24697
|
|
|
|
|
|
|
|
24698
|
|
|
|
|
|
|
|
24699
|
|
|
|
|
|
|
static const u8 deflate_precode_lens_permutation[DEFLATE_NUM_PRECODE_SYMS] = { |
24700
|
|
|
|
|
|
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
24701
|
|
|
|
|
|
|
}; |
24702
|
|
|
|
|
|
|
|
24703
|
|
|
|
|
|
|
unsigned num_explicit_precode_lens; |
24704
|
|
|
|
|
|
|
unsigned i; |
24705
|
|
|
|
|
|
|
|
24706
|
|
|
|
|
|
|
|
24707
|
|
|
|
|
|
|
|
24708
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_LITLEN_SYMS == 257 + BITMASK(5)); |
24709
|
5
|
|
|
|
|
|
num_litlen_syms = 257 + ((bitbuf >> 3) & BITMASK(5)); |
24710
|
|
|
|
|
|
|
|
24711
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_OFFSET_SYMS == 1 + BITMASK(5)); |
24712
|
5
|
|
|
|
|
|
num_offset_syms = 1 + ((bitbuf >> 8) & BITMASK(5)); |
24713
|
|
|
|
|
|
|
|
24714
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_PRECODE_SYMS == 4 + BITMASK(4)); |
24715
|
5
|
|
|
|
|
|
num_explicit_precode_lens = 4 + ((bitbuf >> 13) & BITMASK(4)); |
24716
|
|
|
|
|
|
|
|
24717
|
5
|
|
|
|
|
|
d->static_codes_loaded = false; |
24718
|
|
|
|
|
|
|
|
24719
|
|
|
|
|
|
|
|
24720
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_PRE_CODEWORD_LEN == (1 << 3) - 1); |
24721
|
|
|
|
|
|
|
if (CAN_CONSUME(3 * (DEFLATE_NUM_PRECODE_SYMS - 1))) { |
24722
|
10
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[0]] = |
24723
|
5
|
|
|
|
|
|
(bitbuf >> 17) & BITMASK(3); |
24724
|
5
|
|
|
|
|
|
bitbuf >>= 20; |
24725
|
5
|
|
|
|
|
|
bitsleft -= 20; |
24726
|
10
|
50
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
24727
|
5
|
|
|
|
|
|
i = 1; |
24728
|
|
|
|
|
|
|
do { |
24729
|
65
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = |
24730
|
|
|
|
|
|
|
bitbuf & BITMASK(3); |
24731
|
65
|
|
|
|
|
|
bitbuf >>= 3; |
24732
|
65
|
|
|
|
|
|
bitsleft -= 3; |
24733
|
65
|
100
|
|
|
|
|
} while (++i < num_explicit_precode_lens); |
24734
|
|
|
|
|
|
|
} else { |
24735
|
|
|
|
|
|
|
bitbuf >>= 17; |
24736
|
|
|
|
|
|
|
bitsleft -= 17; |
24737
|
|
|
|
|
|
|
i = 0; |
24738
|
|
|
|
|
|
|
do { |
24739
|
|
|
|
|
|
|
if ((u8)bitsleft < 3) |
24740
|
|
|
|
|
|
|
REFILL_BITS(); |
24741
|
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = |
24742
|
|
|
|
|
|
|
bitbuf & BITMASK(3); |
24743
|
|
|
|
|
|
|
bitbuf >>= 3; |
24744
|
|
|
|
|
|
|
bitsleft -= 3; |
24745
|
|
|
|
|
|
|
} while (++i < num_explicit_precode_lens); |
24746
|
|
|
|
|
|
|
} |
24747
|
30
|
100
|
|
|
|
|
for (; i < DEFLATE_NUM_PRECODE_SYMS; i++) |
24748
|
25
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = 0; |
24749
|
|
|
|
|
|
|
|
24750
|
|
|
|
|
|
|
|
24751
|
5
|
50
|
|
|
|
|
SAFETY_CHECK(build_precode_decode_table(d)); |
24752
|
|
|
|
|
|
|
|
24753
|
|
|
|
|
|
|
|
24754
|
5
|
|
|
|
|
|
i = 0; |
24755
|
|
|
|
|
|
|
do { |
24756
|
|
|
|
|
|
|
unsigned presym; |
24757
|
|
|
|
|
|
|
u8 rep_val; |
24758
|
|
|
|
|
|
|
unsigned rep_count; |
24759
|
|
|
|
|
|
|
|
24760
|
674
|
100
|
|
|
|
|
if ((u8)bitsleft < DEFLATE_MAX_PRE_CODEWORD_LEN + 7) |
24761
|
110
|
50
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
24762
|
|
|
|
|
|
|
|
24763
|
|
|
|
|
|
|
|
24764
|
|
|
|
|
|
|
STATIC_ASSERT(PRECODE_TABLEBITS == DEFLATE_MAX_PRE_CODEWORD_LEN); |
24765
|
|
|
|
|
|
|
|
24766
|
|
|
|
|
|
|
|
24767
|
674
|
|
|
|
|
|
entry = d->u.l.precode_decode_table[ |
24768
|
674
|
|
|
|
|
|
bitbuf & BITMASK(DEFLATE_MAX_PRE_CODEWORD_LEN)]; |
24769
|
674
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
24770
|
674
|
|
|
|
|
|
bitsleft -= entry; |
24771
|
674
|
|
|
|
|
|
presym = entry >> 16; |
24772
|
|
|
|
|
|
|
|
24773
|
674
|
100
|
|
|
|
|
if (presym < 16) { |
24774
|
|
|
|
|
|
|
|
24775
|
626
|
|
|
|
|
|
d->u.l.lens[i++] = presym; |
24776
|
626
|
|
|
|
|
|
continue; |
24777
|
|
|
|
|
|
|
} |
24778
|
|
|
|
|
|
|
|
24779
|
|
|
|
|
|
|
|
24780
|
|
|
|
|
|
|
|
24781
|
|
|
|
|
|
|
|
24782
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_LENS_OVERRUN == 138 - 1); |
24783
|
|
|
|
|
|
|
|
24784
|
48
|
100
|
|
|
|
|
if (presym == 16) { |
24785
|
|
|
|
|
|
|
|
24786
|
15
|
50
|
|
|
|
|
SAFETY_CHECK(i != 0); |
24787
|
15
|
|
|
|
|
|
rep_val = d->u.l.lens[i - 1]; |
24788
|
|
|
|
|
|
|
STATIC_ASSERT(3 + BITMASK(2) == 6); |
24789
|
15
|
|
|
|
|
|
rep_count = 3 + (bitbuf & BITMASK(2)); |
24790
|
15
|
|
|
|
|
|
bitbuf >>= 2; |
24791
|
15
|
|
|
|
|
|
bitsleft -= 2; |
24792
|
15
|
|
|
|
|
|
d->u.l.lens[i + 0] = rep_val; |
24793
|
15
|
|
|
|
|
|
d->u.l.lens[i + 1] = rep_val; |
24794
|
15
|
|
|
|
|
|
d->u.l.lens[i + 2] = rep_val; |
24795
|
15
|
|
|
|
|
|
d->u.l.lens[i + 3] = rep_val; |
24796
|
15
|
|
|
|
|
|
d->u.l.lens[i + 4] = rep_val; |
24797
|
15
|
|
|
|
|
|
d->u.l.lens[i + 5] = rep_val; |
24798
|
15
|
|
|
|
|
|
i += rep_count; |
24799
|
33
|
100
|
|
|
|
|
} else if (presym == 17) { |
24800
|
|
|
|
|
|
|
|
24801
|
|
|
|
|
|
|
STATIC_ASSERT(3 + BITMASK(3) == 10); |
24802
|
15
|
|
|
|
|
|
rep_count = 3 + (bitbuf & BITMASK(3)); |
24803
|
15
|
|
|
|
|
|
bitbuf >>= 3; |
24804
|
15
|
|
|
|
|
|
bitsleft -= 3; |
24805
|
15
|
|
|
|
|
|
d->u.l.lens[i + 0] = 0; |
24806
|
15
|
|
|
|
|
|
d->u.l.lens[i + 1] = 0; |
24807
|
15
|
|
|
|
|
|
d->u.l.lens[i + 2] = 0; |
24808
|
15
|
|
|
|
|
|
d->u.l.lens[i + 3] = 0; |
24809
|
15
|
|
|
|
|
|
d->u.l.lens[i + 4] = 0; |
24810
|
15
|
|
|
|
|
|
d->u.l.lens[i + 5] = 0; |
24811
|
15
|
|
|
|
|
|
d->u.l.lens[i + 6] = 0; |
24812
|
15
|
|
|
|
|
|
d->u.l.lens[i + 7] = 0; |
24813
|
15
|
|
|
|
|
|
d->u.l.lens[i + 8] = 0; |
24814
|
15
|
|
|
|
|
|
d->u.l.lens[i + 9] = 0; |
24815
|
15
|
|
|
|
|
|
i += rep_count; |
24816
|
|
|
|
|
|
|
} else { |
24817
|
|
|
|
|
|
|
|
24818
|
|
|
|
|
|
|
STATIC_ASSERT(11 + BITMASK(7) == 138); |
24819
|
18
|
|
|
|
|
|
rep_count = 11 + (bitbuf & BITMASK(7)); |
24820
|
18
|
|
|
|
|
|
bitbuf >>= 7; |
24821
|
18
|
|
|
|
|
|
bitsleft -= 7; |
24822
|
18
|
|
|
|
|
|
memset(&d->u.l.lens[i], 0, |
24823
|
|
|
|
|
|
|
rep_count * sizeof(d->u.l.lens[i])); |
24824
|
18
|
|
|
|
|
|
i += rep_count; |
24825
|
|
|
|
|
|
|
} |
24826
|
674
|
100
|
|
|
|
|
} while (i < num_litlen_syms + num_offset_syms); |
24827
|
|
|
|
|
|
|
|
24828
|
|
|
|
|
|
|
|
24829
|
5
|
50
|
|
|
|
|
SAFETY_CHECK(i == num_litlen_syms + num_offset_syms); |
24830
|
|
|
|
|
|
|
|
24831
|
36
|
50
|
|
|
|
|
} else if (block_type == DEFLATE_BLOCKTYPE_UNCOMPRESSED) { |
24832
|
|
|
|
|
|
|
u16 len, nlen; |
24833
|
|
|
|
|
|
|
|
24834
|
|
|
|
|
|
|
|
24835
|
|
|
|
|
|
|
|
24836
|
0
|
|
|
|
|
|
bitsleft -= 3; |
24837
|
|
|
|
|
|
|
|
24838
|
|
|
|
|
|
|
|
24839
|
0
|
|
|
|
|
|
bitsleft = (u8)bitsleft; |
24840
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(overread_count <= (bitsleft >> 3)); |
24841
|
0
|
|
|
|
|
|
in_next -= (bitsleft >> 3) - overread_count; |
24842
|
0
|
|
|
|
|
|
overread_count = 0; |
24843
|
0
|
|
|
|
|
|
bitbuf = 0; |
24844
|
0
|
|
|
|
|
|
bitsleft = 0; |
24845
|
|
|
|
|
|
|
|
24846
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(in_end - in_next >= 4); |
24847
|
0
|
|
|
|
|
|
len = get_unaligned_le16(in_next); |
24848
|
0
|
|
|
|
|
|
nlen = get_unaligned_le16(in_next + 2); |
24849
|
0
|
|
|
|
|
|
in_next += 4; |
24850
|
|
|
|
|
|
|
|
24851
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(len == (u16)~nlen); |
24852
|
0
|
0
|
|
|
|
|
if (unlikely(len > out_end - out_next)) |
24853
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
24854
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(len <= in_end - in_next); |
24855
|
|
|
|
|
|
|
|
24856
|
0
|
|
|
|
|
|
memcpy(out_next, in_next, len); |
24857
|
0
|
|
|
|
|
|
in_next += len; |
24858
|
0
|
|
|
|
|
|
out_next += len; |
24859
|
|
|
|
|
|
|
|
24860
|
0
|
|
|
|
|
|
goto block_done; |
24861
|
|
|
|
|
|
|
|
24862
|
|
|
|
|
|
|
} else { |
24863
|
|
|
|
|
|
|
unsigned i; |
24864
|
|
|
|
|
|
|
|
24865
|
36
|
50
|
|
|
|
|
SAFETY_CHECK(block_type == DEFLATE_BLOCKTYPE_STATIC_HUFFMAN); |
24866
|
|
|
|
|
|
|
|
24867
|
|
|
|
|
|
|
|
24868
|
|
|
|
|
|
|
|
24869
|
36
|
|
|
|
|
|
bitbuf >>= 3; |
24870
|
36
|
|
|
|
|
|
bitsleft -= 3; |
24871
|
|
|
|
|
|
|
|
24872
|
36
|
50
|
|
|
|
|
if (d->static_codes_loaded) |
24873
|
0
|
|
|
|
|
|
goto have_decode_tables; |
24874
|
|
|
|
|
|
|
|
24875
|
36
|
|
|
|
|
|
d->static_codes_loaded = true; |
24876
|
|
|
|
|
|
|
|
24877
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_LITLEN_SYMS == 288); |
24878
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_OFFSET_SYMS == 32); |
24879
|
|
|
|
|
|
|
|
24880
|
5220
|
100
|
|
|
|
|
for (i = 0; i < 144; i++) |
24881
|
5184
|
|
|
|
|
|
d->u.l.lens[i] = 8; |
24882
|
4068
|
100
|
|
|
|
|
for (; i < 256; i++) |
24883
|
4032
|
|
|
|
|
|
d->u.l.lens[i] = 9; |
24884
|
900
|
100
|
|
|
|
|
for (; i < 280; i++) |
24885
|
864
|
|
|
|
|
|
d->u.l.lens[i] = 7; |
24886
|
324
|
100
|
|
|
|
|
for (; i < 288; i++) |
24887
|
288
|
|
|
|
|
|
d->u.l.lens[i] = 8; |
24888
|
|
|
|
|
|
|
|
24889
|
1188
|
100
|
|
|
|
|
for (; i < 288 + 32; i++) |
24890
|
1152
|
|
|
|
|
|
d->u.l.lens[i] = 5; |
24891
|
|
|
|
|
|
|
|
24892
|
36
|
|
|
|
|
|
num_litlen_syms = 288; |
24893
|
36
|
|
|
|
|
|
num_offset_syms = 32; |
24894
|
|
|
|
|
|
|
} |
24895
|
|
|
|
|
|
|
|
24896
|
|
|
|
|
|
|
|
24897
|
|
|
|
|
|
|
|
24898
|
41
|
50
|
|
|
|
|
SAFETY_CHECK(build_offset_decode_table(d, num_litlen_syms, num_offset_syms)); |
24899
|
41
|
50
|
|
|
|
|
SAFETY_CHECK(build_litlen_decode_table(d, num_litlen_syms, num_offset_syms)); |
24900
|
|
|
|
|
|
|
have_decode_tables: |
24901
|
41
|
|
|
|
|
|
litlen_tablemask = BITMASK(d->litlen_tablebits); |
24902
|
|
|
|
|
|
|
|
24903
|
|
|
|
|
|
|
|
24904
|
41
|
50
|
|
|
|
|
if (in_next >= in_fastloop_end || out_next >= out_fastloop_end) |
|
|
50
|
|
|
|
|
|
24905
|
|
|
|
|
|
|
goto generic_loop; |
24906
|
41
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
24907
|
41
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
24908
|
|
|
|
|
|
|
do { |
24909
|
|
|
|
|
|
|
u32 length, offset, lit; |
24910
|
|
|
|
|
|
|
const u8 *src; |
24911
|
|
|
|
|
|
|
u8 *dst; |
24912
|
|
|
|
|
|
|
|
24913
|
|
|
|
|
|
|
|
24914
|
10151
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
24915
|
10151
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
24916
|
10151
|
|
|
|
|
|
bitsleft -= entry; |
24917
|
|
|
|
|
|
|
|
24918
|
|
|
|
|
|
|
|
24919
|
10151
|
100
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
24920
|
|
|
|
|
|
|
|
24921
|
|
|
|
|
|
|
if ( |
24922
|
|
|
|
|
|
|
CAN_CONSUME_AND_THEN_PRELOAD(2 * LITLEN_TABLEBITS + |
24923
|
|
|
|
|
|
|
LENGTH_MAXBITS, |
24924
|
|
|
|
|
|
|
OFFSET_TABLEBITS) && |
24925
|
|
|
|
|
|
|
|
24926
|
|
|
|
|
|
|
CAN_CONSUME_AND_THEN_PRELOAD(2 * LITLEN_TABLEBITS + |
24927
|
|
|
|
|
|
|
DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
24928
|
|
|
|
|
|
|
LITLEN_TABLEBITS)) { |
24929
|
|
|
|
|
|
|
|
24930
|
3886
|
|
|
|
|
|
lit = entry >> 16; |
24931
|
3886
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
24932
|
3886
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
24933
|
3886
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
24934
|
3886
|
|
|
|
|
|
bitsleft -= entry; |
24935
|
3886
|
|
|
|
|
|
*out_next++ = lit; |
24936
|
3886
|
100
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
24937
|
|
|
|
|
|
|
|
24938
|
2617
|
|
|
|
|
|
lit = entry >> 16; |
24939
|
2617
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
24940
|
2617
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
24941
|
2617
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
24942
|
2617
|
|
|
|
|
|
bitsleft -= entry; |
24943
|
2617
|
|
|
|
|
|
*out_next++ = lit; |
24944
|
2617
|
100
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
24945
|
|
|
|
|
|
|
|
24946
|
1951
|
|
|
|
|
|
lit = entry >> 16; |
24947
|
1951
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
24948
|
1951
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
24949
|
1951
|
|
|
|
|
|
*out_next++ = lit; |
24950
|
1951
|
|
|
|
|
|
continue; |
24951
|
|
|
|
|
|
|
} |
24952
|
|
|
|
|
|
|
} |
24953
|
|
|
|
|
|
|
} else { |
24954
|
|
|
|
|
|
|
|
24955
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME_AND_THEN_PRELOAD( |
24956
|
|
|
|
|
|
|
LITLEN_TABLEBITS, LITLEN_TABLEBITS)); |
24957
|
|
|
|
|
|
|
lit = entry >> 16; |
24958
|
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
24959
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
24960
|
|
|
|
|
|
|
*out_next++ = lit; |
24961
|
|
|
|
|
|
|
continue; |
24962
|
|
|
|
|
|
|
} |
24963
|
|
|
|
|
|
|
} |
24964
|
|
|
|
|
|
|
|
24965
|
|
|
|
|
|
|
|
24966
|
8200
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
24967
|
|
|
|
|
|
|
|
24968
|
|
|
|
|
|
|
|
24969
|
28
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
24970
|
1
|
|
|
|
|
|
goto block_done; |
24971
|
|
|
|
|
|
|
|
24972
|
|
|
|
|
|
|
|
24973
|
54
|
|
|
|
|
|
entry = d->u.litlen_decode_table[(entry >> 16) + |
24974
|
27
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
24975
|
27
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
24976
|
27
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
24977
|
27
|
|
|
|
|
|
bitsleft -= entry; |
24978
|
|
|
|
|
|
|
|
24979
|
|
|
|
|
|
|
|
24980
|
|
|
|
|
|
|
if (!CAN_CONSUME_AND_THEN_PRELOAD(DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
24981
|
|
|
|
|
|
|
LITLEN_TABLEBITS) || |
24982
|
|
|
|
|
|
|
!CAN_CONSUME_AND_THEN_PRELOAD(LENGTH_MAXBITS, |
24983
|
|
|
|
|
|
|
OFFSET_TABLEBITS)) |
24984
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
24985
|
27
|
50
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
24986
|
|
|
|
|
|
|
|
24987
|
27
|
|
|
|
|
|
lit = entry >> 16; |
24988
|
27
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
24989
|
27
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
24990
|
27
|
|
|
|
|
|
*out_next++ = lit; |
24991
|
27
|
|
|
|
|
|
continue; |
24992
|
|
|
|
|
|
|
} |
24993
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
24994
|
0
|
|
|
|
|
|
goto block_done; |
24995
|
|
|
|
|
|
|
|
24996
|
|
|
|
|
|
|
} |
24997
|
|
|
|
|
|
|
|
24998
|
|
|
|
|
|
|
|
24999
|
8172
|
|
|
|
|
|
length = entry >> 16; |
25000
|
8172
|
|
|
|
|
|
length += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
25001
|
|
|
|
|
|
|
|
25002
|
|
|
|
|
|
|
|
25003
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME_AND_THEN_PRELOAD(LENGTH_MAXFASTBITS, |
25004
|
|
|
|
|
|
|
OFFSET_TABLEBITS)); |
25005
|
8172
|
|
|
|
|
|
entry = d->offset_decode_table[bitbuf & BITMASK(OFFSET_TABLEBITS)]; |
25006
|
|
|
|
|
|
|
if (CAN_CONSUME_AND_THEN_PRELOAD(OFFSET_MAXBITS, |
25007
|
|
|
|
|
|
|
LITLEN_TABLEBITS)) { |
25008
|
|
|
|
|
|
|
|
25009
|
8172
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
25010
|
|
|
|
|
|
|
|
25011
|
17
|
50
|
|
|
|
|
if (unlikely((u8)bitsleft < OFFSET_MAXBITS + |
25012
|
|
|
|
|
|
|
LITLEN_TABLEBITS - PRELOAD_SLACK)) |
25013
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25014
|
17
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
25015
|
17
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
25016
|
17
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
25017
|
17
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25018
|
8155
|
100
|
|
|
|
|
} else if (unlikely((u8)bitsleft < OFFSET_MAXFASTBITS + |
25019
|
|
|
|
|
|
|
LITLEN_TABLEBITS - PRELOAD_SLACK)) |
25020
|
1
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25021
|
|
|
|
|
|
|
} else { |
25022
|
|
|
|
|
|
|
|
25023
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25024
|
|
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
25025
|
|
|
|
|
|
|
|
25026
|
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
25027
|
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
25028
|
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
25029
|
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25030
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25031
|
|
|
|
|
|
|
|
25032
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME( |
25033
|
|
|
|
|
|
|
OFFSET_MAXBITS - OFFSET_TABLEBITS)); |
25034
|
|
|
|
|
|
|
} else { |
25035
|
|
|
|
|
|
|
|
25036
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME(OFFSET_MAXFASTBITS)); |
25037
|
|
|
|
|
|
|
} |
25038
|
|
|
|
|
|
|
} |
25039
|
8172
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25040
|
8172
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25041
|
8172
|
|
|
|
|
|
bitsleft -= entry; |
25042
|
8172
|
|
|
|
|
|
offset = entry >> 16; |
25043
|
8172
|
|
|
|
|
|
offset += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
25044
|
|
|
|
|
|
|
|
25045
|
|
|
|
|
|
|
|
25046
|
8172
|
50
|
|
|
|
|
SAFETY_CHECK(offset <= out_next - (const u8 *)out); |
25047
|
8172
|
|
|
|
|
|
src = out_next - offset; |
25048
|
8172
|
|
|
|
|
|
dst = out_next; |
25049
|
8172
|
|
|
|
|
|
out_next += length; |
25050
|
|
|
|
|
|
|
|
25051
|
|
|
|
|
|
|
|
25052
|
|
|
|
|
|
|
if (!CAN_CONSUME_AND_THEN_PRELOAD( |
25053
|
|
|
|
|
|
|
MAX(OFFSET_MAXBITS - OFFSET_TABLEBITS, |
25054
|
|
|
|
|
|
|
OFFSET_MAXFASTBITS), |
25055
|
|
|
|
|
|
|
LITLEN_TABLEBITS) && |
25056
|
|
|
|
|
|
|
unlikely((u8)bitsleft < LITLEN_TABLEBITS - PRELOAD_SLACK)) |
25057
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25058
|
8172
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25059
|
8172
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
25060
|
|
|
|
|
|
|
|
25061
|
|
|
|
|
|
|
|
25062
|
8172
|
100
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST && offset >= WORDBYTES) { |
25063
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25064
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25065
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25066
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25067
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25068
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25069
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25070
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25071
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25072
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25073
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25074
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25075
|
8163
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25076
|
8163
|
|
|
|
|
|
src += WORDBYTES; |
25077
|
8163
|
|
|
|
|
|
dst += WORDBYTES; |
25078
|
8430
|
100
|
|
|
|
|
while (dst < out_next) { |
25079
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25080
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25081
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25082
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25083
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25084
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25085
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25086
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25087
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25088
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25089
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25090
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25091
|
267
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25092
|
267
|
|
|
|
|
|
src += WORDBYTES; |
25093
|
267
|
|
|
|
|
|
dst += WORDBYTES; |
25094
|
|
|
|
|
|
|
} |
25095
|
9
|
50
|
|
|
|
|
} else if (UNALIGNED_ACCESS_IS_FAST && offset == 1) { |
25096
|
|
|
|
|
|
|
machine_word_t v; |
25097
|
|
|
|
|
|
|
|
25098
|
|
|
|
|
|
|
|
25099
|
0
|
|
|
|
|
|
v = (machine_word_t)0x0101010101010101 * src[0]; |
25100
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25101
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25102
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25103
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25104
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25105
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25106
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25107
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25108
|
0
|
0
|
|
|
|
|
while (dst < out_next) { |
25109
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25110
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25111
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25112
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25113
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25114
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25115
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
25116
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
25117
|
|
|
|
|
|
|
} |
25118
|
|
|
|
|
|
|
} else if (UNALIGNED_ACCESS_IS_FAST) { |
25119
|
9
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25120
|
9
|
|
|
|
|
|
src += offset; |
25121
|
9
|
|
|
|
|
|
dst += offset; |
25122
|
9
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25123
|
9
|
|
|
|
|
|
src += offset; |
25124
|
9
|
|
|
|
|
|
dst += offset; |
25125
|
|
|
|
|
|
|
do { |
25126
|
9
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25127
|
9
|
|
|
|
|
|
src += offset; |
25128
|
9
|
|
|
|
|
|
dst += offset; |
25129
|
9
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
25130
|
9
|
|
|
|
|
|
src += offset; |
25131
|
9
|
|
|
|
|
|
dst += offset; |
25132
|
9
|
50
|
|
|
|
|
} while (dst < out_next); |
25133
|
|
|
|
|
|
|
} else { |
25134
|
|
|
|
|
|
|
*dst++ = *src++; |
25135
|
|
|
|
|
|
|
*dst++ = *src++; |
25136
|
|
|
|
|
|
|
do { |
25137
|
|
|
|
|
|
|
*dst++ = *src++; |
25138
|
|
|
|
|
|
|
} while (dst < out_next); |
25139
|
|
|
|
|
|
|
} |
25140
|
10150
|
100
|
|
|
|
|
} while (in_next < in_fastloop_end && out_next < out_fastloop_end); |
|
|
100
|
|
|
|
|
|
25141
|
|
|
|
|
|
|
|
25142
|
|
|
|
|
|
|
|
25143
|
|
|
|
|
|
|
generic_loop: |
25144
|
|
|
|
|
|
|
for (;;) { |
25145
|
|
|
|
|
|
|
u32 length, offset; |
25146
|
|
|
|
|
|
|
const u8 *src; |
25147
|
|
|
|
|
|
|
u8 *dst; |
25148
|
|
|
|
|
|
|
|
25149
|
2172
|
100
|
|
|
|
|
REFILL_BITS(); |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
25150
|
970
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
25151
|
970
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25152
|
970
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25153
|
970
|
|
|
|
|
|
bitsleft -= entry; |
25154
|
970
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_SUBTABLE_POINTER)) { |
25155
|
6
|
|
|
|
|
|
entry = d->u.litlen_decode_table[(entry >> 16) + |
25156
|
3
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25157
|
3
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
25158
|
3
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25159
|
3
|
|
|
|
|
|
bitsleft -= entry; |
25160
|
|
|
|
|
|
|
} |
25161
|
970
|
|
|
|
|
|
length = entry >> 16; |
25162
|
970
|
100
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
25163
|
588
|
50
|
|
|
|
|
if (unlikely(out_next == out_end)) |
25164
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
25165
|
588
|
|
|
|
|
|
*out_next++ = length; |
25166
|
588
|
|
|
|
|
|
continue; |
25167
|
|
|
|
|
|
|
} |
25168
|
382
|
100
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
25169
|
40
|
|
|
|
|
|
goto block_done; |
25170
|
342
|
|
|
|
|
|
length += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
25171
|
342
|
50
|
|
|
|
|
if (unlikely(length > out_end - out_next)) |
25172
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
25173
|
|
|
|
|
|
|
|
25174
|
|
|
|
|
|
|
if (!CAN_CONSUME(LENGTH_MAXBITS + OFFSET_MAXBITS)) |
25175
|
|
|
|
|
|
|
REFILL_BITS(); |
25176
|
342
|
|
|
|
|
|
entry = d->offset_decode_table[bitbuf & BITMASK(OFFSET_TABLEBITS)]; |
25177
|
342
|
50
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
25178
|
0
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
25179
|
0
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
25180
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
25181
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
25182
|
|
|
|
|
|
|
if (!CAN_CONSUME(OFFSET_MAXBITS)) |
25183
|
|
|
|
|
|
|
REFILL_BITS(); |
25184
|
|
|
|
|
|
|
} |
25185
|
342
|
|
|
|
|
|
offset = entry >> 16; |
25186
|
342
|
|
|
|
|
|
offset += EXTRACT_VARBITS8(bitbuf, entry) >> (u8)(entry >> 8); |
25187
|
342
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
25188
|
342
|
|
|
|
|
|
bitsleft -= entry; |
25189
|
|
|
|
|
|
|
|
25190
|
342
|
50
|
|
|
|
|
SAFETY_CHECK(offset <= out_next - (const u8 *)out); |
25191
|
342
|
|
|
|
|
|
src = out_next - offset; |
25192
|
342
|
|
|
|
|
|
dst = out_next; |
25193
|
342
|
|
|
|
|
|
out_next += length; |
25194
|
|
|
|
|
|
|
|
25195
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MIN_MATCH_LEN == 3); |
25196
|
342
|
|
|
|
|
|
*dst++ = *src++; |
25197
|
342
|
|
|
|
|
|
*dst++ = *src++; |
25198
|
|
|
|
|
|
|
do { |
25199
|
60992
|
|
|
|
|
|
*dst++ = *src++; |
25200
|
60992
|
100
|
|
|
|
|
} while (dst < out_next); |
25201
|
930
|
|
|
|
|
|
} |
25202
|
|
|
|
|
|
|
|
25203
|
|
|
|
|
|
|
block_done: |
25204
|
|
|
|
|
|
|
|
25205
|
|
|
|
|
|
|
|
25206
|
41
|
100
|
|
|
|
|
if (!is_final_block) |
25207
|
1
|
|
|
|
|
|
goto next_block; |
25208
|
|
|
|
|
|
|
|
25209
|
|
|
|
|
|
|
|
25210
|
|
|
|
|
|
|
|
25211
|
40
|
|
|
|
|
|
bitsleft = (u8)bitsleft; |
25212
|
|
|
|
|
|
|
|
25213
|
|
|
|
|
|
|
|
25214
|
40
|
50
|
|
|
|
|
SAFETY_CHECK(overread_count <= (bitsleft >> 3)); |
25215
|
|
|
|
|
|
|
|
25216
|
|
|
|
|
|
|
|
25217
|
40
|
50
|
|
|
|
|
if (actual_in_nbytes_ret) { |
25218
|
|
|
|
|
|
|
|
25219
|
40
|
|
|
|
|
|
in_next -= (bitsleft >> 3) - overread_count; |
25220
|
|
|
|
|
|
|
|
25221
|
40
|
|
|
|
|
|
*actual_in_nbytes_ret = in_next - (u8 *)in; |
25222
|
|
|
|
|
|
|
} |
25223
|
|
|
|
|
|
|
|
25224
|
|
|
|
|
|
|
|
25225
|
40
|
50
|
|
|
|
|
if (actual_out_nbytes_ret) { |
25226
|
40
|
|
|
|
|
|
*actual_out_nbytes_ret = out_next - (u8 *)out; |
25227
|
|
|
|
|
|
|
} else { |
25228
|
0
|
0
|
|
|
|
|
if (out_next != out_end) |
25229
|
0
|
|
|
|
|
|
return LIBDEFLATE_SHORT_OUTPUT; |
25230
|
|
|
|
|
|
|
} |
25231
|
40
|
|
|
|
|
|
return LIBDEFLATE_SUCCESS; |
25232
|
|
|
|
|
|
|
} |
25233
|
|
|
|
|
|
|
|
25234
|
|
|
|
|
|
|
#undef FUNCNAME |
25235
|
|
|
|
|
|
|
#undef ATTRIBUTES |
25236
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS |
25237
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS8 |
25238
|
|
|
|
|
|
|
|
25239
|
|
|
|
|
|
|
|
25240
|
|
|
|
|
|
|
|
25241
|
|
|
|
|
|
|
#undef DEFAULT_IMPL |
25242
|
|
|
|
|
|
|
#undef arch_select_decompress_func |
25243
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
25244
|
|
|
|
|
|
|
/* # include "x86/decompress_impl.h" */ |
25245
|
|
|
|
|
|
|
#ifndef LIB_X86_DECOMPRESS_IMPL_H |
25246
|
|
|
|
|
|
|
#define LIB_X86_DECOMPRESS_IMPL_H |
25247
|
|
|
|
|
|
|
|
25248
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
25249
|
|
|
|
|
|
|
|
25250
|
|
|
|
|
|
|
|
25251
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
25252
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
25253
|
|
|
|
|
|
|
|
25254
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
25255
|
|
|
|
|
|
|
|
25256
|
|
|
|
|
|
|
|
25257
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
25258
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
25259
|
|
|
|
|
|
|
|
25260
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
25261
|
|
|
|
|
|
|
|
25262
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
25263
|
|
|
|
|
|
|
#endif |
25264
|
|
|
|
|
|
|
|
25265
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
25266
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
25267
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
25268
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
25269
|
|
|
|
|
|
|
#else |
25270
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
25271
|
|
|
|
|
|
|
#endif |
25272
|
|
|
|
|
|
|
|
25273
|
|
|
|
|
|
|
|
25274
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
25275
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
25276
|
|
|
|
|
|
|
#else |
25277
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
25278
|
|
|
|
|
|
|
#endif |
25279
|
|
|
|
|
|
|
|
25280
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
25281
|
|
|
|
|
|
|
|
25282
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
25283
|
|
|
|
|
|
|
|
25284
|
|
|
|
|
|
|
|
25285
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
25286
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
25287
|
|
|
|
|
|
|
|
25288
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
25289
|
|
|
|
|
|
|
|
25290
|
|
|
|
|
|
|
|
25291
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
25292
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
25293
|
|
|
|
|
|
|
|
25294
|
|
|
|
|
|
|
#include |
25295
|
|
|
|
|
|
|
#include |
25296
|
|
|
|
|
|
|
|
25297
|
|
|
|
|
|
|
#ifdef __cplusplus |
25298
|
|
|
|
|
|
|
extern "C" { |
25299
|
|
|
|
|
|
|
#endif |
25300
|
|
|
|
|
|
|
|
25301
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
25302
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
25303
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
25304
|
|
|
|
|
|
|
|
25305
|
|
|
|
|
|
|
|
25306
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
25307
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
25308
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
25309
|
|
|
|
|
|
|
# else |
25310
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
25311
|
|
|
|
|
|
|
# endif |
25312
|
|
|
|
|
|
|
#endif |
25313
|
|
|
|
|
|
|
|
25314
|
|
|
|
|
|
|
|
25315
|
|
|
|
|
|
|
|
25316
|
|
|
|
|
|
|
|
25317
|
|
|
|
|
|
|
|
25318
|
|
|
|
|
|
|
struct libdeflate_compressor; |
25319
|
|
|
|
|
|
|
|
25320
|
|
|
|
|
|
|
|
25321
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
25322
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
25323
|
|
|
|
|
|
|
|
25324
|
|
|
|
|
|
|
|
25325
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25326
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
25327
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25328
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
25329
|
|
|
|
|
|
|
|
25330
|
|
|
|
|
|
|
|
25331
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25332
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
25333
|
|
|
|
|
|
|
size_t in_nbytes); |
25334
|
|
|
|
|
|
|
|
25335
|
|
|
|
|
|
|
|
25336
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25337
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
25338
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25339
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
25340
|
|
|
|
|
|
|
|
25341
|
|
|
|
|
|
|
|
25342
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25343
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
25344
|
|
|
|
|
|
|
size_t in_nbytes); |
25345
|
|
|
|
|
|
|
|
25346
|
|
|
|
|
|
|
|
25347
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25348
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
25349
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25350
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
25351
|
|
|
|
|
|
|
|
25352
|
|
|
|
|
|
|
|
25353
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
25354
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
25355
|
|
|
|
|
|
|
size_t in_nbytes); |
25356
|
|
|
|
|
|
|
|
25357
|
|
|
|
|
|
|
|
25358
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
25359
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
25360
|
|
|
|
|
|
|
|
25361
|
|
|
|
|
|
|
|
25362
|
|
|
|
|
|
|
|
25363
|
|
|
|
|
|
|
|
25364
|
|
|
|
|
|
|
|
25365
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
25366
|
|
|
|
|
|
|
|
25367
|
|
|
|
|
|
|
|
25368
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
25369
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
25370
|
|
|
|
|
|
|
|
25371
|
|
|
|
|
|
|
|
25372
|
|
|
|
|
|
|
enum libdeflate_result { |
25373
|
|
|
|
|
|
|
|
25374
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
25375
|
|
|
|
|
|
|
|
25376
|
|
|
|
|
|
|
|
25377
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
25378
|
|
|
|
|
|
|
|
25379
|
|
|
|
|
|
|
|
25380
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
25381
|
|
|
|
|
|
|
|
25382
|
|
|
|
|
|
|
|
25383
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
25384
|
|
|
|
|
|
|
}; |
25385
|
|
|
|
|
|
|
|
25386
|
|
|
|
|
|
|
|
25387
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25388
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
25389
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25390
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25391
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25392
|
|
|
|
|
|
|
|
25393
|
|
|
|
|
|
|
|
25394
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25395
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
25396
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25397
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25398
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
25399
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25400
|
|
|
|
|
|
|
|
25401
|
|
|
|
|
|
|
|
25402
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25403
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
25404
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25405
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25406
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25407
|
|
|
|
|
|
|
|
25408
|
|
|
|
|
|
|
|
25409
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25410
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
25411
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25412
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25413
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
25414
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25415
|
|
|
|
|
|
|
|
25416
|
|
|
|
|
|
|
|
25417
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25418
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
25419
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25420
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25421
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25422
|
|
|
|
|
|
|
|
25423
|
|
|
|
|
|
|
|
25424
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
25425
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
25426
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
25427
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
25428
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
25429
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
25430
|
|
|
|
|
|
|
|
25431
|
|
|
|
|
|
|
|
25432
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
25433
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
25434
|
|
|
|
|
|
|
|
25435
|
|
|
|
|
|
|
|
25436
|
|
|
|
|
|
|
|
25437
|
|
|
|
|
|
|
|
25438
|
|
|
|
|
|
|
|
25439
|
|
|
|
|
|
|
|
25440
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
25441
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
25442
|
|
|
|
|
|
|
|
25443
|
|
|
|
|
|
|
|
25444
|
|
|
|
|
|
|
|
25445
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
25446
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
25447
|
|
|
|
|
|
|
|
25448
|
|
|
|
|
|
|
|
25449
|
|
|
|
|
|
|
|
25450
|
|
|
|
|
|
|
|
25451
|
|
|
|
|
|
|
|
25452
|
|
|
|
|
|
|
|
25453
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
25454
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
25455
|
|
|
|
|
|
|
void (*free_func)(void *)); |
25456
|
|
|
|
|
|
|
|
25457
|
|
|
|
|
|
|
#ifdef __cplusplus |
25458
|
|
|
|
|
|
|
} |
25459
|
|
|
|
|
|
|
#endif |
25460
|
|
|
|
|
|
|
|
25461
|
|
|
|
|
|
|
#endif |
25462
|
|
|
|
|
|
|
|
25463
|
|
|
|
|
|
|
|
25464
|
|
|
|
|
|
|
#include |
25465
|
|
|
|
|
|
|
#include |
25466
|
|
|
|
|
|
|
#include |
25467
|
|
|
|
|
|
|
#ifdef _MSC_VER |
25468
|
|
|
|
|
|
|
# include |
25469
|
|
|
|
|
|
|
# include |
25470
|
|
|
|
|
|
|
|
25471
|
|
|
|
|
|
|
|
25472
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
25473
|
|
|
|
|
|
|
|
25474
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
25475
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
25476
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
25477
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
25478
|
|
|
|
|
|
|
|
25479
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
25480
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
25481
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
25482
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
25483
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
25484
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
25485
|
|
|
|
|
|
|
#endif |
25486
|
|
|
|
|
|
|
#ifndef FREESTANDING |
25487
|
|
|
|
|
|
|
# include |
25488
|
|
|
|
|
|
|
#endif |
25489
|
|
|
|
|
|
|
|
25490
|
|
|
|
|
|
|
|
25491
|
|
|
|
|
|
|
|
25492
|
|
|
|
|
|
|
|
25493
|
|
|
|
|
|
|
|
25494
|
|
|
|
|
|
|
|
25495
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
25496
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
25497
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
25498
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
25499
|
|
|
|
|
|
|
#ifdef _MSC_VER |
25500
|
|
|
|
|
|
|
# if defined(_M_X64) |
25501
|
|
|
|
|
|
|
# define ARCH_X86_64 |
25502
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
25503
|
|
|
|
|
|
|
# define ARCH_X86_32 |
25504
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
25505
|
|
|
|
|
|
|
# define ARCH_ARM64 |
25506
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
25507
|
|
|
|
|
|
|
# define ARCH_ARM32 |
25508
|
|
|
|
|
|
|
# endif |
25509
|
|
|
|
|
|
|
#else |
25510
|
|
|
|
|
|
|
# if defined(__x86_64__) |
25511
|
|
|
|
|
|
|
# define ARCH_X86_64 |
25512
|
|
|
|
|
|
|
# elif defined(__i386__) |
25513
|
|
|
|
|
|
|
# define ARCH_X86_32 |
25514
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
25515
|
|
|
|
|
|
|
# define ARCH_ARM64 |
25516
|
|
|
|
|
|
|
# elif defined(__arm__) |
25517
|
|
|
|
|
|
|
# define ARCH_ARM32 |
25518
|
|
|
|
|
|
|
# endif |
25519
|
|
|
|
|
|
|
#endif |
25520
|
|
|
|
|
|
|
|
25521
|
|
|
|
|
|
|
|
25522
|
|
|
|
|
|
|
|
25523
|
|
|
|
|
|
|
|
25524
|
|
|
|
|
|
|
|
25525
|
|
|
|
|
|
|
|
25526
|
|
|
|
|
|
|
typedef uint8_t u8; |
25527
|
|
|
|
|
|
|
typedef uint16_t u16; |
25528
|
|
|
|
|
|
|
typedef uint32_t u32; |
25529
|
|
|
|
|
|
|
typedef uint64_t u64; |
25530
|
|
|
|
|
|
|
typedef int8_t s8; |
25531
|
|
|
|
|
|
|
typedef int16_t s16; |
25532
|
|
|
|
|
|
|
typedef int32_t s32; |
25533
|
|
|
|
|
|
|
typedef int64_t s64; |
25534
|
|
|
|
|
|
|
|
25535
|
|
|
|
|
|
|
|
25536
|
|
|
|
|
|
|
#ifdef _MSC_VER |
25537
|
|
|
|
|
|
|
# ifdef _WIN64 |
25538
|
|
|
|
|
|
|
typedef long long ssize_t; |
25539
|
|
|
|
|
|
|
# else |
25540
|
|
|
|
|
|
|
typedef long ssize_t; |
25541
|
|
|
|
|
|
|
# endif |
25542
|
|
|
|
|
|
|
#endif |
25543
|
|
|
|
|
|
|
|
25544
|
|
|
|
|
|
|
|
25545
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
25546
|
|
|
|
|
|
|
|
25547
|
|
|
|
|
|
|
|
25548
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
25549
|
|
|
|
|
|
|
|
25550
|
|
|
|
|
|
|
|
25551
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
25552
|
|
|
|
|
|
|
|
25553
|
|
|
|
|
|
|
|
25554
|
|
|
|
|
|
|
|
25555
|
|
|
|
|
|
|
|
25556
|
|
|
|
|
|
|
|
25557
|
|
|
|
|
|
|
|
25558
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
25559
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
25560
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
25561
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
25562
|
|
|
|
|
|
|
#else |
25563
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
25564
|
|
|
|
|
|
|
#endif |
25565
|
|
|
|
|
|
|
#ifdef __clang__ |
25566
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
25567
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
25568
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
25569
|
|
|
|
|
|
|
# else |
25570
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
25571
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
25572
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
25573
|
|
|
|
|
|
|
# endif |
25574
|
|
|
|
|
|
|
#else |
25575
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
25576
|
|
|
|
|
|
|
#endif |
25577
|
|
|
|
|
|
|
|
25578
|
|
|
|
|
|
|
|
25579
|
|
|
|
|
|
|
#ifndef __has_attribute |
25580
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
25581
|
|
|
|
|
|
|
#endif |
25582
|
|
|
|
|
|
|
#ifndef __has_builtin |
25583
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
25584
|
|
|
|
|
|
|
#endif |
25585
|
|
|
|
|
|
|
|
25586
|
|
|
|
|
|
|
|
25587
|
|
|
|
|
|
|
#ifdef _MSC_VER |
25588
|
|
|
|
|
|
|
# define inline __inline |
25589
|
|
|
|
|
|
|
#endif |
25590
|
|
|
|
|
|
|
|
25591
|
|
|
|
|
|
|
|
25592
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
25593
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
25594
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25595
|
|
|
|
|
|
|
# define forceinline __forceinline |
25596
|
|
|
|
|
|
|
#else |
25597
|
|
|
|
|
|
|
# define forceinline inline |
25598
|
|
|
|
|
|
|
#endif |
25599
|
|
|
|
|
|
|
|
25600
|
|
|
|
|
|
|
|
25601
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
25602
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
25603
|
|
|
|
|
|
|
#else |
25604
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
25605
|
|
|
|
|
|
|
#endif |
25606
|
|
|
|
|
|
|
|
25607
|
|
|
|
|
|
|
|
25608
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
25609
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
25610
|
|
|
|
|
|
|
# define restrict __restrict__ |
25611
|
|
|
|
|
|
|
# else |
25612
|
|
|
|
|
|
|
# define restrict |
25613
|
|
|
|
|
|
|
# endif |
25614
|
|
|
|
|
|
|
#endif |
25615
|
|
|
|
|
|
|
|
25616
|
|
|
|
|
|
|
|
25617
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
25618
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
25619
|
|
|
|
|
|
|
#else |
25620
|
|
|
|
|
|
|
# define likely(expr) (expr) |
25621
|
|
|
|
|
|
|
#endif |
25622
|
|
|
|
|
|
|
|
25623
|
|
|
|
|
|
|
|
25624
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
25625
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
25626
|
|
|
|
|
|
|
#else |
25627
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
25628
|
|
|
|
|
|
|
#endif |
25629
|
|
|
|
|
|
|
|
25630
|
|
|
|
|
|
|
|
25631
|
|
|
|
|
|
|
#undef prefetchr |
25632
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
25633
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
25634
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25635
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
25636
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
25637
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
25638
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
25639
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
25640
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
25641
|
|
|
|
|
|
|
# endif |
25642
|
|
|
|
|
|
|
#endif |
25643
|
|
|
|
|
|
|
#ifndef prefetchr |
25644
|
|
|
|
|
|
|
# define prefetchr(addr) |
25645
|
|
|
|
|
|
|
#endif |
25646
|
|
|
|
|
|
|
|
25647
|
|
|
|
|
|
|
|
25648
|
|
|
|
|
|
|
#undef prefetchw |
25649
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
25650
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
25651
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25652
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
25653
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
25654
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
25655
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
25656
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
25657
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
25658
|
|
|
|
|
|
|
# endif |
25659
|
|
|
|
|
|
|
#endif |
25660
|
|
|
|
|
|
|
#ifndef prefetchw |
25661
|
|
|
|
|
|
|
# define prefetchw(addr) |
25662
|
|
|
|
|
|
|
#endif |
25663
|
|
|
|
|
|
|
|
25664
|
|
|
|
|
|
|
|
25665
|
|
|
|
|
|
|
#undef _aligned_attribute |
25666
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
25667
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
25668
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25669
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
25670
|
|
|
|
|
|
|
#endif |
25671
|
|
|
|
|
|
|
|
25672
|
|
|
|
|
|
|
|
25673
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
25674
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
25675
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
25676
|
|
|
|
|
|
|
#else |
25677
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
25678
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
25679
|
|
|
|
|
|
|
#endif |
25680
|
|
|
|
|
|
|
|
25681
|
|
|
|
|
|
|
|
25682
|
|
|
|
|
|
|
|
25683
|
|
|
|
|
|
|
|
25684
|
|
|
|
|
|
|
|
25685
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
25686
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
25687
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
25688
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
25689
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
25690
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
25691
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
25692
|
|
|
|
|
|
|
|
25693
|
|
|
|
|
|
|
|
25694
|
|
|
|
|
|
|
|
25695
|
|
|
|
|
|
|
|
25696
|
|
|
|
|
|
|
|
25697
|
|
|
|
|
|
|
|
25698
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
25699
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
25700
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25701
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
25702
|
|
|
|
|
|
|
#else |
25703
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
25704
|
|
|
|
|
|
|
{ |
25705
|
|
|
|
|
|
|
union { |
25706
|
|
|
|
|
|
|
u32 w; |
25707
|
|
|
|
|
|
|
u8 b; |
25708
|
|
|
|
|
|
|
} u; |
25709
|
|
|
|
|
|
|
|
25710
|
|
|
|
|
|
|
u.w = 1; |
25711
|
|
|
|
|
|
|
return u.b; |
25712
|
|
|
|
|
|
|
} |
25713
|
|
|
|
|
|
|
#endif |
25714
|
|
|
|
|
|
|
|
25715
|
|
|
|
|
|
|
|
25716
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
25717
|
|
|
|
|
|
|
{ |
25718
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
25719
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
25720
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25721
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
25722
|
|
|
|
|
|
|
#else |
25723
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
25724
|
|
|
|
|
|
|
#endif |
25725
|
|
|
|
|
|
|
} |
25726
|
|
|
|
|
|
|
|
25727
|
|
|
|
|
|
|
|
25728
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
25729
|
|
|
|
|
|
|
{ |
25730
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
25731
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
25732
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25733
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
25734
|
|
|
|
|
|
|
#else |
25735
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
25736
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
25737
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
25738
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
25739
|
|
|
|
|
|
|
#endif |
25740
|
|
|
|
|
|
|
} |
25741
|
|
|
|
|
|
|
|
25742
|
|
|
|
|
|
|
|
25743
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
25744
|
|
|
|
|
|
|
{ |
25745
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
25746
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
25747
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25748
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
25749
|
|
|
|
|
|
|
#else |
25750
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
25751
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
25752
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
25753
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
25754
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
25755
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
25756
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
25757
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
25758
|
|
|
|
|
|
|
#endif |
25759
|
|
|
|
|
|
|
} |
25760
|
|
|
|
|
|
|
|
25761
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
25762
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
25763
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
25764
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
25765
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
25766
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
25767
|
|
|
|
|
|
|
|
25768
|
|
|
|
|
|
|
|
25769
|
|
|
|
|
|
|
|
25770
|
|
|
|
|
|
|
|
25771
|
|
|
|
|
|
|
|
25772
|
|
|
|
|
|
|
|
25773
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
25774
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
25775
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
25776
|
|
|
|
|
|
|
defined(__wasm__)) |
25777
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
25778
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25779
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
25780
|
|
|
|
|
|
|
#else |
25781
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
25782
|
|
|
|
|
|
|
#endif |
25783
|
|
|
|
|
|
|
|
25784
|
|
|
|
|
|
|
|
25785
|
|
|
|
|
|
|
|
25786
|
|
|
|
|
|
|
#ifdef FREESTANDING |
25787
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
25788
|
|
|
|
|
|
|
#else |
25789
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
25790
|
|
|
|
|
|
|
#endif |
25791
|
|
|
|
|
|
|
|
25792
|
|
|
|
|
|
|
|
25793
|
|
|
|
|
|
|
|
25794
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
25795
|
|
|
|
|
|
|
static forceinline type \ |
25796
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
25797
|
|
|
|
|
|
|
{ \ |
25798
|
|
|
|
|
|
|
type v; \ |
25799
|
|
|
|
|
|
|
\ |
25800
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
25801
|
|
|
|
|
|
|
return v; \ |
25802
|
|
|
|
|
|
|
} \ |
25803
|
|
|
|
|
|
|
\ |
25804
|
|
|
|
|
|
|
static forceinline void \ |
25805
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
25806
|
|
|
|
|
|
|
{ \ |
25807
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
25808
|
|
|
|
|
|
|
} |
25809
|
|
|
|
|
|
|
|
25810
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
25811
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
25812
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
25813
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
25814
|
|
|
|
|
|
|
|
25815
|
|
|
|
|
|
|
#undef MEMCOPY |
25816
|
|
|
|
|
|
|
|
25817
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
25818
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
25819
|
|
|
|
|
|
|
|
25820
|
|
|
|
|
|
|
|
25821
|
|
|
|
|
|
|
|
25822
|
|
|
|
|
|
|
static forceinline u16 |
25823
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
25824
|
|
|
|
|
|
|
{ |
25825
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
25826
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
25827
|
|
|
|
|
|
|
else |
25828
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
25829
|
|
|
|
|
|
|
} |
25830
|
|
|
|
|
|
|
|
25831
|
|
|
|
|
|
|
static forceinline u16 |
25832
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
25833
|
|
|
|
|
|
|
{ |
25834
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
25835
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
25836
|
|
|
|
|
|
|
else |
25837
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
25838
|
|
|
|
|
|
|
} |
25839
|
|
|
|
|
|
|
|
25840
|
|
|
|
|
|
|
static forceinline u32 |
25841
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
25842
|
|
|
|
|
|
|
{ |
25843
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
25844
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
25845
|
|
|
|
|
|
|
else |
25846
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
25847
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
25848
|
|
|
|
|
|
|
} |
25849
|
|
|
|
|
|
|
|
25850
|
|
|
|
|
|
|
static forceinline u32 |
25851
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
25852
|
|
|
|
|
|
|
{ |
25853
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
25854
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
25855
|
|
|
|
|
|
|
else |
25856
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
25857
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
25858
|
|
|
|
|
|
|
} |
25859
|
|
|
|
|
|
|
|
25860
|
|
|
|
|
|
|
static forceinline u64 |
25861
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
25862
|
|
|
|
|
|
|
{ |
25863
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
25864
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
25865
|
|
|
|
|
|
|
else |
25866
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
25867
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
25868
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
25869
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
25870
|
|
|
|
|
|
|
} |
25871
|
|
|
|
|
|
|
|
25872
|
|
|
|
|
|
|
static forceinline machine_word_t |
25873
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
25874
|
|
|
|
|
|
|
{ |
25875
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
25876
|
|
|
|
|
|
|
if (WORDBITS == 32) |
25877
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
25878
|
|
|
|
|
|
|
else |
25879
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
25880
|
|
|
|
|
|
|
} |
25881
|
|
|
|
|
|
|
|
25882
|
|
|
|
|
|
|
|
25883
|
|
|
|
|
|
|
|
25884
|
|
|
|
|
|
|
static forceinline void |
25885
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
25886
|
|
|
|
|
|
|
{ |
25887
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
25888
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
25889
|
|
|
|
|
|
|
} else { |
25890
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
25891
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
25892
|
|
|
|
|
|
|
} |
25893
|
|
|
|
|
|
|
} |
25894
|
|
|
|
|
|
|
|
25895
|
|
|
|
|
|
|
static forceinline void |
25896
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
25897
|
|
|
|
|
|
|
{ |
25898
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
25899
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
25900
|
|
|
|
|
|
|
} else { |
25901
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
25902
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
25903
|
|
|
|
|
|
|
} |
25904
|
|
|
|
|
|
|
} |
25905
|
|
|
|
|
|
|
|
25906
|
|
|
|
|
|
|
static forceinline void |
25907
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
25908
|
|
|
|
|
|
|
{ |
25909
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
25910
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
25911
|
|
|
|
|
|
|
} else { |
25912
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
25913
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
25914
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
25915
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
25916
|
|
|
|
|
|
|
} |
25917
|
|
|
|
|
|
|
} |
25918
|
|
|
|
|
|
|
|
25919
|
|
|
|
|
|
|
static forceinline void |
25920
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
25921
|
|
|
|
|
|
|
{ |
25922
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
25923
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
25924
|
|
|
|
|
|
|
} else { |
25925
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
25926
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
25927
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
25928
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
25929
|
|
|
|
|
|
|
} |
25930
|
|
|
|
|
|
|
} |
25931
|
|
|
|
|
|
|
|
25932
|
|
|
|
|
|
|
static forceinline void |
25933
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
25934
|
|
|
|
|
|
|
{ |
25935
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
25936
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
25937
|
|
|
|
|
|
|
} else { |
25938
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
25939
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
25940
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
25941
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
25942
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
25943
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
25944
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
25945
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
25946
|
|
|
|
|
|
|
} |
25947
|
|
|
|
|
|
|
} |
25948
|
|
|
|
|
|
|
|
25949
|
|
|
|
|
|
|
static forceinline void |
25950
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
25951
|
|
|
|
|
|
|
{ |
25952
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
25953
|
|
|
|
|
|
|
if (WORDBITS == 32) |
25954
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
25955
|
|
|
|
|
|
|
else |
25956
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
25957
|
|
|
|
|
|
|
} |
25958
|
|
|
|
|
|
|
|
25959
|
|
|
|
|
|
|
|
25960
|
|
|
|
|
|
|
|
25961
|
|
|
|
|
|
|
|
25962
|
|
|
|
|
|
|
|
25963
|
|
|
|
|
|
|
|
25964
|
|
|
|
|
|
|
|
25965
|
|
|
|
|
|
|
static forceinline unsigned |
25966
|
|
|
|
|
|
|
bsr32(u32 v) |
25967
|
|
|
|
|
|
|
{ |
25968
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
25969
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
25970
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
25971
|
|
|
|
|
|
|
unsigned long i; |
25972
|
|
|
|
|
|
|
|
25973
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
25974
|
|
|
|
|
|
|
return i; |
25975
|
|
|
|
|
|
|
#else |
25976
|
|
|
|
|
|
|
unsigned i = 0; |
25977
|
|
|
|
|
|
|
|
25978
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
25979
|
|
|
|
|
|
|
i++; |
25980
|
|
|
|
|
|
|
return i; |
25981
|
|
|
|
|
|
|
#endif |
25982
|
|
|
|
|
|
|
} |
25983
|
|
|
|
|
|
|
|
25984
|
|
|
|
|
|
|
static forceinline unsigned |
25985
|
|
|
|
|
|
|
bsr64(u64 v) |
25986
|
|
|
|
|
|
|
{ |
25987
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
25988
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
25989
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
25990
|
|
|
|
|
|
|
unsigned long i; |
25991
|
|
|
|
|
|
|
|
25992
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
25993
|
|
|
|
|
|
|
return i; |
25994
|
|
|
|
|
|
|
#else |
25995
|
|
|
|
|
|
|
unsigned i = 0; |
25996
|
|
|
|
|
|
|
|
25997
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
25998
|
|
|
|
|
|
|
i++; |
25999
|
|
|
|
|
|
|
return i; |
26000
|
|
|
|
|
|
|
#endif |
26001
|
|
|
|
|
|
|
} |
26002
|
|
|
|
|
|
|
|
26003
|
|
|
|
|
|
|
static forceinline unsigned |
26004
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
26005
|
|
|
|
|
|
|
{ |
26006
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
26007
|
|
|
|
|
|
|
if (WORDBITS == 32) |
26008
|
|
|
|
|
|
|
return bsr32(v); |
26009
|
|
|
|
|
|
|
else |
26010
|
|
|
|
|
|
|
return bsr64(v); |
26011
|
|
|
|
|
|
|
} |
26012
|
|
|
|
|
|
|
|
26013
|
|
|
|
|
|
|
|
26014
|
|
|
|
|
|
|
|
26015
|
|
|
|
|
|
|
static forceinline unsigned |
26016
|
|
|
|
|
|
|
bsf32(u32 v) |
26017
|
|
|
|
|
|
|
{ |
26018
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
26019
|
|
|
|
|
|
|
return __builtin_ctz(v); |
26020
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
26021
|
|
|
|
|
|
|
unsigned long i; |
26022
|
|
|
|
|
|
|
|
26023
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
26024
|
|
|
|
|
|
|
return i; |
26025
|
|
|
|
|
|
|
#else |
26026
|
|
|
|
|
|
|
unsigned i = 0; |
26027
|
|
|
|
|
|
|
|
26028
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
26029
|
|
|
|
|
|
|
i++; |
26030
|
|
|
|
|
|
|
return i; |
26031
|
|
|
|
|
|
|
#endif |
26032
|
|
|
|
|
|
|
} |
26033
|
|
|
|
|
|
|
|
26034
|
|
|
|
|
|
|
static forceinline unsigned |
26035
|
|
|
|
|
|
|
bsf64(u64 v) |
26036
|
|
|
|
|
|
|
{ |
26037
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
26038
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
26039
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
26040
|
|
|
|
|
|
|
unsigned long i; |
26041
|
|
|
|
|
|
|
|
26042
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
26043
|
|
|
|
|
|
|
return i; |
26044
|
|
|
|
|
|
|
#else |
26045
|
|
|
|
|
|
|
unsigned i = 0; |
26046
|
|
|
|
|
|
|
|
26047
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
26048
|
|
|
|
|
|
|
i++; |
26049
|
|
|
|
|
|
|
return i; |
26050
|
|
|
|
|
|
|
#endif |
26051
|
|
|
|
|
|
|
} |
26052
|
|
|
|
|
|
|
|
26053
|
|
|
|
|
|
|
static forceinline unsigned |
26054
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
26055
|
|
|
|
|
|
|
{ |
26056
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
26057
|
|
|
|
|
|
|
if (WORDBITS == 32) |
26058
|
|
|
|
|
|
|
return bsf32(v); |
26059
|
|
|
|
|
|
|
else |
26060
|
|
|
|
|
|
|
return bsf64(v); |
26061
|
|
|
|
|
|
|
} |
26062
|
|
|
|
|
|
|
|
26063
|
|
|
|
|
|
|
|
26064
|
|
|
|
|
|
|
#undef rbit32 |
26065
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
26066
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
26067
|
|
|
|
|
|
|
static forceinline u32 |
26068
|
|
|
|
|
|
|
rbit32(u32 v) |
26069
|
|
|
|
|
|
|
{ |
26070
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
26071
|
|
|
|
|
|
|
return v; |
26072
|
|
|
|
|
|
|
} |
26073
|
|
|
|
|
|
|
#define rbit32 rbit32 |
26074
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
26075
|
|
|
|
|
|
|
static forceinline u32 |
26076
|
|
|
|
|
|
|
rbit32(u32 v) |
26077
|
|
|
|
|
|
|
{ |
26078
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
26079
|
|
|
|
|
|
|
return v; |
26080
|
|
|
|
|
|
|
} |
26081
|
|
|
|
|
|
|
#define rbit32 rbit32 |
26082
|
|
|
|
|
|
|
#endif |
26083
|
|
|
|
|
|
|
|
26084
|
|
|
|
|
|
|
#endif |
26085
|
|
|
|
|
|
|
|
26086
|
|
|
|
|
|
|
|
26087
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
26088
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
26089
|
|
|
|
|
|
|
|
26090
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
26091
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
26092
|
|
|
|
|
|
|
|
26093
|
|
|
|
|
|
|
#ifdef FREESTANDING |
26094
|
|
|
|
|
|
|
|
26095
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
26096
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
26097
|
|
|
|
|
|
|
|
26098
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
26099
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
26100
|
|
|
|
|
|
|
|
26101
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
26102
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
26103
|
|
|
|
|
|
|
|
26104
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
26105
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
26106
|
|
|
|
|
|
|
|
26107
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
26108
|
|
|
|
|
|
|
#else |
26109
|
|
|
|
|
|
|
#include |
26110
|
|
|
|
|
|
|
#endif |
26111
|
|
|
|
|
|
|
|
26112
|
|
|
|
|
|
|
|
26113
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
26114
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
26115
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
26116
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
26117
|
|
|
|
|
|
|
#else |
26118
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
26119
|
|
|
|
|
|
|
#endif |
26120
|
|
|
|
|
|
|
|
26121
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
26122
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
26123
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
26124
|
|
|
|
|
|
|
|
26125
|
|
|
|
|
|
|
#endif |
26126
|
|
|
|
|
|
|
|
26127
|
|
|
|
|
|
|
|
26128
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
26129
|
|
|
|
|
|
|
|
26130
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
26131
|
|
|
|
|
|
|
|
26132
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
26133
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
26134
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
26135
|
|
|
|
|
|
|
#endif |
26136
|
|
|
|
|
|
|
|
26137
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
26138
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
26139
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
26140
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
26141
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
26142
|
|
|
|
|
|
|
|
26143
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
26144
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
26145
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
26146
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
26147
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
26148
|
|
|
|
|
|
|
|
26149
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
26150
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
26151
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
26152
|
|
|
|
|
|
|
|
26153
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
26154
|
|
|
|
|
|
|
|
26155
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
26156
|
|
|
|
|
|
|
{ |
26157
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
26158
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
26159
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
26160
|
|
|
|
|
|
|
} |
26161
|
|
|
|
|
|
|
#else |
26162
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
26163
|
|
|
|
|
|
|
#endif |
26164
|
|
|
|
|
|
|
|
26165
|
|
|
|
|
|
|
|
26166
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
26167
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
26168
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
26169
|
|
|
|
|
|
|
#else |
26170
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
26171
|
|
|
|
|
|
|
#endif |
26172
|
|
|
|
|
|
|
|
26173
|
|
|
|
|
|
|
|
26174
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
26175
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
26176
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
26177
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
26178
|
|
|
|
|
|
|
#else |
26179
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
26180
|
|
|
|
|
|
|
#endif |
26181
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
26182
|
|
|
|
|
|
|
|
26183
|
|
|
|
|
|
|
|
26184
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
26185
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
26186
|
|
|
|
|
|
|
#else |
26187
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
26188
|
|
|
|
|
|
|
#endif |
26189
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
26190
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
26191
|
|
|
|
|
|
|
defined(_MSC_VER))) |
26192
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
26193
|
|
|
|
|
|
|
#else |
26194
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
26195
|
|
|
|
|
|
|
#endif |
26196
|
|
|
|
|
|
|
|
26197
|
|
|
|
|
|
|
|
26198
|
|
|
|
|
|
|
#ifdef __AVX__ |
26199
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
26200
|
|
|
|
|
|
|
#else |
26201
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
26202
|
|
|
|
|
|
|
#endif |
26203
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
26204
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
26205
|
|
|
|
|
|
|
defined(_MSC_VER))) |
26206
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
26207
|
|
|
|
|
|
|
#else |
26208
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
26209
|
|
|
|
|
|
|
#endif |
26210
|
|
|
|
|
|
|
|
26211
|
|
|
|
|
|
|
|
26212
|
|
|
|
|
|
|
#ifdef __AVX2__ |
26213
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
26214
|
|
|
|
|
|
|
#else |
26215
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
26216
|
|
|
|
|
|
|
#endif |
26217
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
26218
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
26219
|
|
|
|
|
|
|
defined(_MSC_VER))) |
26220
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
26221
|
|
|
|
|
|
|
#else |
26222
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
26223
|
|
|
|
|
|
|
#endif |
26224
|
|
|
|
|
|
|
|
26225
|
|
|
|
|
|
|
|
26226
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
26227
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
26228
|
|
|
|
|
|
|
#else |
26229
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
26230
|
|
|
|
|
|
|
#endif |
26231
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
26232
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
26233
|
|
|
|
|
|
|
defined(_MSC_VER))) |
26234
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
26235
|
|
|
|
|
|
|
#else |
26236
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
26237
|
|
|
|
|
|
|
#endif |
26238
|
|
|
|
|
|
|
|
26239
|
|
|
|
|
|
|
#endif |
26240
|
|
|
|
|
|
|
|
26241
|
|
|
|
|
|
|
#endif |
26242
|
|
|
|
|
|
|
|
26243
|
|
|
|
|
|
|
|
26244
|
|
|
|
|
|
|
|
26245
|
|
|
|
|
|
|
#if HAVE_BMI2_INTRIN |
26246
|
|
|
|
|
|
|
# define deflate_decompress_bmi2 deflate_decompress_bmi2 |
26247
|
|
|
|
|
|
|
# define FUNCNAME deflate_decompress_bmi2 |
26248
|
|
|
|
|
|
|
# if !HAVE_BMI2_NATIVE |
26249
|
|
|
|
|
|
|
# define ATTRIBUTES _target_attribute("bmi2") |
26250
|
|
|
|
|
|
|
# endif |
26251
|
|
|
|
|
|
|
|
26252
|
|
|
|
|
|
|
# ifndef __clang__ |
26253
|
|
|
|
|
|
|
# include |
26254
|
|
|
|
|
|
|
# ifdef ARCH_X86_64 |
26255
|
|
|
|
|
|
|
# define EXTRACT_VARBITS(word, count) _bzhi_u64((word), (count)) |
26256
|
|
|
|
|
|
|
# define EXTRACT_VARBITS8(word, count) _bzhi_u64((word), (count)) |
26257
|
|
|
|
|
|
|
# else |
26258
|
|
|
|
|
|
|
# define EXTRACT_VARBITS(word, count) _bzhi_u32((word), (count)) |
26259
|
|
|
|
|
|
|
# define EXTRACT_VARBITS8(word, count) _bzhi_u32((word), (count)) |
26260
|
|
|
|
|
|
|
# endif |
26261
|
|
|
|
|
|
|
# endif |
26262
|
|
|
|
|
|
|
/* #include "decompress_template.h" */ |
26263
|
|
|
|
|
|
|
|
26264
|
|
|
|
|
|
|
|
26265
|
|
|
|
|
|
|
|
26266
|
|
|
|
|
|
|
|
26267
|
|
|
|
|
|
|
#ifndef ATTRIBUTES |
26268
|
|
|
|
|
|
|
# define ATTRIBUTES |
26269
|
|
|
|
|
|
|
#endif |
26270
|
|
|
|
|
|
|
#ifndef EXTRACT_VARBITS |
26271
|
|
|
|
|
|
|
# define EXTRACT_VARBITS(word, count) ((word) & BITMASK(count)) |
26272
|
|
|
|
|
|
|
#endif |
26273
|
|
|
|
|
|
|
#ifndef EXTRACT_VARBITS8 |
26274
|
|
|
|
|
|
|
# define EXTRACT_VARBITS8(word, count) ((word) & BITMASK((u8)(count))) |
26275
|
|
|
|
|
|
|
#endif |
26276
|
|
|
|
|
|
|
|
26277
|
|
|
|
|
|
|
static enum libdeflate_result ATTRIBUTES MAYBE_UNUSED |
26278
|
0
|
|
|
|
|
|
FUNCNAME(struct libdeflate_decompressor * restrict d, |
26279
|
|
|
|
|
|
|
const void * restrict in, size_t in_nbytes, |
26280
|
|
|
|
|
|
|
void * restrict out, size_t out_nbytes_avail, |
26281
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret) |
26282
|
|
|
|
|
|
|
{ |
26283
|
0
|
|
|
|
|
|
u8 *out_next = out; |
26284
|
0
|
|
|
|
|
|
u8 * const out_end = out_next + out_nbytes_avail; |
26285
|
0
|
|
|
|
|
|
u8 * const out_fastloop_end = |
26286
|
0
|
|
|
|
|
|
out_end - MIN(out_nbytes_avail, FASTLOOP_MAX_BYTES_WRITTEN); |
26287
|
|
|
|
|
|
|
|
26288
|
|
|
|
|
|
|
|
26289
|
0
|
|
|
|
|
|
const u8 *in_next = in; |
26290
|
0
|
|
|
|
|
|
const u8 * const in_end = in_next + in_nbytes; |
26291
|
0
|
|
|
|
|
|
const u8 * const in_fastloop_end = |
26292
|
0
|
|
|
|
|
|
in_end - MIN(in_nbytes, FASTLOOP_MAX_BYTES_READ); |
26293
|
0
|
|
|
|
|
|
bitbuf_t bitbuf = 0; |
26294
|
|
|
|
|
|
|
bitbuf_t saved_bitbuf; |
26295
|
0
|
|
|
|
|
|
u32 bitsleft = 0; |
26296
|
0
|
|
|
|
|
|
size_t overread_count = 0; |
26297
|
|
|
|
|
|
|
|
26298
|
|
|
|
|
|
|
bool is_final_block; |
26299
|
|
|
|
|
|
|
unsigned block_type; |
26300
|
|
|
|
|
|
|
unsigned num_litlen_syms; |
26301
|
|
|
|
|
|
|
unsigned num_offset_syms; |
26302
|
|
|
|
|
|
|
bitbuf_t litlen_tablemask; |
26303
|
|
|
|
|
|
|
u32 entry; |
26304
|
|
|
|
|
|
|
|
26305
|
|
|
|
|
|
|
next_block: |
26306
|
|
|
|
|
|
|
|
26307
|
|
|
|
|
|
|
; |
26308
|
|
|
|
|
|
|
|
26309
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME(1 + 2 + 5 + 5 + 4 + 3)); |
26310
|
0
|
0
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26311
|
|
|
|
|
|
|
|
26312
|
|
|
|
|
|
|
|
26313
|
0
|
|
|
|
|
|
is_final_block = bitbuf & BITMASK(1); |
26314
|
|
|
|
|
|
|
|
26315
|
|
|
|
|
|
|
|
26316
|
0
|
|
|
|
|
|
block_type = (bitbuf >> 1) & BITMASK(2); |
26317
|
|
|
|
|
|
|
|
26318
|
0
|
0
|
|
|
|
|
if (block_type == DEFLATE_BLOCKTYPE_DYNAMIC_HUFFMAN) { |
26319
|
|
|
|
|
|
|
|
26320
|
|
|
|
|
|
|
|
26321
|
|
|
|
|
|
|
|
26322
|
|
|
|
|
|
|
|
26323
|
|
|
|
|
|
|
static const u8 deflate_precode_lens_permutation[DEFLATE_NUM_PRECODE_SYMS] = { |
26324
|
|
|
|
|
|
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
26325
|
|
|
|
|
|
|
}; |
26326
|
|
|
|
|
|
|
|
26327
|
|
|
|
|
|
|
unsigned num_explicit_precode_lens; |
26328
|
|
|
|
|
|
|
unsigned i; |
26329
|
|
|
|
|
|
|
|
26330
|
|
|
|
|
|
|
|
26331
|
|
|
|
|
|
|
|
26332
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_LITLEN_SYMS == 257 + BITMASK(5)); |
26333
|
0
|
|
|
|
|
|
num_litlen_syms = 257 + ((bitbuf >> 3) & BITMASK(5)); |
26334
|
|
|
|
|
|
|
|
26335
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_OFFSET_SYMS == 1 + BITMASK(5)); |
26336
|
0
|
|
|
|
|
|
num_offset_syms = 1 + ((bitbuf >> 8) & BITMASK(5)); |
26337
|
|
|
|
|
|
|
|
26338
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_PRECODE_SYMS == 4 + BITMASK(4)); |
26339
|
0
|
|
|
|
|
|
num_explicit_precode_lens = 4 + ((bitbuf >> 13) & BITMASK(4)); |
26340
|
|
|
|
|
|
|
|
26341
|
0
|
|
|
|
|
|
d->static_codes_loaded = false; |
26342
|
|
|
|
|
|
|
|
26343
|
|
|
|
|
|
|
|
26344
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_PRE_CODEWORD_LEN == (1 << 3) - 1); |
26345
|
|
|
|
|
|
|
if (CAN_CONSUME(3 * (DEFLATE_NUM_PRECODE_SYMS - 1))) { |
26346
|
0
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[0]] = |
26347
|
0
|
|
|
|
|
|
(bitbuf >> 17) & BITMASK(3); |
26348
|
0
|
|
|
|
|
|
bitbuf >>= 20; |
26349
|
0
|
|
|
|
|
|
bitsleft -= 20; |
26350
|
0
|
0
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26351
|
0
|
|
|
|
|
|
i = 1; |
26352
|
|
|
|
|
|
|
do { |
26353
|
0
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = |
26354
|
|
|
|
|
|
|
bitbuf & BITMASK(3); |
26355
|
0
|
|
|
|
|
|
bitbuf >>= 3; |
26356
|
0
|
|
|
|
|
|
bitsleft -= 3; |
26357
|
0
|
0
|
|
|
|
|
} while (++i < num_explicit_precode_lens); |
26358
|
|
|
|
|
|
|
} else { |
26359
|
|
|
|
|
|
|
bitbuf >>= 17; |
26360
|
|
|
|
|
|
|
bitsleft -= 17; |
26361
|
|
|
|
|
|
|
i = 0; |
26362
|
|
|
|
|
|
|
do { |
26363
|
|
|
|
|
|
|
if ((u8)bitsleft < 3) |
26364
|
|
|
|
|
|
|
REFILL_BITS(); |
26365
|
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = |
26366
|
|
|
|
|
|
|
bitbuf & BITMASK(3); |
26367
|
|
|
|
|
|
|
bitbuf >>= 3; |
26368
|
|
|
|
|
|
|
bitsleft -= 3; |
26369
|
|
|
|
|
|
|
} while (++i < num_explicit_precode_lens); |
26370
|
|
|
|
|
|
|
} |
26371
|
0
|
0
|
|
|
|
|
for (; i < DEFLATE_NUM_PRECODE_SYMS; i++) |
26372
|
0
|
|
|
|
|
|
d->u.precode_lens[deflate_precode_lens_permutation[i]] = 0; |
26373
|
|
|
|
|
|
|
|
26374
|
|
|
|
|
|
|
|
26375
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(build_precode_decode_table(d)); |
26376
|
|
|
|
|
|
|
|
26377
|
|
|
|
|
|
|
|
26378
|
0
|
|
|
|
|
|
i = 0; |
26379
|
|
|
|
|
|
|
do { |
26380
|
|
|
|
|
|
|
unsigned presym; |
26381
|
|
|
|
|
|
|
u8 rep_val; |
26382
|
|
|
|
|
|
|
unsigned rep_count; |
26383
|
|
|
|
|
|
|
|
26384
|
0
|
0
|
|
|
|
|
if ((u8)bitsleft < DEFLATE_MAX_PRE_CODEWORD_LEN + 7) |
26385
|
0
|
0
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26386
|
|
|
|
|
|
|
|
26387
|
|
|
|
|
|
|
|
26388
|
|
|
|
|
|
|
STATIC_ASSERT(PRECODE_TABLEBITS == DEFLATE_MAX_PRE_CODEWORD_LEN); |
26389
|
|
|
|
|
|
|
|
26390
|
|
|
|
|
|
|
|
26391
|
0
|
|
|
|
|
|
entry = d->u.l.precode_decode_table[ |
26392
|
0
|
|
|
|
|
|
bitbuf & BITMASK(DEFLATE_MAX_PRE_CODEWORD_LEN)]; |
26393
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26394
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26395
|
0
|
|
|
|
|
|
presym = entry >> 16; |
26396
|
|
|
|
|
|
|
|
26397
|
0
|
0
|
|
|
|
|
if (presym < 16) { |
26398
|
|
|
|
|
|
|
|
26399
|
0
|
|
|
|
|
|
d->u.l.lens[i++] = presym; |
26400
|
0
|
|
|
|
|
|
continue; |
26401
|
|
|
|
|
|
|
} |
26402
|
|
|
|
|
|
|
|
26403
|
|
|
|
|
|
|
|
26404
|
|
|
|
|
|
|
|
26405
|
|
|
|
|
|
|
|
26406
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MAX_LENS_OVERRUN == 138 - 1); |
26407
|
|
|
|
|
|
|
|
26408
|
0
|
0
|
|
|
|
|
if (presym == 16) { |
26409
|
|
|
|
|
|
|
|
26410
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(i != 0); |
26411
|
0
|
|
|
|
|
|
rep_val = d->u.l.lens[i - 1]; |
26412
|
|
|
|
|
|
|
STATIC_ASSERT(3 + BITMASK(2) == 6); |
26413
|
0
|
|
|
|
|
|
rep_count = 3 + (bitbuf & BITMASK(2)); |
26414
|
0
|
|
|
|
|
|
bitbuf >>= 2; |
26415
|
0
|
|
|
|
|
|
bitsleft -= 2; |
26416
|
0
|
|
|
|
|
|
d->u.l.lens[i + 0] = rep_val; |
26417
|
0
|
|
|
|
|
|
d->u.l.lens[i + 1] = rep_val; |
26418
|
0
|
|
|
|
|
|
d->u.l.lens[i + 2] = rep_val; |
26419
|
0
|
|
|
|
|
|
d->u.l.lens[i + 3] = rep_val; |
26420
|
0
|
|
|
|
|
|
d->u.l.lens[i + 4] = rep_val; |
26421
|
0
|
|
|
|
|
|
d->u.l.lens[i + 5] = rep_val; |
26422
|
0
|
|
|
|
|
|
i += rep_count; |
26423
|
0
|
0
|
|
|
|
|
} else if (presym == 17) { |
26424
|
|
|
|
|
|
|
|
26425
|
|
|
|
|
|
|
STATIC_ASSERT(3 + BITMASK(3) == 10); |
26426
|
0
|
|
|
|
|
|
rep_count = 3 + (bitbuf & BITMASK(3)); |
26427
|
0
|
|
|
|
|
|
bitbuf >>= 3; |
26428
|
0
|
|
|
|
|
|
bitsleft -= 3; |
26429
|
0
|
|
|
|
|
|
d->u.l.lens[i + 0] = 0; |
26430
|
0
|
|
|
|
|
|
d->u.l.lens[i + 1] = 0; |
26431
|
0
|
|
|
|
|
|
d->u.l.lens[i + 2] = 0; |
26432
|
0
|
|
|
|
|
|
d->u.l.lens[i + 3] = 0; |
26433
|
0
|
|
|
|
|
|
d->u.l.lens[i + 4] = 0; |
26434
|
0
|
|
|
|
|
|
d->u.l.lens[i + 5] = 0; |
26435
|
0
|
|
|
|
|
|
d->u.l.lens[i + 6] = 0; |
26436
|
0
|
|
|
|
|
|
d->u.l.lens[i + 7] = 0; |
26437
|
0
|
|
|
|
|
|
d->u.l.lens[i + 8] = 0; |
26438
|
0
|
|
|
|
|
|
d->u.l.lens[i + 9] = 0; |
26439
|
0
|
|
|
|
|
|
i += rep_count; |
26440
|
|
|
|
|
|
|
} else { |
26441
|
|
|
|
|
|
|
|
26442
|
|
|
|
|
|
|
STATIC_ASSERT(11 + BITMASK(7) == 138); |
26443
|
0
|
|
|
|
|
|
rep_count = 11 + (bitbuf & BITMASK(7)); |
26444
|
0
|
|
|
|
|
|
bitbuf >>= 7; |
26445
|
0
|
|
|
|
|
|
bitsleft -= 7; |
26446
|
0
|
|
|
|
|
|
memset(&d->u.l.lens[i], 0, |
26447
|
|
|
|
|
|
|
rep_count * sizeof(d->u.l.lens[i])); |
26448
|
0
|
|
|
|
|
|
i += rep_count; |
26449
|
|
|
|
|
|
|
} |
26450
|
0
|
0
|
|
|
|
|
} while (i < num_litlen_syms + num_offset_syms); |
26451
|
|
|
|
|
|
|
|
26452
|
|
|
|
|
|
|
|
26453
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(i == num_litlen_syms + num_offset_syms); |
26454
|
|
|
|
|
|
|
|
26455
|
0
|
0
|
|
|
|
|
} else if (block_type == DEFLATE_BLOCKTYPE_UNCOMPRESSED) { |
26456
|
|
|
|
|
|
|
u16 len, nlen; |
26457
|
|
|
|
|
|
|
|
26458
|
|
|
|
|
|
|
|
26459
|
|
|
|
|
|
|
|
26460
|
0
|
|
|
|
|
|
bitsleft -= 3; |
26461
|
|
|
|
|
|
|
|
26462
|
|
|
|
|
|
|
|
26463
|
0
|
|
|
|
|
|
bitsleft = (u8)bitsleft; |
26464
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(overread_count <= (bitsleft >> 3)); |
26465
|
0
|
|
|
|
|
|
in_next -= (bitsleft >> 3) - overread_count; |
26466
|
0
|
|
|
|
|
|
overread_count = 0; |
26467
|
0
|
|
|
|
|
|
bitbuf = 0; |
26468
|
0
|
|
|
|
|
|
bitsleft = 0; |
26469
|
|
|
|
|
|
|
|
26470
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(in_end - in_next >= 4); |
26471
|
0
|
|
|
|
|
|
len = get_unaligned_le16(in_next); |
26472
|
0
|
|
|
|
|
|
nlen = get_unaligned_le16(in_next + 2); |
26473
|
0
|
|
|
|
|
|
in_next += 4; |
26474
|
|
|
|
|
|
|
|
26475
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(len == (u16)~nlen); |
26476
|
0
|
0
|
|
|
|
|
if (unlikely(len > out_end - out_next)) |
26477
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
26478
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(len <= in_end - in_next); |
26479
|
|
|
|
|
|
|
|
26480
|
0
|
|
|
|
|
|
memcpy(out_next, in_next, len); |
26481
|
0
|
|
|
|
|
|
in_next += len; |
26482
|
0
|
|
|
|
|
|
out_next += len; |
26483
|
|
|
|
|
|
|
|
26484
|
0
|
|
|
|
|
|
goto block_done; |
26485
|
|
|
|
|
|
|
|
26486
|
|
|
|
|
|
|
} else { |
26487
|
|
|
|
|
|
|
unsigned i; |
26488
|
|
|
|
|
|
|
|
26489
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(block_type == DEFLATE_BLOCKTYPE_STATIC_HUFFMAN); |
26490
|
|
|
|
|
|
|
|
26491
|
|
|
|
|
|
|
|
26492
|
|
|
|
|
|
|
|
26493
|
0
|
|
|
|
|
|
bitbuf >>= 3; |
26494
|
0
|
|
|
|
|
|
bitsleft -= 3; |
26495
|
|
|
|
|
|
|
|
26496
|
0
|
0
|
|
|
|
|
if (d->static_codes_loaded) |
26497
|
0
|
|
|
|
|
|
goto have_decode_tables; |
26498
|
|
|
|
|
|
|
|
26499
|
0
|
|
|
|
|
|
d->static_codes_loaded = true; |
26500
|
|
|
|
|
|
|
|
26501
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_LITLEN_SYMS == 288); |
26502
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_NUM_OFFSET_SYMS == 32); |
26503
|
|
|
|
|
|
|
|
26504
|
0
|
0
|
|
|
|
|
for (i = 0; i < 144; i++) |
26505
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 8; |
26506
|
0
|
0
|
|
|
|
|
for (; i < 256; i++) |
26507
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 9; |
26508
|
0
|
0
|
|
|
|
|
for (; i < 280; i++) |
26509
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 7; |
26510
|
0
|
0
|
|
|
|
|
for (; i < 288; i++) |
26511
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 8; |
26512
|
|
|
|
|
|
|
|
26513
|
0
|
0
|
|
|
|
|
for (; i < 288 + 32; i++) |
26514
|
0
|
|
|
|
|
|
d->u.l.lens[i] = 5; |
26515
|
|
|
|
|
|
|
|
26516
|
0
|
|
|
|
|
|
num_litlen_syms = 288; |
26517
|
0
|
|
|
|
|
|
num_offset_syms = 32; |
26518
|
|
|
|
|
|
|
} |
26519
|
|
|
|
|
|
|
|
26520
|
|
|
|
|
|
|
|
26521
|
|
|
|
|
|
|
|
26522
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(build_offset_decode_table(d, num_litlen_syms, num_offset_syms)); |
26523
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(build_litlen_decode_table(d, num_litlen_syms, num_offset_syms)); |
26524
|
|
|
|
|
|
|
have_decode_tables: |
26525
|
0
|
|
|
|
|
|
litlen_tablemask = BITMASK(d->litlen_tablebits); |
26526
|
|
|
|
|
|
|
|
26527
|
|
|
|
|
|
|
|
26528
|
0
|
0
|
|
|
|
|
if (in_next >= in_fastloop_end || out_next >= out_fastloop_end) |
|
|
0
|
|
|
|
|
|
26529
|
|
|
|
|
|
|
goto generic_loop; |
26530
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26531
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
26532
|
|
|
|
|
|
|
do { |
26533
|
|
|
|
|
|
|
u32 length, offset, lit; |
26534
|
|
|
|
|
|
|
const u8 *src; |
26535
|
|
|
|
|
|
|
u8 *dst; |
26536
|
|
|
|
|
|
|
|
26537
|
|
|
|
|
|
|
|
26538
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
26539
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26540
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26541
|
|
|
|
|
|
|
|
26542
|
|
|
|
|
|
|
|
26543
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
26544
|
|
|
|
|
|
|
|
26545
|
|
|
|
|
|
|
if ( |
26546
|
|
|
|
|
|
|
CAN_CONSUME_AND_THEN_PRELOAD(2 * LITLEN_TABLEBITS + |
26547
|
|
|
|
|
|
|
LENGTH_MAXBITS, |
26548
|
|
|
|
|
|
|
OFFSET_TABLEBITS) && |
26549
|
|
|
|
|
|
|
|
26550
|
|
|
|
|
|
|
CAN_CONSUME_AND_THEN_PRELOAD(2 * LITLEN_TABLEBITS + |
26551
|
|
|
|
|
|
|
DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
26552
|
|
|
|
|
|
|
LITLEN_TABLEBITS)) { |
26553
|
|
|
|
|
|
|
|
26554
|
0
|
|
|
|
|
|
lit = entry >> 16; |
26555
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
26556
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
26557
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26558
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26559
|
0
|
|
|
|
|
|
*out_next++ = lit; |
26560
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
26561
|
|
|
|
|
|
|
|
26562
|
0
|
|
|
|
|
|
lit = entry >> 16; |
26563
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
26564
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
26565
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26566
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26567
|
0
|
|
|
|
|
|
*out_next++ = lit; |
26568
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
26569
|
|
|
|
|
|
|
|
26570
|
0
|
|
|
|
|
|
lit = entry >> 16; |
26571
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
26572
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26573
|
0
|
|
|
|
|
|
*out_next++ = lit; |
26574
|
0
|
|
|
|
|
|
continue; |
26575
|
|
|
|
|
|
|
} |
26576
|
|
|
|
|
|
|
} |
26577
|
|
|
|
|
|
|
} else { |
26578
|
|
|
|
|
|
|
|
26579
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME_AND_THEN_PRELOAD( |
26580
|
|
|
|
|
|
|
LITLEN_TABLEBITS, LITLEN_TABLEBITS)); |
26581
|
|
|
|
|
|
|
lit = entry >> 16; |
26582
|
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
26583
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26584
|
|
|
|
|
|
|
*out_next++ = lit; |
26585
|
|
|
|
|
|
|
continue; |
26586
|
|
|
|
|
|
|
} |
26587
|
|
|
|
|
|
|
} |
26588
|
|
|
|
|
|
|
|
26589
|
|
|
|
|
|
|
|
26590
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
26591
|
|
|
|
|
|
|
|
26592
|
|
|
|
|
|
|
|
26593
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
26594
|
0
|
|
|
|
|
|
goto block_done; |
26595
|
|
|
|
|
|
|
|
26596
|
|
|
|
|
|
|
|
26597
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[(entry >> 16) + |
26598
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
26599
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
26600
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26601
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26602
|
|
|
|
|
|
|
|
26603
|
|
|
|
|
|
|
|
26604
|
|
|
|
|
|
|
if (!CAN_CONSUME_AND_THEN_PRELOAD(DEFLATE_MAX_LITLEN_CODEWORD_LEN, |
26605
|
|
|
|
|
|
|
LITLEN_TABLEBITS) || |
26606
|
|
|
|
|
|
|
!CAN_CONSUME_AND_THEN_PRELOAD(LENGTH_MAXBITS, |
26607
|
|
|
|
|
|
|
OFFSET_TABLEBITS)) |
26608
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26609
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
26610
|
|
|
|
|
|
|
|
26611
|
0
|
|
|
|
|
|
lit = entry >> 16; |
26612
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
26613
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26614
|
0
|
|
|
|
|
|
*out_next++ = lit; |
26615
|
0
|
|
|
|
|
|
continue; |
26616
|
|
|
|
|
|
|
} |
26617
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
26618
|
0
|
|
|
|
|
|
goto block_done; |
26619
|
|
|
|
|
|
|
|
26620
|
|
|
|
|
|
|
} |
26621
|
|
|
|
|
|
|
|
26622
|
|
|
|
|
|
|
|
26623
|
0
|
|
|
|
|
|
length = entry >> 16; |
26624
|
0
|
|
|
|
|
|
length += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
26625
|
|
|
|
|
|
|
|
26626
|
|
|
|
|
|
|
|
26627
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME_AND_THEN_PRELOAD(LENGTH_MAXFASTBITS, |
26628
|
|
|
|
|
|
|
OFFSET_TABLEBITS)); |
26629
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[bitbuf & BITMASK(OFFSET_TABLEBITS)]; |
26630
|
|
|
|
|
|
|
if (CAN_CONSUME_AND_THEN_PRELOAD(OFFSET_MAXBITS, |
26631
|
|
|
|
|
|
|
LITLEN_TABLEBITS)) { |
26632
|
|
|
|
|
|
|
|
26633
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
26634
|
|
|
|
|
|
|
|
26635
|
0
|
0
|
|
|
|
|
if (unlikely((u8)bitsleft < OFFSET_MAXBITS + |
26636
|
|
|
|
|
|
|
LITLEN_TABLEBITS - PRELOAD_SLACK)) |
26637
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26638
|
0
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
26639
|
0
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
26640
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
26641
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
26642
|
0
|
0
|
|
|
|
|
} else if (unlikely((u8)bitsleft < OFFSET_MAXFASTBITS + |
26643
|
|
|
|
|
|
|
LITLEN_TABLEBITS - PRELOAD_SLACK)) |
26644
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26645
|
|
|
|
|
|
|
} else { |
26646
|
|
|
|
|
|
|
|
26647
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26648
|
|
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
26649
|
|
|
|
|
|
|
|
26650
|
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
26651
|
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
26652
|
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
26653
|
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
26654
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26655
|
|
|
|
|
|
|
|
26656
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME( |
26657
|
|
|
|
|
|
|
OFFSET_MAXBITS - OFFSET_TABLEBITS)); |
26658
|
|
|
|
|
|
|
} else { |
26659
|
|
|
|
|
|
|
|
26660
|
|
|
|
|
|
|
STATIC_ASSERT(CAN_CONSUME(OFFSET_MAXFASTBITS)); |
26661
|
|
|
|
|
|
|
} |
26662
|
|
|
|
|
|
|
} |
26663
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
26664
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26665
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26666
|
0
|
|
|
|
|
|
offset = entry >> 16; |
26667
|
0
|
|
|
|
|
|
offset += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
26668
|
|
|
|
|
|
|
|
26669
|
|
|
|
|
|
|
|
26670
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(offset <= out_next - (const u8 *)out); |
26671
|
0
|
|
|
|
|
|
src = out_next - offset; |
26672
|
0
|
|
|
|
|
|
dst = out_next; |
26673
|
0
|
|
|
|
|
|
out_next += length; |
26674
|
|
|
|
|
|
|
|
26675
|
|
|
|
|
|
|
|
26676
|
|
|
|
|
|
|
if (!CAN_CONSUME_AND_THEN_PRELOAD( |
26677
|
|
|
|
|
|
|
MAX(OFFSET_MAXBITS - OFFSET_TABLEBITS, |
26678
|
|
|
|
|
|
|
OFFSET_MAXFASTBITS), |
26679
|
|
|
|
|
|
|
LITLEN_TABLEBITS) && |
26680
|
|
|
|
|
|
|
unlikely((u8)bitsleft < LITLEN_TABLEBITS - PRELOAD_SLACK)) |
26681
|
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26682
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
26683
|
0
|
|
|
|
|
|
REFILL_BITS_IN_FASTLOOP(); |
26684
|
|
|
|
|
|
|
|
26685
|
|
|
|
|
|
|
|
26686
|
0
|
0
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST && offset >= WORDBYTES) { |
26687
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26688
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26689
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26690
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26691
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26692
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26693
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26694
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26695
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26696
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26697
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26698
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26699
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26700
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26701
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26702
|
0
|
0
|
|
|
|
|
while (dst < out_next) { |
26703
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26704
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26705
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26706
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26707
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26708
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26709
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26710
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26711
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26712
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26713
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26714
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26715
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26716
|
0
|
|
|
|
|
|
src += WORDBYTES; |
26717
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26718
|
|
|
|
|
|
|
} |
26719
|
0
|
0
|
|
|
|
|
} else if (UNALIGNED_ACCESS_IS_FAST && offset == 1) { |
26720
|
|
|
|
|
|
|
machine_word_t v; |
26721
|
|
|
|
|
|
|
|
26722
|
|
|
|
|
|
|
|
26723
|
0
|
|
|
|
|
|
v = (machine_word_t)0x0101010101010101 * src[0]; |
26724
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
26725
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26726
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
26727
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26728
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
26729
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26730
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
26731
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26732
|
0
|
0
|
|
|
|
|
while (dst < out_next) { |
26733
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
26734
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26735
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
26736
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26737
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
26738
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26739
|
|
|
|
|
|
|
store_word_unaligned(v, dst); |
26740
|
0
|
|
|
|
|
|
dst += WORDBYTES; |
26741
|
|
|
|
|
|
|
} |
26742
|
|
|
|
|
|
|
} else if (UNALIGNED_ACCESS_IS_FAST) { |
26743
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26744
|
0
|
|
|
|
|
|
src += offset; |
26745
|
0
|
|
|
|
|
|
dst += offset; |
26746
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26747
|
0
|
|
|
|
|
|
src += offset; |
26748
|
0
|
|
|
|
|
|
dst += offset; |
26749
|
|
|
|
|
|
|
do { |
26750
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26751
|
0
|
|
|
|
|
|
src += offset; |
26752
|
0
|
|
|
|
|
|
dst += offset; |
26753
|
0
|
|
|
|
|
|
store_word_unaligned(load_word_unaligned(src), dst); |
26754
|
0
|
|
|
|
|
|
src += offset; |
26755
|
0
|
|
|
|
|
|
dst += offset; |
26756
|
0
|
0
|
|
|
|
|
} while (dst < out_next); |
26757
|
|
|
|
|
|
|
} else { |
26758
|
|
|
|
|
|
|
*dst++ = *src++; |
26759
|
|
|
|
|
|
|
*dst++ = *src++; |
26760
|
|
|
|
|
|
|
do { |
26761
|
|
|
|
|
|
|
*dst++ = *src++; |
26762
|
|
|
|
|
|
|
} while (dst < out_next); |
26763
|
|
|
|
|
|
|
} |
26764
|
0
|
0
|
|
|
|
|
} while (in_next < in_fastloop_end && out_next < out_fastloop_end); |
|
|
0
|
|
|
|
|
|
26765
|
|
|
|
|
|
|
|
26766
|
|
|
|
|
|
|
|
26767
|
|
|
|
|
|
|
generic_loop: |
26768
|
|
|
|
|
|
|
for (;;) { |
26769
|
|
|
|
|
|
|
u32 length, offset; |
26770
|
|
|
|
|
|
|
const u8 *src; |
26771
|
|
|
|
|
|
|
u8 *dst; |
26772
|
|
|
|
|
|
|
|
26773
|
0
|
0
|
|
|
|
|
REFILL_BITS(); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26774
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[bitbuf & litlen_tablemask]; |
26775
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
26776
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26777
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26778
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_SUBTABLE_POINTER)) { |
26779
|
0
|
|
|
|
|
|
entry = d->u.litlen_decode_table[(entry >> 16) + |
26780
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
26781
|
0
|
|
|
|
|
|
saved_bitbuf = bitbuf; |
26782
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26783
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26784
|
|
|
|
|
|
|
} |
26785
|
0
|
|
|
|
|
|
length = entry >> 16; |
26786
|
0
|
0
|
|
|
|
|
if (entry & HUFFDEC_LITERAL) { |
26787
|
0
|
0
|
|
|
|
|
if (unlikely(out_next == out_end)) |
26788
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
26789
|
0
|
|
|
|
|
|
*out_next++ = length; |
26790
|
0
|
|
|
|
|
|
continue; |
26791
|
|
|
|
|
|
|
} |
26792
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_END_OF_BLOCK)) |
26793
|
0
|
|
|
|
|
|
goto block_done; |
26794
|
0
|
|
|
|
|
|
length += EXTRACT_VARBITS8(saved_bitbuf, entry) >> (u8)(entry >> 8); |
26795
|
0
|
0
|
|
|
|
|
if (unlikely(length > out_end - out_next)) |
26796
|
0
|
|
|
|
|
|
return LIBDEFLATE_INSUFFICIENT_SPACE; |
26797
|
|
|
|
|
|
|
|
26798
|
|
|
|
|
|
|
if (!CAN_CONSUME(LENGTH_MAXBITS + OFFSET_MAXBITS)) |
26799
|
|
|
|
|
|
|
REFILL_BITS(); |
26800
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[bitbuf & BITMASK(OFFSET_TABLEBITS)]; |
26801
|
0
|
0
|
|
|
|
|
if (unlikely(entry & HUFFDEC_EXCEPTIONAL)) { |
26802
|
0
|
|
|
|
|
|
bitbuf >>= OFFSET_TABLEBITS; |
26803
|
0
|
|
|
|
|
|
bitsleft -= OFFSET_TABLEBITS; |
26804
|
0
|
|
|
|
|
|
entry = d->offset_decode_table[(entry >> 16) + |
26805
|
0
|
|
|
|
|
|
EXTRACT_VARBITS(bitbuf, (entry >> 8) & 0x3F)]; |
26806
|
|
|
|
|
|
|
if (!CAN_CONSUME(OFFSET_MAXBITS)) |
26807
|
|
|
|
|
|
|
REFILL_BITS(); |
26808
|
|
|
|
|
|
|
} |
26809
|
0
|
|
|
|
|
|
offset = entry >> 16; |
26810
|
0
|
|
|
|
|
|
offset += EXTRACT_VARBITS8(bitbuf, entry) >> (u8)(entry >> 8); |
26811
|
0
|
|
|
|
|
|
bitbuf >>= (u8)entry; |
26812
|
0
|
|
|
|
|
|
bitsleft -= entry; |
26813
|
|
|
|
|
|
|
|
26814
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(offset <= out_next - (const u8 *)out); |
26815
|
0
|
|
|
|
|
|
src = out_next - offset; |
26816
|
0
|
|
|
|
|
|
dst = out_next; |
26817
|
0
|
|
|
|
|
|
out_next += length; |
26818
|
|
|
|
|
|
|
|
26819
|
|
|
|
|
|
|
STATIC_ASSERT(DEFLATE_MIN_MATCH_LEN == 3); |
26820
|
0
|
|
|
|
|
|
*dst++ = *src++; |
26821
|
0
|
|
|
|
|
|
*dst++ = *src++; |
26822
|
|
|
|
|
|
|
do { |
26823
|
0
|
|
|
|
|
|
*dst++ = *src++; |
26824
|
0
|
0
|
|
|
|
|
} while (dst < out_next); |
26825
|
0
|
|
|
|
|
|
} |
26826
|
|
|
|
|
|
|
|
26827
|
|
|
|
|
|
|
block_done: |
26828
|
|
|
|
|
|
|
|
26829
|
|
|
|
|
|
|
|
26830
|
0
|
0
|
|
|
|
|
if (!is_final_block) |
26831
|
0
|
|
|
|
|
|
goto next_block; |
26832
|
|
|
|
|
|
|
|
26833
|
|
|
|
|
|
|
|
26834
|
|
|
|
|
|
|
|
26835
|
0
|
|
|
|
|
|
bitsleft = (u8)bitsleft; |
26836
|
|
|
|
|
|
|
|
26837
|
|
|
|
|
|
|
|
26838
|
0
|
0
|
|
|
|
|
SAFETY_CHECK(overread_count <= (bitsleft >> 3)); |
26839
|
|
|
|
|
|
|
|
26840
|
|
|
|
|
|
|
|
26841
|
0
|
0
|
|
|
|
|
if (actual_in_nbytes_ret) { |
26842
|
|
|
|
|
|
|
|
26843
|
0
|
|
|
|
|
|
in_next -= (bitsleft >> 3) - overread_count; |
26844
|
|
|
|
|
|
|
|
26845
|
0
|
|
|
|
|
|
*actual_in_nbytes_ret = in_next - (u8 *)in; |
26846
|
|
|
|
|
|
|
} |
26847
|
|
|
|
|
|
|
|
26848
|
|
|
|
|
|
|
|
26849
|
0
|
0
|
|
|
|
|
if (actual_out_nbytes_ret) { |
26850
|
0
|
|
|
|
|
|
*actual_out_nbytes_ret = out_next - (u8 *)out; |
26851
|
|
|
|
|
|
|
} else { |
26852
|
0
|
0
|
|
|
|
|
if (out_next != out_end) |
26853
|
0
|
|
|
|
|
|
return LIBDEFLATE_SHORT_OUTPUT; |
26854
|
|
|
|
|
|
|
} |
26855
|
0
|
|
|
|
|
|
return LIBDEFLATE_SUCCESS; |
26856
|
|
|
|
|
|
|
} |
26857
|
|
|
|
|
|
|
|
26858
|
|
|
|
|
|
|
#undef FUNCNAME |
26859
|
|
|
|
|
|
|
#undef ATTRIBUTES |
26860
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS |
26861
|
|
|
|
|
|
|
#undef EXTRACT_VARBITS8 |
26862
|
|
|
|
|
|
|
|
26863
|
|
|
|
|
|
|
#endif |
26864
|
|
|
|
|
|
|
|
26865
|
|
|
|
|
|
|
#if defined(deflate_decompress_bmi2) && HAVE_BMI2_NATIVE |
26866
|
|
|
|
|
|
|
#define DEFAULT_IMPL deflate_decompress_bmi2 |
26867
|
|
|
|
|
|
|
#else |
26868
|
|
|
|
|
|
|
static inline decompress_func_t |
26869
|
2
|
|
|
|
|
|
arch_select_decompress_func(void) |
26870
|
|
|
|
|
|
|
{ |
26871
|
|
|
|
|
|
|
#ifdef deflate_decompress_bmi2 |
26872
|
2
|
50
|
|
|
|
|
if (HAVE_BMI2(get_x86_cpu_features())) |
26873
|
0
|
|
|
|
|
|
return deflate_decompress_bmi2; |
26874
|
|
|
|
|
|
|
#endif |
26875
|
2
|
|
|
|
|
|
return NULL; |
26876
|
|
|
|
|
|
|
} |
26877
|
|
|
|
|
|
|
#define arch_select_decompress_func arch_select_decompress_func |
26878
|
|
|
|
|
|
|
#endif |
26879
|
|
|
|
|
|
|
|
26880
|
|
|
|
|
|
|
#endif |
26881
|
|
|
|
|
|
|
|
26882
|
|
|
|
|
|
|
#endif |
26883
|
|
|
|
|
|
|
|
26884
|
|
|
|
|
|
|
#ifndef DEFAULT_IMPL |
26885
|
|
|
|
|
|
|
# define DEFAULT_IMPL deflate_decompress_default |
26886
|
|
|
|
|
|
|
#endif |
26887
|
|
|
|
|
|
|
|
26888
|
|
|
|
|
|
|
#ifdef arch_select_decompress_func |
26889
|
|
|
|
|
|
|
static enum libdeflate_result |
26890
|
|
|
|
|
|
|
dispatch_decomp(struct libdeflate_decompressor *d, |
26891
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
26892
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
26893
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret); |
26894
|
|
|
|
|
|
|
|
26895
|
|
|
|
|
|
|
static volatile decompress_func_t decompress_impl = dispatch_decomp; |
26896
|
|
|
|
|
|
|
|
26897
|
|
|
|
|
|
|
|
26898
|
|
|
|
|
|
|
static enum libdeflate_result |
26899
|
2
|
|
|
|
|
|
dispatch_decomp(struct libdeflate_decompressor *d, |
26900
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
26901
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
26902
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret) |
26903
|
|
|
|
|
|
|
{ |
26904
|
2
|
|
|
|
|
|
decompress_func_t f = arch_select_decompress_func(); |
26905
|
|
|
|
|
|
|
|
26906
|
2
|
50
|
|
|
|
|
if (f == NULL) |
26907
|
2
|
|
|
|
|
|
f = DEFAULT_IMPL; |
26908
|
|
|
|
|
|
|
|
26909
|
2
|
|
|
|
|
|
decompress_impl = f; |
26910
|
2
|
|
|
|
|
|
return f(d, in, in_nbytes, out, out_nbytes_avail, |
26911
|
|
|
|
|
|
|
actual_in_nbytes_ret, actual_out_nbytes_ret); |
26912
|
|
|
|
|
|
|
} |
26913
|
|
|
|
|
|
|
#else |
26914
|
|
|
|
|
|
|
|
26915
|
|
|
|
|
|
|
# define decompress_impl DEFAULT_IMPL |
26916
|
|
|
|
|
|
|
#endif |
26917
|
|
|
|
|
|
|
|
26918
|
|
|
|
|
|
|
|
26919
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
26920
|
40
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *d, |
26921
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
26922
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
26923
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
26924
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
26925
|
|
|
|
|
|
|
{ |
26926
|
40
|
|
|
|
|
|
return decompress_impl(d, in, in_nbytes, out, out_nbytes_avail, |
26927
|
|
|
|
|
|
|
actual_in_nbytes_ret, actual_out_nbytes_ret); |
26928
|
|
|
|
|
|
|
} |
26929
|
|
|
|
|
|
|
|
26930
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
26931
|
0
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *d, |
26932
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
26933
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
26934
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
26935
|
|
|
|
|
|
|
{ |
26936
|
0
|
|
|
|
|
|
return libdeflate_deflate_decompress_ex(d, in, in_nbytes, |
26937
|
|
|
|
|
|
|
out, out_nbytes_avail, |
26938
|
|
|
|
|
|
|
NULL, actual_out_nbytes_ret); |
26939
|
|
|
|
|
|
|
} |
26940
|
|
|
|
|
|
|
|
26941
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
26942
|
38
|
|
|
|
|
|
libdeflate_alloc_decompressor(void) |
26943
|
|
|
|
|
|
|
{ |
26944
|
|
|
|
|
|
|
|
26945
|
38
|
|
|
|
|
|
struct libdeflate_decompressor *d = libdeflate_malloc(sizeof(*d)); |
26946
|
|
|
|
|
|
|
|
26947
|
38
|
50
|
|
|
|
|
if (d == NULL) |
26948
|
0
|
|
|
|
|
|
return NULL; |
26949
|
38
|
|
|
|
|
|
memset(d, 0, sizeof(*d)); |
26950
|
38
|
|
|
|
|
|
return d; |
26951
|
|
|
|
|
|
|
} |
26952
|
|
|
|
|
|
|
|
26953
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
26954
|
38
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *d) |
26955
|
|
|
|
|
|
|
{ |
26956
|
38
|
|
|
|
|
|
libdeflate_free(d); |
26957
|
38
|
|
|
|
|
|
} |
26958
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/gzip_compress.c */ |
26959
|
|
|
|
|
|
|
|
26960
|
|
|
|
|
|
|
|
26961
|
|
|
|
|
|
|
/* #include "deflate_compress.h" */ |
26962
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_COMPRESS_H |
26963
|
|
|
|
|
|
|
#define LIB_DEFLATE_COMPRESS_H |
26964
|
|
|
|
|
|
|
|
26965
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
26966
|
|
|
|
|
|
|
|
26967
|
|
|
|
|
|
|
|
26968
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
26969
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
26970
|
|
|
|
|
|
|
|
26971
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
26972
|
|
|
|
|
|
|
|
26973
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
26974
|
|
|
|
|
|
|
#endif |
26975
|
|
|
|
|
|
|
|
26976
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
26977
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
26978
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
26979
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
26980
|
|
|
|
|
|
|
#else |
26981
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
26982
|
|
|
|
|
|
|
#endif |
26983
|
|
|
|
|
|
|
|
26984
|
|
|
|
|
|
|
|
26985
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
26986
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
26987
|
|
|
|
|
|
|
#else |
26988
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
26989
|
|
|
|
|
|
|
#endif |
26990
|
|
|
|
|
|
|
|
26991
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
26992
|
|
|
|
|
|
|
|
26993
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
26994
|
|
|
|
|
|
|
|
26995
|
|
|
|
|
|
|
|
26996
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
26997
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
26998
|
|
|
|
|
|
|
|
26999
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
27000
|
|
|
|
|
|
|
|
27001
|
|
|
|
|
|
|
|
27002
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
27003
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
27004
|
|
|
|
|
|
|
|
27005
|
|
|
|
|
|
|
#include |
27006
|
|
|
|
|
|
|
#include |
27007
|
|
|
|
|
|
|
|
27008
|
|
|
|
|
|
|
#ifdef __cplusplus |
27009
|
|
|
|
|
|
|
extern "C" { |
27010
|
|
|
|
|
|
|
#endif |
27011
|
|
|
|
|
|
|
|
27012
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
27013
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
27014
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
27015
|
|
|
|
|
|
|
|
27016
|
|
|
|
|
|
|
|
27017
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
27018
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
27019
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
27020
|
|
|
|
|
|
|
# else |
27021
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
27022
|
|
|
|
|
|
|
# endif |
27023
|
|
|
|
|
|
|
#endif |
27024
|
|
|
|
|
|
|
|
27025
|
|
|
|
|
|
|
|
27026
|
|
|
|
|
|
|
|
27027
|
|
|
|
|
|
|
|
27028
|
|
|
|
|
|
|
|
27029
|
|
|
|
|
|
|
struct libdeflate_compressor; |
27030
|
|
|
|
|
|
|
|
27031
|
|
|
|
|
|
|
|
27032
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
27033
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
27034
|
|
|
|
|
|
|
|
27035
|
|
|
|
|
|
|
|
27036
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27037
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
27038
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27039
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
27040
|
|
|
|
|
|
|
|
27041
|
|
|
|
|
|
|
|
27042
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27043
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
27044
|
|
|
|
|
|
|
size_t in_nbytes); |
27045
|
|
|
|
|
|
|
|
27046
|
|
|
|
|
|
|
|
27047
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27048
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
27049
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27050
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
27051
|
|
|
|
|
|
|
|
27052
|
|
|
|
|
|
|
|
27053
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27054
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
27055
|
|
|
|
|
|
|
size_t in_nbytes); |
27056
|
|
|
|
|
|
|
|
27057
|
|
|
|
|
|
|
|
27058
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27059
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
27060
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27061
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
27062
|
|
|
|
|
|
|
|
27063
|
|
|
|
|
|
|
|
27064
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27065
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
27066
|
|
|
|
|
|
|
size_t in_nbytes); |
27067
|
|
|
|
|
|
|
|
27068
|
|
|
|
|
|
|
|
27069
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
27070
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
27071
|
|
|
|
|
|
|
|
27072
|
|
|
|
|
|
|
|
27073
|
|
|
|
|
|
|
|
27074
|
|
|
|
|
|
|
|
27075
|
|
|
|
|
|
|
|
27076
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
27077
|
|
|
|
|
|
|
|
27078
|
|
|
|
|
|
|
|
27079
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
27080
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
27081
|
|
|
|
|
|
|
|
27082
|
|
|
|
|
|
|
|
27083
|
|
|
|
|
|
|
enum libdeflate_result { |
27084
|
|
|
|
|
|
|
|
27085
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
27086
|
|
|
|
|
|
|
|
27087
|
|
|
|
|
|
|
|
27088
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
27089
|
|
|
|
|
|
|
|
27090
|
|
|
|
|
|
|
|
27091
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
27092
|
|
|
|
|
|
|
|
27093
|
|
|
|
|
|
|
|
27094
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
27095
|
|
|
|
|
|
|
}; |
27096
|
|
|
|
|
|
|
|
27097
|
|
|
|
|
|
|
|
27098
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27099
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
27100
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27101
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27102
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27103
|
|
|
|
|
|
|
|
27104
|
|
|
|
|
|
|
|
27105
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27106
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
27107
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27108
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27109
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
27110
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27111
|
|
|
|
|
|
|
|
27112
|
|
|
|
|
|
|
|
27113
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27114
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
27115
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27116
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27117
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27118
|
|
|
|
|
|
|
|
27119
|
|
|
|
|
|
|
|
27120
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27121
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
27122
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27123
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27124
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
27125
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27126
|
|
|
|
|
|
|
|
27127
|
|
|
|
|
|
|
|
27128
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27129
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
27130
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27131
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27132
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27133
|
|
|
|
|
|
|
|
27134
|
|
|
|
|
|
|
|
27135
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
27136
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
27137
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27138
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
27139
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
27140
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
27141
|
|
|
|
|
|
|
|
27142
|
|
|
|
|
|
|
|
27143
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
27144
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
27145
|
|
|
|
|
|
|
|
27146
|
|
|
|
|
|
|
|
27147
|
|
|
|
|
|
|
|
27148
|
|
|
|
|
|
|
|
27149
|
|
|
|
|
|
|
|
27150
|
|
|
|
|
|
|
|
27151
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
27152
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
27153
|
|
|
|
|
|
|
|
27154
|
|
|
|
|
|
|
|
27155
|
|
|
|
|
|
|
|
27156
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
27157
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
27158
|
|
|
|
|
|
|
|
27159
|
|
|
|
|
|
|
|
27160
|
|
|
|
|
|
|
|
27161
|
|
|
|
|
|
|
|
27162
|
|
|
|
|
|
|
|
27163
|
|
|
|
|
|
|
|
27164
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
27165
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
27166
|
|
|
|
|
|
|
void (*free_func)(void *)); |
27167
|
|
|
|
|
|
|
|
27168
|
|
|
|
|
|
|
#ifdef __cplusplus |
27169
|
|
|
|
|
|
|
} |
27170
|
|
|
|
|
|
|
#endif |
27171
|
|
|
|
|
|
|
|
27172
|
|
|
|
|
|
|
#endif |
27173
|
|
|
|
|
|
|
|
27174
|
|
|
|
|
|
|
|
27175
|
|
|
|
|
|
|
#include |
27176
|
|
|
|
|
|
|
#include |
27177
|
|
|
|
|
|
|
#include |
27178
|
|
|
|
|
|
|
#ifdef _MSC_VER |
27179
|
|
|
|
|
|
|
# include |
27180
|
|
|
|
|
|
|
# include |
27181
|
|
|
|
|
|
|
|
27182
|
|
|
|
|
|
|
|
27183
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
27184
|
|
|
|
|
|
|
|
27185
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
27186
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
27187
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
27188
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
27189
|
|
|
|
|
|
|
|
27190
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
27191
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
27192
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
27193
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
27194
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
27195
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
27196
|
|
|
|
|
|
|
#endif |
27197
|
|
|
|
|
|
|
#ifndef FREESTANDING |
27198
|
|
|
|
|
|
|
# include |
27199
|
|
|
|
|
|
|
#endif |
27200
|
|
|
|
|
|
|
|
27201
|
|
|
|
|
|
|
|
27202
|
|
|
|
|
|
|
|
27203
|
|
|
|
|
|
|
|
27204
|
|
|
|
|
|
|
|
27205
|
|
|
|
|
|
|
|
27206
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
27207
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
27208
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
27209
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
27210
|
|
|
|
|
|
|
#ifdef _MSC_VER |
27211
|
|
|
|
|
|
|
# if defined(_M_X64) |
27212
|
|
|
|
|
|
|
# define ARCH_X86_64 |
27213
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
27214
|
|
|
|
|
|
|
# define ARCH_X86_32 |
27215
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
27216
|
|
|
|
|
|
|
# define ARCH_ARM64 |
27217
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
27218
|
|
|
|
|
|
|
# define ARCH_ARM32 |
27219
|
|
|
|
|
|
|
# endif |
27220
|
|
|
|
|
|
|
#else |
27221
|
|
|
|
|
|
|
# if defined(__x86_64__) |
27222
|
|
|
|
|
|
|
# define ARCH_X86_64 |
27223
|
|
|
|
|
|
|
# elif defined(__i386__) |
27224
|
|
|
|
|
|
|
# define ARCH_X86_32 |
27225
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
27226
|
|
|
|
|
|
|
# define ARCH_ARM64 |
27227
|
|
|
|
|
|
|
# elif defined(__arm__) |
27228
|
|
|
|
|
|
|
# define ARCH_ARM32 |
27229
|
|
|
|
|
|
|
# endif |
27230
|
|
|
|
|
|
|
#endif |
27231
|
|
|
|
|
|
|
|
27232
|
|
|
|
|
|
|
|
27233
|
|
|
|
|
|
|
|
27234
|
|
|
|
|
|
|
|
27235
|
|
|
|
|
|
|
|
27236
|
|
|
|
|
|
|
|
27237
|
|
|
|
|
|
|
typedef uint8_t u8; |
27238
|
|
|
|
|
|
|
typedef uint16_t u16; |
27239
|
|
|
|
|
|
|
typedef uint32_t u32; |
27240
|
|
|
|
|
|
|
typedef uint64_t u64; |
27241
|
|
|
|
|
|
|
typedef int8_t s8; |
27242
|
|
|
|
|
|
|
typedef int16_t s16; |
27243
|
|
|
|
|
|
|
typedef int32_t s32; |
27244
|
|
|
|
|
|
|
typedef int64_t s64; |
27245
|
|
|
|
|
|
|
|
27246
|
|
|
|
|
|
|
|
27247
|
|
|
|
|
|
|
#ifdef _MSC_VER |
27248
|
|
|
|
|
|
|
# ifdef _WIN64 |
27249
|
|
|
|
|
|
|
typedef long long ssize_t; |
27250
|
|
|
|
|
|
|
# else |
27251
|
|
|
|
|
|
|
typedef long ssize_t; |
27252
|
|
|
|
|
|
|
# endif |
27253
|
|
|
|
|
|
|
#endif |
27254
|
|
|
|
|
|
|
|
27255
|
|
|
|
|
|
|
|
27256
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
27257
|
|
|
|
|
|
|
|
27258
|
|
|
|
|
|
|
|
27259
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
27260
|
|
|
|
|
|
|
|
27261
|
|
|
|
|
|
|
|
27262
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
27263
|
|
|
|
|
|
|
|
27264
|
|
|
|
|
|
|
|
27265
|
|
|
|
|
|
|
|
27266
|
|
|
|
|
|
|
|
27267
|
|
|
|
|
|
|
|
27268
|
|
|
|
|
|
|
|
27269
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
27270
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
27271
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
27272
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
27273
|
|
|
|
|
|
|
#else |
27274
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
27275
|
|
|
|
|
|
|
#endif |
27276
|
|
|
|
|
|
|
#ifdef __clang__ |
27277
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
27278
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
27279
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
27280
|
|
|
|
|
|
|
# else |
27281
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
27282
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
27283
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
27284
|
|
|
|
|
|
|
# endif |
27285
|
|
|
|
|
|
|
#else |
27286
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
27287
|
|
|
|
|
|
|
#endif |
27288
|
|
|
|
|
|
|
|
27289
|
|
|
|
|
|
|
|
27290
|
|
|
|
|
|
|
#ifndef __has_attribute |
27291
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
27292
|
|
|
|
|
|
|
#endif |
27293
|
|
|
|
|
|
|
#ifndef __has_builtin |
27294
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
27295
|
|
|
|
|
|
|
#endif |
27296
|
|
|
|
|
|
|
|
27297
|
|
|
|
|
|
|
|
27298
|
|
|
|
|
|
|
#ifdef _MSC_VER |
27299
|
|
|
|
|
|
|
# define inline __inline |
27300
|
|
|
|
|
|
|
#endif |
27301
|
|
|
|
|
|
|
|
27302
|
|
|
|
|
|
|
|
27303
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
27304
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
27305
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27306
|
|
|
|
|
|
|
# define forceinline __forceinline |
27307
|
|
|
|
|
|
|
#else |
27308
|
|
|
|
|
|
|
# define forceinline inline |
27309
|
|
|
|
|
|
|
#endif |
27310
|
|
|
|
|
|
|
|
27311
|
|
|
|
|
|
|
|
27312
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
27313
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
27314
|
|
|
|
|
|
|
#else |
27315
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
27316
|
|
|
|
|
|
|
#endif |
27317
|
|
|
|
|
|
|
|
27318
|
|
|
|
|
|
|
|
27319
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
27320
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
27321
|
|
|
|
|
|
|
# define restrict __restrict__ |
27322
|
|
|
|
|
|
|
# else |
27323
|
|
|
|
|
|
|
# define restrict |
27324
|
|
|
|
|
|
|
# endif |
27325
|
|
|
|
|
|
|
#endif |
27326
|
|
|
|
|
|
|
|
27327
|
|
|
|
|
|
|
|
27328
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
27329
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
27330
|
|
|
|
|
|
|
#else |
27331
|
|
|
|
|
|
|
# define likely(expr) (expr) |
27332
|
|
|
|
|
|
|
#endif |
27333
|
|
|
|
|
|
|
|
27334
|
|
|
|
|
|
|
|
27335
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
27336
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
27337
|
|
|
|
|
|
|
#else |
27338
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
27339
|
|
|
|
|
|
|
#endif |
27340
|
|
|
|
|
|
|
|
27341
|
|
|
|
|
|
|
|
27342
|
|
|
|
|
|
|
#undef prefetchr |
27343
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
27344
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
27345
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27346
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
27347
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
27348
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
27349
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
27350
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
27351
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
27352
|
|
|
|
|
|
|
# endif |
27353
|
|
|
|
|
|
|
#endif |
27354
|
|
|
|
|
|
|
#ifndef prefetchr |
27355
|
|
|
|
|
|
|
# define prefetchr(addr) |
27356
|
|
|
|
|
|
|
#endif |
27357
|
|
|
|
|
|
|
|
27358
|
|
|
|
|
|
|
|
27359
|
|
|
|
|
|
|
#undef prefetchw |
27360
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
27361
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
27362
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27363
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
27364
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
27365
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
27366
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
27367
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
27368
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
27369
|
|
|
|
|
|
|
# endif |
27370
|
|
|
|
|
|
|
#endif |
27371
|
|
|
|
|
|
|
#ifndef prefetchw |
27372
|
|
|
|
|
|
|
# define prefetchw(addr) |
27373
|
|
|
|
|
|
|
#endif |
27374
|
|
|
|
|
|
|
|
27375
|
|
|
|
|
|
|
|
27376
|
|
|
|
|
|
|
#undef _aligned_attribute |
27377
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
27378
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
27379
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27380
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
27381
|
|
|
|
|
|
|
#endif |
27382
|
|
|
|
|
|
|
|
27383
|
|
|
|
|
|
|
|
27384
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
27385
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
27386
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
27387
|
|
|
|
|
|
|
#else |
27388
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
27389
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
27390
|
|
|
|
|
|
|
#endif |
27391
|
|
|
|
|
|
|
|
27392
|
|
|
|
|
|
|
|
27393
|
|
|
|
|
|
|
|
27394
|
|
|
|
|
|
|
|
27395
|
|
|
|
|
|
|
|
27396
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
27397
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
27398
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
27399
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
27400
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
27401
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
27402
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
27403
|
|
|
|
|
|
|
|
27404
|
|
|
|
|
|
|
|
27405
|
|
|
|
|
|
|
|
27406
|
|
|
|
|
|
|
|
27407
|
|
|
|
|
|
|
|
27408
|
|
|
|
|
|
|
|
27409
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
27410
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
27411
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27412
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
27413
|
|
|
|
|
|
|
#else |
27414
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
27415
|
|
|
|
|
|
|
{ |
27416
|
|
|
|
|
|
|
union { |
27417
|
|
|
|
|
|
|
u32 w; |
27418
|
|
|
|
|
|
|
u8 b; |
27419
|
|
|
|
|
|
|
} u; |
27420
|
|
|
|
|
|
|
|
27421
|
|
|
|
|
|
|
u.w = 1; |
27422
|
|
|
|
|
|
|
return u.b; |
27423
|
|
|
|
|
|
|
} |
27424
|
|
|
|
|
|
|
#endif |
27425
|
|
|
|
|
|
|
|
27426
|
|
|
|
|
|
|
|
27427
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
27428
|
|
|
|
|
|
|
{ |
27429
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
27430
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
27431
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27432
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
27433
|
|
|
|
|
|
|
#else |
27434
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
27435
|
|
|
|
|
|
|
#endif |
27436
|
|
|
|
|
|
|
} |
27437
|
|
|
|
|
|
|
|
27438
|
|
|
|
|
|
|
|
27439
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
27440
|
|
|
|
|
|
|
{ |
27441
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
27442
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
27443
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27444
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
27445
|
|
|
|
|
|
|
#else |
27446
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
27447
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
27448
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
27449
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
27450
|
|
|
|
|
|
|
#endif |
27451
|
|
|
|
|
|
|
} |
27452
|
|
|
|
|
|
|
|
27453
|
|
|
|
|
|
|
|
27454
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
27455
|
|
|
|
|
|
|
{ |
27456
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
27457
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
27458
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27459
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
27460
|
|
|
|
|
|
|
#else |
27461
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
27462
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
27463
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
27464
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
27465
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
27466
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
27467
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
27468
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
27469
|
|
|
|
|
|
|
#endif |
27470
|
|
|
|
|
|
|
} |
27471
|
|
|
|
|
|
|
|
27472
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
27473
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
27474
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
27475
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
27476
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
27477
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
27478
|
|
|
|
|
|
|
|
27479
|
|
|
|
|
|
|
|
27480
|
|
|
|
|
|
|
|
27481
|
|
|
|
|
|
|
|
27482
|
|
|
|
|
|
|
|
27483
|
|
|
|
|
|
|
|
27484
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
27485
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
27486
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
27487
|
|
|
|
|
|
|
defined(__wasm__)) |
27488
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
27489
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27490
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
27491
|
|
|
|
|
|
|
#else |
27492
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
27493
|
|
|
|
|
|
|
#endif |
27494
|
|
|
|
|
|
|
|
27495
|
|
|
|
|
|
|
|
27496
|
|
|
|
|
|
|
|
27497
|
|
|
|
|
|
|
#ifdef FREESTANDING |
27498
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
27499
|
|
|
|
|
|
|
#else |
27500
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
27501
|
|
|
|
|
|
|
#endif |
27502
|
|
|
|
|
|
|
|
27503
|
|
|
|
|
|
|
|
27504
|
|
|
|
|
|
|
|
27505
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
27506
|
|
|
|
|
|
|
static forceinline type \ |
27507
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
27508
|
|
|
|
|
|
|
{ \ |
27509
|
|
|
|
|
|
|
type v; \ |
27510
|
|
|
|
|
|
|
\ |
27511
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
27512
|
|
|
|
|
|
|
return v; \ |
27513
|
|
|
|
|
|
|
} \ |
27514
|
|
|
|
|
|
|
\ |
27515
|
|
|
|
|
|
|
static forceinline void \ |
27516
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
27517
|
|
|
|
|
|
|
{ \ |
27518
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
27519
|
|
|
|
|
|
|
} |
27520
|
|
|
|
|
|
|
|
27521
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
27522
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
27523
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
27524
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
27525
|
|
|
|
|
|
|
|
27526
|
|
|
|
|
|
|
#undef MEMCOPY |
27527
|
|
|
|
|
|
|
|
27528
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
27529
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
27530
|
|
|
|
|
|
|
|
27531
|
|
|
|
|
|
|
|
27532
|
|
|
|
|
|
|
|
27533
|
|
|
|
|
|
|
static forceinline u16 |
27534
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
27535
|
|
|
|
|
|
|
{ |
27536
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
27537
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
27538
|
|
|
|
|
|
|
else |
27539
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
27540
|
|
|
|
|
|
|
} |
27541
|
|
|
|
|
|
|
|
27542
|
|
|
|
|
|
|
static forceinline u16 |
27543
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
27544
|
|
|
|
|
|
|
{ |
27545
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
27546
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
27547
|
|
|
|
|
|
|
else |
27548
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
27549
|
|
|
|
|
|
|
} |
27550
|
|
|
|
|
|
|
|
27551
|
|
|
|
|
|
|
static forceinline u32 |
27552
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
27553
|
|
|
|
|
|
|
{ |
27554
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
27555
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
27556
|
|
|
|
|
|
|
else |
27557
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
27558
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
27559
|
|
|
|
|
|
|
} |
27560
|
|
|
|
|
|
|
|
27561
|
|
|
|
|
|
|
static forceinline u32 |
27562
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
27563
|
|
|
|
|
|
|
{ |
27564
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
27565
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
27566
|
|
|
|
|
|
|
else |
27567
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
27568
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
27569
|
|
|
|
|
|
|
} |
27570
|
|
|
|
|
|
|
|
27571
|
|
|
|
|
|
|
static forceinline u64 |
27572
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
27573
|
|
|
|
|
|
|
{ |
27574
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
27575
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
27576
|
|
|
|
|
|
|
else |
27577
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
27578
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
27579
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
27580
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
27581
|
|
|
|
|
|
|
} |
27582
|
|
|
|
|
|
|
|
27583
|
|
|
|
|
|
|
static forceinline machine_word_t |
27584
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
27585
|
|
|
|
|
|
|
{ |
27586
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
27587
|
|
|
|
|
|
|
if (WORDBITS == 32) |
27588
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
27589
|
|
|
|
|
|
|
else |
27590
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
27591
|
|
|
|
|
|
|
} |
27592
|
|
|
|
|
|
|
|
27593
|
|
|
|
|
|
|
|
27594
|
|
|
|
|
|
|
|
27595
|
|
|
|
|
|
|
static forceinline void |
27596
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
27597
|
|
|
|
|
|
|
{ |
27598
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
27599
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
27600
|
|
|
|
|
|
|
} else { |
27601
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
27602
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
27603
|
|
|
|
|
|
|
} |
27604
|
|
|
|
|
|
|
} |
27605
|
|
|
|
|
|
|
|
27606
|
|
|
|
|
|
|
static forceinline void |
27607
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
27608
|
|
|
|
|
|
|
{ |
27609
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
27610
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
27611
|
|
|
|
|
|
|
} else { |
27612
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
27613
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
27614
|
|
|
|
|
|
|
} |
27615
|
|
|
|
|
|
|
} |
27616
|
|
|
|
|
|
|
|
27617
|
|
|
|
|
|
|
static forceinline void |
27618
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
27619
|
|
|
|
|
|
|
{ |
27620
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
27621
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
27622
|
|
|
|
|
|
|
} else { |
27623
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
27624
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
27625
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
27626
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
27627
|
|
|
|
|
|
|
} |
27628
|
|
|
|
|
|
|
} |
27629
|
|
|
|
|
|
|
|
27630
|
|
|
|
|
|
|
static forceinline void |
27631
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
27632
|
|
|
|
|
|
|
{ |
27633
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
27634
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
27635
|
|
|
|
|
|
|
} else { |
27636
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
27637
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
27638
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
27639
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
27640
|
|
|
|
|
|
|
} |
27641
|
|
|
|
|
|
|
} |
27642
|
|
|
|
|
|
|
|
27643
|
|
|
|
|
|
|
static forceinline void |
27644
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
27645
|
|
|
|
|
|
|
{ |
27646
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
27647
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
27648
|
|
|
|
|
|
|
} else { |
27649
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
27650
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
27651
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
27652
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
27653
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
27654
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
27655
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
27656
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
27657
|
|
|
|
|
|
|
} |
27658
|
|
|
|
|
|
|
} |
27659
|
|
|
|
|
|
|
|
27660
|
|
|
|
|
|
|
static forceinline void |
27661
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
27662
|
|
|
|
|
|
|
{ |
27663
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
27664
|
|
|
|
|
|
|
if (WORDBITS == 32) |
27665
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
27666
|
|
|
|
|
|
|
else |
27667
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
27668
|
|
|
|
|
|
|
} |
27669
|
|
|
|
|
|
|
|
27670
|
|
|
|
|
|
|
|
27671
|
|
|
|
|
|
|
|
27672
|
|
|
|
|
|
|
|
27673
|
|
|
|
|
|
|
|
27674
|
|
|
|
|
|
|
|
27675
|
|
|
|
|
|
|
|
27676
|
|
|
|
|
|
|
static forceinline unsigned |
27677
|
|
|
|
|
|
|
bsr32(u32 v) |
27678
|
|
|
|
|
|
|
{ |
27679
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
27680
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
27681
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27682
|
|
|
|
|
|
|
unsigned long i; |
27683
|
|
|
|
|
|
|
|
27684
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
27685
|
|
|
|
|
|
|
return i; |
27686
|
|
|
|
|
|
|
#else |
27687
|
|
|
|
|
|
|
unsigned i = 0; |
27688
|
|
|
|
|
|
|
|
27689
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
27690
|
|
|
|
|
|
|
i++; |
27691
|
|
|
|
|
|
|
return i; |
27692
|
|
|
|
|
|
|
#endif |
27693
|
|
|
|
|
|
|
} |
27694
|
|
|
|
|
|
|
|
27695
|
|
|
|
|
|
|
static forceinline unsigned |
27696
|
|
|
|
|
|
|
bsr64(u64 v) |
27697
|
|
|
|
|
|
|
{ |
27698
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
27699
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
27700
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
27701
|
|
|
|
|
|
|
unsigned long i; |
27702
|
|
|
|
|
|
|
|
27703
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
27704
|
|
|
|
|
|
|
return i; |
27705
|
|
|
|
|
|
|
#else |
27706
|
|
|
|
|
|
|
unsigned i = 0; |
27707
|
|
|
|
|
|
|
|
27708
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
27709
|
|
|
|
|
|
|
i++; |
27710
|
|
|
|
|
|
|
return i; |
27711
|
|
|
|
|
|
|
#endif |
27712
|
|
|
|
|
|
|
} |
27713
|
|
|
|
|
|
|
|
27714
|
|
|
|
|
|
|
static forceinline unsigned |
27715
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
27716
|
|
|
|
|
|
|
{ |
27717
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
27718
|
|
|
|
|
|
|
if (WORDBITS == 32) |
27719
|
|
|
|
|
|
|
return bsr32(v); |
27720
|
|
|
|
|
|
|
else |
27721
|
|
|
|
|
|
|
return bsr64(v); |
27722
|
|
|
|
|
|
|
} |
27723
|
|
|
|
|
|
|
|
27724
|
|
|
|
|
|
|
|
27725
|
|
|
|
|
|
|
|
27726
|
|
|
|
|
|
|
static forceinline unsigned |
27727
|
|
|
|
|
|
|
bsf32(u32 v) |
27728
|
|
|
|
|
|
|
{ |
27729
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
27730
|
|
|
|
|
|
|
return __builtin_ctz(v); |
27731
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
27732
|
|
|
|
|
|
|
unsigned long i; |
27733
|
|
|
|
|
|
|
|
27734
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
27735
|
|
|
|
|
|
|
return i; |
27736
|
|
|
|
|
|
|
#else |
27737
|
|
|
|
|
|
|
unsigned i = 0; |
27738
|
|
|
|
|
|
|
|
27739
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
27740
|
|
|
|
|
|
|
i++; |
27741
|
|
|
|
|
|
|
return i; |
27742
|
|
|
|
|
|
|
#endif |
27743
|
|
|
|
|
|
|
} |
27744
|
|
|
|
|
|
|
|
27745
|
|
|
|
|
|
|
static forceinline unsigned |
27746
|
|
|
|
|
|
|
bsf64(u64 v) |
27747
|
|
|
|
|
|
|
{ |
27748
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
27749
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
27750
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
27751
|
|
|
|
|
|
|
unsigned long i; |
27752
|
|
|
|
|
|
|
|
27753
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
27754
|
|
|
|
|
|
|
return i; |
27755
|
|
|
|
|
|
|
#else |
27756
|
|
|
|
|
|
|
unsigned i = 0; |
27757
|
|
|
|
|
|
|
|
27758
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
27759
|
|
|
|
|
|
|
i++; |
27760
|
|
|
|
|
|
|
return i; |
27761
|
|
|
|
|
|
|
#endif |
27762
|
|
|
|
|
|
|
} |
27763
|
|
|
|
|
|
|
|
27764
|
|
|
|
|
|
|
static forceinline unsigned |
27765
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
27766
|
|
|
|
|
|
|
{ |
27767
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
27768
|
|
|
|
|
|
|
if (WORDBITS == 32) |
27769
|
|
|
|
|
|
|
return bsf32(v); |
27770
|
|
|
|
|
|
|
else |
27771
|
|
|
|
|
|
|
return bsf64(v); |
27772
|
|
|
|
|
|
|
} |
27773
|
|
|
|
|
|
|
|
27774
|
|
|
|
|
|
|
|
27775
|
|
|
|
|
|
|
#undef rbit32 |
27776
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
27777
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
27778
|
|
|
|
|
|
|
static forceinline u32 |
27779
|
|
|
|
|
|
|
rbit32(u32 v) |
27780
|
|
|
|
|
|
|
{ |
27781
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
27782
|
|
|
|
|
|
|
return v; |
27783
|
|
|
|
|
|
|
} |
27784
|
|
|
|
|
|
|
#define rbit32 rbit32 |
27785
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
27786
|
|
|
|
|
|
|
static forceinline u32 |
27787
|
|
|
|
|
|
|
rbit32(u32 v) |
27788
|
|
|
|
|
|
|
{ |
27789
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
27790
|
|
|
|
|
|
|
return v; |
27791
|
|
|
|
|
|
|
} |
27792
|
|
|
|
|
|
|
#define rbit32 rbit32 |
27793
|
|
|
|
|
|
|
#endif |
27794
|
|
|
|
|
|
|
|
27795
|
|
|
|
|
|
|
#endif |
27796
|
|
|
|
|
|
|
|
27797
|
|
|
|
|
|
|
|
27798
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
27799
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
27800
|
|
|
|
|
|
|
|
27801
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
27802
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
27803
|
|
|
|
|
|
|
|
27804
|
|
|
|
|
|
|
#ifdef FREESTANDING |
27805
|
|
|
|
|
|
|
|
27806
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
27807
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
27808
|
|
|
|
|
|
|
|
27809
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
27810
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
27811
|
|
|
|
|
|
|
|
27812
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
27813
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
27814
|
|
|
|
|
|
|
|
27815
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
27816
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
27817
|
|
|
|
|
|
|
|
27818
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
27819
|
|
|
|
|
|
|
#else |
27820
|
|
|
|
|
|
|
#include |
27821
|
|
|
|
|
|
|
#endif |
27822
|
|
|
|
|
|
|
|
27823
|
|
|
|
|
|
|
|
27824
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
27825
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
27826
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
27827
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
27828
|
|
|
|
|
|
|
#else |
27829
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
27830
|
|
|
|
|
|
|
#endif |
27831
|
|
|
|
|
|
|
|
27832
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
27833
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
27834
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
27835
|
|
|
|
|
|
|
|
27836
|
|
|
|
|
|
|
#endif |
27837
|
|
|
|
|
|
|
|
27838
|
|
|
|
|
|
|
|
27839
|
|
|
|
|
|
|
|
27840
|
|
|
|
|
|
|
|
27841
|
|
|
|
|
|
|
struct libdeflate_compressor; |
27842
|
|
|
|
|
|
|
|
27843
|
|
|
|
|
|
|
unsigned int libdeflate_get_compression_level(struct libdeflate_compressor *c); |
27844
|
|
|
|
|
|
|
|
27845
|
|
|
|
|
|
|
#endif |
27846
|
|
|
|
|
|
|
|
27847
|
|
|
|
|
|
|
/* #include "gzip_constants.h" */ |
27848
|
|
|
|
|
|
|
|
27849
|
|
|
|
|
|
|
|
27850
|
|
|
|
|
|
|
#ifndef LIB_GZIP_CONSTANTS_H |
27851
|
|
|
|
|
|
|
#define LIB_GZIP_CONSTANTS_H |
27852
|
|
|
|
|
|
|
|
27853
|
|
|
|
|
|
|
#define GZIP_MIN_HEADER_SIZE 10 |
27854
|
|
|
|
|
|
|
#define GZIP_FOOTER_SIZE 8 |
27855
|
|
|
|
|
|
|
#define GZIP_MIN_OVERHEAD (GZIP_MIN_HEADER_SIZE + GZIP_FOOTER_SIZE) |
27856
|
|
|
|
|
|
|
|
27857
|
|
|
|
|
|
|
#define GZIP_ID1 0x1F |
27858
|
|
|
|
|
|
|
#define GZIP_ID2 0x8B |
27859
|
|
|
|
|
|
|
|
27860
|
|
|
|
|
|
|
#define GZIP_CM_DEFLATE 8 |
27861
|
|
|
|
|
|
|
|
27862
|
|
|
|
|
|
|
#define GZIP_FTEXT 0x01 |
27863
|
|
|
|
|
|
|
#define GZIP_FHCRC 0x02 |
27864
|
|
|
|
|
|
|
#define GZIP_FEXTRA 0x04 |
27865
|
|
|
|
|
|
|
#define GZIP_FNAME 0x08 |
27866
|
|
|
|
|
|
|
#define GZIP_FCOMMENT 0x10 |
27867
|
|
|
|
|
|
|
#define GZIP_FRESERVED 0xE0 |
27868
|
|
|
|
|
|
|
|
27869
|
|
|
|
|
|
|
#define GZIP_MTIME_UNAVAILABLE 0 |
27870
|
|
|
|
|
|
|
|
27871
|
|
|
|
|
|
|
#define GZIP_XFL_SLOWEST_COMPRESSION 0x02 |
27872
|
|
|
|
|
|
|
#define GZIP_XFL_FASTEST_COMPRESSION 0x04 |
27873
|
|
|
|
|
|
|
|
27874
|
|
|
|
|
|
|
#define GZIP_OS_FAT 0 |
27875
|
|
|
|
|
|
|
#define GZIP_OS_AMIGA 1 |
27876
|
|
|
|
|
|
|
#define GZIP_OS_VMS 2 |
27877
|
|
|
|
|
|
|
#define GZIP_OS_UNIX 3 |
27878
|
|
|
|
|
|
|
#define GZIP_OS_VM_CMS 4 |
27879
|
|
|
|
|
|
|
#define GZIP_OS_ATARI_TOS 5 |
27880
|
|
|
|
|
|
|
#define GZIP_OS_HPFS 6 |
27881
|
|
|
|
|
|
|
#define GZIP_OS_MACINTOSH 7 |
27882
|
|
|
|
|
|
|
#define GZIP_OS_Z_SYSTEM 8 |
27883
|
|
|
|
|
|
|
#define GZIP_OS_CP_M 9 |
27884
|
|
|
|
|
|
|
#define GZIP_OS_TOPS_20 10 |
27885
|
|
|
|
|
|
|
#define GZIP_OS_NTFS 11 |
27886
|
|
|
|
|
|
|
#define GZIP_OS_QDOS 12 |
27887
|
|
|
|
|
|
|
#define GZIP_OS_RISCOS 13 |
27888
|
|
|
|
|
|
|
#define GZIP_OS_UNKNOWN 255 |
27889
|
|
|
|
|
|
|
|
27890
|
|
|
|
|
|
|
#endif |
27891
|
|
|
|
|
|
|
|
27892
|
|
|
|
|
|
|
|
27893
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27894
|
13
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *c, |
27895
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
27896
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail) |
27897
|
|
|
|
|
|
|
{ |
27898
|
13
|
|
|
|
|
|
u8 *out_next = out; |
27899
|
|
|
|
|
|
|
unsigned compression_level; |
27900
|
|
|
|
|
|
|
u8 xfl; |
27901
|
|
|
|
|
|
|
size_t deflate_size; |
27902
|
|
|
|
|
|
|
|
27903
|
13
|
50
|
|
|
|
|
if (out_nbytes_avail <= GZIP_MIN_OVERHEAD) |
27904
|
0
|
|
|
|
|
|
return 0; |
27905
|
|
|
|
|
|
|
|
27906
|
|
|
|
|
|
|
|
27907
|
13
|
|
|
|
|
|
*out_next++ = GZIP_ID1; |
27908
|
|
|
|
|
|
|
|
27909
|
13
|
|
|
|
|
|
*out_next++ = GZIP_ID2; |
27910
|
|
|
|
|
|
|
|
27911
|
13
|
|
|
|
|
|
*out_next++ = GZIP_CM_DEFLATE; |
27912
|
|
|
|
|
|
|
|
27913
|
13
|
|
|
|
|
|
*out_next++ = 0; |
27914
|
|
|
|
|
|
|
|
27915
|
|
|
|
|
|
|
put_unaligned_le32(GZIP_MTIME_UNAVAILABLE, out_next); |
27916
|
13
|
|
|
|
|
|
out_next += 4; |
27917
|
|
|
|
|
|
|
|
27918
|
13
|
|
|
|
|
|
xfl = 0; |
27919
|
13
|
|
|
|
|
|
compression_level = libdeflate_get_compression_level(c); |
27920
|
13
|
100
|
|
|
|
|
if (compression_level < 2) |
27921
|
1
|
|
|
|
|
|
xfl |= GZIP_XFL_FASTEST_COMPRESSION; |
27922
|
12
|
100
|
|
|
|
|
else if (compression_level >= 8) |
27923
|
5
|
|
|
|
|
|
xfl |= GZIP_XFL_SLOWEST_COMPRESSION; |
27924
|
13
|
|
|
|
|
|
*out_next++ = xfl; |
27925
|
|
|
|
|
|
|
|
27926
|
13
|
|
|
|
|
|
*out_next++ = GZIP_OS_UNKNOWN; |
27927
|
|
|
|
|
|
|
|
27928
|
|
|
|
|
|
|
|
27929
|
13
|
|
|
|
|
|
deflate_size = libdeflate_deflate_compress(c, in, in_nbytes, out_next, |
27930
|
|
|
|
|
|
|
out_nbytes_avail - GZIP_MIN_OVERHEAD); |
27931
|
13
|
50
|
|
|
|
|
if (deflate_size == 0) |
27932
|
0
|
|
|
|
|
|
return 0; |
27933
|
13
|
|
|
|
|
|
out_next += deflate_size; |
27934
|
|
|
|
|
|
|
|
27935
|
|
|
|
|
|
|
|
27936
|
13
|
|
|
|
|
|
put_unaligned_le32(libdeflate_crc32(0, in, in_nbytes), out_next); |
27937
|
13
|
|
|
|
|
|
out_next += 4; |
27938
|
|
|
|
|
|
|
|
27939
|
|
|
|
|
|
|
|
27940
|
13
|
|
|
|
|
|
put_unaligned_le32((u32)in_nbytes, out_next); |
27941
|
13
|
|
|
|
|
|
out_next += 4; |
27942
|
|
|
|
|
|
|
|
27943
|
13
|
|
|
|
|
|
return out_next - (u8 *)out; |
27944
|
|
|
|
|
|
|
} |
27945
|
|
|
|
|
|
|
|
27946
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
27947
|
13
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *c, |
27948
|
|
|
|
|
|
|
size_t in_nbytes) |
27949
|
|
|
|
|
|
|
{ |
27950
|
13
|
|
|
|
|
|
return GZIP_MIN_OVERHEAD + |
27951
|
13
|
|
|
|
|
|
libdeflate_deflate_compress_bound(c, in_nbytes); |
27952
|
|
|
|
|
|
|
} |
27953
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/gzip_decompress.c */ |
27954
|
|
|
|
|
|
|
|
27955
|
|
|
|
|
|
|
|
27956
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
27957
|
|
|
|
|
|
|
|
27958
|
|
|
|
|
|
|
|
27959
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
27960
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
27961
|
|
|
|
|
|
|
|
27962
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
27963
|
|
|
|
|
|
|
|
27964
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
27965
|
|
|
|
|
|
|
#endif |
27966
|
|
|
|
|
|
|
|
27967
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
27968
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
27969
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
27970
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
27971
|
|
|
|
|
|
|
#else |
27972
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
27973
|
|
|
|
|
|
|
#endif |
27974
|
|
|
|
|
|
|
|
27975
|
|
|
|
|
|
|
|
27976
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
27977
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
27978
|
|
|
|
|
|
|
#else |
27979
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
27980
|
|
|
|
|
|
|
#endif |
27981
|
|
|
|
|
|
|
|
27982
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
27983
|
|
|
|
|
|
|
|
27984
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
27985
|
|
|
|
|
|
|
|
27986
|
|
|
|
|
|
|
|
27987
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
27988
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
27989
|
|
|
|
|
|
|
|
27990
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
27991
|
|
|
|
|
|
|
|
27992
|
|
|
|
|
|
|
|
27993
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
27994
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
27995
|
|
|
|
|
|
|
|
27996
|
|
|
|
|
|
|
#include |
27997
|
|
|
|
|
|
|
#include |
27998
|
|
|
|
|
|
|
|
27999
|
|
|
|
|
|
|
#ifdef __cplusplus |
28000
|
|
|
|
|
|
|
extern "C" { |
28001
|
|
|
|
|
|
|
#endif |
28002
|
|
|
|
|
|
|
|
28003
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
28004
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
28005
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
28006
|
|
|
|
|
|
|
|
28007
|
|
|
|
|
|
|
|
28008
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
28009
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
28010
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
28011
|
|
|
|
|
|
|
# else |
28012
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
28013
|
|
|
|
|
|
|
# endif |
28014
|
|
|
|
|
|
|
#endif |
28015
|
|
|
|
|
|
|
|
28016
|
|
|
|
|
|
|
|
28017
|
|
|
|
|
|
|
|
28018
|
|
|
|
|
|
|
|
28019
|
|
|
|
|
|
|
|
28020
|
|
|
|
|
|
|
struct libdeflate_compressor; |
28021
|
|
|
|
|
|
|
|
28022
|
|
|
|
|
|
|
|
28023
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
28024
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
28025
|
|
|
|
|
|
|
|
28026
|
|
|
|
|
|
|
|
28027
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28028
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
28029
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28030
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
28031
|
|
|
|
|
|
|
|
28032
|
|
|
|
|
|
|
|
28033
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28034
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
28035
|
|
|
|
|
|
|
size_t in_nbytes); |
28036
|
|
|
|
|
|
|
|
28037
|
|
|
|
|
|
|
|
28038
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28039
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
28040
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28041
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
28042
|
|
|
|
|
|
|
|
28043
|
|
|
|
|
|
|
|
28044
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28045
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
28046
|
|
|
|
|
|
|
size_t in_nbytes); |
28047
|
|
|
|
|
|
|
|
28048
|
|
|
|
|
|
|
|
28049
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28050
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
28051
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28052
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
28053
|
|
|
|
|
|
|
|
28054
|
|
|
|
|
|
|
|
28055
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
28056
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
28057
|
|
|
|
|
|
|
size_t in_nbytes); |
28058
|
|
|
|
|
|
|
|
28059
|
|
|
|
|
|
|
|
28060
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
28061
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
28062
|
|
|
|
|
|
|
|
28063
|
|
|
|
|
|
|
|
28064
|
|
|
|
|
|
|
|
28065
|
|
|
|
|
|
|
|
28066
|
|
|
|
|
|
|
|
28067
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
28068
|
|
|
|
|
|
|
|
28069
|
|
|
|
|
|
|
|
28070
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
28071
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
28072
|
|
|
|
|
|
|
|
28073
|
|
|
|
|
|
|
|
28074
|
|
|
|
|
|
|
enum libdeflate_result { |
28075
|
|
|
|
|
|
|
|
28076
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
28077
|
|
|
|
|
|
|
|
28078
|
|
|
|
|
|
|
|
28079
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
28080
|
|
|
|
|
|
|
|
28081
|
|
|
|
|
|
|
|
28082
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
28083
|
|
|
|
|
|
|
|
28084
|
|
|
|
|
|
|
|
28085
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
28086
|
|
|
|
|
|
|
}; |
28087
|
|
|
|
|
|
|
|
28088
|
|
|
|
|
|
|
|
28089
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28090
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
28091
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28092
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28093
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28094
|
|
|
|
|
|
|
|
28095
|
|
|
|
|
|
|
|
28096
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28097
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
28098
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28099
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28100
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
28101
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28102
|
|
|
|
|
|
|
|
28103
|
|
|
|
|
|
|
|
28104
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28105
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
28106
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28107
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28108
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28109
|
|
|
|
|
|
|
|
28110
|
|
|
|
|
|
|
|
28111
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28112
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
28113
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28114
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28115
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
28116
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28117
|
|
|
|
|
|
|
|
28118
|
|
|
|
|
|
|
|
28119
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28120
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
28121
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28122
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28123
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28124
|
|
|
|
|
|
|
|
28125
|
|
|
|
|
|
|
|
28126
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28127
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
28128
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28129
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28130
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
28131
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
28132
|
|
|
|
|
|
|
|
28133
|
|
|
|
|
|
|
|
28134
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
28135
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
28136
|
|
|
|
|
|
|
|
28137
|
|
|
|
|
|
|
|
28138
|
|
|
|
|
|
|
|
28139
|
|
|
|
|
|
|
|
28140
|
|
|
|
|
|
|
|
28141
|
|
|
|
|
|
|
|
28142
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
28143
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
28144
|
|
|
|
|
|
|
|
28145
|
|
|
|
|
|
|
|
28146
|
|
|
|
|
|
|
|
28147
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
28148
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
28149
|
|
|
|
|
|
|
|
28150
|
|
|
|
|
|
|
|
28151
|
|
|
|
|
|
|
|
28152
|
|
|
|
|
|
|
|
28153
|
|
|
|
|
|
|
|
28154
|
|
|
|
|
|
|
|
28155
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
28156
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
28157
|
|
|
|
|
|
|
void (*free_func)(void *)); |
28158
|
|
|
|
|
|
|
|
28159
|
|
|
|
|
|
|
#ifdef __cplusplus |
28160
|
|
|
|
|
|
|
} |
28161
|
|
|
|
|
|
|
#endif |
28162
|
|
|
|
|
|
|
|
28163
|
|
|
|
|
|
|
#endif |
28164
|
|
|
|
|
|
|
|
28165
|
|
|
|
|
|
|
|
28166
|
|
|
|
|
|
|
#include |
28167
|
|
|
|
|
|
|
#include |
28168
|
|
|
|
|
|
|
#include |
28169
|
|
|
|
|
|
|
#ifdef _MSC_VER |
28170
|
|
|
|
|
|
|
# include |
28171
|
|
|
|
|
|
|
# include |
28172
|
|
|
|
|
|
|
|
28173
|
|
|
|
|
|
|
|
28174
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
28175
|
|
|
|
|
|
|
|
28176
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
28177
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
28178
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
28179
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
28180
|
|
|
|
|
|
|
|
28181
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
28182
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
28183
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
28184
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
28185
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
28186
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
28187
|
|
|
|
|
|
|
#endif |
28188
|
|
|
|
|
|
|
#ifndef FREESTANDING |
28189
|
|
|
|
|
|
|
# include |
28190
|
|
|
|
|
|
|
#endif |
28191
|
|
|
|
|
|
|
|
28192
|
|
|
|
|
|
|
|
28193
|
|
|
|
|
|
|
|
28194
|
|
|
|
|
|
|
|
28195
|
|
|
|
|
|
|
|
28196
|
|
|
|
|
|
|
|
28197
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
28198
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
28199
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
28200
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
28201
|
|
|
|
|
|
|
#ifdef _MSC_VER |
28202
|
|
|
|
|
|
|
# if defined(_M_X64) |
28203
|
|
|
|
|
|
|
# define ARCH_X86_64 |
28204
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
28205
|
|
|
|
|
|
|
# define ARCH_X86_32 |
28206
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
28207
|
|
|
|
|
|
|
# define ARCH_ARM64 |
28208
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
28209
|
|
|
|
|
|
|
# define ARCH_ARM32 |
28210
|
|
|
|
|
|
|
# endif |
28211
|
|
|
|
|
|
|
#else |
28212
|
|
|
|
|
|
|
# if defined(__x86_64__) |
28213
|
|
|
|
|
|
|
# define ARCH_X86_64 |
28214
|
|
|
|
|
|
|
# elif defined(__i386__) |
28215
|
|
|
|
|
|
|
# define ARCH_X86_32 |
28216
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
28217
|
|
|
|
|
|
|
# define ARCH_ARM64 |
28218
|
|
|
|
|
|
|
# elif defined(__arm__) |
28219
|
|
|
|
|
|
|
# define ARCH_ARM32 |
28220
|
|
|
|
|
|
|
# endif |
28221
|
|
|
|
|
|
|
#endif |
28222
|
|
|
|
|
|
|
|
28223
|
|
|
|
|
|
|
|
28224
|
|
|
|
|
|
|
|
28225
|
|
|
|
|
|
|
|
28226
|
|
|
|
|
|
|
|
28227
|
|
|
|
|
|
|
|
28228
|
|
|
|
|
|
|
typedef uint8_t u8; |
28229
|
|
|
|
|
|
|
typedef uint16_t u16; |
28230
|
|
|
|
|
|
|
typedef uint32_t u32; |
28231
|
|
|
|
|
|
|
typedef uint64_t u64; |
28232
|
|
|
|
|
|
|
typedef int8_t s8; |
28233
|
|
|
|
|
|
|
typedef int16_t s16; |
28234
|
|
|
|
|
|
|
typedef int32_t s32; |
28235
|
|
|
|
|
|
|
typedef int64_t s64; |
28236
|
|
|
|
|
|
|
|
28237
|
|
|
|
|
|
|
|
28238
|
|
|
|
|
|
|
#ifdef _MSC_VER |
28239
|
|
|
|
|
|
|
# ifdef _WIN64 |
28240
|
|
|
|
|
|
|
typedef long long ssize_t; |
28241
|
|
|
|
|
|
|
# else |
28242
|
|
|
|
|
|
|
typedef long ssize_t; |
28243
|
|
|
|
|
|
|
# endif |
28244
|
|
|
|
|
|
|
#endif |
28245
|
|
|
|
|
|
|
|
28246
|
|
|
|
|
|
|
|
28247
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
28248
|
|
|
|
|
|
|
|
28249
|
|
|
|
|
|
|
|
28250
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
28251
|
|
|
|
|
|
|
|
28252
|
|
|
|
|
|
|
|
28253
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
28254
|
|
|
|
|
|
|
|
28255
|
|
|
|
|
|
|
|
28256
|
|
|
|
|
|
|
|
28257
|
|
|
|
|
|
|
|
28258
|
|
|
|
|
|
|
|
28259
|
|
|
|
|
|
|
|
28260
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
28261
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
28262
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
28263
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
28264
|
|
|
|
|
|
|
#else |
28265
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
28266
|
|
|
|
|
|
|
#endif |
28267
|
|
|
|
|
|
|
#ifdef __clang__ |
28268
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
28269
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
28270
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
28271
|
|
|
|
|
|
|
# else |
28272
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
28273
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
28274
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
28275
|
|
|
|
|
|
|
# endif |
28276
|
|
|
|
|
|
|
#else |
28277
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
28278
|
|
|
|
|
|
|
#endif |
28279
|
|
|
|
|
|
|
|
28280
|
|
|
|
|
|
|
|
28281
|
|
|
|
|
|
|
#ifndef __has_attribute |
28282
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
28283
|
|
|
|
|
|
|
#endif |
28284
|
|
|
|
|
|
|
#ifndef __has_builtin |
28285
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
28286
|
|
|
|
|
|
|
#endif |
28287
|
|
|
|
|
|
|
|
28288
|
|
|
|
|
|
|
|
28289
|
|
|
|
|
|
|
#ifdef _MSC_VER |
28290
|
|
|
|
|
|
|
# define inline __inline |
28291
|
|
|
|
|
|
|
#endif |
28292
|
|
|
|
|
|
|
|
28293
|
|
|
|
|
|
|
|
28294
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
28295
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
28296
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28297
|
|
|
|
|
|
|
# define forceinline __forceinline |
28298
|
|
|
|
|
|
|
#else |
28299
|
|
|
|
|
|
|
# define forceinline inline |
28300
|
|
|
|
|
|
|
#endif |
28301
|
|
|
|
|
|
|
|
28302
|
|
|
|
|
|
|
|
28303
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
28304
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
28305
|
|
|
|
|
|
|
#else |
28306
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
28307
|
|
|
|
|
|
|
#endif |
28308
|
|
|
|
|
|
|
|
28309
|
|
|
|
|
|
|
|
28310
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
28311
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
28312
|
|
|
|
|
|
|
# define restrict __restrict__ |
28313
|
|
|
|
|
|
|
# else |
28314
|
|
|
|
|
|
|
# define restrict |
28315
|
|
|
|
|
|
|
# endif |
28316
|
|
|
|
|
|
|
#endif |
28317
|
|
|
|
|
|
|
|
28318
|
|
|
|
|
|
|
|
28319
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
28320
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
28321
|
|
|
|
|
|
|
#else |
28322
|
|
|
|
|
|
|
# define likely(expr) (expr) |
28323
|
|
|
|
|
|
|
#endif |
28324
|
|
|
|
|
|
|
|
28325
|
|
|
|
|
|
|
|
28326
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
28327
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
28328
|
|
|
|
|
|
|
#else |
28329
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
28330
|
|
|
|
|
|
|
#endif |
28331
|
|
|
|
|
|
|
|
28332
|
|
|
|
|
|
|
|
28333
|
|
|
|
|
|
|
#undef prefetchr |
28334
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
28335
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
28336
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28337
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
28338
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
28339
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
28340
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
28341
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
28342
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
28343
|
|
|
|
|
|
|
# endif |
28344
|
|
|
|
|
|
|
#endif |
28345
|
|
|
|
|
|
|
#ifndef prefetchr |
28346
|
|
|
|
|
|
|
# define prefetchr(addr) |
28347
|
|
|
|
|
|
|
#endif |
28348
|
|
|
|
|
|
|
|
28349
|
|
|
|
|
|
|
|
28350
|
|
|
|
|
|
|
#undef prefetchw |
28351
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
28352
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
28353
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28354
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
28355
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
28356
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
28357
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
28358
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
28359
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
28360
|
|
|
|
|
|
|
# endif |
28361
|
|
|
|
|
|
|
#endif |
28362
|
|
|
|
|
|
|
#ifndef prefetchw |
28363
|
|
|
|
|
|
|
# define prefetchw(addr) |
28364
|
|
|
|
|
|
|
#endif |
28365
|
|
|
|
|
|
|
|
28366
|
|
|
|
|
|
|
|
28367
|
|
|
|
|
|
|
#undef _aligned_attribute |
28368
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
28369
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
28370
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28371
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
28372
|
|
|
|
|
|
|
#endif |
28373
|
|
|
|
|
|
|
|
28374
|
|
|
|
|
|
|
|
28375
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
28376
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
28377
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
28378
|
|
|
|
|
|
|
#else |
28379
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
28380
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
28381
|
|
|
|
|
|
|
#endif |
28382
|
|
|
|
|
|
|
|
28383
|
|
|
|
|
|
|
|
28384
|
|
|
|
|
|
|
|
28385
|
|
|
|
|
|
|
|
28386
|
|
|
|
|
|
|
|
28387
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
28388
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
28389
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
28390
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
28391
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
28392
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
28393
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
28394
|
|
|
|
|
|
|
|
28395
|
|
|
|
|
|
|
|
28396
|
|
|
|
|
|
|
|
28397
|
|
|
|
|
|
|
|
28398
|
|
|
|
|
|
|
|
28399
|
|
|
|
|
|
|
|
28400
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
28401
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
28402
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28403
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
28404
|
|
|
|
|
|
|
#else |
28405
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
28406
|
|
|
|
|
|
|
{ |
28407
|
|
|
|
|
|
|
union { |
28408
|
|
|
|
|
|
|
u32 w; |
28409
|
|
|
|
|
|
|
u8 b; |
28410
|
|
|
|
|
|
|
} u; |
28411
|
|
|
|
|
|
|
|
28412
|
|
|
|
|
|
|
u.w = 1; |
28413
|
|
|
|
|
|
|
return u.b; |
28414
|
|
|
|
|
|
|
} |
28415
|
|
|
|
|
|
|
#endif |
28416
|
|
|
|
|
|
|
|
28417
|
|
|
|
|
|
|
|
28418
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
28419
|
|
|
|
|
|
|
{ |
28420
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
28421
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
28422
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28423
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
28424
|
|
|
|
|
|
|
#else |
28425
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
28426
|
|
|
|
|
|
|
#endif |
28427
|
|
|
|
|
|
|
} |
28428
|
|
|
|
|
|
|
|
28429
|
|
|
|
|
|
|
|
28430
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
28431
|
|
|
|
|
|
|
{ |
28432
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
28433
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
28434
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28435
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
28436
|
|
|
|
|
|
|
#else |
28437
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
28438
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
28439
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
28440
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
28441
|
|
|
|
|
|
|
#endif |
28442
|
|
|
|
|
|
|
} |
28443
|
|
|
|
|
|
|
|
28444
|
|
|
|
|
|
|
|
28445
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
28446
|
|
|
|
|
|
|
{ |
28447
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
28448
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
28449
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28450
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
28451
|
|
|
|
|
|
|
#else |
28452
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
28453
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
28454
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
28455
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
28456
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
28457
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
28458
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
28459
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
28460
|
|
|
|
|
|
|
#endif |
28461
|
|
|
|
|
|
|
} |
28462
|
|
|
|
|
|
|
|
28463
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
28464
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
28465
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
28466
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
28467
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
28468
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
28469
|
|
|
|
|
|
|
|
28470
|
|
|
|
|
|
|
|
28471
|
|
|
|
|
|
|
|
28472
|
|
|
|
|
|
|
|
28473
|
|
|
|
|
|
|
|
28474
|
|
|
|
|
|
|
|
28475
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
28476
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
28477
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
28478
|
|
|
|
|
|
|
defined(__wasm__)) |
28479
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
28480
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28481
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
28482
|
|
|
|
|
|
|
#else |
28483
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
28484
|
|
|
|
|
|
|
#endif |
28485
|
|
|
|
|
|
|
|
28486
|
|
|
|
|
|
|
|
28487
|
|
|
|
|
|
|
|
28488
|
|
|
|
|
|
|
#ifdef FREESTANDING |
28489
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
28490
|
|
|
|
|
|
|
#else |
28491
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
28492
|
|
|
|
|
|
|
#endif |
28493
|
|
|
|
|
|
|
|
28494
|
|
|
|
|
|
|
|
28495
|
|
|
|
|
|
|
|
28496
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
28497
|
|
|
|
|
|
|
static forceinline type \ |
28498
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
28499
|
|
|
|
|
|
|
{ \ |
28500
|
|
|
|
|
|
|
type v; \ |
28501
|
|
|
|
|
|
|
\ |
28502
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
28503
|
|
|
|
|
|
|
return v; \ |
28504
|
|
|
|
|
|
|
} \ |
28505
|
|
|
|
|
|
|
\ |
28506
|
|
|
|
|
|
|
static forceinline void \ |
28507
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
28508
|
|
|
|
|
|
|
{ \ |
28509
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
28510
|
|
|
|
|
|
|
} |
28511
|
|
|
|
|
|
|
|
28512
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
28513
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
28514
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
28515
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
28516
|
|
|
|
|
|
|
|
28517
|
|
|
|
|
|
|
#undef MEMCOPY |
28518
|
|
|
|
|
|
|
|
28519
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
28520
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
28521
|
|
|
|
|
|
|
|
28522
|
|
|
|
|
|
|
|
28523
|
|
|
|
|
|
|
|
28524
|
|
|
|
|
|
|
static forceinline u16 |
28525
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
28526
|
|
|
|
|
|
|
{ |
28527
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28528
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
28529
|
|
|
|
|
|
|
else |
28530
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
28531
|
|
|
|
|
|
|
} |
28532
|
|
|
|
|
|
|
|
28533
|
|
|
|
|
|
|
static forceinline u16 |
28534
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
28535
|
|
|
|
|
|
|
{ |
28536
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28537
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
28538
|
|
|
|
|
|
|
else |
28539
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
28540
|
|
|
|
|
|
|
} |
28541
|
|
|
|
|
|
|
|
28542
|
|
|
|
|
|
|
static forceinline u32 |
28543
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
28544
|
|
|
|
|
|
|
{ |
28545
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28546
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
28547
|
|
|
|
|
|
|
else |
28548
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
28549
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
28550
|
|
|
|
|
|
|
} |
28551
|
|
|
|
|
|
|
|
28552
|
|
|
|
|
|
|
static forceinline u32 |
28553
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
28554
|
|
|
|
|
|
|
{ |
28555
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28556
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
28557
|
|
|
|
|
|
|
else |
28558
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
28559
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
28560
|
|
|
|
|
|
|
} |
28561
|
|
|
|
|
|
|
|
28562
|
|
|
|
|
|
|
static forceinline u64 |
28563
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
28564
|
|
|
|
|
|
|
{ |
28565
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
28566
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
28567
|
|
|
|
|
|
|
else |
28568
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
28569
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
28570
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
28571
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
28572
|
|
|
|
|
|
|
} |
28573
|
|
|
|
|
|
|
|
28574
|
|
|
|
|
|
|
static forceinline machine_word_t |
28575
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
28576
|
|
|
|
|
|
|
{ |
28577
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
28578
|
|
|
|
|
|
|
if (WORDBITS == 32) |
28579
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
28580
|
|
|
|
|
|
|
else |
28581
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
28582
|
|
|
|
|
|
|
} |
28583
|
|
|
|
|
|
|
|
28584
|
|
|
|
|
|
|
|
28585
|
|
|
|
|
|
|
|
28586
|
|
|
|
|
|
|
static forceinline void |
28587
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
28588
|
|
|
|
|
|
|
{ |
28589
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28590
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
28591
|
|
|
|
|
|
|
} else { |
28592
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
28593
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
28594
|
|
|
|
|
|
|
} |
28595
|
|
|
|
|
|
|
} |
28596
|
|
|
|
|
|
|
|
28597
|
|
|
|
|
|
|
static forceinline void |
28598
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
28599
|
|
|
|
|
|
|
{ |
28600
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28601
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
28602
|
|
|
|
|
|
|
} else { |
28603
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
28604
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
28605
|
|
|
|
|
|
|
} |
28606
|
|
|
|
|
|
|
} |
28607
|
|
|
|
|
|
|
|
28608
|
|
|
|
|
|
|
static forceinline void |
28609
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
28610
|
|
|
|
|
|
|
{ |
28611
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28612
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
28613
|
|
|
|
|
|
|
} else { |
28614
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
28615
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
28616
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
28617
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
28618
|
|
|
|
|
|
|
} |
28619
|
|
|
|
|
|
|
} |
28620
|
|
|
|
|
|
|
|
28621
|
|
|
|
|
|
|
static forceinline void |
28622
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
28623
|
|
|
|
|
|
|
{ |
28624
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28625
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
28626
|
|
|
|
|
|
|
} else { |
28627
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
28628
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
28629
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
28630
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
28631
|
|
|
|
|
|
|
} |
28632
|
|
|
|
|
|
|
} |
28633
|
|
|
|
|
|
|
|
28634
|
|
|
|
|
|
|
static forceinline void |
28635
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
28636
|
|
|
|
|
|
|
{ |
28637
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
28638
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
28639
|
|
|
|
|
|
|
} else { |
28640
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
28641
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
28642
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
28643
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
28644
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
28645
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
28646
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
28647
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
28648
|
|
|
|
|
|
|
} |
28649
|
|
|
|
|
|
|
} |
28650
|
|
|
|
|
|
|
|
28651
|
|
|
|
|
|
|
static forceinline void |
28652
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
28653
|
|
|
|
|
|
|
{ |
28654
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
28655
|
|
|
|
|
|
|
if (WORDBITS == 32) |
28656
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
28657
|
|
|
|
|
|
|
else |
28658
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
28659
|
|
|
|
|
|
|
} |
28660
|
|
|
|
|
|
|
|
28661
|
|
|
|
|
|
|
|
28662
|
|
|
|
|
|
|
|
28663
|
|
|
|
|
|
|
|
28664
|
|
|
|
|
|
|
|
28665
|
|
|
|
|
|
|
|
28666
|
|
|
|
|
|
|
|
28667
|
|
|
|
|
|
|
static forceinline unsigned |
28668
|
|
|
|
|
|
|
bsr32(u32 v) |
28669
|
|
|
|
|
|
|
{ |
28670
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
28671
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
28672
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28673
|
|
|
|
|
|
|
unsigned long i; |
28674
|
|
|
|
|
|
|
|
28675
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
28676
|
|
|
|
|
|
|
return i; |
28677
|
|
|
|
|
|
|
#else |
28678
|
|
|
|
|
|
|
unsigned i = 0; |
28679
|
|
|
|
|
|
|
|
28680
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
28681
|
|
|
|
|
|
|
i++; |
28682
|
|
|
|
|
|
|
return i; |
28683
|
|
|
|
|
|
|
#endif |
28684
|
|
|
|
|
|
|
} |
28685
|
|
|
|
|
|
|
|
28686
|
|
|
|
|
|
|
static forceinline unsigned |
28687
|
|
|
|
|
|
|
bsr64(u64 v) |
28688
|
|
|
|
|
|
|
{ |
28689
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
28690
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
28691
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
28692
|
|
|
|
|
|
|
unsigned long i; |
28693
|
|
|
|
|
|
|
|
28694
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
28695
|
|
|
|
|
|
|
return i; |
28696
|
|
|
|
|
|
|
#else |
28697
|
|
|
|
|
|
|
unsigned i = 0; |
28698
|
|
|
|
|
|
|
|
28699
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
28700
|
|
|
|
|
|
|
i++; |
28701
|
|
|
|
|
|
|
return i; |
28702
|
|
|
|
|
|
|
#endif |
28703
|
|
|
|
|
|
|
} |
28704
|
|
|
|
|
|
|
|
28705
|
|
|
|
|
|
|
static forceinline unsigned |
28706
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
28707
|
|
|
|
|
|
|
{ |
28708
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
28709
|
|
|
|
|
|
|
if (WORDBITS == 32) |
28710
|
|
|
|
|
|
|
return bsr32(v); |
28711
|
|
|
|
|
|
|
else |
28712
|
|
|
|
|
|
|
return bsr64(v); |
28713
|
|
|
|
|
|
|
} |
28714
|
|
|
|
|
|
|
|
28715
|
|
|
|
|
|
|
|
28716
|
|
|
|
|
|
|
|
28717
|
|
|
|
|
|
|
static forceinline unsigned |
28718
|
|
|
|
|
|
|
bsf32(u32 v) |
28719
|
|
|
|
|
|
|
{ |
28720
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
28721
|
|
|
|
|
|
|
return __builtin_ctz(v); |
28722
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
28723
|
|
|
|
|
|
|
unsigned long i; |
28724
|
|
|
|
|
|
|
|
28725
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
28726
|
|
|
|
|
|
|
return i; |
28727
|
|
|
|
|
|
|
#else |
28728
|
|
|
|
|
|
|
unsigned i = 0; |
28729
|
|
|
|
|
|
|
|
28730
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
28731
|
|
|
|
|
|
|
i++; |
28732
|
|
|
|
|
|
|
return i; |
28733
|
|
|
|
|
|
|
#endif |
28734
|
|
|
|
|
|
|
} |
28735
|
|
|
|
|
|
|
|
28736
|
|
|
|
|
|
|
static forceinline unsigned |
28737
|
|
|
|
|
|
|
bsf64(u64 v) |
28738
|
|
|
|
|
|
|
{ |
28739
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
28740
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
28741
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
28742
|
|
|
|
|
|
|
unsigned long i; |
28743
|
|
|
|
|
|
|
|
28744
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
28745
|
|
|
|
|
|
|
return i; |
28746
|
|
|
|
|
|
|
#else |
28747
|
|
|
|
|
|
|
unsigned i = 0; |
28748
|
|
|
|
|
|
|
|
28749
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
28750
|
|
|
|
|
|
|
i++; |
28751
|
|
|
|
|
|
|
return i; |
28752
|
|
|
|
|
|
|
#endif |
28753
|
|
|
|
|
|
|
} |
28754
|
|
|
|
|
|
|
|
28755
|
|
|
|
|
|
|
static forceinline unsigned |
28756
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
28757
|
|
|
|
|
|
|
{ |
28758
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
28759
|
|
|
|
|
|
|
if (WORDBITS == 32) |
28760
|
|
|
|
|
|
|
return bsf32(v); |
28761
|
|
|
|
|
|
|
else |
28762
|
|
|
|
|
|
|
return bsf64(v); |
28763
|
|
|
|
|
|
|
} |
28764
|
|
|
|
|
|
|
|
28765
|
|
|
|
|
|
|
|
28766
|
|
|
|
|
|
|
#undef rbit32 |
28767
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
28768
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
28769
|
|
|
|
|
|
|
static forceinline u32 |
28770
|
|
|
|
|
|
|
rbit32(u32 v) |
28771
|
|
|
|
|
|
|
{ |
28772
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
28773
|
|
|
|
|
|
|
return v; |
28774
|
|
|
|
|
|
|
} |
28775
|
|
|
|
|
|
|
#define rbit32 rbit32 |
28776
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
28777
|
|
|
|
|
|
|
static forceinline u32 |
28778
|
|
|
|
|
|
|
rbit32(u32 v) |
28779
|
|
|
|
|
|
|
{ |
28780
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
28781
|
|
|
|
|
|
|
return v; |
28782
|
|
|
|
|
|
|
} |
28783
|
|
|
|
|
|
|
#define rbit32 rbit32 |
28784
|
|
|
|
|
|
|
#endif |
28785
|
|
|
|
|
|
|
|
28786
|
|
|
|
|
|
|
#endif |
28787
|
|
|
|
|
|
|
|
28788
|
|
|
|
|
|
|
|
28789
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
28790
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
28791
|
|
|
|
|
|
|
|
28792
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
28793
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
28794
|
|
|
|
|
|
|
|
28795
|
|
|
|
|
|
|
#ifdef FREESTANDING |
28796
|
|
|
|
|
|
|
|
28797
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
28798
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
28799
|
|
|
|
|
|
|
|
28800
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
28801
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
28802
|
|
|
|
|
|
|
|
28803
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
28804
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
28805
|
|
|
|
|
|
|
|
28806
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
28807
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
28808
|
|
|
|
|
|
|
|
28809
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
28810
|
|
|
|
|
|
|
#else |
28811
|
|
|
|
|
|
|
#include |
28812
|
|
|
|
|
|
|
#endif |
28813
|
|
|
|
|
|
|
|
28814
|
|
|
|
|
|
|
|
28815
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
28816
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
28817
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
28818
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
28819
|
|
|
|
|
|
|
#else |
28820
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
28821
|
|
|
|
|
|
|
#endif |
28822
|
|
|
|
|
|
|
|
28823
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
28824
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
28825
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
28826
|
|
|
|
|
|
|
|
28827
|
|
|
|
|
|
|
#endif |
28828
|
|
|
|
|
|
|
|
28829
|
|
|
|
|
|
|
/* #include "gzip_constants.h" */ |
28830
|
|
|
|
|
|
|
|
28831
|
|
|
|
|
|
|
|
28832
|
|
|
|
|
|
|
#ifndef LIB_GZIP_CONSTANTS_H |
28833
|
|
|
|
|
|
|
#define LIB_GZIP_CONSTANTS_H |
28834
|
|
|
|
|
|
|
|
28835
|
|
|
|
|
|
|
#define GZIP_MIN_HEADER_SIZE 10 |
28836
|
|
|
|
|
|
|
#define GZIP_FOOTER_SIZE 8 |
28837
|
|
|
|
|
|
|
#define GZIP_MIN_OVERHEAD (GZIP_MIN_HEADER_SIZE + GZIP_FOOTER_SIZE) |
28838
|
|
|
|
|
|
|
|
28839
|
|
|
|
|
|
|
#define GZIP_ID1 0x1F |
28840
|
|
|
|
|
|
|
#define GZIP_ID2 0x8B |
28841
|
|
|
|
|
|
|
|
28842
|
|
|
|
|
|
|
#define GZIP_CM_DEFLATE 8 |
28843
|
|
|
|
|
|
|
|
28844
|
|
|
|
|
|
|
#define GZIP_FTEXT 0x01 |
28845
|
|
|
|
|
|
|
#define GZIP_FHCRC 0x02 |
28846
|
|
|
|
|
|
|
#define GZIP_FEXTRA 0x04 |
28847
|
|
|
|
|
|
|
#define GZIP_FNAME 0x08 |
28848
|
|
|
|
|
|
|
#define GZIP_FCOMMENT 0x10 |
28849
|
|
|
|
|
|
|
#define GZIP_FRESERVED 0xE0 |
28850
|
|
|
|
|
|
|
|
28851
|
|
|
|
|
|
|
#define GZIP_MTIME_UNAVAILABLE 0 |
28852
|
|
|
|
|
|
|
|
28853
|
|
|
|
|
|
|
#define GZIP_XFL_SLOWEST_COMPRESSION 0x02 |
28854
|
|
|
|
|
|
|
#define GZIP_XFL_FASTEST_COMPRESSION 0x04 |
28855
|
|
|
|
|
|
|
|
28856
|
|
|
|
|
|
|
#define GZIP_OS_FAT 0 |
28857
|
|
|
|
|
|
|
#define GZIP_OS_AMIGA 1 |
28858
|
|
|
|
|
|
|
#define GZIP_OS_VMS 2 |
28859
|
|
|
|
|
|
|
#define GZIP_OS_UNIX 3 |
28860
|
|
|
|
|
|
|
#define GZIP_OS_VM_CMS 4 |
28861
|
|
|
|
|
|
|
#define GZIP_OS_ATARI_TOS 5 |
28862
|
|
|
|
|
|
|
#define GZIP_OS_HPFS 6 |
28863
|
|
|
|
|
|
|
#define GZIP_OS_MACINTOSH 7 |
28864
|
|
|
|
|
|
|
#define GZIP_OS_Z_SYSTEM 8 |
28865
|
|
|
|
|
|
|
#define GZIP_OS_CP_M 9 |
28866
|
|
|
|
|
|
|
#define GZIP_OS_TOPS_20 10 |
28867
|
|
|
|
|
|
|
#define GZIP_OS_NTFS 11 |
28868
|
|
|
|
|
|
|
#define GZIP_OS_QDOS 12 |
28869
|
|
|
|
|
|
|
#define GZIP_OS_RISCOS 13 |
28870
|
|
|
|
|
|
|
#define GZIP_OS_UNKNOWN 255 |
28871
|
|
|
|
|
|
|
|
28872
|
|
|
|
|
|
|
#endif |
28873
|
|
|
|
|
|
|
|
28874
|
|
|
|
|
|
|
|
28875
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28876
|
16
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *d, |
28877
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28878
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28879
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
28880
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
28881
|
|
|
|
|
|
|
{ |
28882
|
16
|
|
|
|
|
|
const u8 *in_next = in; |
28883
|
16
|
|
|
|
|
|
const u8 * const in_end = in_next + in_nbytes; |
28884
|
|
|
|
|
|
|
u8 flg; |
28885
|
|
|
|
|
|
|
size_t actual_in_nbytes; |
28886
|
|
|
|
|
|
|
size_t actual_out_nbytes; |
28887
|
|
|
|
|
|
|
enum libdeflate_result result; |
28888
|
|
|
|
|
|
|
|
28889
|
16
|
50
|
|
|
|
|
if (in_nbytes < GZIP_MIN_OVERHEAD) |
28890
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28891
|
|
|
|
|
|
|
|
28892
|
|
|
|
|
|
|
|
28893
|
16
|
50
|
|
|
|
|
if (*in_next++ != GZIP_ID1) |
28894
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28895
|
|
|
|
|
|
|
|
28896
|
16
|
50
|
|
|
|
|
if (*in_next++ != GZIP_ID2) |
28897
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28898
|
|
|
|
|
|
|
|
28899
|
16
|
50
|
|
|
|
|
if (*in_next++ != GZIP_CM_DEFLATE) |
28900
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28901
|
16
|
|
|
|
|
|
flg = *in_next++; |
28902
|
|
|
|
|
|
|
|
28903
|
16
|
|
|
|
|
|
in_next += 4; |
28904
|
|
|
|
|
|
|
|
28905
|
16
|
|
|
|
|
|
in_next += 1; |
28906
|
|
|
|
|
|
|
|
28907
|
16
|
|
|
|
|
|
in_next += 1; |
28908
|
|
|
|
|
|
|
|
28909
|
16
|
50
|
|
|
|
|
if (flg & GZIP_FRESERVED) |
28910
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28911
|
|
|
|
|
|
|
|
28912
|
|
|
|
|
|
|
|
28913
|
16
|
50
|
|
|
|
|
if (flg & GZIP_FEXTRA) { |
28914
|
0
|
|
|
|
|
|
u16 xlen = get_unaligned_le16(in_next); |
28915
|
0
|
|
|
|
|
|
in_next += 2; |
28916
|
|
|
|
|
|
|
|
28917
|
0
|
0
|
|
|
|
|
if (in_end - in_next < (u32)xlen + GZIP_FOOTER_SIZE) |
28918
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28919
|
|
|
|
|
|
|
|
28920
|
0
|
|
|
|
|
|
in_next += xlen; |
28921
|
|
|
|
|
|
|
} |
28922
|
|
|
|
|
|
|
|
28923
|
|
|
|
|
|
|
|
28924
|
16
|
100
|
|
|
|
|
if (flg & GZIP_FNAME) { |
28925
|
33
|
100
|
|
|
|
|
while (*in_next++ != 0 && in_next != in_end) |
|
|
50
|
|
|
|
|
|
28926
|
|
|
|
|
|
|
; |
28927
|
3
|
50
|
|
|
|
|
if (in_end - in_next < GZIP_FOOTER_SIZE) |
28928
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28929
|
|
|
|
|
|
|
} |
28930
|
|
|
|
|
|
|
|
28931
|
|
|
|
|
|
|
|
28932
|
16
|
50
|
|
|
|
|
if (flg & GZIP_FCOMMENT) { |
28933
|
0
|
0
|
|
|
|
|
while (*in_next++ != 0 && in_next != in_end) |
|
|
0
|
|
|
|
|
|
28934
|
|
|
|
|
|
|
; |
28935
|
0
|
0
|
|
|
|
|
if (in_end - in_next < GZIP_FOOTER_SIZE) |
28936
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28937
|
|
|
|
|
|
|
} |
28938
|
|
|
|
|
|
|
|
28939
|
|
|
|
|
|
|
|
28940
|
16
|
50
|
|
|
|
|
if (flg & GZIP_FHCRC) { |
28941
|
0
|
|
|
|
|
|
in_next += 2; |
28942
|
0
|
0
|
|
|
|
|
if (in_end - in_next < GZIP_FOOTER_SIZE) |
28943
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28944
|
|
|
|
|
|
|
} |
28945
|
|
|
|
|
|
|
|
28946
|
|
|
|
|
|
|
|
28947
|
16
|
|
|
|
|
|
result = libdeflate_deflate_decompress_ex(d, in_next, |
28948
|
16
|
|
|
|
|
|
in_end - GZIP_FOOTER_SIZE - in_next, |
28949
|
|
|
|
|
|
|
out, out_nbytes_avail, |
28950
|
|
|
|
|
|
|
&actual_in_nbytes, |
28951
|
|
|
|
|
|
|
actual_out_nbytes_ret); |
28952
|
16
|
50
|
|
|
|
|
if (result != LIBDEFLATE_SUCCESS) |
28953
|
0
|
|
|
|
|
|
return result; |
28954
|
|
|
|
|
|
|
|
28955
|
16
|
50
|
|
|
|
|
if (actual_out_nbytes_ret) |
28956
|
16
|
|
|
|
|
|
actual_out_nbytes = *actual_out_nbytes_ret; |
28957
|
|
|
|
|
|
|
else |
28958
|
0
|
|
|
|
|
|
actual_out_nbytes = out_nbytes_avail; |
28959
|
|
|
|
|
|
|
|
28960
|
16
|
|
|
|
|
|
in_next += actual_in_nbytes; |
28961
|
|
|
|
|
|
|
|
28962
|
|
|
|
|
|
|
|
28963
|
32
|
50
|
|
|
|
|
if (libdeflate_crc32(0, out, actual_out_nbytes) != |
28964
|
16
|
|
|
|
|
|
get_unaligned_le32(in_next)) |
28965
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28966
|
16
|
|
|
|
|
|
in_next += 4; |
28967
|
|
|
|
|
|
|
|
28968
|
|
|
|
|
|
|
|
28969
|
16
|
50
|
|
|
|
|
if ((u32)actual_out_nbytes != get_unaligned_le32(in_next)) |
28970
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
28971
|
16
|
|
|
|
|
|
in_next += 4; |
28972
|
|
|
|
|
|
|
|
28973
|
16
|
50
|
|
|
|
|
if (actual_in_nbytes_ret) |
28974
|
16
|
|
|
|
|
|
*actual_in_nbytes_ret = in_next - (u8 *)in; |
28975
|
|
|
|
|
|
|
|
28976
|
16
|
|
|
|
|
|
return LIBDEFLATE_SUCCESS; |
28977
|
|
|
|
|
|
|
} |
28978
|
|
|
|
|
|
|
|
28979
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
28980
|
0
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *d, |
28981
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
28982
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
28983
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
28984
|
|
|
|
|
|
|
{ |
28985
|
0
|
|
|
|
|
|
return libdeflate_gzip_decompress_ex(d, in, in_nbytes, |
28986
|
|
|
|
|
|
|
out, out_nbytes_avail, |
28987
|
|
|
|
|
|
|
NULL, actual_out_nbytes_ret); |
28988
|
|
|
|
|
|
|
} |
28989
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/utils.c */ |
28990
|
|
|
|
|
|
|
|
28991
|
|
|
|
|
|
|
|
28992
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
28993
|
|
|
|
|
|
|
|
28994
|
|
|
|
|
|
|
|
28995
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
28996
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
28997
|
|
|
|
|
|
|
|
28998
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
28999
|
|
|
|
|
|
|
|
29000
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
29001
|
|
|
|
|
|
|
#endif |
29002
|
|
|
|
|
|
|
|
29003
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
29004
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
29005
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
29006
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
29007
|
|
|
|
|
|
|
#else |
29008
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
29009
|
|
|
|
|
|
|
#endif |
29010
|
|
|
|
|
|
|
|
29011
|
|
|
|
|
|
|
|
29012
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
29013
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
29014
|
|
|
|
|
|
|
#else |
29015
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
29016
|
|
|
|
|
|
|
#endif |
29017
|
|
|
|
|
|
|
|
29018
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
29019
|
|
|
|
|
|
|
|
29020
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
29021
|
|
|
|
|
|
|
|
29022
|
|
|
|
|
|
|
|
29023
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
29024
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
29025
|
|
|
|
|
|
|
|
29026
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
29027
|
|
|
|
|
|
|
|
29028
|
|
|
|
|
|
|
|
29029
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
29030
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
29031
|
|
|
|
|
|
|
|
29032
|
|
|
|
|
|
|
#include |
29033
|
|
|
|
|
|
|
#include |
29034
|
|
|
|
|
|
|
|
29035
|
|
|
|
|
|
|
#ifdef __cplusplus |
29036
|
|
|
|
|
|
|
extern "C" { |
29037
|
|
|
|
|
|
|
#endif |
29038
|
|
|
|
|
|
|
|
29039
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
29040
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
29041
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
29042
|
|
|
|
|
|
|
|
29043
|
|
|
|
|
|
|
|
29044
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
29045
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
29046
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
29047
|
|
|
|
|
|
|
# else |
29048
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
29049
|
|
|
|
|
|
|
# endif |
29050
|
|
|
|
|
|
|
#endif |
29051
|
|
|
|
|
|
|
|
29052
|
|
|
|
|
|
|
|
29053
|
|
|
|
|
|
|
|
29054
|
|
|
|
|
|
|
|
29055
|
|
|
|
|
|
|
|
29056
|
|
|
|
|
|
|
struct libdeflate_compressor; |
29057
|
|
|
|
|
|
|
|
29058
|
|
|
|
|
|
|
|
29059
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
29060
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
29061
|
|
|
|
|
|
|
|
29062
|
|
|
|
|
|
|
|
29063
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29064
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
29065
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29066
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
29067
|
|
|
|
|
|
|
|
29068
|
|
|
|
|
|
|
|
29069
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29070
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
29071
|
|
|
|
|
|
|
size_t in_nbytes); |
29072
|
|
|
|
|
|
|
|
29073
|
|
|
|
|
|
|
|
29074
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29075
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
29076
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29077
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
29078
|
|
|
|
|
|
|
|
29079
|
|
|
|
|
|
|
|
29080
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29081
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
29082
|
|
|
|
|
|
|
size_t in_nbytes); |
29083
|
|
|
|
|
|
|
|
29084
|
|
|
|
|
|
|
|
29085
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29086
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
29087
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29088
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
29089
|
|
|
|
|
|
|
|
29090
|
|
|
|
|
|
|
|
29091
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
29092
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
29093
|
|
|
|
|
|
|
size_t in_nbytes); |
29094
|
|
|
|
|
|
|
|
29095
|
|
|
|
|
|
|
|
29096
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
29097
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
29098
|
|
|
|
|
|
|
|
29099
|
|
|
|
|
|
|
|
29100
|
|
|
|
|
|
|
|
29101
|
|
|
|
|
|
|
|
29102
|
|
|
|
|
|
|
|
29103
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
29104
|
|
|
|
|
|
|
|
29105
|
|
|
|
|
|
|
|
29106
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
29107
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
29108
|
|
|
|
|
|
|
|
29109
|
|
|
|
|
|
|
|
29110
|
|
|
|
|
|
|
enum libdeflate_result { |
29111
|
|
|
|
|
|
|
|
29112
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
29113
|
|
|
|
|
|
|
|
29114
|
|
|
|
|
|
|
|
29115
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
29116
|
|
|
|
|
|
|
|
29117
|
|
|
|
|
|
|
|
29118
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
29119
|
|
|
|
|
|
|
|
29120
|
|
|
|
|
|
|
|
29121
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
29122
|
|
|
|
|
|
|
}; |
29123
|
|
|
|
|
|
|
|
29124
|
|
|
|
|
|
|
|
29125
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29126
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
29127
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29128
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29129
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29130
|
|
|
|
|
|
|
|
29131
|
|
|
|
|
|
|
|
29132
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29133
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
29134
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29135
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29136
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
29137
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29138
|
|
|
|
|
|
|
|
29139
|
|
|
|
|
|
|
|
29140
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29141
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
29142
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29143
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29144
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29145
|
|
|
|
|
|
|
|
29146
|
|
|
|
|
|
|
|
29147
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29148
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
29149
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29150
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29151
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
29152
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29153
|
|
|
|
|
|
|
|
29154
|
|
|
|
|
|
|
|
29155
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29156
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
29157
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29158
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29159
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29160
|
|
|
|
|
|
|
|
29161
|
|
|
|
|
|
|
|
29162
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
29163
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
29164
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
29165
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
29166
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
29167
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
29168
|
|
|
|
|
|
|
|
29169
|
|
|
|
|
|
|
|
29170
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
29171
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
29172
|
|
|
|
|
|
|
|
29173
|
|
|
|
|
|
|
|
29174
|
|
|
|
|
|
|
|
29175
|
|
|
|
|
|
|
|
29176
|
|
|
|
|
|
|
|
29177
|
|
|
|
|
|
|
|
29178
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
29179
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
29180
|
|
|
|
|
|
|
|
29181
|
|
|
|
|
|
|
|
29182
|
|
|
|
|
|
|
|
29183
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
29184
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
29185
|
|
|
|
|
|
|
|
29186
|
|
|
|
|
|
|
|
29187
|
|
|
|
|
|
|
|
29188
|
|
|
|
|
|
|
|
29189
|
|
|
|
|
|
|
|
29190
|
|
|
|
|
|
|
|
29191
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
29192
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
29193
|
|
|
|
|
|
|
void (*free_func)(void *)); |
29194
|
|
|
|
|
|
|
|
29195
|
|
|
|
|
|
|
#ifdef __cplusplus |
29196
|
|
|
|
|
|
|
} |
29197
|
|
|
|
|
|
|
#endif |
29198
|
|
|
|
|
|
|
|
29199
|
|
|
|
|
|
|
#endif |
29200
|
|
|
|
|
|
|
|
29201
|
|
|
|
|
|
|
|
29202
|
|
|
|
|
|
|
#include |
29203
|
|
|
|
|
|
|
#include |
29204
|
|
|
|
|
|
|
#include |
29205
|
|
|
|
|
|
|
#ifdef _MSC_VER |
29206
|
|
|
|
|
|
|
# include |
29207
|
|
|
|
|
|
|
# include |
29208
|
|
|
|
|
|
|
|
29209
|
|
|
|
|
|
|
|
29210
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
29211
|
|
|
|
|
|
|
|
29212
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
29213
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
29214
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
29215
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
29216
|
|
|
|
|
|
|
|
29217
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
29218
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
29219
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
29220
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
29221
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
29222
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
29223
|
|
|
|
|
|
|
#endif |
29224
|
|
|
|
|
|
|
#ifndef FREESTANDING |
29225
|
|
|
|
|
|
|
# include |
29226
|
|
|
|
|
|
|
#endif |
29227
|
|
|
|
|
|
|
|
29228
|
|
|
|
|
|
|
|
29229
|
|
|
|
|
|
|
|
29230
|
|
|
|
|
|
|
|
29231
|
|
|
|
|
|
|
|
29232
|
|
|
|
|
|
|
|
29233
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
29234
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
29235
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
29236
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
29237
|
|
|
|
|
|
|
#ifdef _MSC_VER |
29238
|
|
|
|
|
|
|
# if defined(_M_X64) |
29239
|
|
|
|
|
|
|
# define ARCH_X86_64 |
29240
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
29241
|
|
|
|
|
|
|
# define ARCH_X86_32 |
29242
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
29243
|
|
|
|
|
|
|
# define ARCH_ARM64 |
29244
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
29245
|
|
|
|
|
|
|
# define ARCH_ARM32 |
29246
|
|
|
|
|
|
|
# endif |
29247
|
|
|
|
|
|
|
#else |
29248
|
|
|
|
|
|
|
# if defined(__x86_64__) |
29249
|
|
|
|
|
|
|
# define ARCH_X86_64 |
29250
|
|
|
|
|
|
|
# elif defined(__i386__) |
29251
|
|
|
|
|
|
|
# define ARCH_X86_32 |
29252
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
29253
|
|
|
|
|
|
|
# define ARCH_ARM64 |
29254
|
|
|
|
|
|
|
# elif defined(__arm__) |
29255
|
|
|
|
|
|
|
# define ARCH_ARM32 |
29256
|
|
|
|
|
|
|
# endif |
29257
|
|
|
|
|
|
|
#endif |
29258
|
|
|
|
|
|
|
|
29259
|
|
|
|
|
|
|
|
29260
|
|
|
|
|
|
|
|
29261
|
|
|
|
|
|
|
|
29262
|
|
|
|
|
|
|
|
29263
|
|
|
|
|
|
|
|
29264
|
|
|
|
|
|
|
typedef uint8_t u8; |
29265
|
|
|
|
|
|
|
typedef uint16_t u16; |
29266
|
|
|
|
|
|
|
typedef uint32_t u32; |
29267
|
|
|
|
|
|
|
typedef uint64_t u64; |
29268
|
|
|
|
|
|
|
typedef int8_t s8; |
29269
|
|
|
|
|
|
|
typedef int16_t s16; |
29270
|
|
|
|
|
|
|
typedef int32_t s32; |
29271
|
|
|
|
|
|
|
typedef int64_t s64; |
29272
|
|
|
|
|
|
|
|
29273
|
|
|
|
|
|
|
|
29274
|
|
|
|
|
|
|
#ifdef _MSC_VER |
29275
|
|
|
|
|
|
|
# ifdef _WIN64 |
29276
|
|
|
|
|
|
|
typedef long long ssize_t; |
29277
|
|
|
|
|
|
|
# else |
29278
|
|
|
|
|
|
|
typedef long ssize_t; |
29279
|
|
|
|
|
|
|
# endif |
29280
|
|
|
|
|
|
|
#endif |
29281
|
|
|
|
|
|
|
|
29282
|
|
|
|
|
|
|
|
29283
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
29284
|
|
|
|
|
|
|
|
29285
|
|
|
|
|
|
|
|
29286
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
29287
|
|
|
|
|
|
|
|
29288
|
|
|
|
|
|
|
|
29289
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
29290
|
|
|
|
|
|
|
|
29291
|
|
|
|
|
|
|
|
29292
|
|
|
|
|
|
|
|
29293
|
|
|
|
|
|
|
|
29294
|
|
|
|
|
|
|
|
29295
|
|
|
|
|
|
|
|
29296
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
29297
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
29298
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
29299
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
29300
|
|
|
|
|
|
|
#else |
29301
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
29302
|
|
|
|
|
|
|
#endif |
29303
|
|
|
|
|
|
|
#ifdef __clang__ |
29304
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
29305
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
29306
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
29307
|
|
|
|
|
|
|
# else |
29308
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
29309
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
29310
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
29311
|
|
|
|
|
|
|
# endif |
29312
|
|
|
|
|
|
|
#else |
29313
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
29314
|
|
|
|
|
|
|
#endif |
29315
|
|
|
|
|
|
|
|
29316
|
|
|
|
|
|
|
|
29317
|
|
|
|
|
|
|
#ifndef __has_attribute |
29318
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
29319
|
|
|
|
|
|
|
#endif |
29320
|
|
|
|
|
|
|
#ifndef __has_builtin |
29321
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
29322
|
|
|
|
|
|
|
#endif |
29323
|
|
|
|
|
|
|
|
29324
|
|
|
|
|
|
|
|
29325
|
|
|
|
|
|
|
#ifdef _MSC_VER |
29326
|
|
|
|
|
|
|
# define inline __inline |
29327
|
|
|
|
|
|
|
#endif |
29328
|
|
|
|
|
|
|
|
29329
|
|
|
|
|
|
|
|
29330
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
29331
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
29332
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29333
|
|
|
|
|
|
|
# define forceinline __forceinline |
29334
|
|
|
|
|
|
|
#else |
29335
|
|
|
|
|
|
|
# define forceinline inline |
29336
|
|
|
|
|
|
|
#endif |
29337
|
|
|
|
|
|
|
|
29338
|
|
|
|
|
|
|
|
29339
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
29340
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
29341
|
|
|
|
|
|
|
#else |
29342
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
29343
|
|
|
|
|
|
|
#endif |
29344
|
|
|
|
|
|
|
|
29345
|
|
|
|
|
|
|
|
29346
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
29347
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
29348
|
|
|
|
|
|
|
# define restrict __restrict__ |
29349
|
|
|
|
|
|
|
# else |
29350
|
|
|
|
|
|
|
# define restrict |
29351
|
|
|
|
|
|
|
# endif |
29352
|
|
|
|
|
|
|
#endif |
29353
|
|
|
|
|
|
|
|
29354
|
|
|
|
|
|
|
|
29355
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
29356
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
29357
|
|
|
|
|
|
|
#else |
29358
|
|
|
|
|
|
|
# define likely(expr) (expr) |
29359
|
|
|
|
|
|
|
#endif |
29360
|
|
|
|
|
|
|
|
29361
|
|
|
|
|
|
|
|
29362
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
29363
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
29364
|
|
|
|
|
|
|
#else |
29365
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
29366
|
|
|
|
|
|
|
#endif |
29367
|
|
|
|
|
|
|
|
29368
|
|
|
|
|
|
|
|
29369
|
|
|
|
|
|
|
#undef prefetchr |
29370
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
29371
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
29372
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29373
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
29374
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
29375
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
29376
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
29377
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
29378
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
29379
|
|
|
|
|
|
|
# endif |
29380
|
|
|
|
|
|
|
#endif |
29381
|
|
|
|
|
|
|
#ifndef prefetchr |
29382
|
|
|
|
|
|
|
# define prefetchr(addr) |
29383
|
|
|
|
|
|
|
#endif |
29384
|
|
|
|
|
|
|
|
29385
|
|
|
|
|
|
|
|
29386
|
|
|
|
|
|
|
#undef prefetchw |
29387
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
29388
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
29389
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29390
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
29391
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
29392
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
29393
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
29394
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
29395
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
29396
|
|
|
|
|
|
|
# endif |
29397
|
|
|
|
|
|
|
#endif |
29398
|
|
|
|
|
|
|
#ifndef prefetchw |
29399
|
|
|
|
|
|
|
# define prefetchw(addr) |
29400
|
|
|
|
|
|
|
#endif |
29401
|
|
|
|
|
|
|
|
29402
|
|
|
|
|
|
|
|
29403
|
|
|
|
|
|
|
#undef _aligned_attribute |
29404
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
29405
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
29406
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29407
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
29408
|
|
|
|
|
|
|
#endif |
29409
|
|
|
|
|
|
|
|
29410
|
|
|
|
|
|
|
|
29411
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
29412
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
29413
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
29414
|
|
|
|
|
|
|
#else |
29415
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
29416
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
29417
|
|
|
|
|
|
|
#endif |
29418
|
|
|
|
|
|
|
|
29419
|
|
|
|
|
|
|
|
29420
|
|
|
|
|
|
|
|
29421
|
|
|
|
|
|
|
|
29422
|
|
|
|
|
|
|
|
29423
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
29424
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
29425
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
29426
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
29427
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
29428
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
29429
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
29430
|
|
|
|
|
|
|
|
29431
|
|
|
|
|
|
|
|
29432
|
|
|
|
|
|
|
|
29433
|
|
|
|
|
|
|
|
29434
|
|
|
|
|
|
|
|
29435
|
|
|
|
|
|
|
|
29436
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
29437
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
29438
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29439
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
29440
|
|
|
|
|
|
|
#else |
29441
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
29442
|
|
|
|
|
|
|
{ |
29443
|
|
|
|
|
|
|
union { |
29444
|
|
|
|
|
|
|
u32 w; |
29445
|
|
|
|
|
|
|
u8 b; |
29446
|
|
|
|
|
|
|
} u; |
29447
|
|
|
|
|
|
|
|
29448
|
|
|
|
|
|
|
u.w = 1; |
29449
|
|
|
|
|
|
|
return u.b; |
29450
|
|
|
|
|
|
|
} |
29451
|
|
|
|
|
|
|
#endif |
29452
|
|
|
|
|
|
|
|
29453
|
|
|
|
|
|
|
|
29454
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
29455
|
|
|
|
|
|
|
{ |
29456
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
29457
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
29458
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29459
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
29460
|
|
|
|
|
|
|
#else |
29461
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
29462
|
|
|
|
|
|
|
#endif |
29463
|
|
|
|
|
|
|
} |
29464
|
|
|
|
|
|
|
|
29465
|
|
|
|
|
|
|
|
29466
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
29467
|
|
|
|
|
|
|
{ |
29468
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
29469
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
29470
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29471
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
29472
|
|
|
|
|
|
|
#else |
29473
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
29474
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
29475
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
29476
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
29477
|
|
|
|
|
|
|
#endif |
29478
|
|
|
|
|
|
|
} |
29479
|
|
|
|
|
|
|
|
29480
|
|
|
|
|
|
|
|
29481
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
29482
|
|
|
|
|
|
|
{ |
29483
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
29484
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
29485
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29486
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
29487
|
|
|
|
|
|
|
#else |
29488
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
29489
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
29490
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
29491
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
29492
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
29493
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
29494
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
29495
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
29496
|
|
|
|
|
|
|
#endif |
29497
|
|
|
|
|
|
|
} |
29498
|
|
|
|
|
|
|
|
29499
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
29500
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
29501
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
29502
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
29503
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
29504
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
29505
|
|
|
|
|
|
|
|
29506
|
|
|
|
|
|
|
|
29507
|
|
|
|
|
|
|
|
29508
|
|
|
|
|
|
|
|
29509
|
|
|
|
|
|
|
|
29510
|
|
|
|
|
|
|
|
29511
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
29512
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
29513
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
29514
|
|
|
|
|
|
|
defined(__wasm__)) |
29515
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
29516
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29517
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
29518
|
|
|
|
|
|
|
#else |
29519
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
29520
|
|
|
|
|
|
|
#endif |
29521
|
|
|
|
|
|
|
|
29522
|
|
|
|
|
|
|
|
29523
|
|
|
|
|
|
|
|
29524
|
|
|
|
|
|
|
#ifdef FREESTANDING |
29525
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
29526
|
|
|
|
|
|
|
#else |
29527
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
29528
|
|
|
|
|
|
|
#endif |
29529
|
|
|
|
|
|
|
|
29530
|
|
|
|
|
|
|
|
29531
|
|
|
|
|
|
|
|
29532
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
29533
|
|
|
|
|
|
|
static forceinline type \ |
29534
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
29535
|
|
|
|
|
|
|
{ \ |
29536
|
|
|
|
|
|
|
type v; \ |
29537
|
|
|
|
|
|
|
\ |
29538
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
29539
|
|
|
|
|
|
|
return v; \ |
29540
|
|
|
|
|
|
|
} \ |
29541
|
|
|
|
|
|
|
\ |
29542
|
|
|
|
|
|
|
static forceinline void \ |
29543
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
29544
|
|
|
|
|
|
|
{ \ |
29545
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
29546
|
|
|
|
|
|
|
} |
29547
|
|
|
|
|
|
|
|
29548
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
29549
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
29550
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
29551
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
29552
|
|
|
|
|
|
|
|
29553
|
|
|
|
|
|
|
#undef MEMCOPY |
29554
|
|
|
|
|
|
|
|
29555
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
29556
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
29557
|
|
|
|
|
|
|
|
29558
|
|
|
|
|
|
|
|
29559
|
|
|
|
|
|
|
|
29560
|
|
|
|
|
|
|
static forceinline u16 |
29561
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
29562
|
|
|
|
|
|
|
{ |
29563
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29564
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
29565
|
|
|
|
|
|
|
else |
29566
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
29567
|
|
|
|
|
|
|
} |
29568
|
|
|
|
|
|
|
|
29569
|
|
|
|
|
|
|
static forceinline u16 |
29570
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
29571
|
|
|
|
|
|
|
{ |
29572
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29573
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
29574
|
|
|
|
|
|
|
else |
29575
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
29576
|
|
|
|
|
|
|
} |
29577
|
|
|
|
|
|
|
|
29578
|
|
|
|
|
|
|
static forceinline u32 |
29579
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
29580
|
|
|
|
|
|
|
{ |
29581
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29582
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
29583
|
|
|
|
|
|
|
else |
29584
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
29585
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
29586
|
|
|
|
|
|
|
} |
29587
|
|
|
|
|
|
|
|
29588
|
|
|
|
|
|
|
static forceinline u32 |
29589
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
29590
|
|
|
|
|
|
|
{ |
29591
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29592
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
29593
|
|
|
|
|
|
|
else |
29594
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
29595
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
29596
|
|
|
|
|
|
|
} |
29597
|
|
|
|
|
|
|
|
29598
|
|
|
|
|
|
|
static forceinline u64 |
29599
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
29600
|
|
|
|
|
|
|
{ |
29601
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
29602
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
29603
|
|
|
|
|
|
|
else |
29604
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
29605
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
29606
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
29607
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
29608
|
|
|
|
|
|
|
} |
29609
|
|
|
|
|
|
|
|
29610
|
|
|
|
|
|
|
static forceinline machine_word_t |
29611
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
29612
|
|
|
|
|
|
|
{ |
29613
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
29614
|
|
|
|
|
|
|
if (WORDBITS == 32) |
29615
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
29616
|
|
|
|
|
|
|
else |
29617
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
29618
|
|
|
|
|
|
|
} |
29619
|
|
|
|
|
|
|
|
29620
|
|
|
|
|
|
|
|
29621
|
|
|
|
|
|
|
|
29622
|
|
|
|
|
|
|
static forceinline void |
29623
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
29624
|
|
|
|
|
|
|
{ |
29625
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29626
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
29627
|
|
|
|
|
|
|
} else { |
29628
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
29629
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
29630
|
|
|
|
|
|
|
} |
29631
|
|
|
|
|
|
|
} |
29632
|
|
|
|
|
|
|
|
29633
|
|
|
|
|
|
|
static forceinline void |
29634
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
29635
|
|
|
|
|
|
|
{ |
29636
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29637
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
29638
|
|
|
|
|
|
|
} else { |
29639
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
29640
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
29641
|
|
|
|
|
|
|
} |
29642
|
|
|
|
|
|
|
} |
29643
|
|
|
|
|
|
|
|
29644
|
|
|
|
|
|
|
static forceinline void |
29645
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
29646
|
|
|
|
|
|
|
{ |
29647
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29648
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
29649
|
|
|
|
|
|
|
} else { |
29650
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
29651
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
29652
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
29653
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
29654
|
|
|
|
|
|
|
} |
29655
|
|
|
|
|
|
|
} |
29656
|
|
|
|
|
|
|
|
29657
|
|
|
|
|
|
|
static forceinline void |
29658
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
29659
|
|
|
|
|
|
|
{ |
29660
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29661
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
29662
|
|
|
|
|
|
|
} else { |
29663
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
29664
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
29665
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
29666
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
29667
|
|
|
|
|
|
|
} |
29668
|
|
|
|
|
|
|
} |
29669
|
|
|
|
|
|
|
|
29670
|
|
|
|
|
|
|
static forceinline void |
29671
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
29672
|
|
|
|
|
|
|
{ |
29673
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
29674
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
29675
|
|
|
|
|
|
|
} else { |
29676
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
29677
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
29678
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
29679
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
29680
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
29681
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
29682
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
29683
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
29684
|
|
|
|
|
|
|
} |
29685
|
|
|
|
|
|
|
} |
29686
|
|
|
|
|
|
|
|
29687
|
|
|
|
|
|
|
static forceinline void |
29688
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
29689
|
|
|
|
|
|
|
{ |
29690
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
29691
|
|
|
|
|
|
|
if (WORDBITS == 32) |
29692
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
29693
|
|
|
|
|
|
|
else |
29694
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
29695
|
|
|
|
|
|
|
} |
29696
|
|
|
|
|
|
|
|
29697
|
|
|
|
|
|
|
|
29698
|
|
|
|
|
|
|
|
29699
|
|
|
|
|
|
|
|
29700
|
|
|
|
|
|
|
|
29701
|
|
|
|
|
|
|
|
29702
|
|
|
|
|
|
|
|
29703
|
|
|
|
|
|
|
static forceinline unsigned |
29704
|
|
|
|
|
|
|
bsr32(u32 v) |
29705
|
|
|
|
|
|
|
{ |
29706
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
29707
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
29708
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29709
|
|
|
|
|
|
|
unsigned long i; |
29710
|
|
|
|
|
|
|
|
29711
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
29712
|
|
|
|
|
|
|
return i; |
29713
|
|
|
|
|
|
|
#else |
29714
|
|
|
|
|
|
|
unsigned i = 0; |
29715
|
|
|
|
|
|
|
|
29716
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
29717
|
|
|
|
|
|
|
i++; |
29718
|
|
|
|
|
|
|
return i; |
29719
|
|
|
|
|
|
|
#endif |
29720
|
|
|
|
|
|
|
} |
29721
|
|
|
|
|
|
|
|
29722
|
|
|
|
|
|
|
static forceinline unsigned |
29723
|
|
|
|
|
|
|
bsr64(u64 v) |
29724
|
|
|
|
|
|
|
{ |
29725
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
29726
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
29727
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
29728
|
|
|
|
|
|
|
unsigned long i; |
29729
|
|
|
|
|
|
|
|
29730
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
29731
|
|
|
|
|
|
|
return i; |
29732
|
|
|
|
|
|
|
#else |
29733
|
|
|
|
|
|
|
unsigned i = 0; |
29734
|
|
|
|
|
|
|
|
29735
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
29736
|
|
|
|
|
|
|
i++; |
29737
|
|
|
|
|
|
|
return i; |
29738
|
|
|
|
|
|
|
#endif |
29739
|
|
|
|
|
|
|
} |
29740
|
|
|
|
|
|
|
|
29741
|
|
|
|
|
|
|
static forceinline unsigned |
29742
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
29743
|
|
|
|
|
|
|
{ |
29744
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
29745
|
|
|
|
|
|
|
if (WORDBITS == 32) |
29746
|
|
|
|
|
|
|
return bsr32(v); |
29747
|
|
|
|
|
|
|
else |
29748
|
|
|
|
|
|
|
return bsr64(v); |
29749
|
|
|
|
|
|
|
} |
29750
|
|
|
|
|
|
|
|
29751
|
|
|
|
|
|
|
|
29752
|
|
|
|
|
|
|
|
29753
|
|
|
|
|
|
|
static forceinline unsigned |
29754
|
|
|
|
|
|
|
bsf32(u32 v) |
29755
|
|
|
|
|
|
|
{ |
29756
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
29757
|
|
|
|
|
|
|
return __builtin_ctz(v); |
29758
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
29759
|
|
|
|
|
|
|
unsigned long i; |
29760
|
|
|
|
|
|
|
|
29761
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
29762
|
|
|
|
|
|
|
return i; |
29763
|
|
|
|
|
|
|
#else |
29764
|
|
|
|
|
|
|
unsigned i = 0; |
29765
|
|
|
|
|
|
|
|
29766
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
29767
|
|
|
|
|
|
|
i++; |
29768
|
|
|
|
|
|
|
return i; |
29769
|
|
|
|
|
|
|
#endif |
29770
|
|
|
|
|
|
|
} |
29771
|
|
|
|
|
|
|
|
29772
|
|
|
|
|
|
|
static forceinline unsigned |
29773
|
|
|
|
|
|
|
bsf64(u64 v) |
29774
|
|
|
|
|
|
|
{ |
29775
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
29776
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
29777
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
29778
|
|
|
|
|
|
|
unsigned long i; |
29779
|
|
|
|
|
|
|
|
29780
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
29781
|
|
|
|
|
|
|
return i; |
29782
|
|
|
|
|
|
|
#else |
29783
|
|
|
|
|
|
|
unsigned i = 0; |
29784
|
|
|
|
|
|
|
|
29785
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
29786
|
|
|
|
|
|
|
i++; |
29787
|
|
|
|
|
|
|
return i; |
29788
|
|
|
|
|
|
|
#endif |
29789
|
|
|
|
|
|
|
} |
29790
|
|
|
|
|
|
|
|
29791
|
|
|
|
|
|
|
static forceinline unsigned |
29792
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
29793
|
|
|
|
|
|
|
{ |
29794
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
29795
|
|
|
|
|
|
|
if (WORDBITS == 32) |
29796
|
|
|
|
|
|
|
return bsf32(v); |
29797
|
|
|
|
|
|
|
else |
29798
|
|
|
|
|
|
|
return bsf64(v); |
29799
|
|
|
|
|
|
|
} |
29800
|
|
|
|
|
|
|
|
29801
|
|
|
|
|
|
|
|
29802
|
|
|
|
|
|
|
#undef rbit32 |
29803
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
29804
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
29805
|
|
|
|
|
|
|
static forceinline u32 |
29806
|
|
|
|
|
|
|
rbit32(u32 v) |
29807
|
|
|
|
|
|
|
{ |
29808
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
29809
|
|
|
|
|
|
|
return v; |
29810
|
|
|
|
|
|
|
} |
29811
|
|
|
|
|
|
|
#define rbit32 rbit32 |
29812
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
29813
|
|
|
|
|
|
|
static forceinline u32 |
29814
|
|
|
|
|
|
|
rbit32(u32 v) |
29815
|
|
|
|
|
|
|
{ |
29816
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
29817
|
|
|
|
|
|
|
return v; |
29818
|
|
|
|
|
|
|
} |
29819
|
|
|
|
|
|
|
#define rbit32 rbit32 |
29820
|
|
|
|
|
|
|
#endif |
29821
|
|
|
|
|
|
|
|
29822
|
|
|
|
|
|
|
#endif |
29823
|
|
|
|
|
|
|
|
29824
|
|
|
|
|
|
|
|
29825
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
29826
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
29827
|
|
|
|
|
|
|
|
29828
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
29829
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
29830
|
|
|
|
|
|
|
|
29831
|
|
|
|
|
|
|
#ifdef FREESTANDING |
29832
|
|
|
|
|
|
|
|
29833
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
29834
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
29835
|
|
|
|
|
|
|
|
29836
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
29837
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
29838
|
|
|
|
|
|
|
|
29839
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
29840
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
29841
|
|
|
|
|
|
|
|
29842
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
29843
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
29844
|
|
|
|
|
|
|
|
29845
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
29846
|
|
|
|
|
|
|
#else |
29847
|
|
|
|
|
|
|
#include |
29848
|
|
|
|
|
|
|
#endif |
29849
|
|
|
|
|
|
|
|
29850
|
|
|
|
|
|
|
|
29851
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
29852
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
29853
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
29854
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
29855
|
|
|
|
|
|
|
#else |
29856
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
29857
|
|
|
|
|
|
|
#endif |
29858
|
|
|
|
|
|
|
|
29859
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
29860
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
29861
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
29862
|
|
|
|
|
|
|
|
29863
|
|
|
|
|
|
|
#endif |
29864
|
|
|
|
|
|
|
|
29865
|
|
|
|
|
|
|
|
29866
|
|
|
|
|
|
|
#ifdef FREESTANDING |
29867
|
|
|
|
|
|
|
# define malloc NULL |
29868
|
|
|
|
|
|
|
# define free NULL |
29869
|
|
|
|
|
|
|
#else |
29870
|
|
|
|
|
|
|
# include |
29871
|
|
|
|
|
|
|
#endif |
29872
|
|
|
|
|
|
|
|
29873
|
|
|
|
|
|
|
static void *(*libdeflate_malloc_func)(size_t) = malloc; |
29874
|
|
|
|
|
|
|
static void (*libdeflate_free_func)(void *) = free; |
29875
|
|
|
|
|
|
|
|
29876
|
|
|
|
|
|
|
void * |
29877
|
75
|
|
|
|
|
|
libdeflate_malloc(size_t size) |
29878
|
|
|
|
|
|
|
{ |
29879
|
75
|
|
|
|
|
|
return (*libdeflate_malloc_func)(size); |
29880
|
|
|
|
|
|
|
} |
29881
|
|
|
|
|
|
|
|
29882
|
|
|
|
|
|
|
void |
29883
|
75
|
|
|
|
|
|
libdeflate_free(void *ptr) |
29884
|
|
|
|
|
|
|
{ |
29885
|
75
|
|
|
|
|
|
(*libdeflate_free_func)(ptr); |
29886
|
75
|
|
|
|
|
|
} |
29887
|
|
|
|
|
|
|
|
29888
|
|
|
|
|
|
|
void * |
29889
|
37
|
|
|
|
|
|
libdeflate_aligned_malloc(size_t alignment, size_t size) |
29890
|
|
|
|
|
|
|
{ |
29891
|
37
|
|
|
|
|
|
void *ptr = libdeflate_malloc(sizeof(void *) + alignment - 1 + size); |
29892
|
37
|
50
|
|
|
|
|
if (ptr) { |
29893
|
37
|
|
|
|
|
|
void *orig_ptr = ptr; |
29894
|
37
|
|
|
|
|
|
ptr = (void *)ALIGN((uintptr_t)ptr + sizeof(void *), alignment); |
29895
|
37
|
|
|
|
|
|
((void **)ptr)[-1] = orig_ptr; |
29896
|
|
|
|
|
|
|
} |
29897
|
37
|
|
|
|
|
|
return ptr; |
29898
|
|
|
|
|
|
|
} |
29899
|
|
|
|
|
|
|
|
29900
|
|
|
|
|
|
|
void |
29901
|
37
|
|
|
|
|
|
libdeflate_aligned_free(void *ptr) |
29902
|
|
|
|
|
|
|
{ |
29903
|
37
|
50
|
|
|
|
|
if (ptr) |
29904
|
37
|
|
|
|
|
|
libdeflate_free(((void **)ptr)[-1]); |
29905
|
37
|
|
|
|
|
|
} |
29906
|
|
|
|
|
|
|
|
29907
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
29908
|
0
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
29909
|
|
|
|
|
|
|
void (*free_func)(void *)) |
29910
|
|
|
|
|
|
|
{ |
29911
|
0
|
|
|
|
|
|
libdeflate_malloc_func = malloc_func; |
29912
|
0
|
|
|
|
|
|
libdeflate_free_func = free_func; |
29913
|
0
|
|
|
|
|
|
} |
29914
|
|
|
|
|
|
|
|
29915
|
|
|
|
|
|
|
|
29916
|
|
|
|
|
|
|
#ifdef FREESTANDING |
29917
|
|
|
|
|
|
|
#undef memset |
29918
|
|
|
|
|
|
|
void * __attribute__((weak)) |
29919
|
|
|
|
|
|
|
memset(void *s, int c, size_t n) |
29920
|
|
|
|
|
|
|
{ |
29921
|
|
|
|
|
|
|
u8 *p = s; |
29922
|
|
|
|
|
|
|
size_t i; |
29923
|
|
|
|
|
|
|
|
29924
|
|
|
|
|
|
|
for (i = 0; i < n; i++) |
29925
|
|
|
|
|
|
|
p[i] = c; |
29926
|
|
|
|
|
|
|
return s; |
29927
|
|
|
|
|
|
|
} |
29928
|
|
|
|
|
|
|
|
29929
|
|
|
|
|
|
|
#undef memcpy |
29930
|
|
|
|
|
|
|
void * __attribute__((weak)) |
29931
|
|
|
|
|
|
|
memcpy(void *dest, const void *src, size_t n) |
29932
|
|
|
|
|
|
|
{ |
29933
|
|
|
|
|
|
|
u8 *d = dest; |
29934
|
|
|
|
|
|
|
const u8 *s = src; |
29935
|
|
|
|
|
|
|
size_t i; |
29936
|
|
|
|
|
|
|
|
29937
|
|
|
|
|
|
|
for (i = 0; i < n; i++) |
29938
|
|
|
|
|
|
|
d[i] = s[i]; |
29939
|
|
|
|
|
|
|
return dest; |
29940
|
|
|
|
|
|
|
} |
29941
|
|
|
|
|
|
|
|
29942
|
|
|
|
|
|
|
#undef memmove |
29943
|
|
|
|
|
|
|
void * __attribute__((weak)) |
29944
|
|
|
|
|
|
|
memmove(void *dest, const void *src, size_t n) |
29945
|
|
|
|
|
|
|
{ |
29946
|
|
|
|
|
|
|
u8 *d = dest; |
29947
|
|
|
|
|
|
|
const u8 *s = src; |
29948
|
|
|
|
|
|
|
size_t i; |
29949
|
|
|
|
|
|
|
|
29950
|
|
|
|
|
|
|
if (d <= s) |
29951
|
|
|
|
|
|
|
return memcpy(d, s, n); |
29952
|
|
|
|
|
|
|
|
29953
|
|
|
|
|
|
|
for (i = n; i > 0; i--) |
29954
|
|
|
|
|
|
|
d[i - 1] = s[i - 1]; |
29955
|
|
|
|
|
|
|
return dest; |
29956
|
|
|
|
|
|
|
} |
29957
|
|
|
|
|
|
|
|
29958
|
|
|
|
|
|
|
#undef memcmp |
29959
|
|
|
|
|
|
|
int __attribute__((weak)) |
29960
|
|
|
|
|
|
|
memcmp(const void *s1, const void *s2, size_t n) |
29961
|
|
|
|
|
|
|
{ |
29962
|
|
|
|
|
|
|
const u8 *p1 = s1; |
29963
|
|
|
|
|
|
|
const u8 *p2 = s2; |
29964
|
|
|
|
|
|
|
size_t i; |
29965
|
|
|
|
|
|
|
|
29966
|
|
|
|
|
|
|
for (i = 0; i < n; i++) { |
29967
|
|
|
|
|
|
|
if (p1[i] != p2[i]) |
29968
|
|
|
|
|
|
|
return (int)p1[i] - (int)p2[i]; |
29969
|
|
|
|
|
|
|
} |
29970
|
|
|
|
|
|
|
return 0; |
29971
|
|
|
|
|
|
|
} |
29972
|
|
|
|
|
|
|
#endif |
29973
|
|
|
|
|
|
|
|
29974
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
29975
|
|
|
|
|
|
|
#include |
29976
|
|
|
|
|
|
|
#include |
29977
|
|
|
|
|
|
|
void |
29978
|
|
|
|
|
|
|
libdeflate_assertion_failed(const char *expr, const char *file, int line) |
29979
|
|
|
|
|
|
|
{ |
29980
|
|
|
|
|
|
|
fprintf(stderr, "Assertion failed: %s at %s:%d\n", expr, file, line); |
29981
|
|
|
|
|
|
|
abort(); |
29982
|
|
|
|
|
|
|
} |
29983
|
|
|
|
|
|
|
#endif |
29984
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/zlib_compress.c */ |
29985
|
|
|
|
|
|
|
|
29986
|
|
|
|
|
|
|
|
29987
|
|
|
|
|
|
|
/* #include "deflate_compress.h" */ |
29988
|
|
|
|
|
|
|
#ifndef LIB_DEFLATE_COMPRESS_H |
29989
|
|
|
|
|
|
|
#define LIB_DEFLATE_COMPRESS_H |
29990
|
|
|
|
|
|
|
|
29991
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
29992
|
|
|
|
|
|
|
|
29993
|
|
|
|
|
|
|
|
29994
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
29995
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
29996
|
|
|
|
|
|
|
|
29997
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
29998
|
|
|
|
|
|
|
|
29999
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
30000
|
|
|
|
|
|
|
#endif |
30001
|
|
|
|
|
|
|
|
30002
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
30003
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
30004
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
30005
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
30006
|
|
|
|
|
|
|
#else |
30007
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
30008
|
|
|
|
|
|
|
#endif |
30009
|
|
|
|
|
|
|
|
30010
|
|
|
|
|
|
|
|
30011
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
30012
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
30013
|
|
|
|
|
|
|
#else |
30014
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
30015
|
|
|
|
|
|
|
#endif |
30016
|
|
|
|
|
|
|
|
30017
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
30018
|
|
|
|
|
|
|
|
30019
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
30020
|
|
|
|
|
|
|
|
30021
|
|
|
|
|
|
|
|
30022
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
30023
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
30024
|
|
|
|
|
|
|
|
30025
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
30026
|
|
|
|
|
|
|
|
30027
|
|
|
|
|
|
|
|
30028
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
30029
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
30030
|
|
|
|
|
|
|
|
30031
|
|
|
|
|
|
|
#include |
30032
|
|
|
|
|
|
|
#include |
30033
|
|
|
|
|
|
|
|
30034
|
|
|
|
|
|
|
#ifdef __cplusplus |
30035
|
|
|
|
|
|
|
extern "C" { |
30036
|
|
|
|
|
|
|
#endif |
30037
|
|
|
|
|
|
|
|
30038
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
30039
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
30040
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
30041
|
|
|
|
|
|
|
|
30042
|
|
|
|
|
|
|
|
30043
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
30044
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
30045
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
30046
|
|
|
|
|
|
|
# else |
30047
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
30048
|
|
|
|
|
|
|
# endif |
30049
|
|
|
|
|
|
|
#endif |
30050
|
|
|
|
|
|
|
|
30051
|
|
|
|
|
|
|
|
30052
|
|
|
|
|
|
|
|
30053
|
|
|
|
|
|
|
|
30054
|
|
|
|
|
|
|
|
30055
|
|
|
|
|
|
|
struct libdeflate_compressor; |
30056
|
|
|
|
|
|
|
|
30057
|
|
|
|
|
|
|
|
30058
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
30059
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
30060
|
|
|
|
|
|
|
|
30061
|
|
|
|
|
|
|
|
30062
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30063
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
30064
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30065
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
30066
|
|
|
|
|
|
|
|
30067
|
|
|
|
|
|
|
|
30068
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30069
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
30070
|
|
|
|
|
|
|
size_t in_nbytes); |
30071
|
|
|
|
|
|
|
|
30072
|
|
|
|
|
|
|
|
30073
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30074
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
30075
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30076
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
30077
|
|
|
|
|
|
|
|
30078
|
|
|
|
|
|
|
|
30079
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30080
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
30081
|
|
|
|
|
|
|
size_t in_nbytes); |
30082
|
|
|
|
|
|
|
|
30083
|
|
|
|
|
|
|
|
30084
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30085
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
30086
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30087
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
30088
|
|
|
|
|
|
|
|
30089
|
|
|
|
|
|
|
|
30090
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30091
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
30092
|
|
|
|
|
|
|
size_t in_nbytes); |
30093
|
|
|
|
|
|
|
|
30094
|
|
|
|
|
|
|
|
30095
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
30096
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
30097
|
|
|
|
|
|
|
|
30098
|
|
|
|
|
|
|
|
30099
|
|
|
|
|
|
|
|
30100
|
|
|
|
|
|
|
|
30101
|
|
|
|
|
|
|
|
30102
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
30103
|
|
|
|
|
|
|
|
30104
|
|
|
|
|
|
|
|
30105
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
30106
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
30107
|
|
|
|
|
|
|
|
30108
|
|
|
|
|
|
|
|
30109
|
|
|
|
|
|
|
enum libdeflate_result { |
30110
|
|
|
|
|
|
|
|
30111
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
30112
|
|
|
|
|
|
|
|
30113
|
|
|
|
|
|
|
|
30114
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
30115
|
|
|
|
|
|
|
|
30116
|
|
|
|
|
|
|
|
30117
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
30118
|
|
|
|
|
|
|
|
30119
|
|
|
|
|
|
|
|
30120
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
30121
|
|
|
|
|
|
|
}; |
30122
|
|
|
|
|
|
|
|
30123
|
|
|
|
|
|
|
|
30124
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30125
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
30126
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30127
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30128
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30129
|
|
|
|
|
|
|
|
30130
|
|
|
|
|
|
|
|
30131
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30132
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
30133
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30134
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30135
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
30136
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30137
|
|
|
|
|
|
|
|
30138
|
|
|
|
|
|
|
|
30139
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30140
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
30141
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30142
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30143
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30144
|
|
|
|
|
|
|
|
30145
|
|
|
|
|
|
|
|
30146
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30147
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
30148
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30149
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30150
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
30151
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30152
|
|
|
|
|
|
|
|
30153
|
|
|
|
|
|
|
|
30154
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30155
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
30156
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30157
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30158
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30159
|
|
|
|
|
|
|
|
30160
|
|
|
|
|
|
|
|
30161
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
30162
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
30163
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30164
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
30165
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
30166
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
30167
|
|
|
|
|
|
|
|
30168
|
|
|
|
|
|
|
|
30169
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
30170
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
30171
|
|
|
|
|
|
|
|
30172
|
|
|
|
|
|
|
|
30173
|
|
|
|
|
|
|
|
30174
|
|
|
|
|
|
|
|
30175
|
|
|
|
|
|
|
|
30176
|
|
|
|
|
|
|
|
30177
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
30178
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
30179
|
|
|
|
|
|
|
|
30180
|
|
|
|
|
|
|
|
30181
|
|
|
|
|
|
|
|
30182
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
30183
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
30184
|
|
|
|
|
|
|
|
30185
|
|
|
|
|
|
|
|
30186
|
|
|
|
|
|
|
|
30187
|
|
|
|
|
|
|
|
30188
|
|
|
|
|
|
|
|
30189
|
|
|
|
|
|
|
|
30190
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
30191
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
30192
|
|
|
|
|
|
|
void (*free_func)(void *)); |
30193
|
|
|
|
|
|
|
|
30194
|
|
|
|
|
|
|
#ifdef __cplusplus |
30195
|
|
|
|
|
|
|
} |
30196
|
|
|
|
|
|
|
#endif |
30197
|
|
|
|
|
|
|
|
30198
|
|
|
|
|
|
|
#endif |
30199
|
|
|
|
|
|
|
|
30200
|
|
|
|
|
|
|
|
30201
|
|
|
|
|
|
|
#include |
30202
|
|
|
|
|
|
|
#include |
30203
|
|
|
|
|
|
|
#include |
30204
|
|
|
|
|
|
|
#ifdef _MSC_VER |
30205
|
|
|
|
|
|
|
# include |
30206
|
|
|
|
|
|
|
# include |
30207
|
|
|
|
|
|
|
|
30208
|
|
|
|
|
|
|
|
30209
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
30210
|
|
|
|
|
|
|
|
30211
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
30212
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
30213
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
30214
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
30215
|
|
|
|
|
|
|
|
30216
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
30217
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
30218
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
30219
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
30220
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
30221
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
30222
|
|
|
|
|
|
|
#endif |
30223
|
|
|
|
|
|
|
#ifndef FREESTANDING |
30224
|
|
|
|
|
|
|
# include |
30225
|
|
|
|
|
|
|
#endif |
30226
|
|
|
|
|
|
|
|
30227
|
|
|
|
|
|
|
|
30228
|
|
|
|
|
|
|
|
30229
|
|
|
|
|
|
|
|
30230
|
|
|
|
|
|
|
|
30231
|
|
|
|
|
|
|
|
30232
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
30233
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
30234
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
30235
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
30236
|
|
|
|
|
|
|
#ifdef _MSC_VER |
30237
|
|
|
|
|
|
|
# if defined(_M_X64) |
30238
|
|
|
|
|
|
|
# define ARCH_X86_64 |
30239
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
30240
|
|
|
|
|
|
|
# define ARCH_X86_32 |
30241
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
30242
|
|
|
|
|
|
|
# define ARCH_ARM64 |
30243
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
30244
|
|
|
|
|
|
|
# define ARCH_ARM32 |
30245
|
|
|
|
|
|
|
# endif |
30246
|
|
|
|
|
|
|
#else |
30247
|
|
|
|
|
|
|
# if defined(__x86_64__) |
30248
|
|
|
|
|
|
|
# define ARCH_X86_64 |
30249
|
|
|
|
|
|
|
# elif defined(__i386__) |
30250
|
|
|
|
|
|
|
# define ARCH_X86_32 |
30251
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
30252
|
|
|
|
|
|
|
# define ARCH_ARM64 |
30253
|
|
|
|
|
|
|
# elif defined(__arm__) |
30254
|
|
|
|
|
|
|
# define ARCH_ARM32 |
30255
|
|
|
|
|
|
|
# endif |
30256
|
|
|
|
|
|
|
#endif |
30257
|
|
|
|
|
|
|
|
30258
|
|
|
|
|
|
|
|
30259
|
|
|
|
|
|
|
|
30260
|
|
|
|
|
|
|
|
30261
|
|
|
|
|
|
|
|
30262
|
|
|
|
|
|
|
|
30263
|
|
|
|
|
|
|
typedef uint8_t u8; |
30264
|
|
|
|
|
|
|
typedef uint16_t u16; |
30265
|
|
|
|
|
|
|
typedef uint32_t u32; |
30266
|
|
|
|
|
|
|
typedef uint64_t u64; |
30267
|
|
|
|
|
|
|
typedef int8_t s8; |
30268
|
|
|
|
|
|
|
typedef int16_t s16; |
30269
|
|
|
|
|
|
|
typedef int32_t s32; |
30270
|
|
|
|
|
|
|
typedef int64_t s64; |
30271
|
|
|
|
|
|
|
|
30272
|
|
|
|
|
|
|
|
30273
|
|
|
|
|
|
|
#ifdef _MSC_VER |
30274
|
|
|
|
|
|
|
# ifdef _WIN64 |
30275
|
|
|
|
|
|
|
typedef long long ssize_t; |
30276
|
|
|
|
|
|
|
# else |
30277
|
|
|
|
|
|
|
typedef long ssize_t; |
30278
|
|
|
|
|
|
|
# endif |
30279
|
|
|
|
|
|
|
#endif |
30280
|
|
|
|
|
|
|
|
30281
|
|
|
|
|
|
|
|
30282
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
30283
|
|
|
|
|
|
|
|
30284
|
|
|
|
|
|
|
|
30285
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
30286
|
|
|
|
|
|
|
|
30287
|
|
|
|
|
|
|
|
30288
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
30289
|
|
|
|
|
|
|
|
30290
|
|
|
|
|
|
|
|
30291
|
|
|
|
|
|
|
|
30292
|
|
|
|
|
|
|
|
30293
|
|
|
|
|
|
|
|
30294
|
|
|
|
|
|
|
|
30295
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
30296
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
30297
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
30298
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
30299
|
|
|
|
|
|
|
#else |
30300
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
30301
|
|
|
|
|
|
|
#endif |
30302
|
|
|
|
|
|
|
#ifdef __clang__ |
30303
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
30304
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
30305
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
30306
|
|
|
|
|
|
|
# else |
30307
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
30308
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
30309
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
30310
|
|
|
|
|
|
|
# endif |
30311
|
|
|
|
|
|
|
#else |
30312
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
30313
|
|
|
|
|
|
|
#endif |
30314
|
|
|
|
|
|
|
|
30315
|
|
|
|
|
|
|
|
30316
|
|
|
|
|
|
|
#ifndef __has_attribute |
30317
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
30318
|
|
|
|
|
|
|
#endif |
30319
|
|
|
|
|
|
|
#ifndef __has_builtin |
30320
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
30321
|
|
|
|
|
|
|
#endif |
30322
|
|
|
|
|
|
|
|
30323
|
|
|
|
|
|
|
|
30324
|
|
|
|
|
|
|
#ifdef _MSC_VER |
30325
|
|
|
|
|
|
|
# define inline __inline |
30326
|
|
|
|
|
|
|
#endif |
30327
|
|
|
|
|
|
|
|
30328
|
|
|
|
|
|
|
|
30329
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
30330
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
30331
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30332
|
|
|
|
|
|
|
# define forceinline __forceinline |
30333
|
|
|
|
|
|
|
#else |
30334
|
|
|
|
|
|
|
# define forceinline inline |
30335
|
|
|
|
|
|
|
#endif |
30336
|
|
|
|
|
|
|
|
30337
|
|
|
|
|
|
|
|
30338
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
30339
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
30340
|
|
|
|
|
|
|
#else |
30341
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
30342
|
|
|
|
|
|
|
#endif |
30343
|
|
|
|
|
|
|
|
30344
|
|
|
|
|
|
|
|
30345
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
30346
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
30347
|
|
|
|
|
|
|
# define restrict __restrict__ |
30348
|
|
|
|
|
|
|
# else |
30349
|
|
|
|
|
|
|
# define restrict |
30350
|
|
|
|
|
|
|
# endif |
30351
|
|
|
|
|
|
|
#endif |
30352
|
|
|
|
|
|
|
|
30353
|
|
|
|
|
|
|
|
30354
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
30355
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
30356
|
|
|
|
|
|
|
#else |
30357
|
|
|
|
|
|
|
# define likely(expr) (expr) |
30358
|
|
|
|
|
|
|
#endif |
30359
|
|
|
|
|
|
|
|
30360
|
|
|
|
|
|
|
|
30361
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
30362
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
30363
|
|
|
|
|
|
|
#else |
30364
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
30365
|
|
|
|
|
|
|
#endif |
30366
|
|
|
|
|
|
|
|
30367
|
|
|
|
|
|
|
|
30368
|
|
|
|
|
|
|
#undef prefetchr |
30369
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
30370
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
30371
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30372
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
30373
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
30374
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
30375
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
30376
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
30377
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
30378
|
|
|
|
|
|
|
# endif |
30379
|
|
|
|
|
|
|
#endif |
30380
|
|
|
|
|
|
|
#ifndef prefetchr |
30381
|
|
|
|
|
|
|
# define prefetchr(addr) |
30382
|
|
|
|
|
|
|
#endif |
30383
|
|
|
|
|
|
|
|
30384
|
|
|
|
|
|
|
|
30385
|
|
|
|
|
|
|
#undef prefetchw |
30386
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
30387
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
30388
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30389
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
30390
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
30391
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
30392
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
30393
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
30394
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
30395
|
|
|
|
|
|
|
# endif |
30396
|
|
|
|
|
|
|
#endif |
30397
|
|
|
|
|
|
|
#ifndef prefetchw |
30398
|
|
|
|
|
|
|
# define prefetchw(addr) |
30399
|
|
|
|
|
|
|
#endif |
30400
|
|
|
|
|
|
|
|
30401
|
|
|
|
|
|
|
|
30402
|
|
|
|
|
|
|
#undef _aligned_attribute |
30403
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
30404
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
30405
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30406
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
30407
|
|
|
|
|
|
|
#endif |
30408
|
|
|
|
|
|
|
|
30409
|
|
|
|
|
|
|
|
30410
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
30411
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
30412
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
30413
|
|
|
|
|
|
|
#else |
30414
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
30415
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
30416
|
|
|
|
|
|
|
#endif |
30417
|
|
|
|
|
|
|
|
30418
|
|
|
|
|
|
|
|
30419
|
|
|
|
|
|
|
|
30420
|
|
|
|
|
|
|
|
30421
|
|
|
|
|
|
|
|
30422
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
30423
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
30424
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
30425
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
30426
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
30427
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
30428
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
30429
|
|
|
|
|
|
|
|
30430
|
|
|
|
|
|
|
|
30431
|
|
|
|
|
|
|
|
30432
|
|
|
|
|
|
|
|
30433
|
|
|
|
|
|
|
|
30434
|
|
|
|
|
|
|
|
30435
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
30436
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
30437
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30438
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
30439
|
|
|
|
|
|
|
#else |
30440
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
30441
|
|
|
|
|
|
|
{ |
30442
|
|
|
|
|
|
|
union { |
30443
|
|
|
|
|
|
|
u32 w; |
30444
|
|
|
|
|
|
|
u8 b; |
30445
|
|
|
|
|
|
|
} u; |
30446
|
|
|
|
|
|
|
|
30447
|
|
|
|
|
|
|
u.w = 1; |
30448
|
|
|
|
|
|
|
return u.b; |
30449
|
|
|
|
|
|
|
} |
30450
|
|
|
|
|
|
|
#endif |
30451
|
|
|
|
|
|
|
|
30452
|
|
|
|
|
|
|
|
30453
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
30454
|
|
|
|
|
|
|
{ |
30455
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
30456
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
30457
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30458
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
30459
|
|
|
|
|
|
|
#else |
30460
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
30461
|
|
|
|
|
|
|
#endif |
30462
|
|
|
|
|
|
|
} |
30463
|
|
|
|
|
|
|
|
30464
|
|
|
|
|
|
|
|
30465
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
30466
|
|
|
|
|
|
|
{ |
30467
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
30468
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
30469
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30470
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
30471
|
|
|
|
|
|
|
#else |
30472
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
30473
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
30474
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
30475
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
30476
|
|
|
|
|
|
|
#endif |
30477
|
|
|
|
|
|
|
} |
30478
|
|
|
|
|
|
|
|
30479
|
|
|
|
|
|
|
|
30480
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
30481
|
|
|
|
|
|
|
{ |
30482
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
30483
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
30484
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30485
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
30486
|
|
|
|
|
|
|
#else |
30487
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
30488
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
30489
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
30490
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
30491
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
30492
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
30493
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
30494
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
30495
|
|
|
|
|
|
|
#endif |
30496
|
|
|
|
|
|
|
} |
30497
|
|
|
|
|
|
|
|
30498
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
30499
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
30500
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
30501
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
30502
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
30503
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
30504
|
|
|
|
|
|
|
|
30505
|
|
|
|
|
|
|
|
30506
|
|
|
|
|
|
|
|
30507
|
|
|
|
|
|
|
|
30508
|
|
|
|
|
|
|
|
30509
|
|
|
|
|
|
|
|
30510
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
30511
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
30512
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
30513
|
|
|
|
|
|
|
defined(__wasm__)) |
30514
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
30515
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30516
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
30517
|
|
|
|
|
|
|
#else |
30518
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
30519
|
|
|
|
|
|
|
#endif |
30520
|
|
|
|
|
|
|
|
30521
|
|
|
|
|
|
|
|
30522
|
|
|
|
|
|
|
|
30523
|
|
|
|
|
|
|
#ifdef FREESTANDING |
30524
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
30525
|
|
|
|
|
|
|
#else |
30526
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
30527
|
|
|
|
|
|
|
#endif |
30528
|
|
|
|
|
|
|
|
30529
|
|
|
|
|
|
|
|
30530
|
|
|
|
|
|
|
|
30531
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
30532
|
|
|
|
|
|
|
static forceinline type \ |
30533
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
30534
|
|
|
|
|
|
|
{ \ |
30535
|
|
|
|
|
|
|
type v; \ |
30536
|
|
|
|
|
|
|
\ |
30537
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
30538
|
|
|
|
|
|
|
return v; \ |
30539
|
|
|
|
|
|
|
} \ |
30540
|
|
|
|
|
|
|
\ |
30541
|
|
|
|
|
|
|
static forceinline void \ |
30542
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
30543
|
|
|
|
|
|
|
{ \ |
30544
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
30545
|
|
|
|
|
|
|
} |
30546
|
|
|
|
|
|
|
|
30547
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
30548
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
30549
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
30550
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
30551
|
|
|
|
|
|
|
|
30552
|
|
|
|
|
|
|
#undef MEMCOPY |
30553
|
|
|
|
|
|
|
|
30554
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
30555
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
30556
|
|
|
|
|
|
|
|
30557
|
|
|
|
|
|
|
|
30558
|
|
|
|
|
|
|
|
30559
|
|
|
|
|
|
|
static forceinline u16 |
30560
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
30561
|
|
|
|
|
|
|
{ |
30562
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30563
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
30564
|
|
|
|
|
|
|
else |
30565
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
30566
|
|
|
|
|
|
|
} |
30567
|
|
|
|
|
|
|
|
30568
|
|
|
|
|
|
|
static forceinline u16 |
30569
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
30570
|
|
|
|
|
|
|
{ |
30571
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30572
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
30573
|
|
|
|
|
|
|
else |
30574
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
30575
|
|
|
|
|
|
|
} |
30576
|
|
|
|
|
|
|
|
30577
|
|
|
|
|
|
|
static forceinline u32 |
30578
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
30579
|
|
|
|
|
|
|
{ |
30580
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30581
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
30582
|
|
|
|
|
|
|
else |
30583
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
30584
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
30585
|
|
|
|
|
|
|
} |
30586
|
|
|
|
|
|
|
|
30587
|
|
|
|
|
|
|
static forceinline u32 |
30588
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
30589
|
|
|
|
|
|
|
{ |
30590
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30591
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
30592
|
|
|
|
|
|
|
else |
30593
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
30594
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
30595
|
|
|
|
|
|
|
} |
30596
|
|
|
|
|
|
|
|
30597
|
|
|
|
|
|
|
static forceinline u64 |
30598
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
30599
|
|
|
|
|
|
|
{ |
30600
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
30601
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
30602
|
|
|
|
|
|
|
else |
30603
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
30604
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
30605
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
30606
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
30607
|
|
|
|
|
|
|
} |
30608
|
|
|
|
|
|
|
|
30609
|
|
|
|
|
|
|
static forceinline machine_word_t |
30610
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
30611
|
|
|
|
|
|
|
{ |
30612
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
30613
|
|
|
|
|
|
|
if (WORDBITS == 32) |
30614
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
30615
|
|
|
|
|
|
|
else |
30616
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
30617
|
|
|
|
|
|
|
} |
30618
|
|
|
|
|
|
|
|
30619
|
|
|
|
|
|
|
|
30620
|
|
|
|
|
|
|
|
30621
|
|
|
|
|
|
|
static forceinline void |
30622
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
30623
|
|
|
|
|
|
|
{ |
30624
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30625
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
30626
|
|
|
|
|
|
|
} else { |
30627
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
30628
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
30629
|
|
|
|
|
|
|
} |
30630
|
|
|
|
|
|
|
} |
30631
|
|
|
|
|
|
|
|
30632
|
|
|
|
|
|
|
static forceinline void |
30633
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
30634
|
|
|
|
|
|
|
{ |
30635
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30636
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
30637
|
|
|
|
|
|
|
} else { |
30638
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
30639
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
30640
|
|
|
|
|
|
|
} |
30641
|
|
|
|
|
|
|
} |
30642
|
|
|
|
|
|
|
|
30643
|
|
|
|
|
|
|
static forceinline void |
30644
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
30645
|
|
|
|
|
|
|
{ |
30646
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30647
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
30648
|
|
|
|
|
|
|
} else { |
30649
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
30650
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
30651
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
30652
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
30653
|
|
|
|
|
|
|
} |
30654
|
|
|
|
|
|
|
} |
30655
|
|
|
|
|
|
|
|
30656
|
|
|
|
|
|
|
static forceinline void |
30657
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
30658
|
|
|
|
|
|
|
{ |
30659
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30660
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
30661
|
|
|
|
|
|
|
} else { |
30662
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
30663
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
30664
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
30665
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
30666
|
|
|
|
|
|
|
} |
30667
|
|
|
|
|
|
|
} |
30668
|
|
|
|
|
|
|
|
30669
|
|
|
|
|
|
|
static forceinline void |
30670
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
30671
|
|
|
|
|
|
|
{ |
30672
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
30673
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
30674
|
|
|
|
|
|
|
} else { |
30675
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
30676
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
30677
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
30678
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
30679
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
30680
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
30681
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
30682
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
30683
|
|
|
|
|
|
|
} |
30684
|
|
|
|
|
|
|
} |
30685
|
|
|
|
|
|
|
|
30686
|
|
|
|
|
|
|
static forceinline void |
30687
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
30688
|
|
|
|
|
|
|
{ |
30689
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
30690
|
|
|
|
|
|
|
if (WORDBITS == 32) |
30691
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
30692
|
|
|
|
|
|
|
else |
30693
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
30694
|
|
|
|
|
|
|
} |
30695
|
|
|
|
|
|
|
|
30696
|
|
|
|
|
|
|
|
30697
|
|
|
|
|
|
|
|
30698
|
|
|
|
|
|
|
|
30699
|
|
|
|
|
|
|
|
30700
|
|
|
|
|
|
|
|
30701
|
|
|
|
|
|
|
|
30702
|
|
|
|
|
|
|
static forceinline unsigned |
30703
|
|
|
|
|
|
|
bsr32(u32 v) |
30704
|
|
|
|
|
|
|
{ |
30705
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
30706
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
30707
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30708
|
|
|
|
|
|
|
unsigned long i; |
30709
|
|
|
|
|
|
|
|
30710
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
30711
|
|
|
|
|
|
|
return i; |
30712
|
|
|
|
|
|
|
#else |
30713
|
|
|
|
|
|
|
unsigned i = 0; |
30714
|
|
|
|
|
|
|
|
30715
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
30716
|
|
|
|
|
|
|
i++; |
30717
|
|
|
|
|
|
|
return i; |
30718
|
|
|
|
|
|
|
#endif |
30719
|
|
|
|
|
|
|
} |
30720
|
|
|
|
|
|
|
|
30721
|
|
|
|
|
|
|
static forceinline unsigned |
30722
|
|
|
|
|
|
|
bsr64(u64 v) |
30723
|
|
|
|
|
|
|
{ |
30724
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
30725
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
30726
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
30727
|
|
|
|
|
|
|
unsigned long i; |
30728
|
|
|
|
|
|
|
|
30729
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
30730
|
|
|
|
|
|
|
return i; |
30731
|
|
|
|
|
|
|
#else |
30732
|
|
|
|
|
|
|
unsigned i = 0; |
30733
|
|
|
|
|
|
|
|
30734
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
30735
|
|
|
|
|
|
|
i++; |
30736
|
|
|
|
|
|
|
return i; |
30737
|
|
|
|
|
|
|
#endif |
30738
|
|
|
|
|
|
|
} |
30739
|
|
|
|
|
|
|
|
30740
|
|
|
|
|
|
|
static forceinline unsigned |
30741
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
30742
|
|
|
|
|
|
|
{ |
30743
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
30744
|
|
|
|
|
|
|
if (WORDBITS == 32) |
30745
|
|
|
|
|
|
|
return bsr32(v); |
30746
|
|
|
|
|
|
|
else |
30747
|
|
|
|
|
|
|
return bsr64(v); |
30748
|
|
|
|
|
|
|
} |
30749
|
|
|
|
|
|
|
|
30750
|
|
|
|
|
|
|
|
30751
|
|
|
|
|
|
|
|
30752
|
|
|
|
|
|
|
static forceinline unsigned |
30753
|
|
|
|
|
|
|
bsf32(u32 v) |
30754
|
|
|
|
|
|
|
{ |
30755
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
30756
|
|
|
|
|
|
|
return __builtin_ctz(v); |
30757
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
30758
|
|
|
|
|
|
|
unsigned long i; |
30759
|
|
|
|
|
|
|
|
30760
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
30761
|
|
|
|
|
|
|
return i; |
30762
|
|
|
|
|
|
|
#else |
30763
|
|
|
|
|
|
|
unsigned i = 0; |
30764
|
|
|
|
|
|
|
|
30765
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
30766
|
|
|
|
|
|
|
i++; |
30767
|
|
|
|
|
|
|
return i; |
30768
|
|
|
|
|
|
|
#endif |
30769
|
|
|
|
|
|
|
} |
30770
|
|
|
|
|
|
|
|
30771
|
|
|
|
|
|
|
static forceinline unsigned |
30772
|
|
|
|
|
|
|
bsf64(u64 v) |
30773
|
|
|
|
|
|
|
{ |
30774
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
30775
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
30776
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
30777
|
|
|
|
|
|
|
unsigned long i; |
30778
|
|
|
|
|
|
|
|
30779
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
30780
|
|
|
|
|
|
|
return i; |
30781
|
|
|
|
|
|
|
#else |
30782
|
|
|
|
|
|
|
unsigned i = 0; |
30783
|
|
|
|
|
|
|
|
30784
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
30785
|
|
|
|
|
|
|
i++; |
30786
|
|
|
|
|
|
|
return i; |
30787
|
|
|
|
|
|
|
#endif |
30788
|
|
|
|
|
|
|
} |
30789
|
|
|
|
|
|
|
|
30790
|
|
|
|
|
|
|
static forceinline unsigned |
30791
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
30792
|
|
|
|
|
|
|
{ |
30793
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
30794
|
|
|
|
|
|
|
if (WORDBITS == 32) |
30795
|
|
|
|
|
|
|
return bsf32(v); |
30796
|
|
|
|
|
|
|
else |
30797
|
|
|
|
|
|
|
return bsf64(v); |
30798
|
|
|
|
|
|
|
} |
30799
|
|
|
|
|
|
|
|
30800
|
|
|
|
|
|
|
|
30801
|
|
|
|
|
|
|
#undef rbit32 |
30802
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
30803
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
30804
|
|
|
|
|
|
|
static forceinline u32 |
30805
|
|
|
|
|
|
|
rbit32(u32 v) |
30806
|
|
|
|
|
|
|
{ |
30807
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
30808
|
|
|
|
|
|
|
return v; |
30809
|
|
|
|
|
|
|
} |
30810
|
|
|
|
|
|
|
#define rbit32 rbit32 |
30811
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
30812
|
|
|
|
|
|
|
static forceinline u32 |
30813
|
|
|
|
|
|
|
rbit32(u32 v) |
30814
|
|
|
|
|
|
|
{ |
30815
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
30816
|
|
|
|
|
|
|
return v; |
30817
|
|
|
|
|
|
|
} |
30818
|
|
|
|
|
|
|
#define rbit32 rbit32 |
30819
|
|
|
|
|
|
|
#endif |
30820
|
|
|
|
|
|
|
|
30821
|
|
|
|
|
|
|
#endif |
30822
|
|
|
|
|
|
|
|
30823
|
|
|
|
|
|
|
|
30824
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
30825
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
30826
|
|
|
|
|
|
|
|
30827
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
30828
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
30829
|
|
|
|
|
|
|
|
30830
|
|
|
|
|
|
|
#ifdef FREESTANDING |
30831
|
|
|
|
|
|
|
|
30832
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
30833
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
30834
|
|
|
|
|
|
|
|
30835
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
30836
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
30837
|
|
|
|
|
|
|
|
30838
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
30839
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
30840
|
|
|
|
|
|
|
|
30841
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
30842
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
30843
|
|
|
|
|
|
|
|
30844
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
30845
|
|
|
|
|
|
|
#else |
30846
|
|
|
|
|
|
|
#include |
30847
|
|
|
|
|
|
|
#endif |
30848
|
|
|
|
|
|
|
|
30849
|
|
|
|
|
|
|
|
30850
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
30851
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
30852
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
30853
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
30854
|
|
|
|
|
|
|
#else |
30855
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
30856
|
|
|
|
|
|
|
#endif |
30857
|
|
|
|
|
|
|
|
30858
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
30859
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
30860
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
30861
|
|
|
|
|
|
|
|
30862
|
|
|
|
|
|
|
#endif |
30863
|
|
|
|
|
|
|
|
30864
|
|
|
|
|
|
|
|
30865
|
|
|
|
|
|
|
|
30866
|
|
|
|
|
|
|
|
30867
|
|
|
|
|
|
|
struct libdeflate_compressor; |
30868
|
|
|
|
|
|
|
|
30869
|
|
|
|
|
|
|
unsigned int libdeflate_get_compression_level(struct libdeflate_compressor *c); |
30870
|
|
|
|
|
|
|
|
30871
|
|
|
|
|
|
|
#endif |
30872
|
|
|
|
|
|
|
|
30873
|
|
|
|
|
|
|
/* #include "zlib_constants.h" */ |
30874
|
|
|
|
|
|
|
|
30875
|
|
|
|
|
|
|
|
30876
|
|
|
|
|
|
|
#ifndef LIB_ZLIB_CONSTANTS_H |
30877
|
|
|
|
|
|
|
#define LIB_ZLIB_CONSTANTS_H |
30878
|
|
|
|
|
|
|
|
30879
|
|
|
|
|
|
|
#define ZLIB_MIN_HEADER_SIZE 2 |
30880
|
|
|
|
|
|
|
#define ZLIB_FOOTER_SIZE 4 |
30881
|
|
|
|
|
|
|
#define ZLIB_MIN_OVERHEAD (ZLIB_MIN_HEADER_SIZE + ZLIB_FOOTER_SIZE) |
30882
|
|
|
|
|
|
|
|
30883
|
|
|
|
|
|
|
#define ZLIB_CM_DEFLATE 8 |
30884
|
|
|
|
|
|
|
|
30885
|
|
|
|
|
|
|
#define ZLIB_CINFO_32K_WINDOW 7 |
30886
|
|
|
|
|
|
|
|
30887
|
|
|
|
|
|
|
#define ZLIB_FASTEST_COMPRESSION 0 |
30888
|
|
|
|
|
|
|
#define ZLIB_FAST_COMPRESSION 1 |
30889
|
|
|
|
|
|
|
#define ZLIB_DEFAULT_COMPRESSION 2 |
30890
|
|
|
|
|
|
|
#define ZLIB_SLOWEST_COMPRESSION 3 |
30891
|
|
|
|
|
|
|
|
30892
|
|
|
|
|
|
|
#endif |
30893
|
|
|
|
|
|
|
|
30894
|
|
|
|
|
|
|
|
30895
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30896
|
12
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *c, |
30897
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
30898
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail) |
30899
|
|
|
|
|
|
|
{ |
30900
|
12
|
|
|
|
|
|
u8 *out_next = out; |
30901
|
|
|
|
|
|
|
u16 hdr; |
30902
|
|
|
|
|
|
|
unsigned compression_level; |
30903
|
|
|
|
|
|
|
unsigned level_hint; |
30904
|
|
|
|
|
|
|
size_t deflate_size; |
30905
|
|
|
|
|
|
|
|
30906
|
12
|
50
|
|
|
|
|
if (out_nbytes_avail <= ZLIB_MIN_OVERHEAD) |
30907
|
0
|
|
|
|
|
|
return 0; |
30908
|
|
|
|
|
|
|
|
30909
|
|
|
|
|
|
|
|
30910
|
12
|
|
|
|
|
|
hdr = (ZLIB_CM_DEFLATE << 8) | (ZLIB_CINFO_32K_WINDOW << 12); |
30911
|
12
|
|
|
|
|
|
compression_level = libdeflate_get_compression_level(c); |
30912
|
12
|
100
|
|
|
|
|
if (compression_level < 2) |
30913
|
1
|
|
|
|
|
|
level_hint = ZLIB_FASTEST_COMPRESSION; |
30914
|
11
|
100
|
|
|
|
|
else if (compression_level < 6) |
30915
|
4
|
|
|
|
|
|
level_hint = ZLIB_FAST_COMPRESSION; |
30916
|
7
|
100
|
|
|
|
|
else if (compression_level < 8) |
30917
|
2
|
|
|
|
|
|
level_hint = ZLIB_DEFAULT_COMPRESSION; |
30918
|
|
|
|
|
|
|
else |
30919
|
5
|
|
|
|
|
|
level_hint = ZLIB_SLOWEST_COMPRESSION; |
30920
|
12
|
|
|
|
|
|
hdr |= level_hint << 6; |
30921
|
12
|
|
|
|
|
|
hdr |= 31 - (hdr % 31); |
30922
|
|
|
|
|
|
|
|
30923
|
12
|
|
|
|
|
|
put_unaligned_be16(hdr, out_next); |
30924
|
12
|
|
|
|
|
|
out_next += 2; |
30925
|
|
|
|
|
|
|
|
30926
|
|
|
|
|
|
|
|
30927
|
12
|
|
|
|
|
|
deflate_size = libdeflate_deflate_compress(c, in, in_nbytes, out_next, |
30928
|
|
|
|
|
|
|
out_nbytes_avail - ZLIB_MIN_OVERHEAD); |
30929
|
12
|
50
|
|
|
|
|
if (deflate_size == 0) |
30930
|
0
|
|
|
|
|
|
return 0; |
30931
|
12
|
|
|
|
|
|
out_next += deflate_size; |
30932
|
|
|
|
|
|
|
|
30933
|
|
|
|
|
|
|
|
30934
|
12
|
|
|
|
|
|
put_unaligned_be32(libdeflate_adler32(1, in, in_nbytes), out_next); |
30935
|
12
|
|
|
|
|
|
out_next += 4; |
30936
|
|
|
|
|
|
|
|
30937
|
12
|
|
|
|
|
|
return out_next - (u8 *)out; |
30938
|
|
|
|
|
|
|
} |
30939
|
|
|
|
|
|
|
|
30940
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
30941
|
12
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *c, |
30942
|
|
|
|
|
|
|
size_t in_nbytes) |
30943
|
|
|
|
|
|
|
{ |
30944
|
12
|
|
|
|
|
|
return ZLIB_MIN_OVERHEAD + |
30945
|
12
|
|
|
|
|
|
libdeflate_deflate_compress_bound(c, in_nbytes); |
30946
|
|
|
|
|
|
|
} |
30947
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/zlib_decompress.c */ |
30948
|
|
|
|
|
|
|
|
30949
|
|
|
|
|
|
|
|
30950
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
30951
|
|
|
|
|
|
|
|
30952
|
|
|
|
|
|
|
|
30953
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
30954
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
30955
|
|
|
|
|
|
|
|
30956
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
30957
|
|
|
|
|
|
|
|
30958
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
30959
|
|
|
|
|
|
|
#endif |
30960
|
|
|
|
|
|
|
|
30961
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
30962
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
30963
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
30964
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
30965
|
|
|
|
|
|
|
#else |
30966
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
30967
|
|
|
|
|
|
|
#endif |
30968
|
|
|
|
|
|
|
|
30969
|
|
|
|
|
|
|
|
30970
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
30971
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
30972
|
|
|
|
|
|
|
#else |
30973
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
30974
|
|
|
|
|
|
|
#endif |
30975
|
|
|
|
|
|
|
|
30976
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
30977
|
|
|
|
|
|
|
|
30978
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
30979
|
|
|
|
|
|
|
|
30980
|
|
|
|
|
|
|
|
30981
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
30982
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
30983
|
|
|
|
|
|
|
|
30984
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
30985
|
|
|
|
|
|
|
|
30986
|
|
|
|
|
|
|
|
30987
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
30988
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
30989
|
|
|
|
|
|
|
|
30990
|
|
|
|
|
|
|
#include |
30991
|
|
|
|
|
|
|
#include |
30992
|
|
|
|
|
|
|
|
30993
|
|
|
|
|
|
|
#ifdef __cplusplus |
30994
|
|
|
|
|
|
|
extern "C" { |
30995
|
|
|
|
|
|
|
#endif |
30996
|
|
|
|
|
|
|
|
30997
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
30998
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
30999
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
31000
|
|
|
|
|
|
|
|
31001
|
|
|
|
|
|
|
|
31002
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
31003
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
31004
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
31005
|
|
|
|
|
|
|
# else |
31006
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
31007
|
|
|
|
|
|
|
# endif |
31008
|
|
|
|
|
|
|
#endif |
31009
|
|
|
|
|
|
|
|
31010
|
|
|
|
|
|
|
|
31011
|
|
|
|
|
|
|
|
31012
|
|
|
|
|
|
|
|
31013
|
|
|
|
|
|
|
|
31014
|
|
|
|
|
|
|
struct libdeflate_compressor; |
31015
|
|
|
|
|
|
|
|
31016
|
|
|
|
|
|
|
|
31017
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
31018
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
31019
|
|
|
|
|
|
|
|
31020
|
|
|
|
|
|
|
|
31021
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31022
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
31023
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31024
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
31025
|
|
|
|
|
|
|
|
31026
|
|
|
|
|
|
|
|
31027
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31028
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
31029
|
|
|
|
|
|
|
size_t in_nbytes); |
31030
|
|
|
|
|
|
|
|
31031
|
|
|
|
|
|
|
|
31032
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31033
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
31034
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31035
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
31036
|
|
|
|
|
|
|
|
31037
|
|
|
|
|
|
|
|
31038
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31039
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
31040
|
|
|
|
|
|
|
size_t in_nbytes); |
31041
|
|
|
|
|
|
|
|
31042
|
|
|
|
|
|
|
|
31043
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31044
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
31045
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31046
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
31047
|
|
|
|
|
|
|
|
31048
|
|
|
|
|
|
|
|
31049
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
31050
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
31051
|
|
|
|
|
|
|
size_t in_nbytes); |
31052
|
|
|
|
|
|
|
|
31053
|
|
|
|
|
|
|
|
31054
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
31055
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
31056
|
|
|
|
|
|
|
|
31057
|
|
|
|
|
|
|
|
31058
|
|
|
|
|
|
|
|
31059
|
|
|
|
|
|
|
|
31060
|
|
|
|
|
|
|
|
31061
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
31062
|
|
|
|
|
|
|
|
31063
|
|
|
|
|
|
|
|
31064
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
31065
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
31066
|
|
|
|
|
|
|
|
31067
|
|
|
|
|
|
|
|
31068
|
|
|
|
|
|
|
enum libdeflate_result { |
31069
|
|
|
|
|
|
|
|
31070
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
31071
|
|
|
|
|
|
|
|
31072
|
|
|
|
|
|
|
|
31073
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
31074
|
|
|
|
|
|
|
|
31075
|
|
|
|
|
|
|
|
31076
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
31077
|
|
|
|
|
|
|
|
31078
|
|
|
|
|
|
|
|
31079
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
31080
|
|
|
|
|
|
|
}; |
31081
|
|
|
|
|
|
|
|
31082
|
|
|
|
|
|
|
|
31083
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31084
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
31085
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31086
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31087
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31088
|
|
|
|
|
|
|
|
31089
|
|
|
|
|
|
|
|
31090
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31091
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
31092
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31093
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31094
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
31095
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31096
|
|
|
|
|
|
|
|
31097
|
|
|
|
|
|
|
|
31098
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31099
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
31100
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31101
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31102
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31103
|
|
|
|
|
|
|
|
31104
|
|
|
|
|
|
|
|
31105
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31106
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
31107
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31108
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31109
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
31110
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31111
|
|
|
|
|
|
|
|
31112
|
|
|
|
|
|
|
|
31113
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31114
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
31115
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31116
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31117
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31118
|
|
|
|
|
|
|
|
31119
|
|
|
|
|
|
|
|
31120
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31121
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
31122
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31123
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31124
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
31125
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
31126
|
|
|
|
|
|
|
|
31127
|
|
|
|
|
|
|
|
31128
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
31129
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
31130
|
|
|
|
|
|
|
|
31131
|
|
|
|
|
|
|
|
31132
|
|
|
|
|
|
|
|
31133
|
|
|
|
|
|
|
|
31134
|
|
|
|
|
|
|
|
31135
|
|
|
|
|
|
|
|
31136
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
31137
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
31138
|
|
|
|
|
|
|
|
31139
|
|
|
|
|
|
|
|
31140
|
|
|
|
|
|
|
|
31141
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
31142
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
31143
|
|
|
|
|
|
|
|
31144
|
|
|
|
|
|
|
|
31145
|
|
|
|
|
|
|
|
31146
|
|
|
|
|
|
|
|
31147
|
|
|
|
|
|
|
|
31148
|
|
|
|
|
|
|
|
31149
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
31150
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
31151
|
|
|
|
|
|
|
void (*free_func)(void *)); |
31152
|
|
|
|
|
|
|
|
31153
|
|
|
|
|
|
|
#ifdef __cplusplus |
31154
|
|
|
|
|
|
|
} |
31155
|
|
|
|
|
|
|
#endif |
31156
|
|
|
|
|
|
|
|
31157
|
|
|
|
|
|
|
#endif |
31158
|
|
|
|
|
|
|
|
31159
|
|
|
|
|
|
|
|
31160
|
|
|
|
|
|
|
#include |
31161
|
|
|
|
|
|
|
#include |
31162
|
|
|
|
|
|
|
#include |
31163
|
|
|
|
|
|
|
#ifdef _MSC_VER |
31164
|
|
|
|
|
|
|
# include |
31165
|
|
|
|
|
|
|
# include |
31166
|
|
|
|
|
|
|
|
31167
|
|
|
|
|
|
|
|
31168
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
31169
|
|
|
|
|
|
|
|
31170
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
31171
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
31172
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
31173
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
31174
|
|
|
|
|
|
|
|
31175
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
31176
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
31177
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
31178
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
31179
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
31180
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
31181
|
|
|
|
|
|
|
#endif |
31182
|
|
|
|
|
|
|
#ifndef FREESTANDING |
31183
|
|
|
|
|
|
|
# include |
31184
|
|
|
|
|
|
|
#endif |
31185
|
|
|
|
|
|
|
|
31186
|
|
|
|
|
|
|
|
31187
|
|
|
|
|
|
|
|
31188
|
|
|
|
|
|
|
|
31189
|
|
|
|
|
|
|
|
31190
|
|
|
|
|
|
|
|
31191
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
31192
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
31193
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
31194
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
31195
|
|
|
|
|
|
|
#ifdef _MSC_VER |
31196
|
|
|
|
|
|
|
# if defined(_M_X64) |
31197
|
|
|
|
|
|
|
# define ARCH_X86_64 |
31198
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
31199
|
|
|
|
|
|
|
# define ARCH_X86_32 |
31200
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
31201
|
|
|
|
|
|
|
# define ARCH_ARM64 |
31202
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
31203
|
|
|
|
|
|
|
# define ARCH_ARM32 |
31204
|
|
|
|
|
|
|
# endif |
31205
|
|
|
|
|
|
|
#else |
31206
|
|
|
|
|
|
|
# if defined(__x86_64__) |
31207
|
|
|
|
|
|
|
# define ARCH_X86_64 |
31208
|
|
|
|
|
|
|
# elif defined(__i386__) |
31209
|
|
|
|
|
|
|
# define ARCH_X86_32 |
31210
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
31211
|
|
|
|
|
|
|
# define ARCH_ARM64 |
31212
|
|
|
|
|
|
|
# elif defined(__arm__) |
31213
|
|
|
|
|
|
|
# define ARCH_ARM32 |
31214
|
|
|
|
|
|
|
# endif |
31215
|
|
|
|
|
|
|
#endif |
31216
|
|
|
|
|
|
|
|
31217
|
|
|
|
|
|
|
|
31218
|
|
|
|
|
|
|
|
31219
|
|
|
|
|
|
|
|
31220
|
|
|
|
|
|
|
|
31221
|
|
|
|
|
|
|
|
31222
|
|
|
|
|
|
|
typedef uint8_t u8; |
31223
|
|
|
|
|
|
|
typedef uint16_t u16; |
31224
|
|
|
|
|
|
|
typedef uint32_t u32; |
31225
|
|
|
|
|
|
|
typedef uint64_t u64; |
31226
|
|
|
|
|
|
|
typedef int8_t s8; |
31227
|
|
|
|
|
|
|
typedef int16_t s16; |
31228
|
|
|
|
|
|
|
typedef int32_t s32; |
31229
|
|
|
|
|
|
|
typedef int64_t s64; |
31230
|
|
|
|
|
|
|
|
31231
|
|
|
|
|
|
|
|
31232
|
|
|
|
|
|
|
#ifdef _MSC_VER |
31233
|
|
|
|
|
|
|
# ifdef _WIN64 |
31234
|
|
|
|
|
|
|
typedef long long ssize_t; |
31235
|
|
|
|
|
|
|
# else |
31236
|
|
|
|
|
|
|
typedef long ssize_t; |
31237
|
|
|
|
|
|
|
# endif |
31238
|
|
|
|
|
|
|
#endif |
31239
|
|
|
|
|
|
|
|
31240
|
|
|
|
|
|
|
|
31241
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
31242
|
|
|
|
|
|
|
|
31243
|
|
|
|
|
|
|
|
31244
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
31245
|
|
|
|
|
|
|
|
31246
|
|
|
|
|
|
|
|
31247
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
31248
|
|
|
|
|
|
|
|
31249
|
|
|
|
|
|
|
|
31250
|
|
|
|
|
|
|
|
31251
|
|
|
|
|
|
|
|
31252
|
|
|
|
|
|
|
|
31253
|
|
|
|
|
|
|
|
31254
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
31255
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
31256
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
31257
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
31258
|
|
|
|
|
|
|
#else |
31259
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
31260
|
|
|
|
|
|
|
#endif |
31261
|
|
|
|
|
|
|
#ifdef __clang__ |
31262
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
31263
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
31264
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
31265
|
|
|
|
|
|
|
# else |
31266
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
31267
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
31268
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
31269
|
|
|
|
|
|
|
# endif |
31270
|
|
|
|
|
|
|
#else |
31271
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
31272
|
|
|
|
|
|
|
#endif |
31273
|
|
|
|
|
|
|
|
31274
|
|
|
|
|
|
|
|
31275
|
|
|
|
|
|
|
#ifndef __has_attribute |
31276
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
31277
|
|
|
|
|
|
|
#endif |
31278
|
|
|
|
|
|
|
#ifndef __has_builtin |
31279
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
31280
|
|
|
|
|
|
|
#endif |
31281
|
|
|
|
|
|
|
|
31282
|
|
|
|
|
|
|
|
31283
|
|
|
|
|
|
|
#ifdef _MSC_VER |
31284
|
|
|
|
|
|
|
# define inline __inline |
31285
|
|
|
|
|
|
|
#endif |
31286
|
|
|
|
|
|
|
|
31287
|
|
|
|
|
|
|
|
31288
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
31289
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
31290
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31291
|
|
|
|
|
|
|
# define forceinline __forceinline |
31292
|
|
|
|
|
|
|
#else |
31293
|
|
|
|
|
|
|
# define forceinline inline |
31294
|
|
|
|
|
|
|
#endif |
31295
|
|
|
|
|
|
|
|
31296
|
|
|
|
|
|
|
|
31297
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
31298
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
31299
|
|
|
|
|
|
|
#else |
31300
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
31301
|
|
|
|
|
|
|
#endif |
31302
|
|
|
|
|
|
|
|
31303
|
|
|
|
|
|
|
|
31304
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
31305
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
31306
|
|
|
|
|
|
|
# define restrict __restrict__ |
31307
|
|
|
|
|
|
|
# else |
31308
|
|
|
|
|
|
|
# define restrict |
31309
|
|
|
|
|
|
|
# endif |
31310
|
|
|
|
|
|
|
#endif |
31311
|
|
|
|
|
|
|
|
31312
|
|
|
|
|
|
|
|
31313
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
31314
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
31315
|
|
|
|
|
|
|
#else |
31316
|
|
|
|
|
|
|
# define likely(expr) (expr) |
31317
|
|
|
|
|
|
|
#endif |
31318
|
|
|
|
|
|
|
|
31319
|
|
|
|
|
|
|
|
31320
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
31321
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
31322
|
|
|
|
|
|
|
#else |
31323
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
31324
|
|
|
|
|
|
|
#endif |
31325
|
|
|
|
|
|
|
|
31326
|
|
|
|
|
|
|
|
31327
|
|
|
|
|
|
|
#undef prefetchr |
31328
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
31329
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
31330
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31331
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
31332
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
31333
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
31334
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
31335
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
31336
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
31337
|
|
|
|
|
|
|
# endif |
31338
|
|
|
|
|
|
|
#endif |
31339
|
|
|
|
|
|
|
#ifndef prefetchr |
31340
|
|
|
|
|
|
|
# define prefetchr(addr) |
31341
|
|
|
|
|
|
|
#endif |
31342
|
|
|
|
|
|
|
|
31343
|
|
|
|
|
|
|
|
31344
|
|
|
|
|
|
|
#undef prefetchw |
31345
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
31346
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
31347
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31348
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
31349
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
31350
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
31351
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
31352
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
31353
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
31354
|
|
|
|
|
|
|
# endif |
31355
|
|
|
|
|
|
|
#endif |
31356
|
|
|
|
|
|
|
#ifndef prefetchw |
31357
|
|
|
|
|
|
|
# define prefetchw(addr) |
31358
|
|
|
|
|
|
|
#endif |
31359
|
|
|
|
|
|
|
|
31360
|
|
|
|
|
|
|
|
31361
|
|
|
|
|
|
|
#undef _aligned_attribute |
31362
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
31363
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
31364
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31365
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
31366
|
|
|
|
|
|
|
#endif |
31367
|
|
|
|
|
|
|
|
31368
|
|
|
|
|
|
|
|
31369
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
31370
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
31371
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
31372
|
|
|
|
|
|
|
#else |
31373
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
31374
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
31375
|
|
|
|
|
|
|
#endif |
31376
|
|
|
|
|
|
|
|
31377
|
|
|
|
|
|
|
|
31378
|
|
|
|
|
|
|
|
31379
|
|
|
|
|
|
|
|
31380
|
|
|
|
|
|
|
|
31381
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
31382
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
31383
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
31384
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
31385
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
31386
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
31387
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
31388
|
|
|
|
|
|
|
|
31389
|
|
|
|
|
|
|
|
31390
|
|
|
|
|
|
|
|
31391
|
|
|
|
|
|
|
|
31392
|
|
|
|
|
|
|
|
31393
|
|
|
|
|
|
|
|
31394
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
31395
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
31396
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31397
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
31398
|
|
|
|
|
|
|
#else |
31399
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
31400
|
|
|
|
|
|
|
{ |
31401
|
|
|
|
|
|
|
union { |
31402
|
|
|
|
|
|
|
u32 w; |
31403
|
|
|
|
|
|
|
u8 b; |
31404
|
|
|
|
|
|
|
} u; |
31405
|
|
|
|
|
|
|
|
31406
|
|
|
|
|
|
|
u.w = 1; |
31407
|
|
|
|
|
|
|
return u.b; |
31408
|
|
|
|
|
|
|
} |
31409
|
|
|
|
|
|
|
#endif |
31410
|
|
|
|
|
|
|
|
31411
|
|
|
|
|
|
|
|
31412
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
31413
|
|
|
|
|
|
|
{ |
31414
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
31415
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
31416
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31417
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
31418
|
|
|
|
|
|
|
#else |
31419
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
31420
|
|
|
|
|
|
|
#endif |
31421
|
|
|
|
|
|
|
} |
31422
|
|
|
|
|
|
|
|
31423
|
|
|
|
|
|
|
|
31424
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
31425
|
|
|
|
|
|
|
{ |
31426
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
31427
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
31428
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31429
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
31430
|
|
|
|
|
|
|
#else |
31431
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
31432
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
31433
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
31434
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
31435
|
|
|
|
|
|
|
#endif |
31436
|
|
|
|
|
|
|
} |
31437
|
|
|
|
|
|
|
|
31438
|
|
|
|
|
|
|
|
31439
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
31440
|
|
|
|
|
|
|
{ |
31441
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
31442
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
31443
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31444
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
31445
|
|
|
|
|
|
|
#else |
31446
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
31447
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
31448
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
31449
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
31450
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
31451
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
31452
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
31453
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
31454
|
|
|
|
|
|
|
#endif |
31455
|
|
|
|
|
|
|
} |
31456
|
|
|
|
|
|
|
|
31457
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
31458
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
31459
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
31460
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
31461
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
31462
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
31463
|
|
|
|
|
|
|
|
31464
|
|
|
|
|
|
|
|
31465
|
|
|
|
|
|
|
|
31466
|
|
|
|
|
|
|
|
31467
|
|
|
|
|
|
|
|
31468
|
|
|
|
|
|
|
|
31469
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
31470
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
31471
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
31472
|
|
|
|
|
|
|
defined(__wasm__)) |
31473
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
31474
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31475
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
31476
|
|
|
|
|
|
|
#else |
31477
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
31478
|
|
|
|
|
|
|
#endif |
31479
|
|
|
|
|
|
|
|
31480
|
|
|
|
|
|
|
|
31481
|
|
|
|
|
|
|
|
31482
|
|
|
|
|
|
|
#ifdef FREESTANDING |
31483
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
31484
|
|
|
|
|
|
|
#else |
31485
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
31486
|
|
|
|
|
|
|
#endif |
31487
|
|
|
|
|
|
|
|
31488
|
|
|
|
|
|
|
|
31489
|
|
|
|
|
|
|
|
31490
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
31491
|
|
|
|
|
|
|
static forceinline type \ |
31492
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
31493
|
|
|
|
|
|
|
{ \ |
31494
|
|
|
|
|
|
|
type v; \ |
31495
|
|
|
|
|
|
|
\ |
31496
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
31497
|
|
|
|
|
|
|
return v; \ |
31498
|
|
|
|
|
|
|
} \ |
31499
|
|
|
|
|
|
|
\ |
31500
|
|
|
|
|
|
|
static forceinline void \ |
31501
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
31502
|
|
|
|
|
|
|
{ \ |
31503
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
31504
|
|
|
|
|
|
|
} |
31505
|
|
|
|
|
|
|
|
31506
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
31507
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
31508
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
31509
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
31510
|
|
|
|
|
|
|
|
31511
|
|
|
|
|
|
|
#undef MEMCOPY |
31512
|
|
|
|
|
|
|
|
31513
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
31514
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
31515
|
|
|
|
|
|
|
|
31516
|
|
|
|
|
|
|
|
31517
|
|
|
|
|
|
|
|
31518
|
|
|
|
|
|
|
static forceinline u16 |
31519
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
31520
|
|
|
|
|
|
|
{ |
31521
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31522
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
31523
|
|
|
|
|
|
|
else |
31524
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
31525
|
|
|
|
|
|
|
} |
31526
|
|
|
|
|
|
|
|
31527
|
|
|
|
|
|
|
static forceinline u16 |
31528
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
31529
|
|
|
|
|
|
|
{ |
31530
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31531
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
31532
|
|
|
|
|
|
|
else |
31533
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
31534
|
|
|
|
|
|
|
} |
31535
|
|
|
|
|
|
|
|
31536
|
|
|
|
|
|
|
static forceinline u32 |
31537
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
31538
|
|
|
|
|
|
|
{ |
31539
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31540
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
31541
|
|
|
|
|
|
|
else |
31542
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
31543
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
31544
|
|
|
|
|
|
|
} |
31545
|
|
|
|
|
|
|
|
31546
|
|
|
|
|
|
|
static forceinline u32 |
31547
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
31548
|
|
|
|
|
|
|
{ |
31549
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31550
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
31551
|
|
|
|
|
|
|
else |
31552
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
31553
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
31554
|
|
|
|
|
|
|
} |
31555
|
|
|
|
|
|
|
|
31556
|
|
|
|
|
|
|
static forceinline u64 |
31557
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
31558
|
|
|
|
|
|
|
{ |
31559
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
31560
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
31561
|
|
|
|
|
|
|
else |
31562
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
31563
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
31564
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
31565
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
31566
|
|
|
|
|
|
|
} |
31567
|
|
|
|
|
|
|
|
31568
|
|
|
|
|
|
|
static forceinline machine_word_t |
31569
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
31570
|
|
|
|
|
|
|
{ |
31571
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
31572
|
|
|
|
|
|
|
if (WORDBITS == 32) |
31573
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
31574
|
|
|
|
|
|
|
else |
31575
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
31576
|
|
|
|
|
|
|
} |
31577
|
|
|
|
|
|
|
|
31578
|
|
|
|
|
|
|
|
31579
|
|
|
|
|
|
|
|
31580
|
|
|
|
|
|
|
static forceinline void |
31581
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
31582
|
|
|
|
|
|
|
{ |
31583
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31584
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
31585
|
|
|
|
|
|
|
} else { |
31586
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
31587
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
31588
|
|
|
|
|
|
|
} |
31589
|
|
|
|
|
|
|
} |
31590
|
|
|
|
|
|
|
|
31591
|
|
|
|
|
|
|
static forceinline void |
31592
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
31593
|
|
|
|
|
|
|
{ |
31594
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31595
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
31596
|
|
|
|
|
|
|
} else { |
31597
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
31598
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
31599
|
|
|
|
|
|
|
} |
31600
|
|
|
|
|
|
|
} |
31601
|
|
|
|
|
|
|
|
31602
|
|
|
|
|
|
|
static forceinline void |
31603
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
31604
|
|
|
|
|
|
|
{ |
31605
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31606
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
31607
|
|
|
|
|
|
|
} else { |
31608
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
31609
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
31610
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
31611
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
31612
|
|
|
|
|
|
|
} |
31613
|
|
|
|
|
|
|
} |
31614
|
|
|
|
|
|
|
|
31615
|
|
|
|
|
|
|
static forceinline void |
31616
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
31617
|
|
|
|
|
|
|
{ |
31618
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31619
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
31620
|
|
|
|
|
|
|
} else { |
31621
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
31622
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
31623
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
31624
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
31625
|
|
|
|
|
|
|
} |
31626
|
|
|
|
|
|
|
} |
31627
|
|
|
|
|
|
|
|
31628
|
|
|
|
|
|
|
static forceinline void |
31629
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
31630
|
|
|
|
|
|
|
{ |
31631
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
31632
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
31633
|
|
|
|
|
|
|
} else { |
31634
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
31635
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
31636
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
31637
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
31638
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
31639
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
31640
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
31641
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
31642
|
|
|
|
|
|
|
} |
31643
|
|
|
|
|
|
|
} |
31644
|
|
|
|
|
|
|
|
31645
|
|
|
|
|
|
|
static forceinline void |
31646
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
31647
|
|
|
|
|
|
|
{ |
31648
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
31649
|
|
|
|
|
|
|
if (WORDBITS == 32) |
31650
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
31651
|
|
|
|
|
|
|
else |
31652
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
31653
|
|
|
|
|
|
|
} |
31654
|
|
|
|
|
|
|
|
31655
|
|
|
|
|
|
|
|
31656
|
|
|
|
|
|
|
|
31657
|
|
|
|
|
|
|
|
31658
|
|
|
|
|
|
|
|
31659
|
|
|
|
|
|
|
|
31660
|
|
|
|
|
|
|
|
31661
|
|
|
|
|
|
|
static forceinline unsigned |
31662
|
|
|
|
|
|
|
bsr32(u32 v) |
31663
|
|
|
|
|
|
|
{ |
31664
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
31665
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
31666
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31667
|
|
|
|
|
|
|
unsigned long i; |
31668
|
|
|
|
|
|
|
|
31669
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
31670
|
|
|
|
|
|
|
return i; |
31671
|
|
|
|
|
|
|
#else |
31672
|
|
|
|
|
|
|
unsigned i = 0; |
31673
|
|
|
|
|
|
|
|
31674
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
31675
|
|
|
|
|
|
|
i++; |
31676
|
|
|
|
|
|
|
return i; |
31677
|
|
|
|
|
|
|
#endif |
31678
|
|
|
|
|
|
|
} |
31679
|
|
|
|
|
|
|
|
31680
|
|
|
|
|
|
|
static forceinline unsigned |
31681
|
|
|
|
|
|
|
bsr64(u64 v) |
31682
|
|
|
|
|
|
|
{ |
31683
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
31684
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
31685
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
31686
|
|
|
|
|
|
|
unsigned long i; |
31687
|
|
|
|
|
|
|
|
31688
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
31689
|
|
|
|
|
|
|
return i; |
31690
|
|
|
|
|
|
|
#else |
31691
|
|
|
|
|
|
|
unsigned i = 0; |
31692
|
|
|
|
|
|
|
|
31693
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
31694
|
|
|
|
|
|
|
i++; |
31695
|
|
|
|
|
|
|
return i; |
31696
|
|
|
|
|
|
|
#endif |
31697
|
|
|
|
|
|
|
} |
31698
|
|
|
|
|
|
|
|
31699
|
|
|
|
|
|
|
static forceinline unsigned |
31700
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
31701
|
|
|
|
|
|
|
{ |
31702
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
31703
|
|
|
|
|
|
|
if (WORDBITS == 32) |
31704
|
|
|
|
|
|
|
return bsr32(v); |
31705
|
|
|
|
|
|
|
else |
31706
|
|
|
|
|
|
|
return bsr64(v); |
31707
|
|
|
|
|
|
|
} |
31708
|
|
|
|
|
|
|
|
31709
|
|
|
|
|
|
|
|
31710
|
|
|
|
|
|
|
|
31711
|
|
|
|
|
|
|
static forceinline unsigned |
31712
|
|
|
|
|
|
|
bsf32(u32 v) |
31713
|
|
|
|
|
|
|
{ |
31714
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
31715
|
|
|
|
|
|
|
return __builtin_ctz(v); |
31716
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
31717
|
|
|
|
|
|
|
unsigned long i; |
31718
|
|
|
|
|
|
|
|
31719
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
31720
|
|
|
|
|
|
|
return i; |
31721
|
|
|
|
|
|
|
#else |
31722
|
|
|
|
|
|
|
unsigned i = 0; |
31723
|
|
|
|
|
|
|
|
31724
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
31725
|
|
|
|
|
|
|
i++; |
31726
|
|
|
|
|
|
|
return i; |
31727
|
|
|
|
|
|
|
#endif |
31728
|
|
|
|
|
|
|
} |
31729
|
|
|
|
|
|
|
|
31730
|
|
|
|
|
|
|
static forceinline unsigned |
31731
|
|
|
|
|
|
|
bsf64(u64 v) |
31732
|
|
|
|
|
|
|
{ |
31733
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
31734
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
31735
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
31736
|
|
|
|
|
|
|
unsigned long i; |
31737
|
|
|
|
|
|
|
|
31738
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
31739
|
|
|
|
|
|
|
return i; |
31740
|
|
|
|
|
|
|
#else |
31741
|
|
|
|
|
|
|
unsigned i = 0; |
31742
|
|
|
|
|
|
|
|
31743
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
31744
|
|
|
|
|
|
|
i++; |
31745
|
|
|
|
|
|
|
return i; |
31746
|
|
|
|
|
|
|
#endif |
31747
|
|
|
|
|
|
|
} |
31748
|
|
|
|
|
|
|
|
31749
|
|
|
|
|
|
|
static forceinline unsigned |
31750
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
31751
|
|
|
|
|
|
|
{ |
31752
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
31753
|
|
|
|
|
|
|
if (WORDBITS == 32) |
31754
|
|
|
|
|
|
|
return bsf32(v); |
31755
|
|
|
|
|
|
|
else |
31756
|
|
|
|
|
|
|
return bsf64(v); |
31757
|
|
|
|
|
|
|
} |
31758
|
|
|
|
|
|
|
|
31759
|
|
|
|
|
|
|
|
31760
|
|
|
|
|
|
|
#undef rbit32 |
31761
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
31762
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
31763
|
|
|
|
|
|
|
static forceinline u32 |
31764
|
|
|
|
|
|
|
rbit32(u32 v) |
31765
|
|
|
|
|
|
|
{ |
31766
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
31767
|
|
|
|
|
|
|
return v; |
31768
|
|
|
|
|
|
|
} |
31769
|
|
|
|
|
|
|
#define rbit32 rbit32 |
31770
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
31771
|
|
|
|
|
|
|
static forceinline u32 |
31772
|
|
|
|
|
|
|
rbit32(u32 v) |
31773
|
|
|
|
|
|
|
{ |
31774
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
31775
|
|
|
|
|
|
|
return v; |
31776
|
|
|
|
|
|
|
} |
31777
|
|
|
|
|
|
|
#define rbit32 rbit32 |
31778
|
|
|
|
|
|
|
#endif |
31779
|
|
|
|
|
|
|
|
31780
|
|
|
|
|
|
|
#endif |
31781
|
|
|
|
|
|
|
|
31782
|
|
|
|
|
|
|
|
31783
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
31784
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
31785
|
|
|
|
|
|
|
|
31786
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
31787
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
31788
|
|
|
|
|
|
|
|
31789
|
|
|
|
|
|
|
#ifdef FREESTANDING |
31790
|
|
|
|
|
|
|
|
31791
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
31792
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
31793
|
|
|
|
|
|
|
|
31794
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
31795
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
31796
|
|
|
|
|
|
|
|
31797
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
31798
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
31799
|
|
|
|
|
|
|
|
31800
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
31801
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
31802
|
|
|
|
|
|
|
|
31803
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
31804
|
|
|
|
|
|
|
#else |
31805
|
|
|
|
|
|
|
#include |
31806
|
|
|
|
|
|
|
#endif |
31807
|
|
|
|
|
|
|
|
31808
|
|
|
|
|
|
|
|
31809
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
31810
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
31811
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
31812
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
31813
|
|
|
|
|
|
|
#else |
31814
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
31815
|
|
|
|
|
|
|
#endif |
31816
|
|
|
|
|
|
|
|
31817
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
31818
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
31819
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
31820
|
|
|
|
|
|
|
|
31821
|
|
|
|
|
|
|
#endif |
31822
|
|
|
|
|
|
|
|
31823
|
|
|
|
|
|
|
/* #include "zlib_constants.h" */ |
31824
|
|
|
|
|
|
|
|
31825
|
|
|
|
|
|
|
|
31826
|
|
|
|
|
|
|
#ifndef LIB_ZLIB_CONSTANTS_H |
31827
|
|
|
|
|
|
|
#define LIB_ZLIB_CONSTANTS_H |
31828
|
|
|
|
|
|
|
|
31829
|
|
|
|
|
|
|
#define ZLIB_MIN_HEADER_SIZE 2 |
31830
|
|
|
|
|
|
|
#define ZLIB_FOOTER_SIZE 4 |
31831
|
|
|
|
|
|
|
#define ZLIB_MIN_OVERHEAD (ZLIB_MIN_HEADER_SIZE + ZLIB_FOOTER_SIZE) |
31832
|
|
|
|
|
|
|
|
31833
|
|
|
|
|
|
|
#define ZLIB_CM_DEFLATE 8 |
31834
|
|
|
|
|
|
|
|
31835
|
|
|
|
|
|
|
#define ZLIB_CINFO_32K_WINDOW 7 |
31836
|
|
|
|
|
|
|
|
31837
|
|
|
|
|
|
|
#define ZLIB_FASTEST_COMPRESSION 0 |
31838
|
|
|
|
|
|
|
#define ZLIB_FAST_COMPRESSION 1 |
31839
|
|
|
|
|
|
|
#define ZLIB_DEFAULT_COMPRESSION 2 |
31840
|
|
|
|
|
|
|
#define ZLIB_SLOWEST_COMPRESSION 3 |
31841
|
|
|
|
|
|
|
|
31842
|
|
|
|
|
|
|
#endif |
31843
|
|
|
|
|
|
|
|
31844
|
|
|
|
|
|
|
|
31845
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31846
|
12
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *d, |
31847
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31848
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31849
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
31850
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
31851
|
|
|
|
|
|
|
{ |
31852
|
12
|
|
|
|
|
|
const u8 *in_next = in; |
31853
|
12
|
|
|
|
|
|
const u8 * const in_end = in_next + in_nbytes; |
31854
|
|
|
|
|
|
|
u16 hdr; |
31855
|
|
|
|
|
|
|
size_t actual_in_nbytes; |
31856
|
|
|
|
|
|
|
size_t actual_out_nbytes; |
31857
|
|
|
|
|
|
|
enum libdeflate_result result; |
31858
|
|
|
|
|
|
|
|
31859
|
12
|
50
|
|
|
|
|
if (in_nbytes < ZLIB_MIN_OVERHEAD) |
31860
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
31861
|
|
|
|
|
|
|
|
31862
|
|
|
|
|
|
|
|
31863
|
12
|
|
|
|
|
|
hdr = get_unaligned_be16(in_next); |
31864
|
12
|
|
|
|
|
|
in_next += 2; |
31865
|
|
|
|
|
|
|
|
31866
|
|
|
|
|
|
|
|
31867
|
12
|
50
|
|
|
|
|
if ((hdr % 31) != 0) |
31868
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
31869
|
|
|
|
|
|
|
|
31870
|
|
|
|
|
|
|
|
31871
|
12
|
50
|
|
|
|
|
if (((hdr >> 8) & 0xF) != ZLIB_CM_DEFLATE) |
31872
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
31873
|
|
|
|
|
|
|
|
31874
|
|
|
|
|
|
|
|
31875
|
12
|
50
|
|
|
|
|
if ((hdr >> 12) > ZLIB_CINFO_32K_WINDOW) |
31876
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
31877
|
|
|
|
|
|
|
|
31878
|
|
|
|
|
|
|
|
31879
|
12
|
50
|
|
|
|
|
if ((hdr >> 5) & 1) |
31880
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
31881
|
|
|
|
|
|
|
|
31882
|
|
|
|
|
|
|
|
31883
|
12
|
|
|
|
|
|
result = libdeflate_deflate_decompress_ex(d, in_next, |
31884
|
12
|
|
|
|
|
|
in_end - ZLIB_FOOTER_SIZE - in_next, |
31885
|
|
|
|
|
|
|
out, out_nbytes_avail, |
31886
|
|
|
|
|
|
|
&actual_in_nbytes, actual_out_nbytes_ret); |
31887
|
12
|
50
|
|
|
|
|
if (result != LIBDEFLATE_SUCCESS) |
31888
|
0
|
|
|
|
|
|
return result; |
31889
|
|
|
|
|
|
|
|
31890
|
12
|
50
|
|
|
|
|
if (actual_out_nbytes_ret) |
31891
|
12
|
|
|
|
|
|
actual_out_nbytes = *actual_out_nbytes_ret; |
31892
|
|
|
|
|
|
|
else |
31893
|
0
|
|
|
|
|
|
actual_out_nbytes = out_nbytes_avail; |
31894
|
|
|
|
|
|
|
|
31895
|
12
|
|
|
|
|
|
in_next += actual_in_nbytes; |
31896
|
|
|
|
|
|
|
|
31897
|
|
|
|
|
|
|
|
31898
|
24
|
50
|
|
|
|
|
if (libdeflate_adler32(1, out, actual_out_nbytes) != |
31899
|
12
|
|
|
|
|
|
get_unaligned_be32(in_next)) |
31900
|
0
|
|
|
|
|
|
return LIBDEFLATE_BAD_DATA; |
31901
|
12
|
|
|
|
|
|
in_next += 4; |
31902
|
|
|
|
|
|
|
|
31903
|
12
|
50
|
|
|
|
|
if (actual_in_nbytes_ret) |
31904
|
12
|
|
|
|
|
|
*actual_in_nbytes_ret = in_next - (u8 *)in; |
31905
|
|
|
|
|
|
|
|
31906
|
12
|
|
|
|
|
|
return LIBDEFLATE_SUCCESS; |
31907
|
|
|
|
|
|
|
} |
31908
|
|
|
|
|
|
|
|
31909
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
31910
|
0
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *d, |
31911
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
31912
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
31913
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret) |
31914
|
|
|
|
|
|
|
{ |
31915
|
0
|
|
|
|
|
|
return libdeflate_zlib_decompress_ex(d, in, in_nbytes, |
31916
|
|
|
|
|
|
|
out, out_nbytes_avail, |
31917
|
|
|
|
|
|
|
NULL, actual_out_nbytes_ret); |
31918
|
|
|
|
|
|
|
} |
31919
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/arm/cpu_features.c */ |
31920
|
|
|
|
|
|
|
|
31921
|
|
|
|
|
|
|
|
31922
|
|
|
|
|
|
|
|
31923
|
|
|
|
|
|
|
|
31924
|
|
|
|
|
|
|
#ifdef __APPLE__ |
31925
|
|
|
|
|
|
|
# undef _ANSI_SOURCE |
31926
|
|
|
|
|
|
|
# undef _DARWIN_C_SOURCE |
31927
|
|
|
|
|
|
|
# define _DARWIN_C_SOURCE |
31928
|
|
|
|
|
|
|
#endif |
31929
|
|
|
|
|
|
|
|
31930
|
|
|
|
|
|
|
/* #include "cpu_features_common.h" */ |
31931
|
|
|
|
|
|
|
|
31932
|
|
|
|
|
|
|
|
31933
|
|
|
|
|
|
|
#ifndef LIB_CPU_FEATURES_COMMON_H |
31934
|
|
|
|
|
|
|
#define LIB_CPU_FEATURES_COMMON_H |
31935
|
|
|
|
|
|
|
|
31936
|
|
|
|
|
|
|
#if defined(TEST_SUPPORT__DO_NOT_USE) && !defined(FREESTANDING) |
31937
|
|
|
|
|
|
|
|
31938
|
|
|
|
|
|
|
# undef _ANSI_SOURCE |
31939
|
|
|
|
|
|
|
# ifndef __APPLE__ |
31940
|
|
|
|
|
|
|
# undef _GNU_SOURCE |
31941
|
|
|
|
|
|
|
# define _GNU_SOURCE |
31942
|
|
|
|
|
|
|
# endif |
31943
|
|
|
|
|
|
|
# include |
31944
|
|
|
|
|
|
|
# include |
31945
|
|
|
|
|
|
|
# include |
31946
|
|
|
|
|
|
|
#endif |
31947
|
|
|
|
|
|
|
|
31948
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
31949
|
|
|
|
|
|
|
|
31950
|
|
|
|
|
|
|
|
31951
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
31952
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
31953
|
|
|
|
|
|
|
|
31954
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
31955
|
|
|
|
|
|
|
|
31956
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
31957
|
|
|
|
|
|
|
#endif |
31958
|
|
|
|
|
|
|
|
31959
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
31960
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
31961
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
31962
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
31963
|
|
|
|
|
|
|
#else |
31964
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
31965
|
|
|
|
|
|
|
#endif |
31966
|
|
|
|
|
|
|
|
31967
|
|
|
|
|
|
|
|
31968
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
31969
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
31970
|
|
|
|
|
|
|
#else |
31971
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
31972
|
|
|
|
|
|
|
#endif |
31973
|
|
|
|
|
|
|
|
31974
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
31975
|
|
|
|
|
|
|
|
31976
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
31977
|
|
|
|
|
|
|
|
31978
|
|
|
|
|
|
|
|
31979
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
31980
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
31981
|
|
|
|
|
|
|
|
31982
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
31983
|
|
|
|
|
|
|
|
31984
|
|
|
|
|
|
|
|
31985
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
31986
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
31987
|
|
|
|
|
|
|
|
31988
|
|
|
|
|
|
|
#include |
31989
|
|
|
|
|
|
|
#include |
31990
|
|
|
|
|
|
|
|
31991
|
|
|
|
|
|
|
#ifdef __cplusplus |
31992
|
|
|
|
|
|
|
extern "C" { |
31993
|
|
|
|
|
|
|
#endif |
31994
|
|
|
|
|
|
|
|
31995
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
31996
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
31997
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
31998
|
|
|
|
|
|
|
|
31999
|
|
|
|
|
|
|
|
32000
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
32001
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
32002
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
32003
|
|
|
|
|
|
|
# else |
32004
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
32005
|
|
|
|
|
|
|
# endif |
32006
|
|
|
|
|
|
|
#endif |
32007
|
|
|
|
|
|
|
|
32008
|
|
|
|
|
|
|
|
32009
|
|
|
|
|
|
|
|
32010
|
|
|
|
|
|
|
|
32011
|
|
|
|
|
|
|
|
32012
|
|
|
|
|
|
|
struct libdeflate_compressor; |
32013
|
|
|
|
|
|
|
|
32014
|
|
|
|
|
|
|
|
32015
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
32016
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
32017
|
|
|
|
|
|
|
|
32018
|
|
|
|
|
|
|
|
32019
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32020
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
32021
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32022
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32023
|
|
|
|
|
|
|
|
32024
|
|
|
|
|
|
|
|
32025
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32026
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
32027
|
|
|
|
|
|
|
size_t in_nbytes); |
32028
|
|
|
|
|
|
|
|
32029
|
|
|
|
|
|
|
|
32030
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32031
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
32032
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32033
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32034
|
|
|
|
|
|
|
|
32035
|
|
|
|
|
|
|
|
32036
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32037
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
32038
|
|
|
|
|
|
|
size_t in_nbytes); |
32039
|
|
|
|
|
|
|
|
32040
|
|
|
|
|
|
|
|
32041
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32042
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
32043
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32044
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32045
|
|
|
|
|
|
|
|
32046
|
|
|
|
|
|
|
|
32047
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32048
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
32049
|
|
|
|
|
|
|
size_t in_nbytes); |
32050
|
|
|
|
|
|
|
|
32051
|
|
|
|
|
|
|
|
32052
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
32053
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
32054
|
|
|
|
|
|
|
|
32055
|
|
|
|
|
|
|
|
32056
|
|
|
|
|
|
|
|
32057
|
|
|
|
|
|
|
|
32058
|
|
|
|
|
|
|
|
32059
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
32060
|
|
|
|
|
|
|
|
32061
|
|
|
|
|
|
|
|
32062
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
32063
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
32064
|
|
|
|
|
|
|
|
32065
|
|
|
|
|
|
|
|
32066
|
|
|
|
|
|
|
enum libdeflate_result { |
32067
|
|
|
|
|
|
|
|
32068
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
32069
|
|
|
|
|
|
|
|
32070
|
|
|
|
|
|
|
|
32071
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
32072
|
|
|
|
|
|
|
|
32073
|
|
|
|
|
|
|
|
32074
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
32075
|
|
|
|
|
|
|
|
32076
|
|
|
|
|
|
|
|
32077
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
32078
|
|
|
|
|
|
|
}; |
32079
|
|
|
|
|
|
|
|
32080
|
|
|
|
|
|
|
|
32081
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32082
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
32083
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32084
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32085
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32086
|
|
|
|
|
|
|
|
32087
|
|
|
|
|
|
|
|
32088
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32089
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
32090
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32091
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32092
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
32093
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32094
|
|
|
|
|
|
|
|
32095
|
|
|
|
|
|
|
|
32096
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32097
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
32098
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32099
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32100
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32101
|
|
|
|
|
|
|
|
32102
|
|
|
|
|
|
|
|
32103
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32104
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
32105
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32106
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32107
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
32108
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32109
|
|
|
|
|
|
|
|
32110
|
|
|
|
|
|
|
|
32111
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32112
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
32113
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32114
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32115
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32116
|
|
|
|
|
|
|
|
32117
|
|
|
|
|
|
|
|
32118
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
32119
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
32120
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32121
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
32122
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
32123
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
32124
|
|
|
|
|
|
|
|
32125
|
|
|
|
|
|
|
|
32126
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
32127
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
32128
|
|
|
|
|
|
|
|
32129
|
|
|
|
|
|
|
|
32130
|
|
|
|
|
|
|
|
32131
|
|
|
|
|
|
|
|
32132
|
|
|
|
|
|
|
|
32133
|
|
|
|
|
|
|
|
32134
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
32135
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
32136
|
|
|
|
|
|
|
|
32137
|
|
|
|
|
|
|
|
32138
|
|
|
|
|
|
|
|
32139
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
32140
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
32141
|
|
|
|
|
|
|
|
32142
|
|
|
|
|
|
|
|
32143
|
|
|
|
|
|
|
|
32144
|
|
|
|
|
|
|
|
32145
|
|
|
|
|
|
|
|
32146
|
|
|
|
|
|
|
|
32147
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
32148
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
32149
|
|
|
|
|
|
|
void (*free_func)(void *)); |
32150
|
|
|
|
|
|
|
|
32151
|
|
|
|
|
|
|
#ifdef __cplusplus |
32152
|
|
|
|
|
|
|
} |
32153
|
|
|
|
|
|
|
#endif |
32154
|
|
|
|
|
|
|
|
32155
|
|
|
|
|
|
|
#endif |
32156
|
|
|
|
|
|
|
|
32157
|
|
|
|
|
|
|
|
32158
|
|
|
|
|
|
|
#include |
32159
|
|
|
|
|
|
|
#include |
32160
|
|
|
|
|
|
|
#include |
32161
|
|
|
|
|
|
|
#ifdef _MSC_VER |
32162
|
|
|
|
|
|
|
# include |
32163
|
|
|
|
|
|
|
# include |
32164
|
|
|
|
|
|
|
|
32165
|
|
|
|
|
|
|
|
32166
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
32167
|
|
|
|
|
|
|
|
32168
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
32169
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
32170
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
32171
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
32172
|
|
|
|
|
|
|
|
32173
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
32174
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
32175
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
32176
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
32177
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
32178
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
32179
|
|
|
|
|
|
|
#endif |
32180
|
|
|
|
|
|
|
#ifndef FREESTANDING |
32181
|
|
|
|
|
|
|
# include |
32182
|
|
|
|
|
|
|
#endif |
32183
|
|
|
|
|
|
|
|
32184
|
|
|
|
|
|
|
|
32185
|
|
|
|
|
|
|
|
32186
|
|
|
|
|
|
|
|
32187
|
|
|
|
|
|
|
|
32188
|
|
|
|
|
|
|
|
32189
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
32190
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
32191
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
32192
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
32193
|
|
|
|
|
|
|
#ifdef _MSC_VER |
32194
|
|
|
|
|
|
|
# if defined(_M_X64) |
32195
|
|
|
|
|
|
|
# define ARCH_X86_64 |
32196
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
32197
|
|
|
|
|
|
|
# define ARCH_X86_32 |
32198
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
32199
|
|
|
|
|
|
|
# define ARCH_ARM64 |
32200
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
32201
|
|
|
|
|
|
|
# define ARCH_ARM32 |
32202
|
|
|
|
|
|
|
# endif |
32203
|
|
|
|
|
|
|
#else |
32204
|
|
|
|
|
|
|
# if defined(__x86_64__) |
32205
|
|
|
|
|
|
|
# define ARCH_X86_64 |
32206
|
|
|
|
|
|
|
# elif defined(__i386__) |
32207
|
|
|
|
|
|
|
# define ARCH_X86_32 |
32208
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
32209
|
|
|
|
|
|
|
# define ARCH_ARM64 |
32210
|
|
|
|
|
|
|
# elif defined(__arm__) |
32211
|
|
|
|
|
|
|
# define ARCH_ARM32 |
32212
|
|
|
|
|
|
|
# endif |
32213
|
|
|
|
|
|
|
#endif |
32214
|
|
|
|
|
|
|
|
32215
|
|
|
|
|
|
|
|
32216
|
|
|
|
|
|
|
|
32217
|
|
|
|
|
|
|
|
32218
|
|
|
|
|
|
|
|
32219
|
|
|
|
|
|
|
|
32220
|
|
|
|
|
|
|
typedef uint8_t u8; |
32221
|
|
|
|
|
|
|
typedef uint16_t u16; |
32222
|
|
|
|
|
|
|
typedef uint32_t u32; |
32223
|
|
|
|
|
|
|
typedef uint64_t u64; |
32224
|
|
|
|
|
|
|
typedef int8_t s8; |
32225
|
|
|
|
|
|
|
typedef int16_t s16; |
32226
|
|
|
|
|
|
|
typedef int32_t s32; |
32227
|
|
|
|
|
|
|
typedef int64_t s64; |
32228
|
|
|
|
|
|
|
|
32229
|
|
|
|
|
|
|
|
32230
|
|
|
|
|
|
|
#ifdef _MSC_VER |
32231
|
|
|
|
|
|
|
# ifdef _WIN64 |
32232
|
|
|
|
|
|
|
typedef long long ssize_t; |
32233
|
|
|
|
|
|
|
# else |
32234
|
|
|
|
|
|
|
typedef long ssize_t; |
32235
|
|
|
|
|
|
|
# endif |
32236
|
|
|
|
|
|
|
#endif |
32237
|
|
|
|
|
|
|
|
32238
|
|
|
|
|
|
|
|
32239
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
32240
|
|
|
|
|
|
|
|
32241
|
|
|
|
|
|
|
|
32242
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
32243
|
|
|
|
|
|
|
|
32244
|
|
|
|
|
|
|
|
32245
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
32246
|
|
|
|
|
|
|
|
32247
|
|
|
|
|
|
|
|
32248
|
|
|
|
|
|
|
|
32249
|
|
|
|
|
|
|
|
32250
|
|
|
|
|
|
|
|
32251
|
|
|
|
|
|
|
|
32252
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
32253
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
32254
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
32255
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
32256
|
|
|
|
|
|
|
#else |
32257
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
32258
|
|
|
|
|
|
|
#endif |
32259
|
|
|
|
|
|
|
#ifdef __clang__ |
32260
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
32261
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
32262
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
32263
|
|
|
|
|
|
|
# else |
32264
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
32265
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
32266
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
32267
|
|
|
|
|
|
|
# endif |
32268
|
|
|
|
|
|
|
#else |
32269
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
32270
|
|
|
|
|
|
|
#endif |
32271
|
|
|
|
|
|
|
|
32272
|
|
|
|
|
|
|
|
32273
|
|
|
|
|
|
|
#ifndef __has_attribute |
32274
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
32275
|
|
|
|
|
|
|
#endif |
32276
|
|
|
|
|
|
|
#ifndef __has_builtin |
32277
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
32278
|
|
|
|
|
|
|
#endif |
32279
|
|
|
|
|
|
|
|
32280
|
|
|
|
|
|
|
|
32281
|
|
|
|
|
|
|
#ifdef _MSC_VER |
32282
|
|
|
|
|
|
|
# define inline __inline |
32283
|
|
|
|
|
|
|
#endif |
32284
|
|
|
|
|
|
|
|
32285
|
|
|
|
|
|
|
|
32286
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
32287
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
32288
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32289
|
|
|
|
|
|
|
# define forceinline __forceinline |
32290
|
|
|
|
|
|
|
#else |
32291
|
|
|
|
|
|
|
# define forceinline inline |
32292
|
|
|
|
|
|
|
#endif |
32293
|
|
|
|
|
|
|
|
32294
|
|
|
|
|
|
|
|
32295
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
32296
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
32297
|
|
|
|
|
|
|
#else |
32298
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
32299
|
|
|
|
|
|
|
#endif |
32300
|
|
|
|
|
|
|
|
32301
|
|
|
|
|
|
|
|
32302
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
32303
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
32304
|
|
|
|
|
|
|
# define restrict __restrict__ |
32305
|
|
|
|
|
|
|
# else |
32306
|
|
|
|
|
|
|
# define restrict |
32307
|
|
|
|
|
|
|
# endif |
32308
|
|
|
|
|
|
|
#endif |
32309
|
|
|
|
|
|
|
|
32310
|
|
|
|
|
|
|
|
32311
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
32312
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
32313
|
|
|
|
|
|
|
#else |
32314
|
|
|
|
|
|
|
# define likely(expr) (expr) |
32315
|
|
|
|
|
|
|
#endif |
32316
|
|
|
|
|
|
|
|
32317
|
|
|
|
|
|
|
|
32318
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
32319
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
32320
|
|
|
|
|
|
|
#else |
32321
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
32322
|
|
|
|
|
|
|
#endif |
32323
|
|
|
|
|
|
|
|
32324
|
|
|
|
|
|
|
|
32325
|
|
|
|
|
|
|
#undef prefetchr |
32326
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
32327
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
32328
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32329
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
32330
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
32331
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
32332
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
32333
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
32334
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
32335
|
|
|
|
|
|
|
# endif |
32336
|
|
|
|
|
|
|
#endif |
32337
|
|
|
|
|
|
|
#ifndef prefetchr |
32338
|
|
|
|
|
|
|
# define prefetchr(addr) |
32339
|
|
|
|
|
|
|
#endif |
32340
|
|
|
|
|
|
|
|
32341
|
|
|
|
|
|
|
|
32342
|
|
|
|
|
|
|
#undef prefetchw |
32343
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
32344
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
32345
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32346
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
32347
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
32348
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
32349
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
32350
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
32351
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
32352
|
|
|
|
|
|
|
# endif |
32353
|
|
|
|
|
|
|
#endif |
32354
|
|
|
|
|
|
|
#ifndef prefetchw |
32355
|
|
|
|
|
|
|
# define prefetchw(addr) |
32356
|
|
|
|
|
|
|
#endif |
32357
|
|
|
|
|
|
|
|
32358
|
|
|
|
|
|
|
|
32359
|
|
|
|
|
|
|
#undef _aligned_attribute |
32360
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
32361
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
32362
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32363
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
32364
|
|
|
|
|
|
|
#endif |
32365
|
|
|
|
|
|
|
|
32366
|
|
|
|
|
|
|
|
32367
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
32368
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
32369
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
32370
|
|
|
|
|
|
|
#else |
32371
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
32372
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
32373
|
|
|
|
|
|
|
#endif |
32374
|
|
|
|
|
|
|
|
32375
|
|
|
|
|
|
|
|
32376
|
|
|
|
|
|
|
|
32377
|
|
|
|
|
|
|
|
32378
|
|
|
|
|
|
|
|
32379
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
32380
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
32381
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
32382
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
32383
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
32384
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
32385
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
32386
|
|
|
|
|
|
|
|
32387
|
|
|
|
|
|
|
|
32388
|
|
|
|
|
|
|
|
32389
|
|
|
|
|
|
|
|
32390
|
|
|
|
|
|
|
|
32391
|
|
|
|
|
|
|
|
32392
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
32393
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
32394
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32395
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
32396
|
|
|
|
|
|
|
#else |
32397
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
32398
|
|
|
|
|
|
|
{ |
32399
|
|
|
|
|
|
|
union { |
32400
|
|
|
|
|
|
|
u32 w; |
32401
|
|
|
|
|
|
|
u8 b; |
32402
|
|
|
|
|
|
|
} u; |
32403
|
|
|
|
|
|
|
|
32404
|
|
|
|
|
|
|
u.w = 1; |
32405
|
|
|
|
|
|
|
return u.b; |
32406
|
|
|
|
|
|
|
} |
32407
|
|
|
|
|
|
|
#endif |
32408
|
|
|
|
|
|
|
|
32409
|
|
|
|
|
|
|
|
32410
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
32411
|
|
|
|
|
|
|
{ |
32412
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
32413
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
32414
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32415
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
32416
|
|
|
|
|
|
|
#else |
32417
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
32418
|
|
|
|
|
|
|
#endif |
32419
|
|
|
|
|
|
|
} |
32420
|
|
|
|
|
|
|
|
32421
|
|
|
|
|
|
|
|
32422
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
32423
|
|
|
|
|
|
|
{ |
32424
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
32425
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
32426
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32427
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
32428
|
|
|
|
|
|
|
#else |
32429
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
32430
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
32431
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
32432
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
32433
|
|
|
|
|
|
|
#endif |
32434
|
|
|
|
|
|
|
} |
32435
|
|
|
|
|
|
|
|
32436
|
|
|
|
|
|
|
|
32437
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
32438
|
|
|
|
|
|
|
{ |
32439
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
32440
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
32441
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32442
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
32443
|
|
|
|
|
|
|
#else |
32444
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
32445
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
32446
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
32447
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
32448
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
32449
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
32450
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
32451
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
32452
|
|
|
|
|
|
|
#endif |
32453
|
|
|
|
|
|
|
} |
32454
|
|
|
|
|
|
|
|
32455
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
32456
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
32457
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
32458
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
32459
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
32460
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
32461
|
|
|
|
|
|
|
|
32462
|
|
|
|
|
|
|
|
32463
|
|
|
|
|
|
|
|
32464
|
|
|
|
|
|
|
|
32465
|
|
|
|
|
|
|
|
32466
|
|
|
|
|
|
|
|
32467
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
32468
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
32469
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
32470
|
|
|
|
|
|
|
defined(__wasm__)) |
32471
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
32472
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32473
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
32474
|
|
|
|
|
|
|
#else |
32475
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
32476
|
|
|
|
|
|
|
#endif |
32477
|
|
|
|
|
|
|
|
32478
|
|
|
|
|
|
|
|
32479
|
|
|
|
|
|
|
|
32480
|
|
|
|
|
|
|
#ifdef FREESTANDING |
32481
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
32482
|
|
|
|
|
|
|
#else |
32483
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
32484
|
|
|
|
|
|
|
#endif |
32485
|
|
|
|
|
|
|
|
32486
|
|
|
|
|
|
|
|
32487
|
|
|
|
|
|
|
|
32488
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
32489
|
|
|
|
|
|
|
static forceinline type \ |
32490
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
32491
|
|
|
|
|
|
|
{ \ |
32492
|
|
|
|
|
|
|
type v; \ |
32493
|
|
|
|
|
|
|
\ |
32494
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
32495
|
|
|
|
|
|
|
return v; \ |
32496
|
|
|
|
|
|
|
} \ |
32497
|
|
|
|
|
|
|
\ |
32498
|
|
|
|
|
|
|
static forceinline void \ |
32499
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
32500
|
|
|
|
|
|
|
{ \ |
32501
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
32502
|
|
|
|
|
|
|
} |
32503
|
|
|
|
|
|
|
|
32504
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
32505
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
32506
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
32507
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
32508
|
|
|
|
|
|
|
|
32509
|
|
|
|
|
|
|
#undef MEMCOPY |
32510
|
|
|
|
|
|
|
|
32511
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
32512
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
32513
|
|
|
|
|
|
|
|
32514
|
|
|
|
|
|
|
|
32515
|
|
|
|
|
|
|
|
32516
|
|
|
|
|
|
|
static forceinline u16 |
32517
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
32518
|
|
|
|
|
|
|
{ |
32519
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32520
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
32521
|
|
|
|
|
|
|
else |
32522
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
32523
|
|
|
|
|
|
|
} |
32524
|
|
|
|
|
|
|
|
32525
|
|
|
|
|
|
|
static forceinline u16 |
32526
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
32527
|
|
|
|
|
|
|
{ |
32528
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32529
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
32530
|
|
|
|
|
|
|
else |
32531
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
32532
|
|
|
|
|
|
|
} |
32533
|
|
|
|
|
|
|
|
32534
|
|
|
|
|
|
|
static forceinline u32 |
32535
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
32536
|
|
|
|
|
|
|
{ |
32537
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32538
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
32539
|
|
|
|
|
|
|
else |
32540
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
32541
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
32542
|
|
|
|
|
|
|
} |
32543
|
|
|
|
|
|
|
|
32544
|
|
|
|
|
|
|
static forceinline u32 |
32545
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
32546
|
|
|
|
|
|
|
{ |
32547
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32548
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
32549
|
|
|
|
|
|
|
else |
32550
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
32551
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
32552
|
|
|
|
|
|
|
} |
32553
|
|
|
|
|
|
|
|
32554
|
|
|
|
|
|
|
static forceinline u64 |
32555
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
32556
|
|
|
|
|
|
|
{ |
32557
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
32558
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
32559
|
|
|
|
|
|
|
else |
32560
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
32561
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
32562
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
32563
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
32564
|
|
|
|
|
|
|
} |
32565
|
|
|
|
|
|
|
|
32566
|
|
|
|
|
|
|
static forceinline machine_word_t |
32567
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
32568
|
|
|
|
|
|
|
{ |
32569
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
32570
|
|
|
|
|
|
|
if (WORDBITS == 32) |
32571
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
32572
|
|
|
|
|
|
|
else |
32573
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
32574
|
|
|
|
|
|
|
} |
32575
|
|
|
|
|
|
|
|
32576
|
|
|
|
|
|
|
|
32577
|
|
|
|
|
|
|
|
32578
|
|
|
|
|
|
|
static forceinline void |
32579
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
32580
|
|
|
|
|
|
|
{ |
32581
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32582
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
32583
|
|
|
|
|
|
|
} else { |
32584
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
32585
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
32586
|
|
|
|
|
|
|
} |
32587
|
|
|
|
|
|
|
} |
32588
|
|
|
|
|
|
|
|
32589
|
|
|
|
|
|
|
static forceinline void |
32590
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
32591
|
|
|
|
|
|
|
{ |
32592
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32593
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
32594
|
|
|
|
|
|
|
} else { |
32595
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
32596
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
32597
|
|
|
|
|
|
|
} |
32598
|
|
|
|
|
|
|
} |
32599
|
|
|
|
|
|
|
|
32600
|
|
|
|
|
|
|
static forceinline void |
32601
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
32602
|
|
|
|
|
|
|
{ |
32603
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32604
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
32605
|
|
|
|
|
|
|
} else { |
32606
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
32607
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
32608
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
32609
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
32610
|
|
|
|
|
|
|
} |
32611
|
|
|
|
|
|
|
} |
32612
|
|
|
|
|
|
|
|
32613
|
|
|
|
|
|
|
static forceinline void |
32614
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
32615
|
|
|
|
|
|
|
{ |
32616
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32617
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
32618
|
|
|
|
|
|
|
} else { |
32619
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
32620
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
32621
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
32622
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
32623
|
|
|
|
|
|
|
} |
32624
|
|
|
|
|
|
|
} |
32625
|
|
|
|
|
|
|
|
32626
|
|
|
|
|
|
|
static forceinline void |
32627
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
32628
|
|
|
|
|
|
|
{ |
32629
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
32630
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
32631
|
|
|
|
|
|
|
} else { |
32632
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
32633
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
32634
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
32635
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
32636
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
32637
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
32638
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
32639
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
32640
|
|
|
|
|
|
|
} |
32641
|
|
|
|
|
|
|
} |
32642
|
|
|
|
|
|
|
|
32643
|
|
|
|
|
|
|
static forceinline void |
32644
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
32645
|
|
|
|
|
|
|
{ |
32646
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
32647
|
|
|
|
|
|
|
if (WORDBITS == 32) |
32648
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
32649
|
|
|
|
|
|
|
else |
32650
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
32651
|
|
|
|
|
|
|
} |
32652
|
|
|
|
|
|
|
|
32653
|
|
|
|
|
|
|
|
32654
|
|
|
|
|
|
|
|
32655
|
|
|
|
|
|
|
|
32656
|
|
|
|
|
|
|
|
32657
|
|
|
|
|
|
|
|
32658
|
|
|
|
|
|
|
|
32659
|
|
|
|
|
|
|
static forceinline unsigned |
32660
|
|
|
|
|
|
|
bsr32(u32 v) |
32661
|
|
|
|
|
|
|
{ |
32662
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
32663
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
32664
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32665
|
|
|
|
|
|
|
unsigned long i; |
32666
|
|
|
|
|
|
|
|
32667
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
32668
|
|
|
|
|
|
|
return i; |
32669
|
|
|
|
|
|
|
#else |
32670
|
|
|
|
|
|
|
unsigned i = 0; |
32671
|
|
|
|
|
|
|
|
32672
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
32673
|
|
|
|
|
|
|
i++; |
32674
|
|
|
|
|
|
|
return i; |
32675
|
|
|
|
|
|
|
#endif |
32676
|
|
|
|
|
|
|
} |
32677
|
|
|
|
|
|
|
|
32678
|
|
|
|
|
|
|
static forceinline unsigned |
32679
|
|
|
|
|
|
|
bsr64(u64 v) |
32680
|
|
|
|
|
|
|
{ |
32681
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
32682
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
32683
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
32684
|
|
|
|
|
|
|
unsigned long i; |
32685
|
|
|
|
|
|
|
|
32686
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
32687
|
|
|
|
|
|
|
return i; |
32688
|
|
|
|
|
|
|
#else |
32689
|
|
|
|
|
|
|
unsigned i = 0; |
32690
|
|
|
|
|
|
|
|
32691
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
32692
|
|
|
|
|
|
|
i++; |
32693
|
|
|
|
|
|
|
return i; |
32694
|
|
|
|
|
|
|
#endif |
32695
|
|
|
|
|
|
|
} |
32696
|
|
|
|
|
|
|
|
32697
|
|
|
|
|
|
|
static forceinline unsigned |
32698
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
32699
|
|
|
|
|
|
|
{ |
32700
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
32701
|
|
|
|
|
|
|
if (WORDBITS == 32) |
32702
|
|
|
|
|
|
|
return bsr32(v); |
32703
|
|
|
|
|
|
|
else |
32704
|
|
|
|
|
|
|
return bsr64(v); |
32705
|
|
|
|
|
|
|
} |
32706
|
|
|
|
|
|
|
|
32707
|
|
|
|
|
|
|
|
32708
|
|
|
|
|
|
|
|
32709
|
|
|
|
|
|
|
static forceinline unsigned |
32710
|
|
|
|
|
|
|
bsf32(u32 v) |
32711
|
|
|
|
|
|
|
{ |
32712
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
32713
|
|
|
|
|
|
|
return __builtin_ctz(v); |
32714
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
32715
|
|
|
|
|
|
|
unsigned long i; |
32716
|
|
|
|
|
|
|
|
32717
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
32718
|
|
|
|
|
|
|
return i; |
32719
|
|
|
|
|
|
|
#else |
32720
|
|
|
|
|
|
|
unsigned i = 0; |
32721
|
|
|
|
|
|
|
|
32722
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
32723
|
|
|
|
|
|
|
i++; |
32724
|
|
|
|
|
|
|
return i; |
32725
|
|
|
|
|
|
|
#endif |
32726
|
|
|
|
|
|
|
} |
32727
|
|
|
|
|
|
|
|
32728
|
|
|
|
|
|
|
static forceinline unsigned |
32729
|
|
|
|
|
|
|
bsf64(u64 v) |
32730
|
|
|
|
|
|
|
{ |
32731
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
32732
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
32733
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
32734
|
|
|
|
|
|
|
unsigned long i; |
32735
|
|
|
|
|
|
|
|
32736
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
32737
|
|
|
|
|
|
|
return i; |
32738
|
|
|
|
|
|
|
#else |
32739
|
|
|
|
|
|
|
unsigned i = 0; |
32740
|
|
|
|
|
|
|
|
32741
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
32742
|
|
|
|
|
|
|
i++; |
32743
|
|
|
|
|
|
|
return i; |
32744
|
|
|
|
|
|
|
#endif |
32745
|
|
|
|
|
|
|
} |
32746
|
|
|
|
|
|
|
|
32747
|
|
|
|
|
|
|
static forceinline unsigned |
32748
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
32749
|
|
|
|
|
|
|
{ |
32750
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
32751
|
|
|
|
|
|
|
if (WORDBITS == 32) |
32752
|
|
|
|
|
|
|
return bsf32(v); |
32753
|
|
|
|
|
|
|
else |
32754
|
|
|
|
|
|
|
return bsf64(v); |
32755
|
|
|
|
|
|
|
} |
32756
|
|
|
|
|
|
|
|
32757
|
|
|
|
|
|
|
|
32758
|
|
|
|
|
|
|
#undef rbit32 |
32759
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
32760
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
32761
|
|
|
|
|
|
|
static forceinline u32 |
32762
|
|
|
|
|
|
|
rbit32(u32 v) |
32763
|
|
|
|
|
|
|
{ |
32764
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
32765
|
|
|
|
|
|
|
return v; |
32766
|
|
|
|
|
|
|
} |
32767
|
|
|
|
|
|
|
#define rbit32 rbit32 |
32768
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
32769
|
|
|
|
|
|
|
static forceinline u32 |
32770
|
|
|
|
|
|
|
rbit32(u32 v) |
32771
|
|
|
|
|
|
|
{ |
32772
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
32773
|
|
|
|
|
|
|
return v; |
32774
|
|
|
|
|
|
|
} |
32775
|
|
|
|
|
|
|
#define rbit32 rbit32 |
32776
|
|
|
|
|
|
|
#endif |
32777
|
|
|
|
|
|
|
|
32778
|
|
|
|
|
|
|
#endif |
32779
|
|
|
|
|
|
|
|
32780
|
|
|
|
|
|
|
|
32781
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
32782
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
32783
|
|
|
|
|
|
|
|
32784
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
32785
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
32786
|
|
|
|
|
|
|
|
32787
|
|
|
|
|
|
|
#ifdef FREESTANDING |
32788
|
|
|
|
|
|
|
|
32789
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
32790
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
32791
|
|
|
|
|
|
|
|
32792
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
32793
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
32794
|
|
|
|
|
|
|
|
32795
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
32796
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
32797
|
|
|
|
|
|
|
|
32798
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
32799
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
32800
|
|
|
|
|
|
|
|
32801
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
32802
|
|
|
|
|
|
|
#else |
32803
|
|
|
|
|
|
|
#include |
32804
|
|
|
|
|
|
|
#endif |
32805
|
|
|
|
|
|
|
|
32806
|
|
|
|
|
|
|
|
32807
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
32808
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
32809
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
32810
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
32811
|
|
|
|
|
|
|
#else |
32812
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
32813
|
|
|
|
|
|
|
#endif |
32814
|
|
|
|
|
|
|
|
32815
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
32816
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
32817
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
32818
|
|
|
|
|
|
|
|
32819
|
|
|
|
|
|
|
#endif |
32820
|
|
|
|
|
|
|
|
32821
|
|
|
|
|
|
|
|
32822
|
|
|
|
|
|
|
struct cpu_feature { |
32823
|
|
|
|
|
|
|
u32 bit; |
32824
|
|
|
|
|
|
|
const char *name; |
32825
|
|
|
|
|
|
|
}; |
32826
|
|
|
|
|
|
|
|
32827
|
|
|
|
|
|
|
#if defined(TEST_SUPPORT__DO_NOT_USE) && !defined(FREESTANDING) |
32828
|
|
|
|
|
|
|
|
32829
|
|
|
|
|
|
|
static inline void |
32830
|
|
|
|
|
|
|
disable_cpu_features_for_testing(u32 *features, |
32831
|
|
|
|
|
|
|
const struct cpu_feature *feature_table, |
32832
|
|
|
|
|
|
|
size_t feature_table_length) |
32833
|
|
|
|
|
|
|
{ |
32834
|
|
|
|
|
|
|
char *env_value, *strbuf, *p, *saveptr = NULL; |
32835
|
|
|
|
|
|
|
size_t i; |
32836
|
|
|
|
|
|
|
|
32837
|
|
|
|
|
|
|
env_value = getenv("LIBDEFLATE_DISABLE_CPU_FEATURES"); |
32838
|
|
|
|
|
|
|
if (!env_value) |
32839
|
|
|
|
|
|
|
return; |
32840
|
|
|
|
|
|
|
strbuf = strdup(env_value); |
32841
|
|
|
|
|
|
|
if (!strbuf) |
32842
|
|
|
|
|
|
|
abort(); |
32843
|
|
|
|
|
|
|
p = strtok_r(strbuf, ",", &saveptr); |
32844
|
|
|
|
|
|
|
while (p) { |
32845
|
|
|
|
|
|
|
for (i = 0; i < feature_table_length; i++) { |
32846
|
|
|
|
|
|
|
if (strcmp(p, feature_table[i].name) == 0) { |
32847
|
|
|
|
|
|
|
*features &= ~feature_table[i].bit; |
32848
|
|
|
|
|
|
|
break; |
32849
|
|
|
|
|
|
|
} |
32850
|
|
|
|
|
|
|
} |
32851
|
|
|
|
|
|
|
if (i == feature_table_length) { |
32852
|
|
|
|
|
|
|
fprintf(stderr, |
32853
|
|
|
|
|
|
|
"unrecognized feature in LIBDEFLATE_DISABLE_CPU_FEATURES: \"%s\"\n", |
32854
|
|
|
|
|
|
|
p); |
32855
|
|
|
|
|
|
|
abort(); |
32856
|
|
|
|
|
|
|
} |
32857
|
|
|
|
|
|
|
p = strtok_r(NULL, ",", &saveptr); |
32858
|
|
|
|
|
|
|
} |
32859
|
|
|
|
|
|
|
free(strbuf); |
32860
|
|
|
|
|
|
|
} |
32861
|
|
|
|
|
|
|
#else |
32862
|
|
|
|
|
|
|
static inline void |
32863
|
2
|
|
|
|
|
|
disable_cpu_features_for_testing(u32 *features, |
32864
|
|
|
|
|
|
|
const struct cpu_feature *feature_table, |
32865
|
|
|
|
|
|
|
size_t feature_table_length) |
32866
|
|
|
|
|
|
|
{ |
32867
|
2
|
|
|
|
|
|
} |
32868
|
|
|
|
|
|
|
#endif |
32869
|
|
|
|
|
|
|
|
32870
|
|
|
|
|
|
|
#endif |
32871
|
|
|
|
|
|
|
|
32872
|
|
|
|
|
|
|
/* #include "arm-cpu_features.h" */ |
32873
|
|
|
|
|
|
|
|
32874
|
|
|
|
|
|
|
|
32875
|
|
|
|
|
|
|
#ifndef LIB_ARM_CPU_FEATURES_H |
32876
|
|
|
|
|
|
|
#define LIB_ARM_CPU_FEATURES_H |
32877
|
|
|
|
|
|
|
|
32878
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
32879
|
|
|
|
|
|
|
|
32880
|
|
|
|
|
|
|
|
32881
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
32882
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
32883
|
|
|
|
|
|
|
|
32884
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
32885
|
|
|
|
|
|
|
|
32886
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
32887
|
|
|
|
|
|
|
#endif |
32888
|
|
|
|
|
|
|
|
32889
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
32890
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
32891
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
32892
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
32893
|
|
|
|
|
|
|
#else |
32894
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
32895
|
|
|
|
|
|
|
#endif |
32896
|
|
|
|
|
|
|
|
32897
|
|
|
|
|
|
|
|
32898
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
32899
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
32900
|
|
|
|
|
|
|
#else |
32901
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
32902
|
|
|
|
|
|
|
#endif |
32903
|
|
|
|
|
|
|
|
32904
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
32905
|
|
|
|
|
|
|
|
32906
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
32907
|
|
|
|
|
|
|
|
32908
|
|
|
|
|
|
|
|
32909
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
32910
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
32911
|
|
|
|
|
|
|
|
32912
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
32913
|
|
|
|
|
|
|
|
32914
|
|
|
|
|
|
|
|
32915
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
32916
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
32917
|
|
|
|
|
|
|
|
32918
|
|
|
|
|
|
|
#include |
32919
|
|
|
|
|
|
|
#include |
32920
|
|
|
|
|
|
|
|
32921
|
|
|
|
|
|
|
#ifdef __cplusplus |
32922
|
|
|
|
|
|
|
extern "C" { |
32923
|
|
|
|
|
|
|
#endif |
32924
|
|
|
|
|
|
|
|
32925
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
32926
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
32927
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
32928
|
|
|
|
|
|
|
|
32929
|
|
|
|
|
|
|
|
32930
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
32931
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
32932
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
32933
|
|
|
|
|
|
|
# else |
32934
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
32935
|
|
|
|
|
|
|
# endif |
32936
|
|
|
|
|
|
|
#endif |
32937
|
|
|
|
|
|
|
|
32938
|
|
|
|
|
|
|
|
32939
|
|
|
|
|
|
|
|
32940
|
|
|
|
|
|
|
|
32941
|
|
|
|
|
|
|
|
32942
|
|
|
|
|
|
|
struct libdeflate_compressor; |
32943
|
|
|
|
|
|
|
|
32944
|
|
|
|
|
|
|
|
32945
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
32946
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
32947
|
|
|
|
|
|
|
|
32948
|
|
|
|
|
|
|
|
32949
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32950
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
32951
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32952
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32953
|
|
|
|
|
|
|
|
32954
|
|
|
|
|
|
|
|
32955
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32956
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
32957
|
|
|
|
|
|
|
size_t in_nbytes); |
32958
|
|
|
|
|
|
|
|
32959
|
|
|
|
|
|
|
|
32960
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32961
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
32962
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32963
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32964
|
|
|
|
|
|
|
|
32965
|
|
|
|
|
|
|
|
32966
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32967
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
32968
|
|
|
|
|
|
|
size_t in_nbytes); |
32969
|
|
|
|
|
|
|
|
32970
|
|
|
|
|
|
|
|
32971
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32972
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
32973
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
32974
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
32975
|
|
|
|
|
|
|
|
32976
|
|
|
|
|
|
|
|
32977
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
32978
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
32979
|
|
|
|
|
|
|
size_t in_nbytes); |
32980
|
|
|
|
|
|
|
|
32981
|
|
|
|
|
|
|
|
32982
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
32983
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
32984
|
|
|
|
|
|
|
|
32985
|
|
|
|
|
|
|
|
32986
|
|
|
|
|
|
|
|
32987
|
|
|
|
|
|
|
|
32988
|
|
|
|
|
|
|
|
32989
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
32990
|
|
|
|
|
|
|
|
32991
|
|
|
|
|
|
|
|
32992
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
32993
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
32994
|
|
|
|
|
|
|
|
32995
|
|
|
|
|
|
|
|
32996
|
|
|
|
|
|
|
enum libdeflate_result { |
32997
|
|
|
|
|
|
|
|
32998
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
32999
|
|
|
|
|
|
|
|
33000
|
|
|
|
|
|
|
|
33001
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
33002
|
|
|
|
|
|
|
|
33003
|
|
|
|
|
|
|
|
33004
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
33005
|
|
|
|
|
|
|
|
33006
|
|
|
|
|
|
|
|
33007
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
33008
|
|
|
|
|
|
|
}; |
33009
|
|
|
|
|
|
|
|
33010
|
|
|
|
|
|
|
|
33011
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33012
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
33013
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33014
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33015
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33016
|
|
|
|
|
|
|
|
33017
|
|
|
|
|
|
|
|
33018
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33019
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
33020
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33021
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33022
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
33023
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33024
|
|
|
|
|
|
|
|
33025
|
|
|
|
|
|
|
|
33026
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33027
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
33028
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33029
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33030
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33031
|
|
|
|
|
|
|
|
33032
|
|
|
|
|
|
|
|
33033
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33034
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
33035
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33036
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33037
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
33038
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33039
|
|
|
|
|
|
|
|
33040
|
|
|
|
|
|
|
|
33041
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33042
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
33043
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33044
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33045
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33046
|
|
|
|
|
|
|
|
33047
|
|
|
|
|
|
|
|
33048
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
33049
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
33050
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
33051
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
33052
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
33053
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
33054
|
|
|
|
|
|
|
|
33055
|
|
|
|
|
|
|
|
33056
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
33057
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
33058
|
|
|
|
|
|
|
|
33059
|
|
|
|
|
|
|
|
33060
|
|
|
|
|
|
|
|
33061
|
|
|
|
|
|
|
|
33062
|
|
|
|
|
|
|
|
33063
|
|
|
|
|
|
|
|
33064
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
33065
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
33066
|
|
|
|
|
|
|
|
33067
|
|
|
|
|
|
|
|
33068
|
|
|
|
|
|
|
|
33069
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
33070
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
33071
|
|
|
|
|
|
|
|
33072
|
|
|
|
|
|
|
|
33073
|
|
|
|
|
|
|
|
33074
|
|
|
|
|
|
|
|
33075
|
|
|
|
|
|
|
|
33076
|
|
|
|
|
|
|
|
33077
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
33078
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
33079
|
|
|
|
|
|
|
void (*free_func)(void *)); |
33080
|
|
|
|
|
|
|
|
33081
|
|
|
|
|
|
|
#ifdef __cplusplus |
33082
|
|
|
|
|
|
|
} |
33083
|
|
|
|
|
|
|
#endif |
33084
|
|
|
|
|
|
|
|
33085
|
|
|
|
|
|
|
#endif |
33086
|
|
|
|
|
|
|
|
33087
|
|
|
|
|
|
|
|
33088
|
|
|
|
|
|
|
#include |
33089
|
|
|
|
|
|
|
#include |
33090
|
|
|
|
|
|
|
#include |
33091
|
|
|
|
|
|
|
#ifdef _MSC_VER |
33092
|
|
|
|
|
|
|
# include |
33093
|
|
|
|
|
|
|
# include |
33094
|
|
|
|
|
|
|
|
33095
|
|
|
|
|
|
|
|
33096
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
33097
|
|
|
|
|
|
|
|
33098
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
33099
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
33100
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
33101
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
33102
|
|
|
|
|
|
|
|
33103
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
33104
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
33105
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
33106
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
33107
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
33108
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
33109
|
|
|
|
|
|
|
#endif |
33110
|
|
|
|
|
|
|
#ifndef FREESTANDING |
33111
|
|
|
|
|
|
|
# include |
33112
|
|
|
|
|
|
|
#endif |
33113
|
|
|
|
|
|
|
|
33114
|
|
|
|
|
|
|
|
33115
|
|
|
|
|
|
|
|
33116
|
|
|
|
|
|
|
|
33117
|
|
|
|
|
|
|
|
33118
|
|
|
|
|
|
|
|
33119
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
33120
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
33121
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
33122
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
33123
|
|
|
|
|
|
|
#ifdef _MSC_VER |
33124
|
|
|
|
|
|
|
# if defined(_M_X64) |
33125
|
|
|
|
|
|
|
# define ARCH_X86_64 |
33126
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
33127
|
|
|
|
|
|
|
# define ARCH_X86_32 |
33128
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
33129
|
|
|
|
|
|
|
# define ARCH_ARM64 |
33130
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
33131
|
|
|
|
|
|
|
# define ARCH_ARM32 |
33132
|
|
|
|
|
|
|
# endif |
33133
|
|
|
|
|
|
|
#else |
33134
|
|
|
|
|
|
|
# if defined(__x86_64__) |
33135
|
|
|
|
|
|
|
# define ARCH_X86_64 |
33136
|
|
|
|
|
|
|
# elif defined(__i386__) |
33137
|
|
|
|
|
|
|
# define ARCH_X86_32 |
33138
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
33139
|
|
|
|
|
|
|
# define ARCH_ARM64 |
33140
|
|
|
|
|
|
|
# elif defined(__arm__) |
33141
|
|
|
|
|
|
|
# define ARCH_ARM32 |
33142
|
|
|
|
|
|
|
# endif |
33143
|
|
|
|
|
|
|
#endif |
33144
|
|
|
|
|
|
|
|
33145
|
|
|
|
|
|
|
|
33146
|
|
|
|
|
|
|
|
33147
|
|
|
|
|
|
|
|
33148
|
|
|
|
|
|
|
|
33149
|
|
|
|
|
|
|
|
33150
|
|
|
|
|
|
|
typedef uint8_t u8; |
33151
|
|
|
|
|
|
|
typedef uint16_t u16; |
33152
|
|
|
|
|
|
|
typedef uint32_t u32; |
33153
|
|
|
|
|
|
|
typedef uint64_t u64; |
33154
|
|
|
|
|
|
|
typedef int8_t s8; |
33155
|
|
|
|
|
|
|
typedef int16_t s16; |
33156
|
|
|
|
|
|
|
typedef int32_t s32; |
33157
|
|
|
|
|
|
|
typedef int64_t s64; |
33158
|
|
|
|
|
|
|
|
33159
|
|
|
|
|
|
|
|
33160
|
|
|
|
|
|
|
#ifdef _MSC_VER |
33161
|
|
|
|
|
|
|
# ifdef _WIN64 |
33162
|
|
|
|
|
|
|
typedef long long ssize_t; |
33163
|
|
|
|
|
|
|
# else |
33164
|
|
|
|
|
|
|
typedef long ssize_t; |
33165
|
|
|
|
|
|
|
# endif |
33166
|
|
|
|
|
|
|
#endif |
33167
|
|
|
|
|
|
|
|
33168
|
|
|
|
|
|
|
|
33169
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
33170
|
|
|
|
|
|
|
|
33171
|
|
|
|
|
|
|
|
33172
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
33173
|
|
|
|
|
|
|
|
33174
|
|
|
|
|
|
|
|
33175
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
33176
|
|
|
|
|
|
|
|
33177
|
|
|
|
|
|
|
|
33178
|
|
|
|
|
|
|
|
33179
|
|
|
|
|
|
|
|
33180
|
|
|
|
|
|
|
|
33181
|
|
|
|
|
|
|
|
33182
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
33183
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
33184
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
33185
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
33186
|
|
|
|
|
|
|
#else |
33187
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
33188
|
|
|
|
|
|
|
#endif |
33189
|
|
|
|
|
|
|
#ifdef __clang__ |
33190
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
33191
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
33192
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
33193
|
|
|
|
|
|
|
# else |
33194
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
33195
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
33196
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
33197
|
|
|
|
|
|
|
# endif |
33198
|
|
|
|
|
|
|
#else |
33199
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
33200
|
|
|
|
|
|
|
#endif |
33201
|
|
|
|
|
|
|
|
33202
|
|
|
|
|
|
|
|
33203
|
|
|
|
|
|
|
#ifndef __has_attribute |
33204
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
33205
|
|
|
|
|
|
|
#endif |
33206
|
|
|
|
|
|
|
#ifndef __has_builtin |
33207
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
33208
|
|
|
|
|
|
|
#endif |
33209
|
|
|
|
|
|
|
|
33210
|
|
|
|
|
|
|
|
33211
|
|
|
|
|
|
|
#ifdef _MSC_VER |
33212
|
|
|
|
|
|
|
# define inline __inline |
33213
|
|
|
|
|
|
|
#endif |
33214
|
|
|
|
|
|
|
|
33215
|
|
|
|
|
|
|
|
33216
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
33217
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
33218
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33219
|
|
|
|
|
|
|
# define forceinline __forceinline |
33220
|
|
|
|
|
|
|
#else |
33221
|
|
|
|
|
|
|
# define forceinline inline |
33222
|
|
|
|
|
|
|
#endif |
33223
|
|
|
|
|
|
|
|
33224
|
|
|
|
|
|
|
|
33225
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
33226
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
33227
|
|
|
|
|
|
|
#else |
33228
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
33229
|
|
|
|
|
|
|
#endif |
33230
|
|
|
|
|
|
|
|
33231
|
|
|
|
|
|
|
|
33232
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
33233
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
33234
|
|
|
|
|
|
|
# define restrict __restrict__ |
33235
|
|
|
|
|
|
|
# else |
33236
|
|
|
|
|
|
|
# define restrict |
33237
|
|
|
|
|
|
|
# endif |
33238
|
|
|
|
|
|
|
#endif |
33239
|
|
|
|
|
|
|
|
33240
|
|
|
|
|
|
|
|
33241
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
33242
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
33243
|
|
|
|
|
|
|
#else |
33244
|
|
|
|
|
|
|
# define likely(expr) (expr) |
33245
|
|
|
|
|
|
|
#endif |
33246
|
|
|
|
|
|
|
|
33247
|
|
|
|
|
|
|
|
33248
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
33249
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
33250
|
|
|
|
|
|
|
#else |
33251
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
33252
|
|
|
|
|
|
|
#endif |
33253
|
|
|
|
|
|
|
|
33254
|
|
|
|
|
|
|
|
33255
|
|
|
|
|
|
|
#undef prefetchr |
33256
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
33257
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
33258
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33259
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
33260
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
33261
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
33262
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
33263
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
33264
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
33265
|
|
|
|
|
|
|
# endif |
33266
|
|
|
|
|
|
|
#endif |
33267
|
|
|
|
|
|
|
#ifndef prefetchr |
33268
|
|
|
|
|
|
|
# define prefetchr(addr) |
33269
|
|
|
|
|
|
|
#endif |
33270
|
|
|
|
|
|
|
|
33271
|
|
|
|
|
|
|
|
33272
|
|
|
|
|
|
|
#undef prefetchw |
33273
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
33274
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
33275
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33276
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
33277
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
33278
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
33279
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
33280
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
33281
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
33282
|
|
|
|
|
|
|
# endif |
33283
|
|
|
|
|
|
|
#endif |
33284
|
|
|
|
|
|
|
#ifndef prefetchw |
33285
|
|
|
|
|
|
|
# define prefetchw(addr) |
33286
|
|
|
|
|
|
|
#endif |
33287
|
|
|
|
|
|
|
|
33288
|
|
|
|
|
|
|
|
33289
|
|
|
|
|
|
|
#undef _aligned_attribute |
33290
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
33291
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
33292
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33293
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
33294
|
|
|
|
|
|
|
#endif |
33295
|
|
|
|
|
|
|
|
33296
|
|
|
|
|
|
|
|
33297
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
33298
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
33299
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
33300
|
|
|
|
|
|
|
#else |
33301
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
33302
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
33303
|
|
|
|
|
|
|
#endif |
33304
|
|
|
|
|
|
|
|
33305
|
|
|
|
|
|
|
|
33306
|
|
|
|
|
|
|
|
33307
|
|
|
|
|
|
|
|
33308
|
|
|
|
|
|
|
|
33309
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
33310
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
33311
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
33312
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
33313
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
33314
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
33315
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
33316
|
|
|
|
|
|
|
|
33317
|
|
|
|
|
|
|
|
33318
|
|
|
|
|
|
|
|
33319
|
|
|
|
|
|
|
|
33320
|
|
|
|
|
|
|
|
33321
|
|
|
|
|
|
|
|
33322
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
33323
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
33324
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33325
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
33326
|
|
|
|
|
|
|
#else |
33327
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
33328
|
|
|
|
|
|
|
{ |
33329
|
|
|
|
|
|
|
union { |
33330
|
|
|
|
|
|
|
u32 w; |
33331
|
|
|
|
|
|
|
u8 b; |
33332
|
|
|
|
|
|
|
} u; |
33333
|
|
|
|
|
|
|
|
33334
|
|
|
|
|
|
|
u.w = 1; |
33335
|
|
|
|
|
|
|
return u.b; |
33336
|
|
|
|
|
|
|
} |
33337
|
|
|
|
|
|
|
#endif |
33338
|
|
|
|
|
|
|
|
33339
|
|
|
|
|
|
|
|
33340
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
33341
|
|
|
|
|
|
|
{ |
33342
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
33343
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
33344
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33345
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
33346
|
|
|
|
|
|
|
#else |
33347
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
33348
|
|
|
|
|
|
|
#endif |
33349
|
|
|
|
|
|
|
} |
33350
|
|
|
|
|
|
|
|
33351
|
|
|
|
|
|
|
|
33352
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
33353
|
|
|
|
|
|
|
{ |
33354
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
33355
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
33356
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33357
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
33358
|
|
|
|
|
|
|
#else |
33359
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
33360
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
33361
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
33362
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
33363
|
|
|
|
|
|
|
#endif |
33364
|
|
|
|
|
|
|
} |
33365
|
|
|
|
|
|
|
|
33366
|
|
|
|
|
|
|
|
33367
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
33368
|
|
|
|
|
|
|
{ |
33369
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
33370
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
33371
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33372
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
33373
|
|
|
|
|
|
|
#else |
33374
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
33375
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
33376
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
33377
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
33378
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
33379
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
33380
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
33381
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
33382
|
|
|
|
|
|
|
#endif |
33383
|
|
|
|
|
|
|
} |
33384
|
|
|
|
|
|
|
|
33385
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
33386
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
33387
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
33388
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
33389
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
33390
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
33391
|
|
|
|
|
|
|
|
33392
|
|
|
|
|
|
|
|
33393
|
|
|
|
|
|
|
|
33394
|
|
|
|
|
|
|
|
33395
|
|
|
|
|
|
|
|
33396
|
|
|
|
|
|
|
|
33397
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
33398
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
33399
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
33400
|
|
|
|
|
|
|
defined(__wasm__)) |
33401
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
33402
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33403
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
33404
|
|
|
|
|
|
|
#else |
33405
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
33406
|
|
|
|
|
|
|
#endif |
33407
|
|
|
|
|
|
|
|
33408
|
|
|
|
|
|
|
|
33409
|
|
|
|
|
|
|
|
33410
|
|
|
|
|
|
|
#ifdef FREESTANDING |
33411
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
33412
|
|
|
|
|
|
|
#else |
33413
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
33414
|
|
|
|
|
|
|
#endif |
33415
|
|
|
|
|
|
|
|
33416
|
|
|
|
|
|
|
|
33417
|
|
|
|
|
|
|
|
33418
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
33419
|
|
|
|
|
|
|
static forceinline type \ |
33420
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
33421
|
|
|
|
|
|
|
{ \ |
33422
|
|
|
|
|
|
|
type v; \ |
33423
|
|
|
|
|
|
|
\ |
33424
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
33425
|
|
|
|
|
|
|
return v; \ |
33426
|
|
|
|
|
|
|
} \ |
33427
|
|
|
|
|
|
|
\ |
33428
|
|
|
|
|
|
|
static forceinline void \ |
33429
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
33430
|
|
|
|
|
|
|
{ \ |
33431
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
33432
|
|
|
|
|
|
|
} |
33433
|
|
|
|
|
|
|
|
33434
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
33435
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
33436
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
33437
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
33438
|
|
|
|
|
|
|
|
33439
|
|
|
|
|
|
|
#undef MEMCOPY |
33440
|
|
|
|
|
|
|
|
33441
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
33442
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
33443
|
|
|
|
|
|
|
|
33444
|
|
|
|
|
|
|
|
33445
|
|
|
|
|
|
|
|
33446
|
|
|
|
|
|
|
static forceinline u16 |
33447
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
33448
|
|
|
|
|
|
|
{ |
33449
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33450
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
33451
|
|
|
|
|
|
|
else |
33452
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
33453
|
|
|
|
|
|
|
} |
33454
|
|
|
|
|
|
|
|
33455
|
|
|
|
|
|
|
static forceinline u16 |
33456
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
33457
|
|
|
|
|
|
|
{ |
33458
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33459
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
33460
|
|
|
|
|
|
|
else |
33461
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
33462
|
|
|
|
|
|
|
} |
33463
|
|
|
|
|
|
|
|
33464
|
|
|
|
|
|
|
static forceinline u32 |
33465
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
33466
|
|
|
|
|
|
|
{ |
33467
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33468
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
33469
|
|
|
|
|
|
|
else |
33470
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
33471
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
33472
|
|
|
|
|
|
|
} |
33473
|
|
|
|
|
|
|
|
33474
|
|
|
|
|
|
|
static forceinline u32 |
33475
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
33476
|
|
|
|
|
|
|
{ |
33477
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33478
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
33479
|
|
|
|
|
|
|
else |
33480
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
33481
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
33482
|
|
|
|
|
|
|
} |
33483
|
|
|
|
|
|
|
|
33484
|
|
|
|
|
|
|
static forceinline u64 |
33485
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
33486
|
|
|
|
|
|
|
{ |
33487
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
33488
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
33489
|
|
|
|
|
|
|
else |
33490
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
33491
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
33492
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
33493
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
33494
|
|
|
|
|
|
|
} |
33495
|
|
|
|
|
|
|
|
33496
|
|
|
|
|
|
|
static forceinline machine_word_t |
33497
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
33498
|
|
|
|
|
|
|
{ |
33499
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
33500
|
|
|
|
|
|
|
if (WORDBITS == 32) |
33501
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
33502
|
|
|
|
|
|
|
else |
33503
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
33504
|
|
|
|
|
|
|
} |
33505
|
|
|
|
|
|
|
|
33506
|
|
|
|
|
|
|
|
33507
|
|
|
|
|
|
|
|
33508
|
|
|
|
|
|
|
static forceinline void |
33509
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
33510
|
|
|
|
|
|
|
{ |
33511
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33512
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
33513
|
|
|
|
|
|
|
} else { |
33514
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
33515
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
33516
|
|
|
|
|
|
|
} |
33517
|
|
|
|
|
|
|
} |
33518
|
|
|
|
|
|
|
|
33519
|
|
|
|
|
|
|
static forceinline void |
33520
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
33521
|
|
|
|
|
|
|
{ |
33522
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33523
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
33524
|
|
|
|
|
|
|
} else { |
33525
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
33526
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
33527
|
|
|
|
|
|
|
} |
33528
|
|
|
|
|
|
|
} |
33529
|
|
|
|
|
|
|
|
33530
|
|
|
|
|
|
|
static forceinline void |
33531
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
33532
|
|
|
|
|
|
|
{ |
33533
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33534
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
33535
|
|
|
|
|
|
|
} else { |
33536
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
33537
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
33538
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
33539
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
33540
|
|
|
|
|
|
|
} |
33541
|
|
|
|
|
|
|
} |
33542
|
|
|
|
|
|
|
|
33543
|
|
|
|
|
|
|
static forceinline void |
33544
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
33545
|
|
|
|
|
|
|
{ |
33546
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33547
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
33548
|
|
|
|
|
|
|
} else { |
33549
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
33550
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
33551
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
33552
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
33553
|
|
|
|
|
|
|
} |
33554
|
|
|
|
|
|
|
} |
33555
|
|
|
|
|
|
|
|
33556
|
|
|
|
|
|
|
static forceinline void |
33557
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
33558
|
|
|
|
|
|
|
{ |
33559
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
33560
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
33561
|
|
|
|
|
|
|
} else { |
33562
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
33563
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
33564
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
33565
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
33566
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
33567
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
33568
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
33569
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
33570
|
|
|
|
|
|
|
} |
33571
|
|
|
|
|
|
|
} |
33572
|
|
|
|
|
|
|
|
33573
|
|
|
|
|
|
|
static forceinline void |
33574
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
33575
|
|
|
|
|
|
|
{ |
33576
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
33577
|
|
|
|
|
|
|
if (WORDBITS == 32) |
33578
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
33579
|
|
|
|
|
|
|
else |
33580
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
33581
|
|
|
|
|
|
|
} |
33582
|
|
|
|
|
|
|
|
33583
|
|
|
|
|
|
|
|
33584
|
|
|
|
|
|
|
|
33585
|
|
|
|
|
|
|
|
33586
|
|
|
|
|
|
|
|
33587
|
|
|
|
|
|
|
|
33588
|
|
|
|
|
|
|
|
33589
|
|
|
|
|
|
|
static forceinline unsigned |
33590
|
|
|
|
|
|
|
bsr32(u32 v) |
33591
|
|
|
|
|
|
|
{ |
33592
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
33593
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
33594
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33595
|
|
|
|
|
|
|
unsigned long i; |
33596
|
|
|
|
|
|
|
|
33597
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
33598
|
|
|
|
|
|
|
return i; |
33599
|
|
|
|
|
|
|
#else |
33600
|
|
|
|
|
|
|
unsigned i = 0; |
33601
|
|
|
|
|
|
|
|
33602
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
33603
|
|
|
|
|
|
|
i++; |
33604
|
|
|
|
|
|
|
return i; |
33605
|
|
|
|
|
|
|
#endif |
33606
|
|
|
|
|
|
|
} |
33607
|
|
|
|
|
|
|
|
33608
|
|
|
|
|
|
|
static forceinline unsigned |
33609
|
|
|
|
|
|
|
bsr64(u64 v) |
33610
|
|
|
|
|
|
|
{ |
33611
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
33612
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
33613
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
33614
|
|
|
|
|
|
|
unsigned long i; |
33615
|
|
|
|
|
|
|
|
33616
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
33617
|
|
|
|
|
|
|
return i; |
33618
|
|
|
|
|
|
|
#else |
33619
|
|
|
|
|
|
|
unsigned i = 0; |
33620
|
|
|
|
|
|
|
|
33621
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
33622
|
|
|
|
|
|
|
i++; |
33623
|
|
|
|
|
|
|
return i; |
33624
|
|
|
|
|
|
|
#endif |
33625
|
|
|
|
|
|
|
} |
33626
|
|
|
|
|
|
|
|
33627
|
|
|
|
|
|
|
static forceinline unsigned |
33628
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
33629
|
|
|
|
|
|
|
{ |
33630
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
33631
|
|
|
|
|
|
|
if (WORDBITS == 32) |
33632
|
|
|
|
|
|
|
return bsr32(v); |
33633
|
|
|
|
|
|
|
else |
33634
|
|
|
|
|
|
|
return bsr64(v); |
33635
|
|
|
|
|
|
|
} |
33636
|
|
|
|
|
|
|
|
33637
|
|
|
|
|
|
|
|
33638
|
|
|
|
|
|
|
|
33639
|
|
|
|
|
|
|
static forceinline unsigned |
33640
|
|
|
|
|
|
|
bsf32(u32 v) |
33641
|
|
|
|
|
|
|
{ |
33642
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
33643
|
|
|
|
|
|
|
return __builtin_ctz(v); |
33644
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
33645
|
|
|
|
|
|
|
unsigned long i; |
33646
|
|
|
|
|
|
|
|
33647
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
33648
|
|
|
|
|
|
|
return i; |
33649
|
|
|
|
|
|
|
#else |
33650
|
|
|
|
|
|
|
unsigned i = 0; |
33651
|
|
|
|
|
|
|
|
33652
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
33653
|
|
|
|
|
|
|
i++; |
33654
|
|
|
|
|
|
|
return i; |
33655
|
|
|
|
|
|
|
#endif |
33656
|
|
|
|
|
|
|
} |
33657
|
|
|
|
|
|
|
|
33658
|
|
|
|
|
|
|
static forceinline unsigned |
33659
|
|
|
|
|
|
|
bsf64(u64 v) |
33660
|
|
|
|
|
|
|
{ |
33661
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
33662
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
33663
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
33664
|
|
|
|
|
|
|
unsigned long i; |
33665
|
|
|
|
|
|
|
|
33666
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
33667
|
|
|
|
|
|
|
return i; |
33668
|
|
|
|
|
|
|
#else |
33669
|
|
|
|
|
|
|
unsigned i = 0; |
33670
|
|
|
|
|
|
|
|
33671
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
33672
|
|
|
|
|
|
|
i++; |
33673
|
|
|
|
|
|
|
return i; |
33674
|
|
|
|
|
|
|
#endif |
33675
|
|
|
|
|
|
|
} |
33676
|
|
|
|
|
|
|
|
33677
|
|
|
|
|
|
|
static forceinline unsigned |
33678
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
33679
|
|
|
|
|
|
|
{ |
33680
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
33681
|
|
|
|
|
|
|
if (WORDBITS == 32) |
33682
|
|
|
|
|
|
|
return bsf32(v); |
33683
|
|
|
|
|
|
|
else |
33684
|
|
|
|
|
|
|
return bsf64(v); |
33685
|
|
|
|
|
|
|
} |
33686
|
|
|
|
|
|
|
|
33687
|
|
|
|
|
|
|
|
33688
|
|
|
|
|
|
|
#undef rbit32 |
33689
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
33690
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
33691
|
|
|
|
|
|
|
static forceinline u32 |
33692
|
|
|
|
|
|
|
rbit32(u32 v) |
33693
|
|
|
|
|
|
|
{ |
33694
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
33695
|
|
|
|
|
|
|
return v; |
33696
|
|
|
|
|
|
|
} |
33697
|
|
|
|
|
|
|
#define rbit32 rbit32 |
33698
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
33699
|
|
|
|
|
|
|
static forceinline u32 |
33700
|
|
|
|
|
|
|
rbit32(u32 v) |
33701
|
|
|
|
|
|
|
{ |
33702
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
33703
|
|
|
|
|
|
|
return v; |
33704
|
|
|
|
|
|
|
} |
33705
|
|
|
|
|
|
|
#define rbit32 rbit32 |
33706
|
|
|
|
|
|
|
#endif |
33707
|
|
|
|
|
|
|
|
33708
|
|
|
|
|
|
|
#endif |
33709
|
|
|
|
|
|
|
|
33710
|
|
|
|
|
|
|
|
33711
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
33712
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
33713
|
|
|
|
|
|
|
|
33714
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
33715
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
33716
|
|
|
|
|
|
|
|
33717
|
|
|
|
|
|
|
#ifdef FREESTANDING |
33718
|
|
|
|
|
|
|
|
33719
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
33720
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
33721
|
|
|
|
|
|
|
|
33722
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
33723
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
33724
|
|
|
|
|
|
|
|
33725
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
33726
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
33727
|
|
|
|
|
|
|
|
33728
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
33729
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
33730
|
|
|
|
|
|
|
|
33731
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
33732
|
|
|
|
|
|
|
#else |
33733
|
|
|
|
|
|
|
#include |
33734
|
|
|
|
|
|
|
#endif |
33735
|
|
|
|
|
|
|
|
33736
|
|
|
|
|
|
|
|
33737
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
33738
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
33739
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
33740
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
33741
|
|
|
|
|
|
|
#else |
33742
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
33743
|
|
|
|
|
|
|
#endif |
33744
|
|
|
|
|
|
|
|
33745
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
33746
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
33747
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
33748
|
|
|
|
|
|
|
|
33749
|
|
|
|
|
|
|
#endif |
33750
|
|
|
|
|
|
|
|
33751
|
|
|
|
|
|
|
|
33752
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_ARM_CPU_FEATURES 0 |
33753
|
|
|
|
|
|
|
|
33754
|
|
|
|
|
|
|
#if defined(ARCH_ARM32) || defined(ARCH_ARM64) |
33755
|
|
|
|
|
|
|
|
33756
|
|
|
|
|
|
|
#if !defined(FREESTANDING) && \ |
33757
|
|
|
|
|
|
|
(COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER)) && \ |
33758
|
|
|
|
|
|
|
(defined(__linux__) || \ |
33759
|
|
|
|
|
|
|
(defined(__APPLE__) && defined(ARCH_ARM64)) || \ |
33760
|
|
|
|
|
|
|
(defined(_WIN32) && defined(ARCH_ARM64))) |
33761
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_ARM_CPU_FEATURES |
33762
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_ARM_CPU_FEATURES 1 |
33763
|
|
|
|
|
|
|
#endif |
33764
|
|
|
|
|
|
|
|
33765
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_NEON 0x00000001 |
33766
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_PMULL 0x00000002 |
33767
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_CRC32 0x00000004 |
33768
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_SHA3 0x00000008 |
33769
|
|
|
|
|
|
|
#define ARM_CPU_FEATURE_DOTPROD 0x00000010 |
33770
|
|
|
|
|
|
|
|
33771
|
|
|
|
|
|
|
#define HAVE_NEON(features) (HAVE_NEON_NATIVE || ((features) & ARM_CPU_FEATURE_NEON)) |
33772
|
|
|
|
|
|
|
#define HAVE_PMULL(features) (HAVE_PMULL_NATIVE || ((features) & ARM_CPU_FEATURE_PMULL)) |
33773
|
|
|
|
|
|
|
#define HAVE_CRC32(features) (HAVE_CRC32_NATIVE || ((features) & ARM_CPU_FEATURE_CRC32)) |
33774
|
|
|
|
|
|
|
#define HAVE_SHA3(features) (HAVE_SHA3_NATIVE || ((features) & ARM_CPU_FEATURE_SHA3)) |
33775
|
|
|
|
|
|
|
#define HAVE_DOTPROD(features) (HAVE_DOTPROD_NATIVE || ((features) & ARM_CPU_FEATURE_DOTPROD)) |
33776
|
|
|
|
|
|
|
|
33777
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
33778
|
|
|
|
|
|
|
#define ARM_CPU_FEATURES_KNOWN 0x80000000 |
33779
|
|
|
|
|
|
|
extern volatile u32 libdeflate_arm_cpu_features; |
33780
|
|
|
|
|
|
|
|
33781
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void); |
33782
|
|
|
|
|
|
|
|
33783
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) |
33784
|
|
|
|
|
|
|
{ |
33785
|
|
|
|
|
|
|
if (libdeflate_arm_cpu_features == 0) |
33786
|
|
|
|
|
|
|
libdeflate_init_arm_cpu_features(); |
33787
|
|
|
|
|
|
|
return libdeflate_arm_cpu_features; |
33788
|
|
|
|
|
|
|
} |
33789
|
|
|
|
|
|
|
#else |
33790
|
|
|
|
|
|
|
static inline u32 get_arm_cpu_features(void) { return 0; } |
33791
|
|
|
|
|
|
|
#endif |
33792
|
|
|
|
|
|
|
|
33793
|
|
|
|
|
|
|
|
33794
|
|
|
|
|
|
|
#if defined(__ARM_NEON) || defined(ARCH_ARM64) |
33795
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 1 |
33796
|
|
|
|
|
|
|
#else |
33797
|
|
|
|
|
|
|
# define HAVE_NEON_NATIVE 0 |
33798
|
|
|
|
|
|
|
#endif |
33799
|
|
|
|
|
|
|
|
33800
|
|
|
|
|
|
|
#if HAVE_NEON_NATIVE || \ |
33801
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && GCC_PREREQ(6, 1) && defined(__ARM_FP)) |
33802
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 1 |
33803
|
|
|
|
|
|
|
#else |
33804
|
|
|
|
|
|
|
# define HAVE_NEON_INTRIN 0 |
33805
|
|
|
|
|
|
|
#endif |
33806
|
|
|
|
|
|
|
|
33807
|
|
|
|
|
|
|
|
33808
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRYPTO |
33809
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 1 |
33810
|
|
|
|
|
|
|
#else |
33811
|
|
|
|
|
|
|
# define HAVE_PMULL_NATIVE 0 |
33812
|
|
|
|
|
|
|
#endif |
33813
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE || \ |
33814
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
33815
|
|
|
|
|
|
|
HAVE_NEON_INTRIN && \ |
33816
|
|
|
|
|
|
|
(GCC_PREREQ(6, 1) || CLANG_PREREQ(3, 5, 6010000) || \ |
33817
|
|
|
|
|
|
|
defined(_MSC_VER)) && \ |
33818
|
|
|
|
|
|
|
\ |
33819
|
|
|
|
|
|
|
!(defined(ARCH_ARM32) && defined(__clang__))) |
33820
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN CPU_IS_LITTLE_ENDIAN() |
33821
|
|
|
|
|
|
|
|
33822
|
|
|
|
|
|
|
# ifdef _MSC_VER |
33823
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64(vcreate_p64(a), vcreate_p64(b)) |
33824
|
|
|
|
|
|
|
# else |
33825
|
|
|
|
|
|
|
# define compat_vmull_p64(a, b) vmull_p64((a), (b)) |
33826
|
|
|
|
|
|
|
# endif |
33827
|
|
|
|
|
|
|
#else |
33828
|
|
|
|
|
|
|
# define HAVE_PMULL_INTRIN 0 |
33829
|
|
|
|
|
|
|
#endif |
33830
|
|
|
|
|
|
|
|
33831
|
|
|
|
|
|
|
#if HAVE_PMULL_NATIVE && defined(ARCH_ARM64) && \ |
33832
|
|
|
|
|
|
|
GCC_PREREQ(6, 1) && !GCC_PREREQ(13, 1) |
33833
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 1 |
33834
|
|
|
|
|
|
|
#else |
33835
|
|
|
|
|
|
|
# define USE_PMULL_TARGET_EVEN_IF_NATIVE 0 |
33836
|
|
|
|
|
|
|
#endif |
33837
|
|
|
|
|
|
|
|
33838
|
|
|
|
|
|
|
|
33839
|
|
|
|
|
|
|
#ifdef __ARM_FEATURE_CRC32 |
33840
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 1 |
33841
|
|
|
|
|
|
|
#else |
33842
|
|
|
|
|
|
|
# define HAVE_CRC32_NATIVE 0 |
33843
|
|
|
|
|
|
|
#endif |
33844
|
|
|
|
|
|
|
#undef HAVE_CRC32_INTRIN |
33845
|
|
|
|
|
|
|
#if HAVE_CRC32_NATIVE |
33846
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
33847
|
|
|
|
|
|
|
#elif HAVE_DYNAMIC_ARM_CPU_FEATURES |
33848
|
|
|
|
|
|
|
# if GCC_PREREQ(1, 0) |
33849
|
|
|
|
|
|
|
|
33850
|
|
|
|
|
|
|
# if (GCC_PREREQ(11, 3) || \ |
33851
|
|
|
|
|
|
|
(GCC_PREREQ(10, 4) && !GCC_PREREQ(11, 0)) || \ |
33852
|
|
|
|
|
|
|
(GCC_PREREQ(9, 5) && !GCC_PREREQ(10, 0))) && \ |
33853
|
|
|
|
|
|
|
!defined(__ARM_ARCH_6KZ__) && \ |
33854
|
|
|
|
|
|
|
!defined(__ARM_ARCH_7EM__) |
33855
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
33856
|
|
|
|
|
|
|
# endif |
33857
|
|
|
|
|
|
|
# elif CLANG_PREREQ(3, 4, 6000000) |
33858
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
33859
|
|
|
|
|
|
|
# elif defined(_MSC_VER) |
33860
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 1 |
33861
|
|
|
|
|
|
|
# endif |
33862
|
|
|
|
|
|
|
#endif |
33863
|
|
|
|
|
|
|
#ifndef HAVE_CRC32_INTRIN |
33864
|
|
|
|
|
|
|
# define HAVE_CRC32_INTRIN 0 |
33865
|
|
|
|
|
|
|
#endif |
33866
|
|
|
|
|
|
|
|
33867
|
|
|
|
|
|
|
|
33868
|
|
|
|
|
|
|
#if defined(ARCH_ARM64) && !defined(_MSC_VER) |
33869
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_SHA3 |
33870
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 1 |
33871
|
|
|
|
|
|
|
# else |
33872
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
33873
|
|
|
|
|
|
|
# endif |
33874
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET (HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
33875
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || \ |
33876
|
|
|
|
|
|
|
CLANG_PREREQ(7, 0, 10010463) )) |
33877
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN (HAVE_NEON_INTRIN && \ |
33878
|
|
|
|
|
|
|
(HAVE_SHA3_NATIVE || HAVE_SHA3_TARGET) && \ |
33879
|
|
|
|
|
|
|
(GCC_PREREQ(9, 1) || \ |
33880
|
|
|
|
|
|
|
CLANG_PREREQ(13, 0, 13160000))) |
33881
|
|
|
|
|
|
|
#else |
33882
|
|
|
|
|
|
|
# define HAVE_SHA3_NATIVE 0 |
33883
|
|
|
|
|
|
|
# define HAVE_SHA3_TARGET 0 |
33884
|
|
|
|
|
|
|
# define HAVE_SHA3_INTRIN 0 |
33885
|
|
|
|
|
|
|
#endif |
33886
|
|
|
|
|
|
|
|
33887
|
|
|
|
|
|
|
|
33888
|
|
|
|
|
|
|
#ifdef ARCH_ARM64 |
33889
|
|
|
|
|
|
|
# ifdef __ARM_FEATURE_DOTPROD |
33890
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 1 |
33891
|
|
|
|
|
|
|
# else |
33892
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
33893
|
|
|
|
|
|
|
# endif |
33894
|
|
|
|
|
|
|
# if HAVE_DOTPROD_NATIVE || \ |
33895
|
|
|
|
|
|
|
(HAVE_DYNAMIC_ARM_CPU_FEATURES && \ |
33896
|
|
|
|
|
|
|
(GCC_PREREQ(8, 1) || CLANG_PREREQ(7, 0, 10010000) || \ |
33897
|
|
|
|
|
|
|
defined(_MSC_VER))) |
33898
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 1 |
33899
|
|
|
|
|
|
|
# else |
33900
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
33901
|
|
|
|
|
|
|
# endif |
33902
|
|
|
|
|
|
|
#else |
33903
|
|
|
|
|
|
|
# define HAVE_DOTPROD_NATIVE 0 |
33904
|
|
|
|
|
|
|
# define HAVE_DOTPROD_INTRIN 0 |
33905
|
|
|
|
|
|
|
#endif |
33906
|
|
|
|
|
|
|
|
33907
|
|
|
|
|
|
|
|
33908
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
33909
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
33910
|
|
|
|
|
|
|
# define __ARM_FEATURE_CRC32 1 |
33911
|
|
|
|
|
|
|
#endif |
33912
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
33913
|
|
|
|
|
|
|
# define __ARM_FEATURE_SHA3 1 |
33914
|
|
|
|
|
|
|
#endif |
33915
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
33916
|
|
|
|
|
|
|
# define __ARM_FEATURE_DOTPROD 1 |
33917
|
|
|
|
|
|
|
#endif |
33918
|
|
|
|
|
|
|
#if HAVE_CRC32_INTRIN && !HAVE_CRC32_NATIVE && \ |
33919
|
|
|
|
|
|
|
(defined(__clang__) || defined(ARCH_ARM32)) |
33920
|
|
|
|
|
|
|
# include |
33921
|
|
|
|
|
|
|
# undef __ARM_FEATURE_CRC32 |
33922
|
|
|
|
|
|
|
#endif |
33923
|
|
|
|
|
|
|
#if HAVE_SHA3_INTRIN && !HAVE_SHA3_NATIVE && defined(__clang__) |
33924
|
|
|
|
|
|
|
# include |
33925
|
|
|
|
|
|
|
# undef __ARM_FEATURE_SHA3 |
33926
|
|
|
|
|
|
|
#endif |
33927
|
|
|
|
|
|
|
#if HAVE_DOTPROD_INTRIN && !HAVE_DOTPROD_NATIVE && defined(__clang__) |
33928
|
|
|
|
|
|
|
# include |
33929
|
|
|
|
|
|
|
# undef __ARM_FEATURE_DOTPROD |
33930
|
|
|
|
|
|
|
#endif |
33931
|
|
|
|
|
|
|
|
33932
|
|
|
|
|
|
|
#endif |
33933
|
|
|
|
|
|
|
|
33934
|
|
|
|
|
|
|
#endif |
33935
|
|
|
|
|
|
|
|
33936
|
|
|
|
|
|
|
|
33937
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_ARM_CPU_FEATURES |
33938
|
|
|
|
|
|
|
|
33939
|
|
|
|
|
|
|
#ifdef __linux__ |
33940
|
|
|
|
|
|
|
|
33941
|
|
|
|
|
|
|
|
33942
|
|
|
|
|
|
|
#include |
33943
|
|
|
|
|
|
|
#include |
33944
|
|
|
|
|
|
|
#include |
33945
|
|
|
|
|
|
|
#include |
33946
|
|
|
|
|
|
|
|
33947
|
|
|
|
|
|
|
#define AT_HWCAP 16 |
33948
|
|
|
|
|
|
|
#define AT_HWCAP2 26 |
33949
|
|
|
|
|
|
|
|
33950
|
|
|
|
|
|
|
static void scan_auxv(unsigned long *hwcap, unsigned long *hwcap2) |
33951
|
|
|
|
|
|
|
{ |
33952
|
|
|
|
|
|
|
int fd; |
33953
|
|
|
|
|
|
|
unsigned long auxbuf[32]; |
33954
|
|
|
|
|
|
|
int filled = 0; |
33955
|
|
|
|
|
|
|
int i; |
33956
|
|
|
|
|
|
|
|
33957
|
|
|
|
|
|
|
fd = open("/proc/self/auxv", O_RDONLY); |
33958
|
|
|
|
|
|
|
if (fd < 0) |
33959
|
|
|
|
|
|
|
return; |
33960
|
|
|
|
|
|
|
|
33961
|
|
|
|
|
|
|
for (;;) { |
33962
|
|
|
|
|
|
|
do { |
33963
|
|
|
|
|
|
|
int ret = read(fd, &((char *)auxbuf)[filled], |
33964
|
|
|
|
|
|
|
sizeof(auxbuf) - filled); |
33965
|
|
|
|
|
|
|
if (ret <= 0) { |
33966
|
|
|
|
|
|
|
if (ret < 0 && errno == EINTR) |
33967
|
|
|
|
|
|
|
continue; |
33968
|
|
|
|
|
|
|
goto out; |
33969
|
|
|
|
|
|
|
} |
33970
|
|
|
|
|
|
|
filled += ret; |
33971
|
|
|
|
|
|
|
} while (filled < 2 * sizeof(long)); |
33972
|
|
|
|
|
|
|
|
33973
|
|
|
|
|
|
|
i = 0; |
33974
|
|
|
|
|
|
|
do { |
33975
|
|
|
|
|
|
|
unsigned long type = auxbuf[i]; |
33976
|
|
|
|
|
|
|
unsigned long value = auxbuf[i + 1]; |
33977
|
|
|
|
|
|
|
|
33978
|
|
|
|
|
|
|
if (type == AT_HWCAP) |
33979
|
|
|
|
|
|
|
*hwcap = value; |
33980
|
|
|
|
|
|
|
else if (type == AT_HWCAP2) |
33981
|
|
|
|
|
|
|
*hwcap2 = value; |
33982
|
|
|
|
|
|
|
i += 2; |
33983
|
|
|
|
|
|
|
filled -= 2 * sizeof(long); |
33984
|
|
|
|
|
|
|
} while (filled >= 2 * sizeof(long)); |
33985
|
|
|
|
|
|
|
|
33986
|
|
|
|
|
|
|
memmove(auxbuf, &auxbuf[i], filled); |
33987
|
|
|
|
|
|
|
} |
33988
|
|
|
|
|
|
|
out: |
33989
|
|
|
|
|
|
|
close(fd); |
33990
|
|
|
|
|
|
|
} |
33991
|
|
|
|
|
|
|
|
33992
|
|
|
|
|
|
|
static u32 query_arm_cpu_features(void) |
33993
|
|
|
|
|
|
|
{ |
33994
|
|
|
|
|
|
|
u32 features = 0; |
33995
|
|
|
|
|
|
|
unsigned long hwcap = 0; |
33996
|
|
|
|
|
|
|
unsigned long hwcap2 = 0; |
33997
|
|
|
|
|
|
|
|
33998
|
|
|
|
|
|
|
scan_auxv(&hwcap, &hwcap2); |
33999
|
|
|
|
|
|
|
|
34000
|
|
|
|
|
|
|
#ifdef ARCH_ARM32 |
34001
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(long) == 4); |
34002
|
|
|
|
|
|
|
if (hwcap & (1 << 12)) |
34003
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_NEON; |
34004
|
|
|
|
|
|
|
if (hwcap2 & (1 << 1)) |
34005
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_PMULL; |
34006
|
|
|
|
|
|
|
if (hwcap2 & (1 << 4)) |
34007
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_CRC32; |
34008
|
|
|
|
|
|
|
#else |
34009
|
|
|
|
|
|
|
STATIC_ASSERT(sizeof(long) == 8); |
34010
|
|
|
|
|
|
|
if (hwcap & (1 << 1)) |
34011
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_NEON; |
34012
|
|
|
|
|
|
|
if (hwcap & (1 << 4)) |
34013
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_PMULL; |
34014
|
|
|
|
|
|
|
if (hwcap & (1 << 7)) |
34015
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_CRC32; |
34016
|
|
|
|
|
|
|
if (hwcap & (1 << 17)) |
34017
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_SHA3; |
34018
|
|
|
|
|
|
|
if (hwcap & (1 << 20)) |
34019
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_DOTPROD; |
34020
|
|
|
|
|
|
|
#endif |
34021
|
|
|
|
|
|
|
return features; |
34022
|
|
|
|
|
|
|
} |
34023
|
|
|
|
|
|
|
|
34024
|
|
|
|
|
|
|
#elif defined(__APPLE__) |
34025
|
|
|
|
|
|
|
|
34026
|
|
|
|
|
|
|
|
34027
|
|
|
|
|
|
|
#include |
34028
|
|
|
|
|
|
|
#include |
34029
|
|
|
|
|
|
|
|
34030
|
|
|
|
|
|
|
static const struct { |
34031
|
|
|
|
|
|
|
const char *name; |
34032
|
|
|
|
|
|
|
u32 feature; |
34033
|
|
|
|
|
|
|
} feature_sysctls[] = { |
34034
|
|
|
|
|
|
|
{ "hw.optional.neon", ARM_CPU_FEATURE_NEON }, |
34035
|
|
|
|
|
|
|
{ "hw.optional.AdvSIMD", ARM_CPU_FEATURE_NEON }, |
34036
|
|
|
|
|
|
|
{ "hw.optional.arm.FEAT_PMULL", ARM_CPU_FEATURE_PMULL }, |
34037
|
|
|
|
|
|
|
{ "hw.optional.armv8_crc32", ARM_CPU_FEATURE_CRC32 }, |
34038
|
|
|
|
|
|
|
{ "hw.optional.armv8_2_sha3", ARM_CPU_FEATURE_SHA3 }, |
34039
|
|
|
|
|
|
|
{ "hw.optional.arm.FEAT_SHA3", ARM_CPU_FEATURE_SHA3 }, |
34040
|
|
|
|
|
|
|
{ "hw.optional.arm.FEAT_DotProd", ARM_CPU_FEATURE_DOTPROD }, |
34041
|
|
|
|
|
|
|
}; |
34042
|
|
|
|
|
|
|
|
34043
|
|
|
|
|
|
|
static u32 query_arm_cpu_features(void) |
34044
|
|
|
|
|
|
|
{ |
34045
|
|
|
|
|
|
|
u32 features = 0; |
34046
|
|
|
|
|
|
|
size_t i; |
34047
|
|
|
|
|
|
|
|
34048
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(feature_sysctls); i++) { |
34049
|
|
|
|
|
|
|
const char *name = feature_sysctls[i].name; |
34050
|
|
|
|
|
|
|
u32 val = 0; |
34051
|
|
|
|
|
|
|
size_t valsize = sizeof(val); |
34052
|
|
|
|
|
|
|
|
34053
|
|
|
|
|
|
|
if (sysctlbyname(name, &val, &valsize, NULL, 0) == 0 && |
34054
|
|
|
|
|
|
|
valsize == sizeof(val) && val == 1) |
34055
|
|
|
|
|
|
|
features |= feature_sysctls[i].feature; |
34056
|
|
|
|
|
|
|
} |
34057
|
|
|
|
|
|
|
return features; |
34058
|
|
|
|
|
|
|
} |
34059
|
|
|
|
|
|
|
#elif defined(_WIN32) |
34060
|
|
|
|
|
|
|
|
34061
|
|
|
|
|
|
|
#include |
34062
|
|
|
|
|
|
|
|
34063
|
|
|
|
|
|
|
static u32 query_arm_cpu_features(void) |
34064
|
|
|
|
|
|
|
{ |
34065
|
|
|
|
|
|
|
u32 features = ARM_CPU_FEATURE_NEON; |
34066
|
|
|
|
|
|
|
|
34067
|
|
|
|
|
|
|
if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) |
34068
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_PMULL; |
34069
|
|
|
|
|
|
|
if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)) |
34070
|
|
|
|
|
|
|
features |= ARM_CPU_FEATURE_CRC32; |
34071
|
|
|
|
|
|
|
|
34072
|
|
|
|
|
|
|
|
34073
|
|
|
|
|
|
|
|
34074
|
|
|
|
|
|
|
return features; |
34075
|
|
|
|
|
|
|
} |
34076
|
|
|
|
|
|
|
#else |
34077
|
|
|
|
|
|
|
#error "unhandled case" |
34078
|
|
|
|
|
|
|
#endif |
34079
|
|
|
|
|
|
|
|
34080
|
|
|
|
|
|
|
static const struct cpu_feature arm_cpu_feature_table[] = { |
34081
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_NEON, "neon"}, |
34082
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_PMULL, "pmull"}, |
34083
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_CRC32, "crc32"}, |
34084
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_SHA3, "sha3"}, |
34085
|
|
|
|
|
|
|
{ARM_CPU_FEATURE_DOTPROD, "dotprod"}, |
34086
|
|
|
|
|
|
|
}; |
34087
|
|
|
|
|
|
|
|
34088
|
|
|
|
|
|
|
volatile u32 libdeflate_arm_cpu_features = 0; |
34089
|
|
|
|
|
|
|
|
34090
|
|
|
|
|
|
|
void libdeflate_init_arm_cpu_features(void) |
34091
|
|
|
|
|
|
|
{ |
34092
|
|
|
|
|
|
|
u32 features = query_arm_cpu_features(); |
34093
|
|
|
|
|
|
|
|
34094
|
|
|
|
|
|
|
disable_cpu_features_for_testing(&features, arm_cpu_feature_table, |
34095
|
|
|
|
|
|
|
ARRAY_LEN(arm_cpu_feature_table)); |
34096
|
|
|
|
|
|
|
|
34097
|
|
|
|
|
|
|
libdeflate_arm_cpu_features = features | ARM_CPU_FEATURES_KNOWN; |
34098
|
|
|
|
|
|
|
} |
34099
|
|
|
|
|
|
|
|
34100
|
|
|
|
|
|
|
#endif |
34101
|
|
|
|
|
|
|
/* /usr/home/ben/projects/gzip-libdeflate/../../software/libdeflate/libdeflate-1.18/lib/x86/cpu_features.c */ |
34102
|
|
|
|
|
|
|
|
34103
|
|
|
|
|
|
|
|
34104
|
|
|
|
|
|
|
/* #include "cpu_features_common.h" - no include guard */ |
34105
|
|
|
|
|
|
|
/* #include "x86-cpu_features.h" */ |
34106
|
|
|
|
|
|
|
|
34107
|
|
|
|
|
|
|
|
34108
|
|
|
|
|
|
|
#ifndef LIB_X86_CPU_FEATURES_H |
34109
|
|
|
|
|
|
|
#define LIB_X86_CPU_FEATURES_H |
34110
|
|
|
|
|
|
|
|
34111
|
|
|
|
|
|
|
/* #include "lib_common.h" */ |
34112
|
|
|
|
|
|
|
|
34113
|
|
|
|
|
|
|
|
34114
|
|
|
|
|
|
|
#ifndef LIB_LIB_COMMON_H |
34115
|
|
|
|
|
|
|
#define LIB_LIB_COMMON_H |
34116
|
|
|
|
|
|
|
|
34117
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_H |
34118
|
|
|
|
|
|
|
|
34119
|
|
|
|
|
|
|
# error "lib_common.h must always be included before libdeflate.h" |
34120
|
|
|
|
|
|
|
#endif |
34121
|
|
|
|
|
|
|
|
34122
|
|
|
|
|
|
|
#if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
34123
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __declspec(dllexport) |
34124
|
|
|
|
|
|
|
#elif defined(__GNUC__) |
34125
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM __attribute__((visibility("default"))) |
34126
|
|
|
|
|
|
|
#else |
34127
|
|
|
|
|
|
|
# define LIBDEFLATE_EXPORT_SYM |
34128
|
|
|
|
|
|
|
#endif |
34129
|
|
|
|
|
|
|
|
34130
|
|
|
|
|
|
|
|
34131
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(__i386__) |
34132
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK __attribute__((force_align_arg_pointer)) |
34133
|
|
|
|
|
|
|
#else |
34134
|
|
|
|
|
|
|
# define LIBDEFLATE_ALIGN_STACK |
34135
|
|
|
|
|
|
|
#endif |
34136
|
|
|
|
|
|
|
|
34137
|
|
|
|
|
|
|
#define LIBDEFLATEAPI LIBDEFLATE_EXPORT_SYM LIBDEFLATE_ALIGN_STACK |
34138
|
|
|
|
|
|
|
|
34139
|
|
|
|
|
|
|
/* #include "../common_defs.h" */ |
34140
|
|
|
|
|
|
|
|
34141
|
|
|
|
|
|
|
|
34142
|
|
|
|
|
|
|
#ifndef COMMON_DEFS_H |
34143
|
|
|
|
|
|
|
#define COMMON_DEFS_H |
34144
|
|
|
|
|
|
|
|
34145
|
|
|
|
|
|
|
/* #include "libdeflate.h" */ |
34146
|
|
|
|
|
|
|
|
34147
|
|
|
|
|
|
|
|
34148
|
|
|
|
|
|
|
#ifndef LIBDEFLATE_H |
34149
|
|
|
|
|
|
|
#define LIBDEFLATE_H |
34150
|
|
|
|
|
|
|
|
34151
|
|
|
|
|
|
|
#include |
34152
|
|
|
|
|
|
|
#include |
34153
|
|
|
|
|
|
|
|
34154
|
|
|
|
|
|
|
#ifdef __cplusplus |
34155
|
|
|
|
|
|
|
extern "C" { |
34156
|
|
|
|
|
|
|
#endif |
34157
|
|
|
|
|
|
|
|
34158
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MAJOR 1 |
34159
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_MINOR 18 |
34160
|
|
|
|
|
|
|
#define LIBDEFLATE_VERSION_STRING "1.18" |
34161
|
|
|
|
|
|
|
|
34162
|
|
|
|
|
|
|
|
34163
|
|
|
|
|
|
|
#ifndef LIBDEFLATEAPI |
34164
|
|
|
|
|
|
|
# if defined(LIBDEFLATE_DLL) && (defined(_WIN32) || defined(__CYGWIN__)) |
34165
|
|
|
|
|
|
|
# define LIBDEFLATEAPI __declspec(dllimport) |
34166
|
|
|
|
|
|
|
# else |
34167
|
|
|
|
|
|
|
# define LIBDEFLATEAPI |
34168
|
|
|
|
|
|
|
# endif |
34169
|
|
|
|
|
|
|
#endif |
34170
|
|
|
|
|
|
|
|
34171
|
|
|
|
|
|
|
|
34172
|
|
|
|
|
|
|
|
34173
|
|
|
|
|
|
|
|
34174
|
|
|
|
|
|
|
|
34175
|
|
|
|
|
|
|
struct libdeflate_compressor; |
34176
|
|
|
|
|
|
|
|
34177
|
|
|
|
|
|
|
|
34178
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_compressor * |
34179
|
|
|
|
|
|
|
libdeflate_alloc_compressor(int compression_level); |
34180
|
|
|
|
|
|
|
|
34181
|
|
|
|
|
|
|
|
34182
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34183
|
|
|
|
|
|
|
libdeflate_deflate_compress(struct libdeflate_compressor *compressor, |
34184
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34185
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
34186
|
|
|
|
|
|
|
|
34187
|
|
|
|
|
|
|
|
34188
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34189
|
|
|
|
|
|
|
libdeflate_deflate_compress_bound(struct libdeflate_compressor *compressor, |
34190
|
|
|
|
|
|
|
size_t in_nbytes); |
34191
|
|
|
|
|
|
|
|
34192
|
|
|
|
|
|
|
|
34193
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34194
|
|
|
|
|
|
|
libdeflate_zlib_compress(struct libdeflate_compressor *compressor, |
34195
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34196
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
34197
|
|
|
|
|
|
|
|
34198
|
|
|
|
|
|
|
|
34199
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34200
|
|
|
|
|
|
|
libdeflate_zlib_compress_bound(struct libdeflate_compressor *compressor, |
34201
|
|
|
|
|
|
|
size_t in_nbytes); |
34202
|
|
|
|
|
|
|
|
34203
|
|
|
|
|
|
|
|
34204
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34205
|
|
|
|
|
|
|
libdeflate_gzip_compress(struct libdeflate_compressor *compressor, |
34206
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34207
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail); |
34208
|
|
|
|
|
|
|
|
34209
|
|
|
|
|
|
|
|
34210
|
|
|
|
|
|
|
LIBDEFLATEAPI size_t |
34211
|
|
|
|
|
|
|
libdeflate_gzip_compress_bound(struct libdeflate_compressor *compressor, |
34212
|
|
|
|
|
|
|
size_t in_nbytes); |
34213
|
|
|
|
|
|
|
|
34214
|
|
|
|
|
|
|
|
34215
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
34216
|
|
|
|
|
|
|
libdeflate_free_compressor(struct libdeflate_compressor *compressor); |
34217
|
|
|
|
|
|
|
|
34218
|
|
|
|
|
|
|
|
34219
|
|
|
|
|
|
|
|
34220
|
|
|
|
|
|
|
|
34221
|
|
|
|
|
|
|
|
34222
|
|
|
|
|
|
|
struct libdeflate_decompressor; |
34223
|
|
|
|
|
|
|
|
34224
|
|
|
|
|
|
|
|
34225
|
|
|
|
|
|
|
LIBDEFLATEAPI struct libdeflate_decompressor * |
34226
|
|
|
|
|
|
|
libdeflate_alloc_decompressor(void); |
34227
|
|
|
|
|
|
|
|
34228
|
|
|
|
|
|
|
|
34229
|
|
|
|
|
|
|
enum libdeflate_result { |
34230
|
|
|
|
|
|
|
|
34231
|
|
|
|
|
|
|
LIBDEFLATE_SUCCESS = 0, |
34232
|
|
|
|
|
|
|
|
34233
|
|
|
|
|
|
|
|
34234
|
|
|
|
|
|
|
LIBDEFLATE_BAD_DATA = 1, |
34235
|
|
|
|
|
|
|
|
34236
|
|
|
|
|
|
|
|
34237
|
|
|
|
|
|
|
LIBDEFLATE_SHORT_OUTPUT = 2, |
34238
|
|
|
|
|
|
|
|
34239
|
|
|
|
|
|
|
|
34240
|
|
|
|
|
|
|
LIBDEFLATE_INSUFFICIENT_SPACE = 3, |
34241
|
|
|
|
|
|
|
}; |
34242
|
|
|
|
|
|
|
|
34243
|
|
|
|
|
|
|
|
34244
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
34245
|
|
|
|
|
|
|
libdeflate_deflate_decompress(struct libdeflate_decompressor *decompressor, |
34246
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34247
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
34248
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
34249
|
|
|
|
|
|
|
|
34250
|
|
|
|
|
|
|
|
34251
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
34252
|
|
|
|
|
|
|
libdeflate_deflate_decompress_ex(struct libdeflate_decompressor *decompressor, |
34253
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34254
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
34255
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
34256
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
34257
|
|
|
|
|
|
|
|
34258
|
|
|
|
|
|
|
|
34259
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
34260
|
|
|
|
|
|
|
libdeflate_zlib_decompress(struct libdeflate_decompressor *decompressor, |
34261
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34262
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
34263
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
34264
|
|
|
|
|
|
|
|
34265
|
|
|
|
|
|
|
|
34266
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
34267
|
|
|
|
|
|
|
libdeflate_zlib_decompress_ex(struct libdeflate_decompressor *decompressor, |
34268
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34269
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
34270
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
34271
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
34272
|
|
|
|
|
|
|
|
34273
|
|
|
|
|
|
|
|
34274
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
34275
|
|
|
|
|
|
|
libdeflate_gzip_decompress(struct libdeflate_decompressor *decompressor, |
34276
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34277
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
34278
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
34279
|
|
|
|
|
|
|
|
34280
|
|
|
|
|
|
|
|
34281
|
|
|
|
|
|
|
LIBDEFLATEAPI enum libdeflate_result |
34282
|
|
|
|
|
|
|
libdeflate_gzip_decompress_ex(struct libdeflate_decompressor *decompressor, |
34283
|
|
|
|
|
|
|
const void *in, size_t in_nbytes, |
34284
|
|
|
|
|
|
|
void *out, size_t out_nbytes_avail, |
34285
|
|
|
|
|
|
|
size_t *actual_in_nbytes_ret, |
34286
|
|
|
|
|
|
|
size_t *actual_out_nbytes_ret); |
34287
|
|
|
|
|
|
|
|
34288
|
|
|
|
|
|
|
|
34289
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
34290
|
|
|
|
|
|
|
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor); |
34291
|
|
|
|
|
|
|
|
34292
|
|
|
|
|
|
|
|
34293
|
|
|
|
|
|
|
|
34294
|
|
|
|
|
|
|
|
34295
|
|
|
|
|
|
|
|
34296
|
|
|
|
|
|
|
|
34297
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
34298
|
|
|
|
|
|
|
libdeflate_adler32(uint32_t adler, const void *buffer, size_t len); |
34299
|
|
|
|
|
|
|
|
34300
|
|
|
|
|
|
|
|
34301
|
|
|
|
|
|
|
|
34302
|
|
|
|
|
|
|
LIBDEFLATEAPI uint32_t |
34303
|
|
|
|
|
|
|
libdeflate_crc32(uint32_t crc, const void *buffer, size_t len); |
34304
|
|
|
|
|
|
|
|
34305
|
|
|
|
|
|
|
|
34306
|
|
|
|
|
|
|
|
34307
|
|
|
|
|
|
|
|
34308
|
|
|
|
|
|
|
|
34309
|
|
|
|
|
|
|
|
34310
|
|
|
|
|
|
|
LIBDEFLATEAPI void |
34311
|
|
|
|
|
|
|
libdeflate_set_memory_allocator(void *(*malloc_func)(size_t), |
34312
|
|
|
|
|
|
|
void (*free_func)(void *)); |
34313
|
|
|
|
|
|
|
|
34314
|
|
|
|
|
|
|
#ifdef __cplusplus |
34315
|
|
|
|
|
|
|
} |
34316
|
|
|
|
|
|
|
#endif |
34317
|
|
|
|
|
|
|
|
34318
|
|
|
|
|
|
|
#endif |
34319
|
|
|
|
|
|
|
|
34320
|
|
|
|
|
|
|
|
34321
|
|
|
|
|
|
|
#include |
34322
|
|
|
|
|
|
|
#include |
34323
|
|
|
|
|
|
|
#include |
34324
|
|
|
|
|
|
|
#ifdef _MSC_VER |
34325
|
|
|
|
|
|
|
# include |
34326
|
|
|
|
|
|
|
# include |
34327
|
|
|
|
|
|
|
|
34328
|
|
|
|
|
|
|
|
34329
|
|
|
|
|
|
|
# pragma warning(disable : 4146) |
34330
|
|
|
|
|
|
|
|
34331
|
|
|
|
|
|
|
# pragma warning(disable : 4018) |
34332
|
|
|
|
|
|
|
# pragma warning(disable : 4244) |
34333
|
|
|
|
|
|
|
# pragma warning(disable : 4267) |
34334
|
|
|
|
|
|
|
# pragma warning(disable : 4310) |
34335
|
|
|
|
|
|
|
|
34336
|
|
|
|
|
|
|
# pragma warning(disable : 4100) |
34337
|
|
|
|
|
|
|
# pragma warning(disable : 4127) |
34338
|
|
|
|
|
|
|
# pragma warning(disable : 4189) |
34339
|
|
|
|
|
|
|
# pragma warning(disable : 4232) |
34340
|
|
|
|
|
|
|
# pragma warning(disable : 4245) |
34341
|
|
|
|
|
|
|
# pragma warning(disable : 4295) |
34342
|
|
|
|
|
|
|
#endif |
34343
|
|
|
|
|
|
|
#ifndef FREESTANDING |
34344
|
|
|
|
|
|
|
# include |
34345
|
|
|
|
|
|
|
#endif |
34346
|
|
|
|
|
|
|
|
34347
|
|
|
|
|
|
|
|
34348
|
|
|
|
|
|
|
|
34349
|
|
|
|
|
|
|
|
34350
|
|
|
|
|
|
|
|
34351
|
|
|
|
|
|
|
|
34352
|
|
|
|
|
|
|
#undef ARCH_X86_64 |
34353
|
|
|
|
|
|
|
#undef ARCH_X86_32 |
34354
|
|
|
|
|
|
|
#undef ARCH_ARM64 |
34355
|
|
|
|
|
|
|
#undef ARCH_ARM32 |
34356
|
|
|
|
|
|
|
#ifdef _MSC_VER |
34357
|
|
|
|
|
|
|
# if defined(_M_X64) |
34358
|
|
|
|
|
|
|
# define ARCH_X86_64 |
34359
|
|
|
|
|
|
|
# elif defined(_M_IX86) |
34360
|
|
|
|
|
|
|
# define ARCH_X86_32 |
34361
|
|
|
|
|
|
|
# elif defined(_M_ARM64) |
34362
|
|
|
|
|
|
|
# define ARCH_ARM64 |
34363
|
|
|
|
|
|
|
# elif defined(_M_ARM) |
34364
|
|
|
|
|
|
|
# define ARCH_ARM32 |
34365
|
|
|
|
|
|
|
# endif |
34366
|
|
|
|
|
|
|
#else |
34367
|
|
|
|
|
|
|
# if defined(__x86_64__) |
34368
|
|
|
|
|
|
|
# define ARCH_X86_64 |
34369
|
|
|
|
|
|
|
# elif defined(__i386__) |
34370
|
|
|
|
|
|
|
# define ARCH_X86_32 |
34371
|
|
|
|
|
|
|
# elif defined(__aarch64__) |
34372
|
|
|
|
|
|
|
# define ARCH_ARM64 |
34373
|
|
|
|
|
|
|
# elif defined(__arm__) |
34374
|
|
|
|
|
|
|
# define ARCH_ARM32 |
34375
|
|
|
|
|
|
|
# endif |
34376
|
|
|
|
|
|
|
#endif |
34377
|
|
|
|
|
|
|
|
34378
|
|
|
|
|
|
|
|
34379
|
|
|
|
|
|
|
|
34380
|
|
|
|
|
|
|
|
34381
|
|
|
|
|
|
|
|
34382
|
|
|
|
|
|
|
|
34383
|
|
|
|
|
|
|
typedef uint8_t u8; |
34384
|
|
|
|
|
|
|
typedef uint16_t u16; |
34385
|
|
|
|
|
|
|
typedef uint32_t u32; |
34386
|
|
|
|
|
|
|
typedef uint64_t u64; |
34387
|
|
|
|
|
|
|
typedef int8_t s8; |
34388
|
|
|
|
|
|
|
typedef int16_t s16; |
34389
|
|
|
|
|
|
|
typedef int32_t s32; |
34390
|
|
|
|
|
|
|
typedef int64_t s64; |
34391
|
|
|
|
|
|
|
|
34392
|
|
|
|
|
|
|
|
34393
|
|
|
|
|
|
|
#ifdef _MSC_VER |
34394
|
|
|
|
|
|
|
# ifdef _WIN64 |
34395
|
|
|
|
|
|
|
typedef long long ssize_t; |
34396
|
|
|
|
|
|
|
# else |
34397
|
|
|
|
|
|
|
typedef long ssize_t; |
34398
|
|
|
|
|
|
|
# endif |
34399
|
|
|
|
|
|
|
#endif |
34400
|
|
|
|
|
|
|
|
34401
|
|
|
|
|
|
|
|
34402
|
|
|
|
|
|
|
typedef size_t machine_word_t; |
34403
|
|
|
|
|
|
|
|
34404
|
|
|
|
|
|
|
|
34405
|
|
|
|
|
|
|
#define WORDBYTES ((int)sizeof(machine_word_t)) |
34406
|
|
|
|
|
|
|
|
34407
|
|
|
|
|
|
|
|
34408
|
|
|
|
|
|
|
#define WORDBITS (8 * WORDBYTES) |
34409
|
|
|
|
|
|
|
|
34410
|
|
|
|
|
|
|
|
34411
|
|
|
|
|
|
|
|
34412
|
|
|
|
|
|
|
|
34413
|
|
|
|
|
|
|
|
34414
|
|
|
|
|
|
|
|
34415
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
34416
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) \ |
34417
|
|
|
|
|
|
|
(__GNUC__ > (major) || \ |
34418
|
|
|
|
|
|
|
(__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
34419
|
|
|
|
|
|
|
#else |
34420
|
|
|
|
|
|
|
# define GCC_PREREQ(major, minor) 0 |
34421
|
|
|
|
|
|
|
#endif |
34422
|
|
|
|
|
|
|
#ifdef __clang__ |
34423
|
|
|
|
|
|
|
# ifdef __apple_build_version__ |
34424
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
34425
|
|
|
|
|
|
|
(__apple_build_version__ >= (apple_version)) |
34426
|
|
|
|
|
|
|
# else |
34427
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) \ |
34428
|
|
|
|
|
|
|
(__clang_major__ > (major) || \ |
34429
|
|
|
|
|
|
|
(__clang_major__ == (major) && __clang_minor__ >= (minor))) |
34430
|
|
|
|
|
|
|
# endif |
34431
|
|
|
|
|
|
|
#else |
34432
|
|
|
|
|
|
|
# define CLANG_PREREQ(major, minor, apple_version) 0 |
34433
|
|
|
|
|
|
|
#endif |
34434
|
|
|
|
|
|
|
|
34435
|
|
|
|
|
|
|
|
34436
|
|
|
|
|
|
|
#ifndef __has_attribute |
34437
|
|
|
|
|
|
|
# define __has_attribute(attribute) 0 |
34438
|
|
|
|
|
|
|
#endif |
34439
|
|
|
|
|
|
|
#ifndef __has_builtin |
34440
|
|
|
|
|
|
|
# define __has_builtin(builtin) 0 |
34441
|
|
|
|
|
|
|
#endif |
34442
|
|
|
|
|
|
|
|
34443
|
|
|
|
|
|
|
|
34444
|
|
|
|
|
|
|
#ifdef _MSC_VER |
34445
|
|
|
|
|
|
|
# define inline __inline |
34446
|
|
|
|
|
|
|
#endif |
34447
|
|
|
|
|
|
|
|
34448
|
|
|
|
|
|
|
|
34449
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(always_inline) |
34450
|
|
|
|
|
|
|
# define forceinline inline __attribute__((always_inline)) |
34451
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34452
|
|
|
|
|
|
|
# define forceinline __forceinline |
34453
|
|
|
|
|
|
|
#else |
34454
|
|
|
|
|
|
|
# define forceinline inline |
34455
|
|
|
|
|
|
|
#endif |
34456
|
|
|
|
|
|
|
|
34457
|
|
|
|
|
|
|
|
34458
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(unused) |
34459
|
|
|
|
|
|
|
# define MAYBE_UNUSED __attribute__((unused)) |
34460
|
|
|
|
|
|
|
#else |
34461
|
|
|
|
|
|
|
# define MAYBE_UNUSED |
34462
|
|
|
|
|
|
|
#endif |
34463
|
|
|
|
|
|
|
|
34464
|
|
|
|
|
|
|
|
34465
|
|
|
|
|
|
|
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L) |
34466
|
|
|
|
|
|
|
# if defined(__GNUC__) || defined(__clang__) |
34467
|
|
|
|
|
|
|
# define restrict __restrict__ |
34468
|
|
|
|
|
|
|
# else |
34469
|
|
|
|
|
|
|
# define restrict |
34470
|
|
|
|
|
|
|
# endif |
34471
|
|
|
|
|
|
|
#endif |
34472
|
|
|
|
|
|
|
|
34473
|
|
|
|
|
|
|
|
34474
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
34475
|
|
|
|
|
|
|
# define likely(expr) __builtin_expect(!!(expr), 1) |
34476
|
|
|
|
|
|
|
#else |
34477
|
|
|
|
|
|
|
# define likely(expr) (expr) |
34478
|
|
|
|
|
|
|
#endif |
34479
|
|
|
|
|
|
|
|
34480
|
|
|
|
|
|
|
|
34481
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_expect) |
34482
|
|
|
|
|
|
|
# define unlikely(expr) __builtin_expect(!!(expr), 0) |
34483
|
|
|
|
|
|
|
#else |
34484
|
|
|
|
|
|
|
# define unlikely(expr) (expr) |
34485
|
|
|
|
|
|
|
#endif |
34486
|
|
|
|
|
|
|
|
34487
|
|
|
|
|
|
|
|
34488
|
|
|
|
|
|
|
#undef prefetchr |
34489
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
34490
|
|
|
|
|
|
|
# define prefetchr(addr) __builtin_prefetch((addr), 0) |
34491
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34492
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
34493
|
|
|
|
|
|
|
# define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
34494
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
34495
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch2((addr), 0x00 ) |
34496
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
34497
|
|
|
|
|
|
|
# define prefetchr(addr) __prefetch(addr) |
34498
|
|
|
|
|
|
|
# endif |
34499
|
|
|
|
|
|
|
#endif |
34500
|
|
|
|
|
|
|
#ifndef prefetchr |
34501
|
|
|
|
|
|
|
# define prefetchr(addr) |
34502
|
|
|
|
|
|
|
#endif |
34503
|
|
|
|
|
|
|
|
34504
|
|
|
|
|
|
|
|
34505
|
|
|
|
|
|
|
#undef prefetchw |
34506
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
34507
|
|
|
|
|
|
|
# define prefetchw(addr) __builtin_prefetch((addr), 1) |
34508
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34509
|
|
|
|
|
|
|
# if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
34510
|
|
|
|
|
|
|
# define prefetchw(addr) _m_prefetchw(addr) |
34511
|
|
|
|
|
|
|
# elif defined(ARCH_ARM64) |
34512
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetch2((addr), 0x10 ) |
34513
|
|
|
|
|
|
|
# elif defined(ARCH_ARM32) |
34514
|
|
|
|
|
|
|
# define prefetchw(addr) __prefetchw(addr) |
34515
|
|
|
|
|
|
|
# endif |
34516
|
|
|
|
|
|
|
#endif |
34517
|
|
|
|
|
|
|
#ifndef prefetchw |
34518
|
|
|
|
|
|
|
# define prefetchw(addr) |
34519
|
|
|
|
|
|
|
#endif |
34520
|
|
|
|
|
|
|
|
34521
|
|
|
|
|
|
|
|
34522
|
|
|
|
|
|
|
#undef _aligned_attribute |
34523
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_attribute(aligned) |
34524
|
|
|
|
|
|
|
# define _aligned_attribute(n) __attribute__((aligned(n))) |
34525
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34526
|
|
|
|
|
|
|
# define _aligned_attribute(n) __declspec(align(n)) |
34527
|
|
|
|
|
|
|
#endif |
34528
|
|
|
|
|
|
|
|
34529
|
|
|
|
|
|
|
|
34530
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 4) || __has_attribute(target) |
34531
|
|
|
|
|
|
|
# define _target_attribute(attrs) __attribute__((target(attrs))) |
34532
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 1 |
34533
|
|
|
|
|
|
|
#else |
34534
|
|
|
|
|
|
|
# define _target_attribute(attrs) |
34535
|
|
|
|
|
|
|
# define COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE 0 |
34536
|
|
|
|
|
|
|
#endif |
34537
|
|
|
|
|
|
|
|
34538
|
|
|
|
|
|
|
|
34539
|
|
|
|
|
|
|
|
34540
|
|
|
|
|
|
|
|
34541
|
|
|
|
|
|
|
|
34542
|
|
|
|
|
|
|
#define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
34543
|
|
|
|
|
|
|
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
34544
|
|
|
|
|
|
|
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
34545
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
34546
|
|
|
|
|
|
|
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
34547
|
|
|
|
|
|
|
#define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
34548
|
|
|
|
|
|
|
#define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
34549
|
|
|
|
|
|
|
|
34550
|
|
|
|
|
|
|
|
34551
|
|
|
|
|
|
|
|
34552
|
|
|
|
|
|
|
|
34553
|
|
|
|
|
|
|
|
34554
|
|
|
|
|
|
|
|
34555
|
|
|
|
|
|
|
#if defined(__BYTE_ORDER__) |
34556
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
34557
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34558
|
|
|
|
|
|
|
# define CPU_IS_LITTLE_ENDIAN() true |
34559
|
|
|
|
|
|
|
#else |
34560
|
|
|
|
|
|
|
static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
34561
|
|
|
|
|
|
|
{ |
34562
|
|
|
|
|
|
|
union { |
34563
|
|
|
|
|
|
|
u32 w; |
34564
|
|
|
|
|
|
|
u8 b; |
34565
|
|
|
|
|
|
|
} u; |
34566
|
|
|
|
|
|
|
|
34567
|
|
|
|
|
|
|
u.w = 1; |
34568
|
|
|
|
|
|
|
return u.b; |
34569
|
|
|
|
|
|
|
} |
34570
|
|
|
|
|
|
|
#endif |
34571
|
|
|
|
|
|
|
|
34572
|
|
|
|
|
|
|
|
34573
|
|
|
|
|
|
|
static forceinline u16 bswap16(u16 v) |
34574
|
|
|
|
|
|
|
{ |
34575
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16) |
34576
|
|
|
|
|
|
|
return __builtin_bswap16(v); |
34577
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34578
|
|
|
|
|
|
|
return _byteswap_ushort(v); |
34579
|
|
|
|
|
|
|
#else |
34580
|
|
|
|
|
|
|
return (v << 8) | (v >> 8); |
34581
|
|
|
|
|
|
|
#endif |
34582
|
|
|
|
|
|
|
} |
34583
|
|
|
|
|
|
|
|
34584
|
|
|
|
|
|
|
|
34585
|
|
|
|
|
|
|
static forceinline u32 bswap32(u32 v) |
34586
|
|
|
|
|
|
|
{ |
34587
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap32) |
34588
|
|
|
|
|
|
|
return __builtin_bswap32(v); |
34589
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34590
|
|
|
|
|
|
|
return _byteswap_ulong(v); |
34591
|
|
|
|
|
|
|
#else |
34592
|
|
|
|
|
|
|
return ((v & 0x000000FF) << 24) | |
34593
|
|
|
|
|
|
|
((v & 0x0000FF00) << 8) | |
34594
|
|
|
|
|
|
|
((v & 0x00FF0000) >> 8) | |
34595
|
|
|
|
|
|
|
((v & 0xFF000000) >> 24); |
34596
|
|
|
|
|
|
|
#endif |
34597
|
|
|
|
|
|
|
} |
34598
|
|
|
|
|
|
|
|
34599
|
|
|
|
|
|
|
|
34600
|
|
|
|
|
|
|
static forceinline u64 bswap64(u64 v) |
34601
|
|
|
|
|
|
|
{ |
34602
|
|
|
|
|
|
|
#if GCC_PREREQ(4, 3) || __has_builtin(__builtin_bswap64) |
34603
|
|
|
|
|
|
|
return __builtin_bswap64(v); |
34604
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34605
|
|
|
|
|
|
|
return _byteswap_uint64(v); |
34606
|
|
|
|
|
|
|
#else |
34607
|
|
|
|
|
|
|
return ((v & 0x00000000000000FF) << 56) | |
34608
|
|
|
|
|
|
|
((v & 0x000000000000FF00) << 40) | |
34609
|
|
|
|
|
|
|
((v & 0x0000000000FF0000) << 24) | |
34610
|
|
|
|
|
|
|
((v & 0x00000000FF000000) << 8) | |
34611
|
|
|
|
|
|
|
((v & 0x000000FF00000000) >> 8) | |
34612
|
|
|
|
|
|
|
((v & 0x0000FF0000000000) >> 24) | |
34613
|
|
|
|
|
|
|
((v & 0x00FF000000000000) >> 40) | |
34614
|
|
|
|
|
|
|
((v & 0xFF00000000000000) >> 56); |
34615
|
|
|
|
|
|
|
#endif |
34616
|
|
|
|
|
|
|
} |
34617
|
|
|
|
|
|
|
|
34618
|
|
|
|
|
|
|
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
34619
|
|
|
|
|
|
|
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
34620
|
|
|
|
|
|
|
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
34621
|
|
|
|
|
|
|
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
34622
|
|
|
|
|
|
|
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
34623
|
|
|
|
|
|
|
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
34624
|
|
|
|
|
|
|
|
34625
|
|
|
|
|
|
|
|
34626
|
|
|
|
|
|
|
|
34627
|
|
|
|
|
|
|
|
34628
|
|
|
|
|
|
|
|
34629
|
|
|
|
|
|
|
|
34630
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && \ |
34631
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
34632
|
|
|
|
|
|
|
defined(__ARM_FEATURE_UNALIGNED) || defined(__powerpc64__) || \ |
34633
|
|
|
|
|
|
|
defined(__wasm__)) |
34634
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
34635
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34636
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 1 |
34637
|
|
|
|
|
|
|
#else |
34638
|
|
|
|
|
|
|
# define UNALIGNED_ACCESS_IS_FAST 0 |
34639
|
|
|
|
|
|
|
#endif |
34640
|
|
|
|
|
|
|
|
34641
|
|
|
|
|
|
|
|
34642
|
|
|
|
|
|
|
|
34643
|
|
|
|
|
|
|
#ifdef FREESTANDING |
34644
|
|
|
|
|
|
|
# define MEMCOPY __builtin_memcpy |
34645
|
|
|
|
|
|
|
#else |
34646
|
|
|
|
|
|
|
# define MEMCOPY memcpy |
34647
|
|
|
|
|
|
|
#endif |
34648
|
|
|
|
|
|
|
|
34649
|
|
|
|
|
|
|
|
34650
|
|
|
|
|
|
|
|
34651
|
|
|
|
|
|
|
#define DEFINE_UNALIGNED_TYPE(type) \ |
34652
|
|
|
|
|
|
|
static forceinline type \ |
34653
|
|
|
|
|
|
|
load_##type##_unaligned(const void *p) \ |
34654
|
|
|
|
|
|
|
{ \ |
34655
|
|
|
|
|
|
|
type v; \ |
34656
|
|
|
|
|
|
|
\ |
34657
|
|
|
|
|
|
|
MEMCOPY(&v, p, sizeof(v)); \ |
34658
|
|
|
|
|
|
|
return v; \ |
34659
|
|
|
|
|
|
|
} \ |
34660
|
|
|
|
|
|
|
\ |
34661
|
|
|
|
|
|
|
static forceinline void \ |
34662
|
|
|
|
|
|
|
store_##type##_unaligned(type v, void *p) \ |
34663
|
|
|
|
|
|
|
{ \ |
34664
|
|
|
|
|
|
|
MEMCOPY(p, &v, sizeof(v)); \ |
34665
|
|
|
|
|
|
|
} |
34666
|
|
|
|
|
|
|
|
34667
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u16) |
34668
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u32) |
34669
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(u64) |
34670
|
|
|
|
|
|
|
DEFINE_UNALIGNED_TYPE(machine_word_t) |
34671
|
|
|
|
|
|
|
|
34672
|
|
|
|
|
|
|
#undef MEMCOPY |
34673
|
|
|
|
|
|
|
|
34674
|
|
|
|
|
|
|
#define load_word_unaligned load_machine_word_t_unaligned |
34675
|
|
|
|
|
|
|
#define store_word_unaligned store_machine_word_t_unaligned |
34676
|
|
|
|
|
|
|
|
34677
|
|
|
|
|
|
|
|
34678
|
|
|
|
|
|
|
|
34679
|
|
|
|
|
|
|
static forceinline u16 |
34680
|
|
|
|
|
|
|
get_unaligned_le16(const u8 *p) |
34681
|
|
|
|
|
|
|
{ |
34682
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34683
|
|
|
|
|
|
|
return le16_bswap(load_u16_unaligned(p)); |
34684
|
|
|
|
|
|
|
else |
34685
|
|
|
|
|
|
|
return ((u16)p[1] << 8) | p[0]; |
34686
|
|
|
|
|
|
|
} |
34687
|
|
|
|
|
|
|
|
34688
|
|
|
|
|
|
|
static forceinline u16 |
34689
|
|
|
|
|
|
|
get_unaligned_be16(const u8 *p) |
34690
|
|
|
|
|
|
|
{ |
34691
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34692
|
|
|
|
|
|
|
return be16_bswap(load_u16_unaligned(p)); |
34693
|
|
|
|
|
|
|
else |
34694
|
|
|
|
|
|
|
return ((u16)p[0] << 8) | p[1]; |
34695
|
|
|
|
|
|
|
} |
34696
|
|
|
|
|
|
|
|
34697
|
|
|
|
|
|
|
static forceinline u32 |
34698
|
|
|
|
|
|
|
get_unaligned_le32(const u8 *p) |
34699
|
|
|
|
|
|
|
{ |
34700
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34701
|
|
|
|
|
|
|
return le32_bswap(load_u32_unaligned(p)); |
34702
|
|
|
|
|
|
|
else |
34703
|
|
|
|
|
|
|
return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
34704
|
|
|
|
|
|
|
((u32)p[1] << 8) | p[0]; |
34705
|
|
|
|
|
|
|
} |
34706
|
|
|
|
|
|
|
|
34707
|
|
|
|
|
|
|
static forceinline u32 |
34708
|
|
|
|
|
|
|
get_unaligned_be32(const u8 *p) |
34709
|
|
|
|
|
|
|
{ |
34710
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34711
|
|
|
|
|
|
|
return be32_bswap(load_u32_unaligned(p)); |
34712
|
|
|
|
|
|
|
else |
34713
|
|
|
|
|
|
|
return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
34714
|
|
|
|
|
|
|
((u32)p[2] << 8) | p[3]; |
34715
|
|
|
|
|
|
|
} |
34716
|
|
|
|
|
|
|
|
34717
|
|
|
|
|
|
|
static forceinline u64 |
34718
|
|
|
|
|
|
|
get_unaligned_le64(const u8 *p) |
34719
|
|
|
|
|
|
|
{ |
34720
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) |
34721
|
|
|
|
|
|
|
return le64_bswap(load_u64_unaligned(p)); |
34722
|
|
|
|
|
|
|
else |
34723
|
|
|
|
|
|
|
return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
34724
|
|
|
|
|
|
|
((u64)p[5] << 40) | ((u64)p[4] << 32) | |
34725
|
|
|
|
|
|
|
((u64)p[3] << 24) | ((u64)p[2] << 16) | |
34726
|
|
|
|
|
|
|
((u64)p[1] << 8) | p[0]; |
34727
|
|
|
|
|
|
|
} |
34728
|
|
|
|
|
|
|
|
34729
|
|
|
|
|
|
|
static forceinline machine_word_t |
34730
|
|
|
|
|
|
|
get_unaligned_leword(const u8 *p) |
34731
|
|
|
|
|
|
|
{ |
34732
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
34733
|
|
|
|
|
|
|
if (WORDBITS == 32) |
34734
|
|
|
|
|
|
|
return get_unaligned_le32(p); |
34735
|
|
|
|
|
|
|
else |
34736
|
|
|
|
|
|
|
return get_unaligned_le64(p); |
34737
|
|
|
|
|
|
|
} |
34738
|
|
|
|
|
|
|
|
34739
|
|
|
|
|
|
|
|
34740
|
|
|
|
|
|
|
|
34741
|
|
|
|
|
|
|
static forceinline void |
34742
|
|
|
|
|
|
|
put_unaligned_le16(u16 v, u8 *p) |
34743
|
|
|
|
|
|
|
{ |
34744
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34745
|
|
|
|
|
|
|
store_u16_unaligned(le16_bswap(v), p); |
34746
|
|
|
|
|
|
|
} else { |
34747
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
34748
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
34749
|
|
|
|
|
|
|
} |
34750
|
|
|
|
|
|
|
} |
34751
|
|
|
|
|
|
|
|
34752
|
|
|
|
|
|
|
static forceinline void |
34753
|
|
|
|
|
|
|
put_unaligned_be16(u16 v, u8 *p) |
34754
|
|
|
|
|
|
|
{ |
34755
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34756
|
|
|
|
|
|
|
store_u16_unaligned(be16_bswap(v), p); |
34757
|
|
|
|
|
|
|
} else { |
34758
|
|
|
|
|
|
|
p[0] = (u8)(v >> 8); |
34759
|
|
|
|
|
|
|
p[1] = (u8)(v >> 0); |
34760
|
|
|
|
|
|
|
} |
34761
|
|
|
|
|
|
|
} |
34762
|
|
|
|
|
|
|
|
34763
|
|
|
|
|
|
|
static forceinline void |
34764
|
|
|
|
|
|
|
put_unaligned_le32(u32 v, u8 *p) |
34765
|
|
|
|
|
|
|
{ |
34766
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34767
|
|
|
|
|
|
|
store_u32_unaligned(le32_bswap(v), p); |
34768
|
|
|
|
|
|
|
} else { |
34769
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
34770
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
34771
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
34772
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
34773
|
|
|
|
|
|
|
} |
34774
|
|
|
|
|
|
|
} |
34775
|
|
|
|
|
|
|
|
34776
|
|
|
|
|
|
|
static forceinline void |
34777
|
|
|
|
|
|
|
put_unaligned_be32(u32 v, u8 *p) |
34778
|
|
|
|
|
|
|
{ |
34779
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34780
|
|
|
|
|
|
|
store_u32_unaligned(be32_bswap(v), p); |
34781
|
|
|
|
|
|
|
} else { |
34782
|
|
|
|
|
|
|
p[0] = (u8)(v >> 24); |
34783
|
|
|
|
|
|
|
p[1] = (u8)(v >> 16); |
34784
|
|
|
|
|
|
|
p[2] = (u8)(v >> 8); |
34785
|
|
|
|
|
|
|
p[3] = (u8)(v >> 0); |
34786
|
|
|
|
|
|
|
} |
34787
|
|
|
|
|
|
|
} |
34788
|
|
|
|
|
|
|
|
34789
|
|
|
|
|
|
|
static forceinline void |
34790
|
|
|
|
|
|
|
put_unaligned_le64(u64 v, u8 *p) |
34791
|
|
|
|
|
|
|
{ |
34792
|
|
|
|
|
|
|
if (UNALIGNED_ACCESS_IS_FAST) { |
34793
|
|
|
|
|
|
|
store_u64_unaligned(le64_bswap(v), p); |
34794
|
|
|
|
|
|
|
} else { |
34795
|
|
|
|
|
|
|
p[0] = (u8)(v >> 0); |
34796
|
|
|
|
|
|
|
p[1] = (u8)(v >> 8); |
34797
|
|
|
|
|
|
|
p[2] = (u8)(v >> 16); |
34798
|
|
|
|
|
|
|
p[3] = (u8)(v >> 24); |
34799
|
|
|
|
|
|
|
p[4] = (u8)(v >> 32); |
34800
|
|
|
|
|
|
|
p[5] = (u8)(v >> 40); |
34801
|
|
|
|
|
|
|
p[6] = (u8)(v >> 48); |
34802
|
|
|
|
|
|
|
p[7] = (u8)(v >> 56); |
34803
|
|
|
|
|
|
|
} |
34804
|
|
|
|
|
|
|
} |
34805
|
|
|
|
|
|
|
|
34806
|
|
|
|
|
|
|
static forceinline void |
34807
|
|
|
|
|
|
|
put_unaligned_leword(machine_word_t v, u8 *p) |
34808
|
|
|
|
|
|
|
{ |
34809
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
34810
|
|
|
|
|
|
|
if (WORDBITS == 32) |
34811
|
|
|
|
|
|
|
put_unaligned_le32(v, p); |
34812
|
|
|
|
|
|
|
else |
34813
|
|
|
|
|
|
|
put_unaligned_le64(v, p); |
34814
|
|
|
|
|
|
|
} |
34815
|
|
|
|
|
|
|
|
34816
|
|
|
|
|
|
|
|
34817
|
|
|
|
|
|
|
|
34818
|
|
|
|
|
|
|
|
34819
|
|
|
|
|
|
|
|
34820
|
|
|
|
|
|
|
|
34821
|
|
|
|
|
|
|
|
34822
|
|
|
|
|
|
|
static forceinline unsigned |
34823
|
|
|
|
|
|
|
bsr32(u32 v) |
34824
|
|
|
|
|
|
|
{ |
34825
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clz) |
34826
|
|
|
|
|
|
|
return 31 - __builtin_clz(v); |
34827
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34828
|
|
|
|
|
|
|
unsigned long i; |
34829
|
|
|
|
|
|
|
|
34830
|
|
|
|
|
|
|
_BitScanReverse(&i, v); |
34831
|
|
|
|
|
|
|
return i; |
34832
|
|
|
|
|
|
|
#else |
34833
|
|
|
|
|
|
|
unsigned i = 0; |
34834
|
|
|
|
|
|
|
|
34835
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
34836
|
|
|
|
|
|
|
i++; |
34837
|
|
|
|
|
|
|
return i; |
34838
|
|
|
|
|
|
|
#endif |
34839
|
|
|
|
|
|
|
} |
34840
|
|
|
|
|
|
|
|
34841
|
|
|
|
|
|
|
static forceinline unsigned |
34842
|
|
|
|
|
|
|
bsr64(u64 v) |
34843
|
|
|
|
|
|
|
{ |
34844
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
34845
|
|
|
|
|
|
|
return 63 - __builtin_clzll(v); |
34846
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
34847
|
|
|
|
|
|
|
unsigned long i; |
34848
|
|
|
|
|
|
|
|
34849
|
|
|
|
|
|
|
_BitScanReverse64(&i, v); |
34850
|
|
|
|
|
|
|
return i; |
34851
|
|
|
|
|
|
|
#else |
34852
|
|
|
|
|
|
|
unsigned i = 0; |
34853
|
|
|
|
|
|
|
|
34854
|
|
|
|
|
|
|
while ((v >>= 1) != 0) |
34855
|
|
|
|
|
|
|
i++; |
34856
|
|
|
|
|
|
|
return i; |
34857
|
|
|
|
|
|
|
#endif |
34858
|
|
|
|
|
|
|
} |
34859
|
|
|
|
|
|
|
|
34860
|
|
|
|
|
|
|
static forceinline unsigned |
34861
|
|
|
|
|
|
|
bsrw(machine_word_t v) |
34862
|
|
|
|
|
|
|
{ |
34863
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
34864
|
|
|
|
|
|
|
if (WORDBITS == 32) |
34865
|
|
|
|
|
|
|
return bsr32(v); |
34866
|
|
|
|
|
|
|
else |
34867
|
|
|
|
|
|
|
return bsr64(v); |
34868
|
|
|
|
|
|
|
} |
34869
|
|
|
|
|
|
|
|
34870
|
|
|
|
|
|
|
|
34871
|
|
|
|
|
|
|
|
34872
|
|
|
|
|
|
|
static forceinline unsigned |
34873
|
|
|
|
|
|
|
bsf32(u32 v) |
34874
|
|
|
|
|
|
|
{ |
34875
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
34876
|
|
|
|
|
|
|
return __builtin_ctz(v); |
34877
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
34878
|
|
|
|
|
|
|
unsigned long i; |
34879
|
|
|
|
|
|
|
|
34880
|
|
|
|
|
|
|
_BitScanForward(&i, v); |
34881
|
|
|
|
|
|
|
return i; |
34882
|
|
|
|
|
|
|
#else |
34883
|
|
|
|
|
|
|
unsigned i = 0; |
34884
|
|
|
|
|
|
|
|
34885
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
34886
|
|
|
|
|
|
|
i++; |
34887
|
|
|
|
|
|
|
return i; |
34888
|
|
|
|
|
|
|
#endif |
34889
|
|
|
|
|
|
|
} |
34890
|
|
|
|
|
|
|
|
34891
|
|
|
|
|
|
|
static forceinline unsigned |
34892
|
|
|
|
|
|
|
bsf64(u64 v) |
34893
|
|
|
|
|
|
|
{ |
34894
|
|
|
|
|
|
|
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
34895
|
|
|
|
|
|
|
return __builtin_ctzll(v); |
34896
|
|
|
|
|
|
|
#elif defined(_MSC_VER) && defined(_WIN64) |
34897
|
|
|
|
|
|
|
unsigned long i; |
34898
|
|
|
|
|
|
|
|
34899
|
|
|
|
|
|
|
_BitScanForward64(&i, v); |
34900
|
|
|
|
|
|
|
return i; |
34901
|
|
|
|
|
|
|
#else |
34902
|
|
|
|
|
|
|
unsigned i = 0; |
34903
|
|
|
|
|
|
|
|
34904
|
|
|
|
|
|
|
for (; (v & 1) == 0; v >>= 1) |
34905
|
|
|
|
|
|
|
i++; |
34906
|
|
|
|
|
|
|
return i; |
34907
|
|
|
|
|
|
|
#endif |
34908
|
|
|
|
|
|
|
} |
34909
|
|
|
|
|
|
|
|
34910
|
|
|
|
|
|
|
static forceinline unsigned |
34911
|
|
|
|
|
|
|
bsfw(machine_word_t v) |
34912
|
|
|
|
|
|
|
{ |
34913
|
|
|
|
|
|
|
STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
34914
|
|
|
|
|
|
|
if (WORDBITS == 32) |
34915
|
|
|
|
|
|
|
return bsf32(v); |
34916
|
|
|
|
|
|
|
else |
34917
|
|
|
|
|
|
|
return bsf64(v); |
34918
|
|
|
|
|
|
|
} |
34919
|
|
|
|
|
|
|
|
34920
|
|
|
|
|
|
|
|
34921
|
|
|
|
|
|
|
#undef rbit32 |
34922
|
|
|
|
|
|
|
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
34923
|
|
|
|
|
|
|
(__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
34924
|
|
|
|
|
|
|
static forceinline u32 |
34925
|
|
|
|
|
|
|
rbit32(u32 v) |
34926
|
|
|
|
|
|
|
{ |
34927
|
|
|
|
|
|
|
__asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
34928
|
|
|
|
|
|
|
return v; |
34929
|
|
|
|
|
|
|
} |
34930
|
|
|
|
|
|
|
#define rbit32 rbit32 |
34931
|
|
|
|
|
|
|
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
34932
|
|
|
|
|
|
|
static forceinline u32 |
34933
|
|
|
|
|
|
|
rbit32(u32 v) |
34934
|
|
|
|
|
|
|
{ |
34935
|
|
|
|
|
|
|
__asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
34936
|
|
|
|
|
|
|
return v; |
34937
|
|
|
|
|
|
|
} |
34938
|
|
|
|
|
|
|
#define rbit32 rbit32 |
34939
|
|
|
|
|
|
|
#endif |
34940
|
|
|
|
|
|
|
|
34941
|
|
|
|
|
|
|
#endif |
34942
|
|
|
|
|
|
|
|
34943
|
|
|
|
|
|
|
|
34944
|
|
|
|
|
|
|
void *libdeflate_malloc(size_t size); |
34945
|
|
|
|
|
|
|
void libdeflate_free(void *ptr); |
34946
|
|
|
|
|
|
|
|
34947
|
|
|
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size); |
34948
|
|
|
|
|
|
|
void libdeflate_aligned_free(void *ptr); |
34949
|
|
|
|
|
|
|
|
34950
|
|
|
|
|
|
|
#ifdef FREESTANDING |
34951
|
|
|
|
|
|
|
|
34952
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n); |
34953
|
|
|
|
|
|
|
#define memset(s, c, n) __builtin_memset((s), (c), (n)) |
34954
|
|
|
|
|
|
|
|
34955
|
|
|
|
|
|
|
void *memcpy(void *dest, const void *src, size_t n); |
34956
|
|
|
|
|
|
|
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n)) |
34957
|
|
|
|
|
|
|
|
34958
|
|
|
|
|
|
|
void *memmove(void *dest, const void *src, size_t n); |
34959
|
|
|
|
|
|
|
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) |
34960
|
|
|
|
|
|
|
|
34961
|
|
|
|
|
|
|
int memcmp(const void *s1, const void *s2, size_t n); |
34962
|
|
|
|
|
|
|
#define memcmp(s1, s2, n) __builtin_memcmp((s1), (s2), (n)) |
34963
|
|
|
|
|
|
|
|
34964
|
|
|
|
|
|
|
#undef LIBDEFLATE_ENABLE_ASSERTIONS |
34965
|
|
|
|
|
|
|
#else |
34966
|
|
|
|
|
|
|
#include |
34967
|
|
|
|
|
|
|
#endif |
34968
|
|
|
|
|
|
|
|
34969
|
|
|
|
|
|
|
|
34970
|
|
|
|
|
|
|
#ifdef LIBDEFLATE_ENABLE_ASSERTIONS |
34971
|
|
|
|
|
|
|
void libdeflate_assertion_failed(const char *expr, const char *file, int line); |
34972
|
|
|
|
|
|
|
#define ASSERT(expr) { if (unlikely(!(expr))) \ |
34973
|
|
|
|
|
|
|
libdeflate_assertion_failed(#expr, __FILE__, __LINE__); } |
34974
|
|
|
|
|
|
|
#else |
34975
|
|
|
|
|
|
|
#define ASSERT(expr) (void)(expr) |
34976
|
|
|
|
|
|
|
#endif |
34977
|
|
|
|
|
|
|
|
34978
|
|
|
|
|
|
|
#define CONCAT_IMPL(a, b) a##b |
34979
|
|
|
|
|
|
|
#define CONCAT(a, b) CONCAT_IMPL(a, b) |
34980
|
|
|
|
|
|
|
#define ADD_SUFFIX(name) CONCAT(name, SUFFIX) |
34981
|
|
|
|
|
|
|
|
34982
|
|
|
|
|
|
|
#endif |
34983
|
|
|
|
|
|
|
|
34984
|
|
|
|
|
|
|
|
34985
|
|
|
|
|
|
|
#define HAVE_DYNAMIC_X86_CPU_FEATURES 0 |
34986
|
|
|
|
|
|
|
|
34987
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
34988
|
|
|
|
|
|
|
|
34989
|
|
|
|
|
|
|
#if COMPILER_SUPPORTS_TARGET_FUNCTION_ATTRIBUTE || defined(_MSC_VER) |
34990
|
|
|
|
|
|
|
# undef HAVE_DYNAMIC_X86_CPU_FEATURES |
34991
|
|
|
|
|
|
|
# define HAVE_DYNAMIC_X86_CPU_FEATURES 1 |
34992
|
|
|
|
|
|
|
#endif |
34993
|
|
|
|
|
|
|
|
34994
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_SSE2 0x00000001 |
34995
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_PCLMUL 0x00000002 |
34996
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX 0x00000004 |
34997
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_AVX2 0x00000008 |
34998
|
|
|
|
|
|
|
#define X86_CPU_FEATURE_BMI2 0x00000010 |
34999
|
|
|
|
|
|
|
|
35000
|
|
|
|
|
|
|
#define HAVE_SSE2(features) (HAVE_SSE2_NATIVE || ((features) & X86_CPU_FEATURE_SSE2)) |
35001
|
|
|
|
|
|
|
#define HAVE_PCLMUL(features) (HAVE_PCLMUL_NATIVE || ((features) & X86_CPU_FEATURE_PCLMUL)) |
35002
|
|
|
|
|
|
|
#define HAVE_AVX(features) (HAVE_AVX_NATIVE || ((features) & X86_CPU_FEATURE_AVX)) |
35003
|
|
|
|
|
|
|
#define HAVE_AVX2(features) (HAVE_AVX2_NATIVE || ((features) & X86_CPU_FEATURE_AVX2)) |
35004
|
|
|
|
|
|
|
#define HAVE_BMI2(features) (HAVE_BMI2_NATIVE || ((features) & X86_CPU_FEATURE_BMI2)) |
35005
|
|
|
|
|
|
|
|
35006
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
35007
|
|
|
|
|
|
|
#define X86_CPU_FEATURES_KNOWN 0x80000000 |
35008
|
|
|
|
|
|
|
extern volatile u32 libdeflate_x86_cpu_features; |
35009
|
|
|
|
|
|
|
|
35010
|
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void); |
35011
|
|
|
|
|
|
|
|
35012
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) |
35013
|
|
|
|
|
|
|
{ |
35014
|
|
|
|
|
|
|
if (libdeflate_x86_cpu_features == 0) |
35015
|
|
|
|
|
|
|
libdeflate_init_x86_cpu_features(); |
35016
|
|
|
|
|
|
|
return libdeflate_x86_cpu_features; |
35017
|
|
|
|
|
|
|
} |
35018
|
|
|
|
|
|
|
#else |
35019
|
|
|
|
|
|
|
static inline u32 get_x86_cpu_features(void) { return 0; } |
35020
|
|
|
|
|
|
|
#endif |
35021
|
|
|
|
|
|
|
|
35022
|
|
|
|
|
|
|
|
35023
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES && \ |
35024
|
|
|
|
|
|
|
(GCC_PREREQ(4, 9) || CLANG_PREREQ(3, 8, 7030000) || defined(_MSC_VER)) |
35025
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 1 |
35026
|
|
|
|
|
|
|
#else |
35027
|
|
|
|
|
|
|
# define HAVE_TARGET_INTRINSICS 0 |
35028
|
|
|
|
|
|
|
#endif |
35029
|
|
|
|
|
|
|
|
35030
|
|
|
|
|
|
|
|
35031
|
|
|
|
|
|
|
#if defined(__SSE2__) || \ |
35032
|
|
|
|
|
|
|
(defined(_MSC_VER) && \ |
35033
|
|
|
|
|
|
|
(defined(ARCH_X86_64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2))) |
35034
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 1 |
35035
|
|
|
|
|
|
|
#else |
35036
|
|
|
|
|
|
|
# define HAVE_SSE2_NATIVE 0 |
35037
|
|
|
|
|
|
|
#endif |
35038
|
|
|
|
|
|
|
#define HAVE_SSE2_INTRIN (HAVE_SSE2_NATIVE || HAVE_TARGET_INTRINSICS) |
35039
|
|
|
|
|
|
|
|
35040
|
|
|
|
|
|
|
|
35041
|
|
|
|
|
|
|
#if defined(__PCLMUL__) || (defined(_MSC_VER) && defined(__AVX2__)) |
35042
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 1 |
35043
|
|
|
|
|
|
|
#else |
35044
|
|
|
|
|
|
|
# define HAVE_PCLMUL_NATIVE 0 |
35045
|
|
|
|
|
|
|
#endif |
35046
|
|
|
|
|
|
|
#if HAVE_PCLMUL_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
35047
|
|
|
|
|
|
|
(GCC_PREREQ(4, 4) || CLANG_PREREQ(3, 2, 0) || \ |
35048
|
|
|
|
|
|
|
defined(_MSC_VER))) |
35049
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 1 |
35050
|
|
|
|
|
|
|
#else |
35051
|
|
|
|
|
|
|
# define HAVE_PCLMUL_INTRIN 0 |
35052
|
|
|
|
|
|
|
#endif |
35053
|
|
|
|
|
|
|
|
35054
|
|
|
|
|
|
|
|
35055
|
|
|
|
|
|
|
#ifdef __AVX__ |
35056
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 1 |
35057
|
|
|
|
|
|
|
#else |
35058
|
|
|
|
|
|
|
# define HAVE_AVX_NATIVE 0 |
35059
|
|
|
|
|
|
|
#endif |
35060
|
|
|
|
|
|
|
#if HAVE_AVX_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
35061
|
|
|
|
|
|
|
(GCC_PREREQ(4, 6) || CLANG_PREREQ(3, 0, 0) || \ |
35062
|
|
|
|
|
|
|
defined(_MSC_VER))) |
35063
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 1 |
35064
|
|
|
|
|
|
|
#else |
35065
|
|
|
|
|
|
|
# define HAVE_AVX_INTRIN 0 |
35066
|
|
|
|
|
|
|
#endif |
35067
|
|
|
|
|
|
|
|
35068
|
|
|
|
|
|
|
|
35069
|
|
|
|
|
|
|
#ifdef __AVX2__ |
35070
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 1 |
35071
|
|
|
|
|
|
|
#else |
35072
|
|
|
|
|
|
|
# define HAVE_AVX2_NATIVE 0 |
35073
|
|
|
|
|
|
|
#endif |
35074
|
|
|
|
|
|
|
#if HAVE_AVX2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
35075
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
35076
|
|
|
|
|
|
|
defined(_MSC_VER))) |
35077
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 1 |
35078
|
|
|
|
|
|
|
#else |
35079
|
|
|
|
|
|
|
# define HAVE_AVX2_INTRIN 0 |
35080
|
|
|
|
|
|
|
#endif |
35081
|
|
|
|
|
|
|
|
35082
|
|
|
|
|
|
|
|
35083
|
|
|
|
|
|
|
#if defined(__BMI2__) || (defined(_MSC_VER) && defined(__AVX2__)) |
35084
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 1 |
35085
|
|
|
|
|
|
|
#else |
35086
|
|
|
|
|
|
|
# define HAVE_BMI2_NATIVE 0 |
35087
|
|
|
|
|
|
|
#endif |
35088
|
|
|
|
|
|
|
#if HAVE_BMI2_NATIVE || (HAVE_TARGET_INTRINSICS && \ |
35089
|
|
|
|
|
|
|
(GCC_PREREQ(4, 7) || CLANG_PREREQ(3, 1, 0) || \ |
35090
|
|
|
|
|
|
|
defined(_MSC_VER))) |
35091
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 1 |
35092
|
|
|
|
|
|
|
#else |
35093
|
|
|
|
|
|
|
# define HAVE_BMI2_INTRIN 0 |
35094
|
|
|
|
|
|
|
#endif |
35095
|
|
|
|
|
|
|
|
35096
|
|
|
|
|
|
|
#endif |
35097
|
|
|
|
|
|
|
|
35098
|
|
|
|
|
|
|
#endif |
35099
|
|
|
|
|
|
|
|
35100
|
|
|
|
|
|
|
|
35101
|
|
|
|
|
|
|
#if HAVE_DYNAMIC_X86_CPU_FEATURES |
35102
|
|
|
|
|
|
|
|
35103
|
|
|
|
|
|
|
|
35104
|
|
|
|
|
|
|
#if defined(ARCH_X86_32) && defined(__PIC__) |
35105
|
|
|
|
|
|
|
# define EBX_CONSTRAINT "=&r" |
35106
|
|
|
|
|
|
|
#else |
35107
|
|
|
|
|
|
|
# define EBX_CONSTRAINT "=b" |
35108
|
|
|
|
|
|
|
#endif |
35109
|
|
|
|
|
|
|
|
35110
|
|
|
|
|
|
|
|
35111
|
|
|
|
|
|
|
static inline void |
35112
|
4
|
|
|
|
|
|
cpuid(u32 leaf, u32 subleaf, u32 *a, u32 *b, u32 *c, u32 *d) |
35113
|
|
|
|
|
|
|
{ |
35114
|
|
|
|
|
|
|
#ifdef _MSC_VER |
35115
|
|
|
|
|
|
|
int result[4]; |
35116
|
|
|
|
|
|
|
|
35117
|
|
|
|
|
|
|
__cpuidex(result, leaf, subleaf); |
35118
|
|
|
|
|
|
|
*a = result[0]; |
35119
|
|
|
|
|
|
|
*b = result[1]; |
35120
|
|
|
|
|
|
|
*c = result[2]; |
35121
|
|
|
|
|
|
|
*d = result[3]; |
35122
|
|
|
|
|
|
|
#else |
35123
|
4
|
|
|
|
|
|
__asm__(".ifnc %%ebx, %1; mov %%ebx, %1; .endif\n" |
35124
|
|
|
|
|
|
|
"cpuid \n" |
35125
|
|
|
|
|
|
|
".ifnc %%ebx, %1; xchg %%ebx, %1; .endif\n" |
35126
|
|
|
|
|
|
|
: "=a" (*a), EBX_CONSTRAINT (*b), "=c" (*c), "=d" (*d) |
35127
|
|
|
|
|
|
|
: "a" (leaf), "c" (subleaf)); |
35128
|
|
|
|
|
|
|
#endif |
35129
|
4
|
|
|
|
|
|
} |
35130
|
|
|
|
|
|
|
|
35131
|
|
|
|
|
|
|
|
35132
|
|
|
|
|
|
|
static inline u64 |
35133
|
0
|
|
|
|
|
|
read_xcr(u32 index) |
35134
|
|
|
|
|
|
|
{ |
35135
|
|
|
|
|
|
|
#ifdef _MSC_VER |
35136
|
|
|
|
|
|
|
return _xgetbv(index); |
35137
|
|
|
|
|
|
|
#else |
35138
|
|
|
|
|
|
|
u32 edx, eax; |
35139
|
|
|
|
|
|
|
|
35140
|
|
|
|
|
|
|
|
35141
|
0
|
|
|
|
|
|
__asm__ (".byte 0x0f, 0x01, 0xd0" : "=d" (edx), "=a" (eax) : "c" (index)); |
35142
|
|
|
|
|
|
|
|
35143
|
0
|
|
|
|
|
|
return ((u64)edx << 32) | eax; |
35144
|
|
|
|
|
|
|
#endif |
35145
|
|
|
|
|
|
|
} |
35146
|
|
|
|
|
|
|
|
35147
|
|
|
|
|
|
|
#undef BIT |
35148
|
|
|
|
|
|
|
#define BIT(nr) (1UL << (nr)) |
35149
|
|
|
|
|
|
|
|
35150
|
|
|
|
|
|
|
#define XCR0_BIT_SSE BIT(1) |
35151
|
|
|
|
|
|
|
#define XCR0_BIT_AVX BIT(2) |
35152
|
|
|
|
|
|
|
|
35153
|
|
|
|
|
|
|
#define IS_SET(reg, nr) ((reg) & BIT(nr)) |
35154
|
|
|
|
|
|
|
#define IS_ALL_SET(reg, mask) (((reg) & (mask)) == (mask)) |
35155
|
|
|
|
|
|
|
|
35156
|
|
|
|
|
|
|
static const struct cpu_feature x86_cpu_feature_table[] = { |
35157
|
|
|
|
|
|
|
{X86_CPU_FEATURE_SSE2, "sse2"}, |
35158
|
|
|
|
|
|
|
{X86_CPU_FEATURE_PCLMUL, "pclmul"}, |
35159
|
|
|
|
|
|
|
{X86_CPU_FEATURE_AVX, "avx"}, |
35160
|
|
|
|
|
|
|
{X86_CPU_FEATURE_AVX2, "avx2"}, |
35161
|
|
|
|
|
|
|
{X86_CPU_FEATURE_BMI2, "bmi2"}, |
35162
|
|
|
|
|
|
|
}; |
35163
|
|
|
|
|
|
|
|
35164
|
|
|
|
|
|
|
volatile u32 libdeflate_x86_cpu_features = 0; |
35165
|
|
|
|
|
|
|
|
35166
|
|
|
|
|
|
|
|
35167
|
2
|
|
|
|
|
|
void libdeflate_init_x86_cpu_features(void) |
35168
|
|
|
|
|
|
|
{ |
35169
|
2
|
|
|
|
|
|
u32 features = 0; |
35170
|
|
|
|
|
|
|
u32 dummy1, dummy2, dummy3, dummy4; |
35171
|
|
|
|
|
|
|
u32 max_function; |
35172
|
|
|
|
|
|
|
u32 features_1, features_2, features_3, features_4; |
35173
|
2
|
|
|
|
|
|
bool os_avx_support = false; |
35174
|
|
|
|
|
|
|
|
35175
|
|
|
|
|
|
|
|
35176
|
2
|
|
|
|
|
|
cpuid(0, 0, &max_function, &dummy2, &dummy3, &dummy4); |
35177
|
2
|
50
|
|
|
|
|
if (max_function < 1) |
35178
|
0
|
|
|
|
|
|
goto out; |
35179
|
|
|
|
|
|
|
|
35180
|
|
|
|
|
|
|
|
35181
|
2
|
|
|
|
|
|
cpuid(1, 0, &dummy1, &dummy2, &features_2, &features_1); |
35182
|
|
|
|
|
|
|
|
35183
|
2
|
50
|
|
|
|
|
if (IS_SET(features_1, 26)) |
35184
|
2
|
|
|
|
|
|
features |= X86_CPU_FEATURE_SSE2; |
35185
|
|
|
|
|
|
|
|
35186
|
2
|
50
|
|
|
|
|
if (IS_SET(features_2, 1)) |
35187
|
0
|
|
|
|
|
|
features |= X86_CPU_FEATURE_PCLMUL; |
35188
|
|
|
|
|
|
|
|
35189
|
2
|
50
|
|
|
|
|
if (IS_SET(features_2, 27)) { |
35190
|
0
|
|
|
|
|
|
u64 xcr0 = read_xcr(0); |
35191
|
|
|
|
|
|
|
|
35192
|
0
|
|
|
|
|
|
os_avx_support = IS_ALL_SET(xcr0, |
35193
|
|
|
|
|
|
|
XCR0_BIT_SSE | |
35194
|
|
|
|
|
|
|
XCR0_BIT_AVX); |
35195
|
|
|
|
|
|
|
} |
35196
|
|
|
|
|
|
|
|
35197
|
2
|
50
|
|
|
|
|
if (os_avx_support && IS_SET(features_2, 28)) |
|
|
0
|
|
|
|
|
|
35198
|
0
|
|
|
|
|
|
features |= X86_CPU_FEATURE_AVX; |
35199
|
|
|
|
|
|
|
|
35200
|
2
|
50
|
|
|
|
|
if (max_function < 7) |
35201
|
2
|
|
|
|
|
|
goto out; |
35202
|
|
|
|
|
|
|
|
35203
|
|
|
|
|
|
|
|
35204
|
0
|
|
|
|
|
|
cpuid(7, 0, &dummy1, &features_3, &features_4, &dummy4); |
35205
|
|
|
|
|
|
|
|
35206
|
0
|
0
|
|
|
|
|
if (os_avx_support && IS_SET(features_3, 5)) |
|
|
0
|
|
|
|
|
|
35207
|
0
|
|
|
|
|
|
features |= X86_CPU_FEATURE_AVX2; |
35208
|
|
|
|
|
|
|
|
35209
|
0
|
0
|
|
|
|
|
if (IS_SET(features_3, 8)) |
35210
|
0
|
|
|
|
|
|
features |= X86_CPU_FEATURE_BMI2; |
35211
|
|
|
|
|
|
|
|
35212
|
|
|
|
|
|
|
out: |
35213
|
2
|
|
|
|
|
|
disable_cpu_features_for_testing(&features, x86_cpu_feature_table, |
35214
|
|
|
|
|
|
|
ARRAY_LEN(x86_cpu_feature_table)); |
35215
|
|
|
|
|
|
|
|
35216
|
2
|
|
|
|
|
|
libdeflate_x86_cpu_features = features | X86_CPU_FEATURES_KNOWN; |
35217
|
2
|
|
|
|
|
|
} |
35218
|
|
|
|
|
|
|
|
35219
|
|
|
|
|
|
|
#endif |