/src/libdeflate/common_defs.h
Line | Count | Source |
1 | | /* |
2 | | * common_defs.h |
3 | | * |
4 | | * Copyright 2016 Eric Biggers |
5 | | * |
6 | | * Permission is hereby granted, free of charge, to any person |
7 | | * obtaining a copy of this software and associated documentation |
8 | | * files (the "Software"), to deal in the Software without |
9 | | * restriction, including without limitation the rights to use, |
10 | | * copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | | * copies of the Software, and to permit persons to whom the |
12 | | * Software is furnished to do so, subject to the following |
13 | | * conditions: |
14 | | * |
15 | | * The above copyright notice and this permission notice shall be |
16 | | * included in all copies or substantial portions of the Software. |
17 | | * |
18 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
19 | | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
20 | | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
21 | | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
22 | | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
23 | | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
24 | | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
25 | | * OTHER DEALINGS IN THE SOFTWARE. |
26 | | */ |
27 | | |
28 | | #ifndef COMMON_DEFS_H |
29 | | #define COMMON_DEFS_H |
30 | | |
31 | | #include "libdeflate.h" |
32 | | |
33 | | #include <stdbool.h> |
34 | | #include <stddef.h> /* for size_t */ |
35 | | #include <stdint.h> |
36 | | #ifdef _MSC_VER |
37 | | # include <intrin.h> /* for _BitScan*() and other intrinsics */ |
38 | | # include <stdlib.h> /* for _byteswap_*() */ |
39 | | /* Disable MSVC warnings that are expected. */ |
40 | | /* /W2 */ |
41 | | # pragma warning(disable : 4146) /* unary minus on unsigned type */ |
42 | | /* /W3 */ |
43 | | # pragma warning(disable : 4018) /* signed/unsigned mismatch */ |
44 | | # pragma warning(disable : 4244) /* possible loss of data */ |
45 | | # pragma warning(disable : 4267) /* possible loss of precision */ |
46 | | # pragma warning(disable : 4310) /* cast truncates constant value */ |
47 | | /* /W4 */ |
48 | | # pragma warning(disable : 4100) /* unreferenced formal parameter */ |
49 | | # pragma warning(disable : 4127) /* conditional expression is constant */ |
50 | | # pragma warning(disable : 4189) /* local variable initialized but not referenced */ |
51 | | # pragma warning(disable : 4232) /* nonstandard extension used */ |
52 | | # pragma warning(disable : 4245) /* conversion from 'int' to 'unsigned int' */ |
53 | | # pragma warning(disable : 4295) /* array too small to include terminating null */ |
54 | | # pragma warning(disable : 4324) /* structure padded due to alignment specifier */ |
55 | | #endif |
56 | | #ifndef FREESTANDING |
57 | | # include <string.h> /* for memcpy() */ |
58 | | #endif |
59 | | |
60 | | /* ========================================================================== */ |
61 | | /* Target architecture */ |
62 | | /* ========================================================================== */ |
63 | | |
64 | | /* If possible, define a compiler-independent ARCH_* macro. */ |
65 | | #undef ARCH_X86_64 |
66 | | #undef ARCH_X86_32 |
67 | | #undef ARCH_ARM64 |
68 | | #undef ARCH_ARM32 |
69 | | #undef ARCH_RISCV |
70 | | #ifdef _MSC_VER |
71 | | /* Way too many things are broken in ARM64EC to pretend that it is x86_64. */ |
72 | | # if defined(_M_X64) && !defined(_M_ARM64EC) |
73 | | # define ARCH_X86_64 |
74 | | # elif defined(_M_IX86) |
75 | | # define ARCH_X86_32 |
76 | | # elif defined(_M_ARM64) |
77 | | # define ARCH_ARM64 |
78 | | # elif defined(_M_ARM) |
79 | | # define ARCH_ARM32 |
80 | | # endif |
81 | | #else |
82 | | # if defined(__x86_64__) |
83 | | # define ARCH_X86_64 |
84 | | # elif defined(__i386__) |
85 | | # define ARCH_X86_32 |
86 | | # elif defined(__aarch64__) |
87 | | # define ARCH_ARM64 |
88 | | # elif defined(__arm__) |
89 | | # define ARCH_ARM32 |
90 | | # elif defined(__riscv) |
91 | | # define ARCH_RISCV |
92 | | # endif |
93 | | #endif |
94 | | |
95 | | /* ========================================================================== */ |
96 | | /* Type definitions */ |
97 | | /* ========================================================================== */ |
98 | | |
99 | | /* Fixed-width integer types */ |
100 | | typedef uint8_t u8; |
101 | | typedef uint16_t u16; |
102 | | typedef uint32_t u32; |
103 | | typedef uint64_t u64; |
104 | | typedef int8_t s8; |
105 | | typedef int16_t s16; |
106 | | typedef int32_t s32; |
107 | | typedef int64_t s64; |
108 | | |
109 | | /* ssize_t, if not available in <sys/types.h> */ |
110 | | #ifdef _MSC_VER |
111 | | # ifdef _WIN64 |
112 | | typedef long long ssize_t; |
113 | | # else |
114 | | typedef long ssize_t; |
115 | | # endif |
116 | | #endif |
117 | | |
118 | | /* |
119 | | * Word type of the target architecture. Use 'size_t' instead of |
120 | | * 'unsigned long' to account for platforms such as Windows that use 32-bit |
121 | | * 'unsigned long' on 64-bit architectures. |
122 | | */ |
123 | | typedef size_t machine_word_t; |
124 | | |
125 | | /* Number of bytes in a word */ |
126 | 643k | #define WORDBYTES ((int)sizeof(machine_word_t)) |
127 | | |
128 | | /* Number of bits in a word */ |
129 | 173k | #define WORDBITS (8 * WORDBYTES) |
130 | | |
131 | | /* ========================================================================== */ |
132 | | /* Optional compiler features */ |
133 | | /* ========================================================================== */ |
134 | | |
135 | | /* Compiler version checks. Only use when absolutely necessary. */ |
136 | | #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) |
137 | | # define GCC_PREREQ(major, minor) \ |
138 | | (__GNUC__ > (major) || \ |
139 | | (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
140 | | # if !GCC_PREREQ(4, 9) |
141 | | # error "gcc versions older than 4.9 are no longer supported" |
142 | | # endif |
143 | | #else |
144 | | # define GCC_PREREQ(major, minor) 0 |
145 | | #endif |
146 | | #ifdef __clang__ |
147 | | # ifdef __apple_build_version__ |
148 | | # define CLANG_PREREQ(major, minor, apple_version) \ |
149 | | (__apple_build_version__ >= (apple_version)) |
150 | | # else |
151 | | # define CLANG_PREREQ(major, minor, apple_version) \ |
152 | | (__clang_major__ > (major) || \ |
153 | | (__clang_major__ == (major) && __clang_minor__ >= (minor))) |
154 | | # endif |
155 | | # if !CLANG_PREREQ(3, 9, 8000000) |
156 | | # error "clang versions older than 3.9 are no longer supported" |
157 | | # endif |
158 | | #else |
159 | | # define CLANG_PREREQ(major, minor, apple_version) 0 |
160 | | #endif |
161 | | #ifdef _MSC_VER |
162 | | # define MSVC_PREREQ(version) (_MSC_VER >= (version)) |
163 | | # if !MSVC_PREREQ(1928) |
164 | | # error "MSVC versions older than Visual Studio 2019 v16.8 are no longer supported" |
165 | | # endif |
166 | | #else |
167 | | # define MSVC_PREREQ(version) 0 |
168 | | #endif |
169 | | |
170 | | /* |
171 | | * __has_attribute(attribute) - check whether the compiler supports the given |
172 | | * attribute (and also supports doing the check in the first place). Mostly |
173 | | * useful just for clang, since gcc didn't add this macro until gcc 5. |
174 | | */ |
175 | | #ifndef __has_attribute |
176 | | # define __has_attribute(attribute) 0 |
177 | | #endif |
178 | | |
179 | | /* |
180 | | * __has_builtin(builtin) - check whether the compiler supports the given |
181 | | * builtin (and also supports doing the check in the first place). Mostly |
182 | | * useful just for clang, since gcc didn't add this macro until gcc 10. |
183 | | */ |
184 | | #ifndef __has_builtin |
185 | | # define __has_builtin(builtin) 0 |
186 | | #endif |
187 | | |
188 | | /* inline - suggest that a function be inlined */ |
189 | | #ifdef _MSC_VER |
190 | | # define inline __inline |
191 | | #endif /* else assume 'inline' is usable as-is */ |
192 | | |
193 | | /* forceinline - force a function to be inlined, if possible */ |
194 | | #if defined(__GNUC__) || __has_attribute(always_inline) |
195 | | # define forceinline inline __attribute__((always_inline)) |
196 | | #elif defined(_MSC_VER) |
197 | | # define forceinline __forceinline |
198 | | #else |
199 | | # define forceinline inline |
200 | | #endif |
201 | | |
202 | | /* MAYBE_UNUSED - mark a function or variable as maybe unused */ |
203 | | #if defined(__GNUC__) || __has_attribute(unused) |
204 | | # define MAYBE_UNUSED __attribute__((unused)) |
205 | | #else |
206 | | # define MAYBE_UNUSED |
207 | | #endif |
208 | | |
209 | | /* NORETURN - mark a function as never returning, e.g. due to calling abort() */ |
210 | | #if defined(__GNUC__) || __has_attribute(noreturn) |
211 | | # define NORETURN __attribute__((noreturn)) |
212 | | #else |
213 | | # define NORETURN |
214 | | #endif |
215 | | |
216 | | /* likely(expr) - hint that an expression is usually true */ |
217 | | #if defined(__GNUC__) || __has_builtin(__builtin_expect) |
218 | 183k | # define likely(expr) __builtin_expect(!!(expr), 1) |
219 | | #else |
220 | | # define likely(expr) (expr) |
221 | | #endif |
222 | | |
223 | | /* unlikely(expr) - hint that an expression is usually false */ |
224 | | #if defined(__GNUC__) || __has_builtin(__builtin_expect) |
225 | 829k | # define unlikely(expr) __builtin_expect(!!(expr), 0) |
226 | | #else |
227 | | # define unlikely(expr) (expr) |
228 | | #endif |
229 | | |
230 | | /* prefetchr(addr) - prefetch into L1 cache for read */ |
231 | | #undef prefetchr |
232 | | #if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
233 | | # define prefetchr(addr) __builtin_prefetch((addr), 0) |
234 | | #elif defined(_MSC_VER) |
235 | | # if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
236 | | # define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0) |
237 | | # elif defined(ARCH_ARM64) |
238 | | # define prefetchr(addr) __prefetch2((addr), 0x00 /* prfop=PLDL1KEEP */) |
239 | | # elif defined(ARCH_ARM32) |
240 | | # define prefetchr(addr) __prefetch(addr) |
241 | | # endif |
242 | | #endif |
243 | | #ifndef prefetchr |
244 | | # define prefetchr(addr) |
245 | | #endif |
246 | | |
247 | | /* prefetchw(addr) - prefetch into L1 cache for write */ |
248 | | #undef prefetchw |
249 | | #if defined(__GNUC__) || __has_builtin(__builtin_prefetch) |
250 | 0 | # define prefetchw(addr) __builtin_prefetch((addr), 1) |
251 | | #elif defined(_MSC_VER) |
252 | | # if defined(ARCH_X86_32) || defined(ARCH_X86_64) |
253 | | # define prefetchw(addr) _m_prefetchw(addr) |
254 | | # elif defined(ARCH_ARM64) |
255 | | # define prefetchw(addr) __prefetch2((addr), 0x10 /* prfop=PSTL1KEEP */) |
256 | | # elif defined(ARCH_ARM32) |
257 | | # define prefetchw(addr) __prefetchw(addr) |
258 | | # endif |
259 | | #endif |
260 | | #ifndef prefetchw |
261 | | # define prefetchw(addr) |
262 | | #endif |
263 | | |
264 | | /* |
265 | | * _aligned_attribute(n) - declare that the annotated variable, or variables of |
266 | | * the annotated type, must be aligned on n-byte boundaries. |
267 | | */ |
268 | | #undef _aligned_attribute |
269 | | #if defined(__GNUC__) || __has_attribute(aligned) |
270 | | # define _aligned_attribute(n) __attribute__((aligned(n))) |
271 | | #elif defined(_MSC_VER) |
272 | | # define _aligned_attribute(n) __declspec(align(n)) |
273 | | #endif |
274 | | |
275 | | /* |
276 | | * _target_attribute(attrs) - override the compilation target for a function. |
277 | | * |
278 | | * This accepts one or more comma-separated suffixes to the -m prefix jointly |
279 | | * forming the name of a machine-dependent option. On gcc-like compilers, this |
280 | | * enables codegen for the given targets, including arbitrary compiler-generated |
281 | | * code as well as the corresponding intrinsics. On other compilers this macro |
282 | | * expands to nothing, though MSVC allows intrinsics to be used anywhere anyway. |
283 | | */ |
284 | | #if defined(__GNUC__) || __has_attribute(target) |
285 | | # define _target_attribute(attrs) __attribute__((target(attrs))) |
286 | | #else |
287 | | # define _target_attribute(attrs) |
288 | | #endif |
289 | | |
290 | | /* ========================================================================== */ |
291 | | /* Miscellaneous macros */ |
292 | | /* ========================================================================== */ |
293 | | |
294 | 6 | #define ARRAY_LEN(A) (sizeof(A) / sizeof((A)[0])) |
295 | 18.6k | #define MIN(a, b) ((a) <= (b) ? (a) : (b)) |
296 | 0 | #define MAX(a, b) ((a) >= (b) ? (a) : (b)) |
297 | | #define MAX3(a, b, c) MAX(MAX((a), (b)), (c)) |
298 | 0 | #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) |
299 | 677k | #define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
300 | 0 | #define ALIGN(n, a) (((n) + (a) - 1) & ~((a) - 1)) |
301 | | #define ROUND_UP(n, d) ((d) * DIV_ROUND_UP((n), (d))) |
302 | | |
303 | | /* ========================================================================== */ |
304 | | /* Endianness handling */ |
305 | | /* ========================================================================== */ |
306 | | |
307 | | /* |
308 | | * CPU_IS_LITTLE_ENDIAN() - 1 if the CPU is little endian, or 0 if it is big |
309 | | * endian. When possible this is a compile-time macro that can be used in |
310 | | * preprocessor conditionals. As a fallback, a generic method is used that |
311 | | * can't be used in preprocessor conditionals but should still be optimized out. |
312 | | */ |
313 | | #if defined(__BYTE_ORDER__) /* gcc v4.6+ and clang */ |
314 | 185k | # define CPU_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
315 | | #elif defined(_MSC_VER) |
316 | | # define CPU_IS_LITTLE_ENDIAN() true |
317 | | #else |
318 | | static forceinline bool CPU_IS_LITTLE_ENDIAN(void) |
319 | | { |
320 | | union { |
321 | | u32 w; |
322 | | u8 b; |
323 | | } u; |
324 | | |
325 | | u.w = 1; |
326 | | return u.b; |
327 | | } |
328 | | #endif |
329 | | |
330 | | /* bswap16(v) - swap the bytes of a 16-bit integer */ |
331 | | static forceinline u16 bswap16(u16 v) |
332 | 8.80k | { |
333 | 8.80k | #if defined(__GNUC__) || __has_builtin(__builtin_bswap16) |
334 | 8.80k | return __builtin_bswap16(v); |
335 | | #elif defined(_MSC_VER) |
336 | | return _byteswap_ushort(v); |
337 | | #else |
338 | | return (v << 8) | (v >> 8); |
339 | | #endif |
340 | 8.80k | } Unexecuted instantiation: deflate_compress.c:bswap16 Unexecuted instantiation: utils.c:bswap16 Unexecuted instantiation: cpu_features.c:bswap16 Unexecuted instantiation: deflate_decompress.c:bswap16 Unexecuted instantiation: zlib_compress.c:bswap16 Unexecuted instantiation: adler32.c:bswap16 zlib_decompress.c:bswap16 Line | Count | Source | 332 | 8.80k | { | 333 | 8.80k | #if defined(__GNUC__) || __has_builtin(__builtin_bswap16) | 334 | 8.80k | return __builtin_bswap16(v); | 335 | | #elif defined(_MSC_VER) | 336 | | return _byteswap_ushort(v); | 337 | | #else | 338 | | return (v << 8) | (v >> 8); | 339 | | #endif | 340 | 8.80k | } |
|
341 | | |
342 | | /* bswap32(v) - swap the bytes of a 32-bit integer */ |
343 | | static forceinline u32 bswap32(u32 v) |
344 | 1.77k | { |
345 | 1.77k | #if defined(__GNUC__) || __has_builtin(__builtin_bswap32) |
346 | 1.77k | return __builtin_bswap32(v); |
347 | | #elif defined(_MSC_VER) |
348 | | return _byteswap_ulong(v); |
349 | | #else |
350 | | return ((v & 0x000000FF) << 24) | |
351 | | ((v & 0x0000FF00) << 8) | |
352 | | ((v & 0x00FF0000) >> 8) | |
353 | | ((v & 0xFF000000) >> 24); |
354 | | #endif |
355 | 1.77k | } Unexecuted instantiation: deflate_compress.c:bswap32 Unexecuted instantiation: utils.c:bswap32 Unexecuted instantiation: cpu_features.c:bswap32 Unexecuted instantiation: deflate_decompress.c:bswap32 Unexecuted instantiation: zlib_compress.c:bswap32 Unexecuted instantiation: adler32.c:bswap32 zlib_decompress.c:bswap32 Line | Count | Source | 344 | 1.77k | { | 345 | 1.77k | #if defined(__GNUC__) || __has_builtin(__builtin_bswap32) | 346 | 1.77k | return __builtin_bswap32(v); | 347 | | #elif defined(_MSC_VER) | 348 | | return _byteswap_ulong(v); | 349 | | #else | 350 | | return ((v & 0x000000FF) << 24) | | 351 | | ((v & 0x0000FF00) << 8) | | 352 | | ((v & 0x00FF0000) >> 8) | | 353 | | ((v & 0xFF000000) >> 24); | 354 | | #endif | 355 | 1.77k | } |
|
356 | | |
357 | | /* bswap64(v) - swap the bytes of a 64-bit integer */ |
358 | | static forceinline u64 bswap64(u64 v) |
359 | 0 | { |
360 | 0 | #if defined(__GNUC__) || __has_builtin(__builtin_bswap64) |
361 | 0 | return __builtin_bswap64(v); |
362 | 0 | #elif defined(_MSC_VER) |
363 | 0 | return _byteswap_uint64(v); |
364 | 0 | #else |
365 | 0 | return ((v & 0x00000000000000FF) << 56) | |
366 | 0 | ((v & 0x000000000000FF00) << 40) | |
367 | 0 | ((v & 0x0000000000FF0000) << 24) | |
368 | 0 | ((v & 0x00000000FF000000) << 8) | |
369 | 0 | ((v & 0x000000FF00000000) >> 8) | |
370 | 0 | ((v & 0x0000FF0000000000) >> 24) | |
371 | 0 | ((v & 0x00FF000000000000) >> 40) | |
372 | 0 | ((v & 0xFF00000000000000) >> 56); |
373 | 0 | #endif |
374 | 0 | } Unexecuted instantiation: deflate_compress.c:bswap64 Unexecuted instantiation: utils.c:bswap64 Unexecuted instantiation: cpu_features.c:bswap64 Unexecuted instantiation: deflate_decompress.c:bswap64 Unexecuted instantiation: zlib_compress.c:bswap64 Unexecuted instantiation: adler32.c:bswap64 Unexecuted instantiation: zlib_decompress.c:bswap64 |
375 | | |
376 | 794 | #define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v)) |
377 | 0 | #define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v)) |
378 | 173k | #define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v)) |
379 | 8.80k | #define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v)) |
380 | 1.77k | #define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v)) |
381 | | #define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v)) |
382 | | |
383 | | /* ========================================================================== */ |
384 | | /* Unaligned memory accesses */ |
385 | | /* ========================================================================== */ |
386 | | |
387 | | /* |
388 | | * UNALIGNED_ACCESS_IS_FAST() - 1 if unaligned memory accesses can be performed |
389 | | * efficiently on the target platform, otherwise 0. |
390 | | */ |
391 | | #if (defined(__GNUC__) || defined(__clang__)) && \ |
392 | | (defined(ARCH_X86_64) || defined(ARCH_X86_32) || \ |
393 | | defined(__ARM_FEATURE_UNALIGNED) || \ |
394 | | defined(__powerpc64__) || defined(__powerpc__) || defined(__POWERPC__) || \ |
395 | | defined(__riscv_misaligned_fast) || \ |
396 | | /* |
397 | | * For all compilation purposes, WebAssembly behaves like any other CPU |
398 | | * instruction set. Even though WebAssembly engine might be running on |
399 | | * top of different actual CPU architectures, the WebAssembly spec |
400 | | * itself permits unaligned access and it will be fast on most of those |
401 | | * platforms, and simulated at the engine level on others, so it's |
402 | | * worth treating it as a CPU architecture with fast unaligned access. |
403 | | */ defined(__wasm__)) |
404 | 1.37M | # define UNALIGNED_ACCESS_IS_FAST 1 |
405 | | #elif defined(_MSC_VER) |
406 | | # define UNALIGNED_ACCESS_IS_FAST 1 |
407 | | #else |
408 | | # define UNALIGNED_ACCESS_IS_FAST 0 |
409 | | #endif |
410 | | |
411 | | /* |
412 | | * Implementing unaligned memory accesses using memcpy() is portable, and it |
413 | | * usually gets optimized appropriately by modern compilers. I.e., each |
414 | | * memcpy() of 1, 2, 4, or WORDBYTES bytes gets compiled to a load or store |
415 | | * instruction, not to an actual function call. |
416 | | * |
417 | | * We no longer use the "packed struct" approach to unaligned accesses, as that |
418 | | * is nonstandard, has unclear semantics, and doesn't receive enough testing |
419 | | * (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94994). |
420 | | * |
421 | | * arm32 with __ARM_FEATURE_UNALIGNED in gcc 5 and earlier is a known exception |
422 | | * where memcpy() generates inefficient code |
423 | | * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67366). However, we no longer |
424 | | * consider that one case important enough to maintain different code for. |
425 | | * If you run into it, please just use a newer version of gcc (or use clang). |
426 | | */ |
427 | | |
428 | | #ifdef FREESTANDING |
429 | | # define MEMCOPY __builtin_memcpy |
430 | | #else |
431 | 3.68M | # define MEMCOPY memcpy |
432 | | #endif |
433 | | |
434 | | /* Unaligned loads and stores without endianness conversion */ |
435 | | |
436 | | #define DEFINE_UNALIGNED_TYPE(type) \ |
437 | | static forceinline type \ |
438 | 1.86M | load_##type##_unaligned(const void *p) \ |
439 | 1.86M | { \ |
440 | 1.86M | type v; \ |
441 | 1.86M | \ |
442 | 1.86M | MEMCOPY(&v, p, sizeof(v)); \ |
443 | 1.86M | return v; \ |
444 | 1.86M | } \ Unexecuted instantiation: deflate_compress.c:load_u32_unaligned Unexecuted instantiation: deflate_compress.c:load_machine_word_t_unaligned Unexecuted instantiation: deflate_compress.c:load_u16_unaligned Unexecuted instantiation: deflate_compress.c:load_u64_unaligned Unexecuted instantiation: utils.c:load_u16_unaligned Unexecuted instantiation: utils.c:load_u32_unaligned Unexecuted instantiation: utils.c:load_u64_unaligned Unexecuted instantiation: utils.c:load_machine_word_t_unaligned Unexecuted instantiation: cpu_features.c:load_u16_unaligned Unexecuted instantiation: cpu_features.c:load_u32_unaligned Unexecuted instantiation: cpu_features.c:load_u64_unaligned Unexecuted instantiation: cpu_features.c:load_machine_word_t_unaligned deflate_decompress.c:load_u64_unaligned Line | Count | Source | 438 | 173k | load_##type##_unaligned(const void *p) \ | 439 | 173k | { \ | 440 | 173k | type v; \ | 441 | 173k | \ | 442 | 173k | MEMCOPY(&v, p, sizeof(v)); \ | 443 | 173k | return v; \ | 444 | 173k | } \ |
deflate_decompress.c:load_u16_unaligned Line | Count | Source | 438 | 794 | load_##type##_unaligned(const void *p) \ | 439 | 794 | { \ | 440 | 794 | type v; \ | 441 | 794 | \ | 442 | 794 | MEMCOPY(&v, p, sizeof(v)); \ | 443 | 794 | return v; \ | 444 | 794 | } \ |
deflate_decompress.c:load_machine_word_t_unaligned Line | Count | Source | 438 | 1.67M | load_##type##_unaligned(const void *p) \ | 439 | 1.67M | { \ | 440 | 1.67M | type v; \ | 441 | 1.67M | \ | 442 | 1.67M | MEMCOPY(&v, p, sizeof(v)); \ | 443 | 1.67M | return v; \ | 444 | 1.67M | } \ |
Unexecuted instantiation: deflate_decompress.c:load_u32_unaligned Unexecuted instantiation: zlib_compress.c:load_u16_unaligned Unexecuted instantiation: zlib_compress.c:load_u32_unaligned Unexecuted instantiation: zlib_compress.c:load_u64_unaligned Unexecuted instantiation: zlib_compress.c:load_machine_word_t_unaligned Unexecuted instantiation: adler32.c:load_u16_unaligned Unexecuted instantiation: adler32.c:load_u32_unaligned Unexecuted instantiation: adler32.c:load_u64_unaligned Unexecuted instantiation: adler32.c:load_machine_word_t_unaligned zlib_decompress.c:load_u16_unaligned Line | Count | Source | 438 | 8.80k | load_##type##_unaligned(const void *p) \ | 439 | 8.80k | { \ | 440 | 8.80k | type v; \ | 441 | 8.80k | \ | 442 | 8.80k | MEMCOPY(&v, p, sizeof(v)); \ | 443 | 8.80k | return v; \ | 444 | 8.80k | } \ |
zlib_decompress.c:load_u32_unaligned Line | Count | Source | 438 | 1.77k | load_##type##_unaligned(const void *p) \ | 439 | 1.77k | { \ | 440 | 1.77k | type v; \ | 441 | 1.77k | \ | 442 | 1.77k | MEMCOPY(&v, p, sizeof(v)); \ | 443 | 1.77k | return v; \ | 444 | 1.77k | } \ |
Unexecuted instantiation: zlib_decompress.c:load_u64_unaligned Unexecuted instantiation: zlib_decompress.c:load_machine_word_t_unaligned |
445 | | \ |
446 | | static forceinline void \ |
447 | 1.82M | store_##type##_unaligned(type v, void *p) \ |
448 | 1.82M | { \ |
449 | 1.82M | MEMCOPY(p, &v, sizeof(v)); \ |
450 | 1.82M | } Unexecuted instantiation: deflate_compress.c:store_u16_unaligned Unexecuted instantiation: deflate_compress.c:store_u64_unaligned Unexecuted instantiation: deflate_compress.c:store_u32_unaligned Unexecuted instantiation: deflate_compress.c:store_machine_word_t_unaligned Unexecuted instantiation: utils.c:store_u16_unaligned Unexecuted instantiation: utils.c:store_u32_unaligned Unexecuted instantiation: utils.c:store_u64_unaligned Unexecuted instantiation: utils.c:store_machine_word_t_unaligned Unexecuted instantiation: cpu_features.c:store_u16_unaligned Unexecuted instantiation: cpu_features.c:store_u32_unaligned Unexecuted instantiation: cpu_features.c:store_u64_unaligned Unexecuted instantiation: cpu_features.c:store_machine_word_t_unaligned deflate_decompress.c:store_machine_word_t_unaligned Line | Count | Source | 447 | 1.82M | store_##type##_unaligned(type v, void *p) \ | 448 | 1.82M | { \ | 449 | 1.82M | MEMCOPY(p, &v, sizeof(v)); \ | 450 | 1.82M | } |
Unexecuted instantiation: deflate_decompress.c:store_u16_unaligned Unexecuted instantiation: deflate_decompress.c:store_u32_unaligned Unexecuted instantiation: deflate_decompress.c:store_u64_unaligned Unexecuted instantiation: zlib_compress.c:store_u16_unaligned Unexecuted instantiation: zlib_compress.c:store_u32_unaligned Unexecuted instantiation: zlib_compress.c:store_u64_unaligned Unexecuted instantiation: zlib_compress.c:store_machine_word_t_unaligned Unexecuted instantiation: adler32.c:store_u16_unaligned Unexecuted instantiation: adler32.c:store_u32_unaligned Unexecuted instantiation: adler32.c:store_u64_unaligned Unexecuted instantiation: adler32.c:store_machine_word_t_unaligned Unexecuted instantiation: zlib_decompress.c:store_u16_unaligned Unexecuted instantiation: zlib_decompress.c:store_u32_unaligned Unexecuted instantiation: zlib_decompress.c:store_u64_unaligned Unexecuted instantiation: zlib_decompress.c:store_machine_word_t_unaligned |
451 | | |
452 | | DEFINE_UNALIGNED_TYPE(u16) |
453 | | DEFINE_UNALIGNED_TYPE(u32) |
454 | | DEFINE_UNALIGNED_TYPE(u64) |
455 | | DEFINE_UNALIGNED_TYPE(machine_word_t) |
456 | | |
457 | | #undef MEMCOPY |
458 | | |
459 | 1.67M | #define load_word_unaligned load_machine_word_t_unaligned |
460 | 1.82M | #define store_word_unaligned store_machine_word_t_unaligned |
461 | | |
462 | | /* Unaligned loads with endianness conversion */ |
463 | | |
464 | | static forceinline u16 |
465 | | get_unaligned_le16(const u8 *p) |
466 | 794 | { |
467 | 794 | if (UNALIGNED_ACCESS_IS_FAST) |
468 | 794 | return le16_bswap(load_u16_unaligned(p)); |
469 | 0 | else |
470 | 0 | return ((u16)p[1] << 8) | p[0]; |
471 | 794 | } Unexecuted instantiation: deflate_compress.c:get_unaligned_le16 Unexecuted instantiation: utils.c:get_unaligned_le16 Unexecuted instantiation: cpu_features.c:get_unaligned_le16 deflate_decompress.c:get_unaligned_le16 Line | Count | Source | 466 | 794 | { | 467 | 794 | if (UNALIGNED_ACCESS_IS_FAST) | 468 | 794 | return le16_bswap(load_u16_unaligned(p)); | 469 | 0 | else | 470 | 0 | return ((u16)p[1] << 8) | p[0]; | 471 | 794 | } |
Unexecuted instantiation: zlib_compress.c:get_unaligned_le16 Unexecuted instantiation: adler32.c:get_unaligned_le16 Unexecuted instantiation: zlib_decompress.c:get_unaligned_le16 |
472 | | |
473 | | static forceinline u16 |
474 | | get_unaligned_be16(const u8 *p) |
475 | 8.80k | { |
476 | 8.80k | if (UNALIGNED_ACCESS_IS_FAST) |
477 | 8.80k | return be16_bswap(load_u16_unaligned(p)); |
478 | 0 | else |
479 | 0 | return ((u16)p[0] << 8) | p[1]; |
480 | 8.80k | } Unexecuted instantiation: deflate_compress.c:get_unaligned_be16 Unexecuted instantiation: utils.c:get_unaligned_be16 Unexecuted instantiation: cpu_features.c:get_unaligned_be16 Unexecuted instantiation: deflate_decompress.c:get_unaligned_be16 Unexecuted instantiation: zlib_compress.c:get_unaligned_be16 Unexecuted instantiation: adler32.c:get_unaligned_be16 zlib_decompress.c:get_unaligned_be16 Line | Count | Source | 475 | 8.80k | { | 476 | 8.80k | if (UNALIGNED_ACCESS_IS_FAST) | 477 | 8.80k | return be16_bswap(load_u16_unaligned(p)); | 478 | 0 | else | 479 | 0 | return ((u16)p[0] << 8) | p[1]; | 480 | 8.80k | } |
|
481 | | |
482 | | static forceinline u32 |
483 | | get_unaligned_le32(const u8 *p) |
484 | 0 | { |
485 | 0 | if (UNALIGNED_ACCESS_IS_FAST) |
486 | 0 | return le32_bswap(load_u32_unaligned(p)); |
487 | 0 | else |
488 | 0 | return ((u32)p[3] << 24) | ((u32)p[2] << 16) | |
489 | 0 | ((u32)p[1] << 8) | p[0]; |
490 | 0 | } Unexecuted instantiation: deflate_compress.c:get_unaligned_le32 Unexecuted instantiation: utils.c:get_unaligned_le32 Unexecuted instantiation: cpu_features.c:get_unaligned_le32 Unexecuted instantiation: deflate_decompress.c:get_unaligned_le32 Unexecuted instantiation: zlib_compress.c:get_unaligned_le32 Unexecuted instantiation: adler32.c:get_unaligned_le32 Unexecuted instantiation: zlib_decompress.c:get_unaligned_le32 |
491 | | |
492 | | static forceinline u32 |
493 | | get_unaligned_be32(const u8 *p) |
494 | 1.77k | { |
495 | 1.77k | if (UNALIGNED_ACCESS_IS_FAST) |
496 | 1.77k | return be32_bswap(load_u32_unaligned(p)); |
497 | 0 | else |
498 | 0 | return ((u32)p[0] << 24) | ((u32)p[1] << 16) | |
499 | 0 | ((u32)p[2] << 8) | p[3]; |
500 | 1.77k | } Unexecuted instantiation: deflate_compress.c:get_unaligned_be32 Unexecuted instantiation: utils.c:get_unaligned_be32 Unexecuted instantiation: cpu_features.c:get_unaligned_be32 Unexecuted instantiation: deflate_decompress.c:get_unaligned_be32 Unexecuted instantiation: zlib_compress.c:get_unaligned_be32 Unexecuted instantiation: adler32.c:get_unaligned_be32 zlib_decompress.c:get_unaligned_be32 Line | Count | Source | 494 | 1.77k | { | 495 | 1.77k | if (UNALIGNED_ACCESS_IS_FAST) | 496 | 1.77k | return be32_bswap(load_u32_unaligned(p)); | 497 | 0 | else | 498 | 0 | return ((u32)p[0] << 24) | ((u32)p[1] << 16) | | 499 | 0 | ((u32)p[2] << 8) | p[3]; | 500 | 1.77k | } |
|
501 | | |
502 | | static forceinline u64 |
503 | | get_unaligned_le64(const u8 *p) |
504 | 173k | { |
505 | 173k | if (UNALIGNED_ACCESS_IS_FAST) |
506 | 173k | return le64_bswap(load_u64_unaligned(p)); |
507 | 0 | else |
508 | 0 | return ((u64)p[7] << 56) | ((u64)p[6] << 48) | |
509 | 0 | ((u64)p[5] << 40) | ((u64)p[4] << 32) | |
510 | 0 | ((u64)p[3] << 24) | ((u64)p[2] << 16) | |
511 | 0 | ((u64)p[1] << 8) | p[0]; |
512 | 173k | } Unexecuted instantiation: deflate_compress.c:get_unaligned_le64 Unexecuted instantiation: utils.c:get_unaligned_le64 Unexecuted instantiation: cpu_features.c:get_unaligned_le64 deflate_decompress.c:get_unaligned_le64 Line | Count | Source | 504 | 173k | { | 505 | 173k | if (UNALIGNED_ACCESS_IS_FAST) | 506 | 173k | return le64_bswap(load_u64_unaligned(p)); | 507 | 0 | else | 508 | 0 | return ((u64)p[7] << 56) | ((u64)p[6] << 48) | | 509 | 0 | ((u64)p[5] << 40) | ((u64)p[4] << 32) | | 510 | 0 | ((u64)p[3] << 24) | ((u64)p[2] << 16) | | 511 | 0 | ((u64)p[1] << 8) | p[0]; | 512 | 173k | } |
Unexecuted instantiation: zlib_compress.c:get_unaligned_le64 Unexecuted instantiation: adler32.c:get_unaligned_le64 Unexecuted instantiation: zlib_decompress.c:get_unaligned_le64 |
513 | | |
514 | | static forceinline machine_word_t |
515 | | get_unaligned_leword(const u8 *p) |
516 | 173k | { |
517 | 173k | STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
518 | 173k | if (WORDBITS == 32) |
519 | 0 | return get_unaligned_le32(p); |
520 | 173k | else |
521 | 173k | return get_unaligned_le64(p); |
522 | 173k | } Unexecuted instantiation: deflate_compress.c:get_unaligned_leword Unexecuted instantiation: utils.c:get_unaligned_leword Unexecuted instantiation: cpu_features.c:get_unaligned_leword deflate_decompress.c:get_unaligned_leword Line | Count | Source | 516 | 173k | { | 517 | 173k | STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); | 518 | 173k | if (WORDBITS == 32) | 519 | 0 | return get_unaligned_le32(p); | 520 | 173k | else | 521 | 173k | return get_unaligned_le64(p); | 522 | 173k | } |
Unexecuted instantiation: zlib_compress.c:get_unaligned_leword Unexecuted instantiation: adler32.c:get_unaligned_leword Unexecuted instantiation: zlib_decompress.c:get_unaligned_leword |
523 | | |
524 | | /* Unaligned stores with endianness conversion */ |
525 | | |
526 | | static forceinline void |
527 | | put_unaligned_le16(u16 v, u8 *p) |
528 | 0 | { |
529 | 0 | if (UNALIGNED_ACCESS_IS_FAST) { |
530 | 0 | store_u16_unaligned(le16_bswap(v), p); |
531 | 0 | } else { |
532 | 0 | p[0] = (u8)(v >> 0); |
533 | 0 | p[1] = (u8)(v >> 8); |
534 | 0 | } |
535 | 0 | } Unexecuted instantiation: deflate_compress.c:put_unaligned_le16 Unexecuted instantiation: utils.c:put_unaligned_le16 Unexecuted instantiation: cpu_features.c:put_unaligned_le16 Unexecuted instantiation: deflate_decompress.c:put_unaligned_le16 Unexecuted instantiation: zlib_compress.c:put_unaligned_le16 Unexecuted instantiation: adler32.c:put_unaligned_le16 Unexecuted instantiation: zlib_decompress.c:put_unaligned_le16 |
536 | | |
537 | | static forceinline void |
538 | | put_unaligned_be16(u16 v, u8 *p) |
539 | 0 | { |
540 | 0 | if (UNALIGNED_ACCESS_IS_FAST) { |
541 | 0 | store_u16_unaligned(be16_bswap(v), p); |
542 | 0 | } else { |
543 | 0 | p[0] = (u8)(v >> 8); |
544 | 0 | p[1] = (u8)(v >> 0); |
545 | 0 | } |
546 | 0 | } Unexecuted instantiation: deflate_compress.c:put_unaligned_be16 Unexecuted instantiation: utils.c:put_unaligned_be16 Unexecuted instantiation: cpu_features.c:put_unaligned_be16 Unexecuted instantiation: deflate_decompress.c:put_unaligned_be16 Unexecuted instantiation: zlib_compress.c:put_unaligned_be16 Unexecuted instantiation: adler32.c:put_unaligned_be16 Unexecuted instantiation: zlib_decompress.c:put_unaligned_be16 |
547 | | |
548 | | static forceinline void |
549 | | put_unaligned_le32(u32 v, u8 *p) |
550 | 0 | { |
551 | 0 | if (UNALIGNED_ACCESS_IS_FAST) { |
552 | 0 | store_u32_unaligned(le32_bswap(v), p); |
553 | 0 | } else { |
554 | 0 | p[0] = (u8)(v >> 0); |
555 | 0 | p[1] = (u8)(v >> 8); |
556 | 0 | p[2] = (u8)(v >> 16); |
557 | 0 | p[3] = (u8)(v >> 24); |
558 | 0 | } |
559 | 0 | } Unexecuted instantiation: deflate_compress.c:put_unaligned_le32 Unexecuted instantiation: utils.c:put_unaligned_le32 Unexecuted instantiation: cpu_features.c:put_unaligned_le32 Unexecuted instantiation: deflate_decompress.c:put_unaligned_le32 Unexecuted instantiation: zlib_compress.c:put_unaligned_le32 Unexecuted instantiation: adler32.c:put_unaligned_le32 Unexecuted instantiation: zlib_decompress.c:put_unaligned_le32 |
560 | | |
561 | | static forceinline void |
562 | | put_unaligned_be32(u32 v, u8 *p) |
563 | 0 | { |
564 | 0 | if (UNALIGNED_ACCESS_IS_FAST) { |
565 | 0 | store_u32_unaligned(be32_bswap(v), p); |
566 | 0 | } else { |
567 | 0 | p[0] = (u8)(v >> 24); |
568 | 0 | p[1] = (u8)(v >> 16); |
569 | 0 | p[2] = (u8)(v >> 8); |
570 | 0 | p[3] = (u8)(v >> 0); |
571 | 0 | } |
572 | 0 | } Unexecuted instantiation: deflate_compress.c:put_unaligned_be32 Unexecuted instantiation: utils.c:put_unaligned_be32 Unexecuted instantiation: cpu_features.c:put_unaligned_be32 Unexecuted instantiation: deflate_decompress.c:put_unaligned_be32 Unexecuted instantiation: zlib_compress.c:put_unaligned_be32 Unexecuted instantiation: adler32.c:put_unaligned_be32 Unexecuted instantiation: zlib_decompress.c:put_unaligned_be32 |
573 | | |
574 | | static forceinline void |
575 | | put_unaligned_le64(u64 v, u8 *p) |
576 | 0 | { |
577 | 0 | if (UNALIGNED_ACCESS_IS_FAST) { |
578 | 0 | store_u64_unaligned(le64_bswap(v), p); |
579 | 0 | } else { |
580 | 0 | p[0] = (u8)(v >> 0); |
581 | 0 | p[1] = (u8)(v >> 8); |
582 | 0 | p[2] = (u8)(v >> 16); |
583 | 0 | p[3] = (u8)(v >> 24); |
584 | 0 | p[4] = (u8)(v >> 32); |
585 | 0 | p[5] = (u8)(v >> 40); |
586 | 0 | p[6] = (u8)(v >> 48); |
587 | 0 | p[7] = (u8)(v >> 56); |
588 | 0 | } |
589 | 0 | } Unexecuted instantiation: deflate_compress.c:put_unaligned_le64 Unexecuted instantiation: utils.c:put_unaligned_le64 Unexecuted instantiation: cpu_features.c:put_unaligned_le64 Unexecuted instantiation: deflate_decompress.c:put_unaligned_le64 Unexecuted instantiation: zlib_compress.c:put_unaligned_le64 Unexecuted instantiation: adler32.c:put_unaligned_le64 Unexecuted instantiation: zlib_decompress.c:put_unaligned_le64 |
590 | | |
591 | | static forceinline void |
592 | | put_unaligned_leword(machine_word_t v, u8 *p) |
593 | 0 | { |
594 | 0 | STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
595 | 0 | if (WORDBITS == 32) |
596 | 0 | put_unaligned_le32(v, p); |
597 | 0 | else |
598 | 0 | put_unaligned_le64(v, p); |
599 | 0 | } Unexecuted instantiation: deflate_compress.c:put_unaligned_leword Unexecuted instantiation: utils.c:put_unaligned_leword Unexecuted instantiation: cpu_features.c:put_unaligned_leword Unexecuted instantiation: deflate_decompress.c:put_unaligned_leword Unexecuted instantiation: zlib_compress.c:put_unaligned_leword Unexecuted instantiation: adler32.c:put_unaligned_leword Unexecuted instantiation: zlib_decompress.c:put_unaligned_leword |
600 | | |
601 | | /* ========================================================================== */ |
602 | | /* Bit manipulation functions */ |
603 | | /* ========================================================================== */ |
604 | | |
605 | | /* |
606 | | * Bit Scan Reverse (BSR) - find the 0-based index (relative to the least |
607 | | * significant end) of the *most* significant 1 bit in the input value. The |
608 | | * input value must be nonzero! |
609 | | */ |
610 | | |
611 | | static forceinline unsigned |
612 | | bsr32(u32 v) |
613 | 269k | { |
614 | 269k | #if defined(__GNUC__) || __has_builtin(__builtin_clz) |
615 | 269k | return 31 - __builtin_clz(v); |
616 | | #elif defined(_MSC_VER) |
617 | | unsigned long i; |
618 | | |
619 | | _BitScanReverse(&i, v); |
620 | | return i; |
621 | | #else |
622 | | unsigned i = 0; |
623 | | |
624 | | while ((v >>= 1) != 0) |
625 | | i++; |
626 | | return i; |
627 | | #endif |
628 | 269k | } Unexecuted instantiation: deflate_compress.c:bsr32 Unexecuted instantiation: utils.c:bsr32 Unexecuted instantiation: cpu_features.c:bsr32 deflate_decompress.c:bsr32 Line | Count | Source | 613 | 269k | { | 614 | 269k | #if defined(__GNUC__) || __has_builtin(__builtin_clz) | 615 | 269k | return 31 - __builtin_clz(v); | 616 | | #elif defined(_MSC_VER) | 617 | | unsigned long i; | 618 | | | 619 | | _BitScanReverse(&i, v); | 620 | | return i; | 621 | | #else | 622 | | unsigned i = 0; | 623 | | | 624 | | while ((v >>= 1) != 0) | 625 | | i++; | 626 | | return i; | 627 | | #endif | 628 | 269k | } |
Unexecuted instantiation: zlib_compress.c:bsr32 Unexecuted instantiation: adler32.c:bsr32 Unexecuted instantiation: zlib_decompress.c:bsr32 |
629 | | |
630 | | static forceinline unsigned |
631 | | bsr64(u64 v) |
632 | 0 | { |
633 | 0 | #if defined(__GNUC__) || __has_builtin(__builtin_clzll) |
634 | 0 | return 63 - __builtin_clzll(v); |
635 | 0 | #elif defined(_MSC_VER) && defined(_WIN64) |
636 | 0 | unsigned long i; |
637 | 0 |
|
638 | 0 | _BitScanReverse64(&i, v); |
639 | 0 | return i; |
640 | 0 | #else |
641 | 0 | unsigned i = 0; |
642 | 0 |
|
643 | 0 | while ((v >>= 1) != 0) |
644 | 0 | i++; |
645 | 0 | return i; |
646 | 0 | #endif |
647 | 0 | } Unexecuted instantiation: deflate_compress.c:bsr64 Unexecuted instantiation: utils.c:bsr64 Unexecuted instantiation: cpu_features.c:bsr64 Unexecuted instantiation: deflate_decompress.c:bsr64 Unexecuted instantiation: zlib_compress.c:bsr64 Unexecuted instantiation: adler32.c:bsr64 Unexecuted instantiation: zlib_decompress.c:bsr64 |
648 | | |
649 | | static forceinline unsigned |
650 | | bsrw(machine_word_t v) |
651 | 0 | { |
652 | 0 | STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
653 | 0 | if (WORDBITS == 32) |
654 | 0 | return bsr32(v); |
655 | 0 | else |
656 | 0 | return bsr64(v); |
657 | 0 | } Unexecuted instantiation: deflate_compress.c:bsrw Unexecuted instantiation: utils.c:bsrw Unexecuted instantiation: cpu_features.c:bsrw Unexecuted instantiation: deflate_decompress.c:bsrw Unexecuted instantiation: zlib_compress.c:bsrw Unexecuted instantiation: adler32.c:bsrw Unexecuted instantiation: zlib_decompress.c:bsrw |
658 | | |
659 | | /* |
660 | | * Bit Scan Forward (BSF) - find the 0-based index (relative to the least |
661 | | * significant end) of the *least* significant 1 bit in the input value. The |
662 | | * input value must be nonzero! |
663 | | */ |
664 | | |
665 | | static forceinline unsigned |
666 | | bsf32(u32 v) |
667 | 0 | { |
668 | 0 | #if defined(__GNUC__) || __has_builtin(__builtin_ctz) |
669 | 0 | return __builtin_ctz(v); |
670 | 0 | #elif defined(_MSC_VER) |
671 | 0 | unsigned long i; |
672 | 0 |
|
673 | 0 | _BitScanForward(&i, v); |
674 | 0 | return i; |
675 | 0 | #else |
676 | 0 | unsigned i = 0; |
677 | 0 |
|
678 | 0 | for (; (v & 1) == 0; v >>= 1) |
679 | 0 | i++; |
680 | 0 | return i; |
681 | 0 | #endif |
682 | 0 | } Unexecuted instantiation: deflate_compress.c:bsf32 Unexecuted instantiation: utils.c:bsf32 Unexecuted instantiation: cpu_features.c:bsf32 Unexecuted instantiation: deflate_decompress.c:bsf32 Unexecuted instantiation: zlib_compress.c:bsf32 Unexecuted instantiation: adler32.c:bsf32 Unexecuted instantiation: zlib_decompress.c:bsf32 |
683 | | |
684 | | static forceinline unsigned |
685 | | bsf64(u64 v) |
686 | 0 | { |
687 | 0 | #if defined(__GNUC__) || __has_builtin(__builtin_ctzll) |
688 | 0 | return __builtin_ctzll(v); |
689 | | #elif defined(_MSC_VER) && defined(_WIN64) |
690 | | unsigned long i; |
691 | | |
692 | | _BitScanForward64(&i, v); |
693 | | return i; |
694 | | #else |
695 | | unsigned i = 0; |
696 | | |
697 | | for (; (v & 1) == 0; v >>= 1) |
698 | | i++; |
699 | | return i; |
700 | | #endif |
701 | 0 | } Unexecuted instantiation: deflate_compress.c:bsf64 Unexecuted instantiation: utils.c:bsf64 Unexecuted instantiation: cpu_features.c:bsf64 Unexecuted instantiation: deflate_decompress.c:bsf64 Unexecuted instantiation: zlib_compress.c:bsf64 Unexecuted instantiation: adler32.c:bsf64 Unexecuted instantiation: zlib_decompress.c:bsf64 |
702 | | |
703 | | static forceinline unsigned |
704 | | bsfw(machine_word_t v) |
705 | 0 | { |
706 | 0 | STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64); |
707 | 0 | if (WORDBITS == 32) |
708 | 0 | return bsf32(v); |
709 | 0 | else |
710 | 0 | return bsf64(v); |
711 | 0 | } Unexecuted instantiation: deflate_compress.c:bsfw Unexecuted instantiation: utils.c:bsfw Unexecuted instantiation: cpu_features.c:bsfw Unexecuted instantiation: deflate_decompress.c:bsfw Unexecuted instantiation: zlib_compress.c:bsfw Unexecuted instantiation: adler32.c:bsfw Unexecuted instantiation: zlib_decompress.c:bsfw |
712 | | |
713 | | /* |
714 | | * rbit32(v): reverse the bits in a 32-bit integer. This doesn't have a |
715 | | * fallback implementation; use '#ifdef rbit32' to check if this is available. |
716 | | */ |
717 | | #undef rbit32 |
718 | | #if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \ |
719 | | (__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__))) |
720 | | static forceinline u32 |
721 | | rbit32(u32 v) |
722 | | { |
723 | | __asm__("rbit %0, %1" : "=r" (v) : "r" (v)); |
724 | | return v; |
725 | | } |
726 | | #define rbit32 rbit32 |
727 | | #elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64) |
728 | | static forceinline u32 |
729 | | rbit32(u32 v) |
730 | | { |
731 | | __asm__("rbit %w0, %w1" : "=r" (v) : "r" (v)); |
732 | | return v; |
733 | | } |
734 | | #define rbit32 rbit32 |
735 | | #endif |
736 | | |
737 | | #endif /* COMMON_DEFS_H */ |