Coverage Report

Created: 2026-05-24 07:45

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