Coverage Report

Created: 2026-10-28 07:26

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
#  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
42.4M
#define WORDBYTES ((int)sizeof(machine_word_t))
127
128
/* Number of bits in a word */
129
6.03M
#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
2.76M
#  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
30.1M
#  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
4.71M
#  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
113k
#define ARRAY_LEN(A)    (sizeof(A) / sizeof((A)[0]))
295
2.06M
#define MIN(a, b)   ((a) <= (b) ? (a) : (b))
296
1.93k
#define MAX(a, b)   ((a) >= (b) ? (a) : (b))
297
3.65k
#define DIV_ROUND_UP(n, d)  (((n) + (d) - 1) / (d))
298
15.9M
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)]))
299
1.49k
#define ALIGN(n, a)   (((n) + (a) - 1) & ~((a) - 1))
300
#define ROUND_UP(n, d)    ((d) * DIV_ROUND_UP((n), (d)))
301
302
/* ========================================================================== */
303
/*                           Endianness handling                              */
304
/* ========================================================================== */
305
306
/*
307
 * CPU_IS_LITTLE_ENDIAN() - 1 if the CPU is little endian, or 0 if it is big
308
 * endian.  When possible this is a compile-time macro that can be used in
309
 * preprocessor conditionals.  As a fallback, a generic method is used that
310
 * can't be used in preprocessor conditionals but should still be optimized out.
311
 */
312
#if defined(__BYTE_ORDER__) /* gcc v4.6+ and clang */
313
12.9M
#  define CPU_IS_LITTLE_ENDIAN()  (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
314
#elif defined(_MSC_VER)
315
#  define CPU_IS_LITTLE_ENDIAN()  true
316
#else
317
static forceinline bool CPU_IS_LITTLE_ENDIAN(void)
318
{
319
  union {
320
    u32 w;
321
    u8 b;
322
  } u;
323
324
  u.w = 1;
325
  return u.b;
326
}
327
#endif
328
329
/* bswap16(v) - swap the bytes of a 16-bit integer */
330
static forceinline u16 bswap16(u16 v)
331
21.3k
{
332
21.3k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap16)
333
21.3k
  return __builtin_bswap16(v);
334
#elif defined(_MSC_VER)
335
  return _byteswap_ushort(v);
336
#else
337
  return (v << 8) | (v >> 8);
338
#endif
339
21.3k
}
Unexecuted instantiation: deflate_compress.c:bswap16
Unexecuted instantiation: deflate_decompress.c:bswap16
zlib_compress.c:bswap16
Line
Count
Source
331
1.93k
{
332
1.93k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap16)
333
1.93k
  return __builtin_bswap16(v);
334
#elif defined(_MSC_VER)
335
  return _byteswap_ushort(v);
336
#else
337
  return (v << 8) | (v >> 8);
338
#endif
339
1.93k
}
zlib_decompress.c:bswap16
Line
Count
Source
331
19.4k
{
332
19.4k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap16)
333
19.4k
  return __builtin_bswap16(v);
334
#elif defined(_MSC_VER)
335
  return _byteswap_ushort(v);
336
#else
337
  return (v << 8) | (v >> 8);
338
#endif
339
19.4k
}
Unexecuted instantiation: utils.c:bswap16
Unexecuted instantiation: cpu_features.c:bswap16
Unexecuted instantiation: adler32.c:bswap16
340
341
/* bswap32(v) - swap the bytes of a 32-bit integer */
342
static forceinline u32 bswap32(u32 v)
343
3.27k
{
344
3.27k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap32)
345
3.27k
  return __builtin_bswap32(v);
346
#elif defined(_MSC_VER)
347
  return _byteswap_ulong(v);
348
#else
349
  return ((v & 0x000000FF) << 24) |
350
         ((v & 0x0000FF00) << 8) |
351
         ((v & 0x00FF0000) >> 8) |
352
         ((v & 0xFF000000) >> 24);
353
#endif
354
3.27k
}
Unexecuted instantiation: deflate_compress.c:bswap32
Unexecuted instantiation: deflate_decompress.c:bswap32
zlib_compress.c:bswap32
Line
Count
Source
343
1.93k
{
344
1.93k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap32)
345
1.93k
  return __builtin_bswap32(v);
346
#elif defined(_MSC_VER)
347
  return _byteswap_ulong(v);
348
#else
349
  return ((v & 0x000000FF) << 24) |
350
         ((v & 0x0000FF00) << 8) |
351
         ((v & 0x00FF0000) >> 8) |
352
         ((v & 0xFF000000) >> 24);
353
#endif
354
1.93k
}
zlib_decompress.c:bswap32
Line
Count
Source
343
1.33k
{
344
1.33k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap32)
345
1.33k
  return __builtin_bswap32(v);
346
#elif defined(_MSC_VER)
347
  return _byteswap_ulong(v);
348
#else
349
  return ((v & 0x000000FF) << 24) |
350
         ((v & 0x0000FF00) << 8) |
351
         ((v & 0x00FF0000) >> 8) |
352
         ((v & 0xFF000000) >> 24);
353
#endif
354
1.33k
}
Unexecuted instantiation: utils.c:bswap32
Unexecuted instantiation: cpu_features.c:bswap32
Unexecuted instantiation: adler32.c:bswap32
355
356
/* bswap64(v) - swap the bytes of a 64-bit integer */
357
static forceinline u64 bswap64(u64 v)
358
0
{
359
0
#if defined(__GNUC__) || __has_builtin(__builtin_bswap64)
360
0
  return __builtin_bswap64(v);
361
0
#elif defined(_MSC_VER)
362
0
  return _byteswap_uint64(v);
363
0
#else
364
0
  return ((v & 0x00000000000000FF) << 56) |
365
0
         ((v & 0x000000000000FF00) << 40) |
366
0
         ((v & 0x0000000000FF0000) << 24) |
367
0
         ((v & 0x00000000FF000000) << 8) |
368
0
         ((v & 0x000000FF00000000) >> 8) |
369
0
         ((v & 0x0000FF0000000000) >> 24) |
370
0
         ((v & 0x00FF000000000000) >> 40) |
371
0
         ((v & 0xFF00000000000000) >> 56);
372
0
#endif
373
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
374
375
1.79k
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v))
376
6.13M
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v))
377
4.68M
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v))
378
21.3k
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v))
379
3.27k
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v))
380
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v))
381
382
/* ========================================================================== */
383
/*                          Unaligned memory accesses                         */
384
/* ========================================================================== */
385
386
/*
387
 * UNALIGNED_ACCESS_IS_FAST() - 1 if unaligned memory accesses can be performed
388
 * efficiently on the target platform, otherwise 0.
389
 */
390
#if (defined(__GNUC__) || defined(__clang__)) && \
391
  (defined(ARCH_X86_64) || defined(ARCH_X86_32) || \
392
   defined(__ARM_FEATURE_UNALIGNED) || \
393
   defined(__powerpc64__) || defined(__powerpc__) || defined(__POWERPC__) || \
394
   defined(__riscv_misaligned_fast) || \
395
   /*
396
    * For all compilation purposes, WebAssembly behaves like any other CPU
397
    * instruction set. Even though WebAssembly engine might be running on
398
    * top of different actual CPU architectures, the WebAssembly spec
399
    * itself permits unaligned access and it will be fast on most of those
400
    * platforms, and simulated at the engine level on others, so it's
401
    * worth treating it as a CPU architecture with fast unaligned access.
402
    */ defined(__wasm__))
403
34.9M
#  define UNALIGNED_ACCESS_IS_FAST  1
404
#elif defined(_MSC_VER)
405
#  define UNALIGNED_ACCESS_IS_FAST  1
406
#else
407
#  define UNALIGNED_ACCESS_IS_FAST  0
408
#endif
409
410
/*
411
 * Implementing unaligned memory accesses using memcpy() is portable, and it
412
 * usually gets optimized appropriately by modern compilers.  I.e., each
413
 * memcpy() of 1, 2, 4, or WORDBYTES bytes gets compiled to a load or store
414
 * instruction, not to an actual function call.
415
 *
416
 * We no longer use the "packed struct" approach to unaligned accesses, as that
417
 * is nonstandard, has unclear semantics, and doesn't receive enough testing
418
 * (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94994).
419
 *
420
 * arm32 with __ARM_FEATURE_UNALIGNED in gcc 5 and earlier is a known exception
421
 * where memcpy() generates inefficient code
422
 * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67366).  However, we no longer
423
 * consider that one case important enough to maintain different code for.
424
 * If you run into it, please just use a newer version of gcc (or use clang).
425
 */
426
427
#ifdef FREESTANDING
428
#  define MEMCOPY __builtin_memcpy
429
#else
430
116M
#  define MEMCOPY memcpy
431
#endif
432
433
/* Unaligned loads and stores without endianness conversion */
434
435
#define DEFINE_UNALIGNED_TYPE(type)       \
436
static forceinline type           \
437
93.8M
load_##type##_unaligned(const void *p)        \
438
93.8M
{               \
439
93.8M
  type v;             \
440
93.8M
                \
441
93.8M
  MEMCOPY(&v, p, sizeof(v));       \
442
93.8M
  return v;           \
443
93.8M
}                \
deflate_compress.c:load_u32_unaligned
Line
Count
Source
437
60.0M
load_##type##_unaligned(const void *p)        \
438
60.0M
{               \
439
60.0M
  type v;             \
440
60.0M
                \
441
60.0M
  MEMCOPY(&v, p, sizeof(v));       \
442
60.0M
  return v;           \
443
60.0M
}                \
deflate_compress.c:load_machine_word_t_unaligned
Line
Count
Source
437
8.66M
load_##type##_unaligned(const void *p)        \
438
8.66M
{               \
439
8.66M
  type v;             \
440
8.66M
                \
441
8.66M
  MEMCOPY(&v, p, sizeof(v));       \
442
8.66M
  return v;           \
443
8.66M
}                \
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
437
3.68M
load_##type##_unaligned(const void *p)        \
438
3.68M
{               \
439
3.68M
  type v;             \
440
3.68M
                \
441
3.68M
  MEMCOPY(&v, p, sizeof(v));       \
442
3.68M
  return v;           \
443
3.68M
}                \
deflate_decompress.c:load_u16_unaligned
Line
Count
Source
437
1.57k
load_##type##_unaligned(const void *p)        \
438
1.57k
{               \
439
1.57k
  type v;             \
440
1.57k
                \
441
1.57k
  MEMCOPY(&v, p, sizeof(v));       \
442
1.57k
  return v;           \
443
1.57k
}                \
deflate_decompress.c:load_machine_word_t_unaligned
Line
Count
Source
437
21.3M
load_##type##_unaligned(const void *p)        \
438
21.3M
{               \
439
21.3M
  type v;             \
440
21.3M
                \
441
21.3M
  MEMCOPY(&v, p, sizeof(v));       \
442
21.3M
  return v;           \
443
21.3M
}                \
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
437
19.4k
load_##type##_unaligned(const void *p)        \
438
19.4k
{               \
439
19.4k
  type v;             \
440
19.4k
                \
441
19.4k
  MEMCOPY(&v, p, sizeof(v));       \
442
19.4k
  return v;           \
443
19.4k
}                \
zlib_decompress.c:load_u32_unaligned
Line
Count
Source
437
1.33k
load_##type##_unaligned(const void *p)        \
438
1.33k
{               \
439
1.33k
  type v;             \
440
1.33k
                \
441
1.33k
  MEMCOPY(&v, p, sizeof(v));       \
442
1.33k
  return v;           \
443
1.33k
}                \
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
444
                \
445
static forceinline void           \
446
22.6M
store_##type##_unaligned(type v, void *p)     \
447
22.6M
{               \
448
22.6M
  MEMCOPY(p, &v, sizeof(v));       \
449
22.6M
}
deflate_compress.c:store_u16_unaligned
Line
Count
Source
446
224
store_##type##_unaligned(type v, void *p)     \
447
224
{               \
448
224
  MEMCOPY(p, &v, sizeof(v));       \
449
224
}
deflate_compress.c:store_u64_unaligned
Line
Count
Source
446
998k
store_##type##_unaligned(type v, void *p)     \
447
998k
{               \
448
998k
  MEMCOPY(p, &v, sizeof(v));       \
449
998k
}
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
446
21.6M
store_##type##_unaligned(type v, void *p)     \
447
21.6M
{               \
448
21.6M
  MEMCOPY(p, &v, sizeof(v));       \
449
21.6M
}
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
446
1.93k
store_##type##_unaligned(type v, void *p)     \
447
1.93k
{               \
448
1.93k
  MEMCOPY(p, &v, sizeof(v));       \
449
1.93k
}
zlib_compress.c:store_u32_unaligned
Line
Count
Source
446
1.93k
store_##type##_unaligned(type v, void *p)     \
447
1.93k
{               \
448
1.93k
  MEMCOPY(p, &v, sizeof(v));       \
449
1.93k
}
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
450
451
DEFINE_UNALIGNED_TYPE(u16)
452
DEFINE_UNALIGNED_TYPE(u32)
453
DEFINE_UNALIGNED_TYPE(u64)
454
DEFINE_UNALIGNED_TYPE(machine_word_t)
455
456
#undef MEMCOPY
457
458
30.0M
#define load_word_unaligned load_machine_word_t_unaligned
459
21.6M
#define store_word_unaligned  store_machine_word_t_unaligned
460
461
/* Unaligned loads with endianness conversion */
462
463
static forceinline u16
464
get_unaligned_le16(const u8 *p)
465
1.57k
{
466
1.57k
  if (UNALIGNED_ACCESS_IS_FAST)
467
1.57k
    return le16_bswap(load_u16_unaligned(p));
468
0
  else
469
0
    return ((u16)p[1] << 8) | p[0];
470
1.57k
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_le16
deflate_decompress.c:get_unaligned_le16
Line
Count
Source
465
1.57k
{
466
1.57k
  if (UNALIGNED_ACCESS_IS_FAST)
467
1.57k
    return le16_bswap(load_u16_unaligned(p));
468
0
  else
469
0
    return ((u16)p[1] << 8) | p[0];
470
1.57k
}
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
471
472
static forceinline u16
473
get_unaligned_be16(const u8 *p)
474
19.4k
{
475
19.4k
  if (UNALIGNED_ACCESS_IS_FAST)
476
19.4k
    return be16_bswap(load_u16_unaligned(p));
477
0
  else
478
0
    return ((u16)p[0] << 8) | p[1];
479
19.4k
}
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
474
19.4k
{
475
19.4k
  if (UNALIGNED_ACCESS_IS_FAST)
476
19.4k
    return be16_bswap(load_u16_unaligned(p));
477
0
  else
478
0
    return ((u16)p[0] << 8) | p[1];
479
19.4k
}
Unexecuted instantiation: utils.c:get_unaligned_be16
Unexecuted instantiation: cpu_features.c:get_unaligned_be16
Unexecuted instantiation: adler32.c:get_unaligned_be16
480
481
static forceinline u32
482
get_unaligned_le32(const u8 *p)
483
6.13M
{
484
6.13M
  if (UNALIGNED_ACCESS_IS_FAST)
485
6.13M
    return le32_bswap(load_u32_unaligned(p));
486
0
  else
487
0
    return ((u32)p[3] << 24) | ((u32)p[2] << 16) |
488
0
      ((u32)p[1] << 8) | p[0];
489
6.13M
}
deflate_compress.c:get_unaligned_le32
Line
Count
Source
483
6.13M
{
484
6.13M
  if (UNALIGNED_ACCESS_IS_FAST)
485
6.13M
    return le32_bswap(load_u32_unaligned(p));
486
0
  else
487
0
    return ((u32)p[3] << 24) | ((u32)p[2] << 16) |
488
0
      ((u32)p[1] << 8) | p[0];
489
6.13M
}
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
490
491
static forceinline u32
492
get_unaligned_be32(const u8 *p)
493
1.33k
{
494
1.33k
  if (UNALIGNED_ACCESS_IS_FAST)
495
1.33k
    return be32_bswap(load_u32_unaligned(p));
496
0
  else
497
0
    return ((u32)p[0] << 24) | ((u32)p[1] << 16) |
498
0
      ((u32)p[2] << 8) | p[3];
499
1.33k
}
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
493
1.33k
{
494
1.33k
  if (UNALIGNED_ACCESS_IS_FAST)
495
1.33k
    return be32_bswap(load_u32_unaligned(p));
496
0
  else
497
0
    return ((u32)p[0] << 24) | ((u32)p[1] << 16) |
498
0
      ((u32)p[2] << 8) | p[3];
499
1.33k
}
Unexecuted instantiation: utils.c:get_unaligned_be32
Unexecuted instantiation: cpu_features.c:get_unaligned_be32
Unexecuted instantiation: adler32.c:get_unaligned_be32
500
501
static forceinline u64
502
get_unaligned_le64(const u8 *p)
503
3.68M
{
504
3.68M
  if (UNALIGNED_ACCESS_IS_FAST)
505
3.68M
    return le64_bswap(load_u64_unaligned(p));
506
0
  else
507
0
    return ((u64)p[7] << 56) | ((u64)p[6] << 48) |
508
0
      ((u64)p[5] << 40) | ((u64)p[4] << 32) |
509
0
      ((u64)p[3] << 24) | ((u64)p[2] << 16) |
510
0
      ((u64)p[1] << 8) | p[0];
511
3.68M
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_le64
deflate_decompress.c:get_unaligned_le64
Line
Count
Source
503
3.68M
{
504
3.68M
  if (UNALIGNED_ACCESS_IS_FAST)
505
3.68M
    return le64_bswap(load_u64_unaligned(p));
506
0
  else
507
0
    return ((u64)p[7] << 56) | ((u64)p[6] << 48) |
508
0
      ((u64)p[5] << 40) | ((u64)p[4] << 32) |
509
0
      ((u64)p[3] << 24) | ((u64)p[2] << 16) |
510
0
      ((u64)p[1] << 8) | p[0];
511
3.68M
}
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
512
513
static forceinline machine_word_t
514
get_unaligned_leword(const u8 *p)
515
3.68M
{
516
3.68M
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
517
3.68M
  if (WORDBITS == 32)
518
0
    return get_unaligned_le32(p);
519
3.68M
  else
520
3.68M
    return get_unaligned_le64(p);
521
3.68M
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_leword
deflate_decompress.c:get_unaligned_leword
Line
Count
Source
515
3.68M
{
516
3.68M
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
517
3.68M
  if (WORDBITS == 32)
518
0
    return get_unaligned_le32(p);
519
3.68M
  else
520
3.68M
    return get_unaligned_le64(p);
521
3.68M
}
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
522
523
/* Unaligned stores with endianness conversion */
524
525
static forceinline void
526
put_unaligned_le16(u16 v, u8 *p)
527
224
{
528
224
  if (UNALIGNED_ACCESS_IS_FAST) {
529
224
    store_u16_unaligned(le16_bswap(v), p);
530
224
  } else {
531
0
    p[0] = (u8)(v >> 0);
532
0
    p[1] = (u8)(v >> 8);
533
0
  }
534
224
}
deflate_compress.c:put_unaligned_le16
Line
Count
Source
527
224
{
528
224
  if (UNALIGNED_ACCESS_IS_FAST) {
529
224
    store_u16_unaligned(le16_bswap(v), p);
530
224
  } else {
531
0
    p[0] = (u8)(v >> 0);
532
0
    p[1] = (u8)(v >> 8);
533
0
  }
534
224
}
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
535
536
static forceinline void
537
put_unaligned_be16(u16 v, u8 *p)
538
1.93k
{
539
1.93k
  if (UNALIGNED_ACCESS_IS_FAST) {
540
1.93k
    store_u16_unaligned(be16_bswap(v), p);
541
1.93k
  } else {
542
0
    p[0] = (u8)(v >> 8);
543
0
    p[1] = (u8)(v >> 0);
544
0
  }
545
1.93k
}
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
538
1.93k
{
539
1.93k
  if (UNALIGNED_ACCESS_IS_FAST) {
540
1.93k
    store_u16_unaligned(be16_bswap(v), p);
541
1.93k
  } else {
542
0
    p[0] = (u8)(v >> 8);
543
0
    p[1] = (u8)(v >> 0);
544
0
  }
545
1.93k
}
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
546
547
static forceinline void
548
put_unaligned_le32(u32 v, u8 *p)
549
0
{
550
0
  if (UNALIGNED_ACCESS_IS_FAST) {
551
0
    store_u32_unaligned(le32_bswap(v), p);
552
0
  } else {
553
0
    p[0] = (u8)(v >> 0);
554
0
    p[1] = (u8)(v >> 8);
555
0
    p[2] = (u8)(v >> 16);
556
0
    p[3] = (u8)(v >> 24);
557
0
  }
558
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
559
560
static forceinline void
561
put_unaligned_be32(u32 v, u8 *p)
562
1.93k
{
563
1.93k
  if (UNALIGNED_ACCESS_IS_FAST) {
564
1.93k
    store_u32_unaligned(be32_bswap(v), p);
565
1.93k
  } else {
566
0
    p[0] = (u8)(v >> 24);
567
0
    p[1] = (u8)(v >> 16);
568
0
    p[2] = (u8)(v >> 8);
569
0
    p[3] = (u8)(v >> 0);
570
0
  }
571
1.93k
}
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
562
1.93k
{
563
1.93k
  if (UNALIGNED_ACCESS_IS_FAST) {
564
1.93k
    store_u32_unaligned(be32_bswap(v), p);
565
1.93k
  } else {
566
0
    p[0] = (u8)(v >> 24);
567
0
    p[1] = (u8)(v >> 16);
568
0
    p[2] = (u8)(v >> 8);
569
0
    p[3] = (u8)(v >> 0);
570
0
  }
571
1.93k
}
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
572
573
static forceinline void
574
put_unaligned_le64(u64 v, u8 *p)
575
998k
{
576
998k
  if (UNALIGNED_ACCESS_IS_FAST) {
577
998k
    store_u64_unaligned(le64_bswap(v), p);
578
998k
  } else {
579
0
    p[0] = (u8)(v >> 0);
580
0
    p[1] = (u8)(v >> 8);
581
0
    p[2] = (u8)(v >> 16);
582
0
    p[3] = (u8)(v >> 24);
583
0
    p[4] = (u8)(v >> 32);
584
0
    p[5] = (u8)(v >> 40);
585
0
    p[6] = (u8)(v >> 48);
586
0
    p[7] = (u8)(v >> 56);
587
0
  }
588
998k
}
deflate_compress.c:put_unaligned_le64
Line
Count
Source
575
998k
{
576
998k
  if (UNALIGNED_ACCESS_IS_FAST) {
577
998k
    store_u64_unaligned(le64_bswap(v), p);
578
998k
  } else {
579
0
    p[0] = (u8)(v >> 0);
580
0
    p[1] = (u8)(v >> 8);
581
0
    p[2] = (u8)(v >> 16);
582
0
    p[3] = (u8)(v >> 24);
583
0
    p[4] = (u8)(v >> 32);
584
0
    p[5] = (u8)(v >> 40);
585
0
    p[6] = (u8)(v >> 48);
586
0
    p[7] = (u8)(v >> 56);
587
0
  }
588
998k
}
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
589
590
static forceinline void
591
put_unaligned_leword(machine_word_t v, u8 *p)
592
998k
{
593
998k
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
594
998k
  if (WORDBITS == 32)
595
0
    put_unaligned_le32(v, p);
596
998k
  else
597
998k
    put_unaligned_le64(v, p);
598
998k
}
deflate_compress.c:put_unaligned_leword
Line
Count
Source
592
998k
{
593
998k
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
594
998k
  if (WORDBITS == 32)
595
0
    put_unaligned_le32(v, p);
596
998k
  else
597
998k
    put_unaligned_le64(v, p);
598
998k
}
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
599
600
/* ========================================================================== */
601
/*                         Bit manipulation functions                         */
602
/* ========================================================================== */
603
604
/*
605
 * Bit Scan Reverse (BSR) - find the 0-based index (relative to the least
606
 * significant end) of the *most* significant 1 bit in the input value.  The
607
 * input value must be nonzero!
608
 */
609
610
static forceinline unsigned
611
bsr32(u32 v)
612
806k
{
613
806k
#if defined(__GNUC__) || __has_builtin(__builtin_clz)
614
806k
  return 31 - __builtin_clz(v);
615
#elif defined(_MSC_VER)
616
  unsigned long i;
617
618
  _BitScanReverse(&i, v);
619
  return i;
620
#else
621
  unsigned i = 0;
622
623
  while ((v >>= 1) != 0)
624
    i++;
625
  return i;
626
#endif
627
806k
}
deflate_compress.c:bsr32
Line
Count
Source
612
170k
{
613
170k
#if defined(__GNUC__) || __has_builtin(__builtin_clz)
614
170k
  return 31 - __builtin_clz(v);
615
#elif defined(_MSC_VER)
616
  unsigned long i;
617
618
  _BitScanReverse(&i, v);
619
  return i;
620
#else
621
  unsigned i = 0;
622
623
  while ((v >>= 1) != 0)
624
    i++;
625
  return i;
626
#endif
627
170k
}
deflate_decompress.c:bsr32
Line
Count
Source
612
636k
{
613
636k
#if defined(__GNUC__) || __has_builtin(__builtin_clz)
614
636k
  return 31 - __builtin_clz(v);
615
#elif defined(_MSC_VER)
616
  unsigned long i;
617
618
  _BitScanReverse(&i, v);
619
  return i;
620
#else
621
  unsigned i = 0;
622
623
  while ((v >>= 1) != 0)
624
    i++;
625
  return i;
626
#endif
627
636k
}
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
628
629
static forceinline unsigned
630
bsr64(u64 v)
631
0
{
632
0
#if defined(__GNUC__) || __has_builtin(__builtin_clzll)
633
0
  return 63 - __builtin_clzll(v);
634
0
#elif defined(_MSC_VER) && defined(_WIN64)
635
0
  unsigned long i;
636
0
637
0
  _BitScanReverse64(&i, v);
638
0
  return i;
639
0
#else
640
0
  unsigned i = 0;
641
0
642
0
  while ((v >>= 1) != 0)
643
0
    i++;
644
0
  return i;
645
0
#endif
646
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
647
648
static forceinline unsigned
649
bsrw(machine_word_t v)
650
0
{
651
0
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
652
0
  if (WORDBITS == 32)
653
0
    return bsr32(v);
654
0
  else
655
0
    return bsr64(v);
656
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
657
658
/*
659
 * Bit Scan Forward (BSF) - find the 0-based index (relative to the least
660
 * significant end) of the *least* significant 1 bit in the input value.  The
661
 * input value must be nonzero!
662
 */
663
664
static forceinline unsigned
665
bsf32(u32 v)
666
0
{
667
0
#if defined(__GNUC__) || __has_builtin(__builtin_ctz)
668
0
  return __builtin_ctz(v);
669
0
#elif defined(_MSC_VER)
670
0
  unsigned long i;
671
0
672
0
  _BitScanForward(&i, v);
673
0
  return i;
674
0
#else
675
0
  unsigned i = 0;
676
0
677
0
  for (; (v & 1) == 0; v >>= 1)
678
0
    i++;
679
0
  return i;
680
0
#endif
681
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
682
683
static forceinline unsigned
684
bsf64(u64 v)
685
1.35M
{
686
1.35M
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll)
687
1.35M
  return __builtin_ctzll(v);
688
#elif defined(_MSC_VER) && defined(_WIN64)
689
  unsigned long i;
690
691
  _BitScanForward64(&i, v);
692
  return i;
693
#else
694
  unsigned i = 0;
695
696
  for (; (v & 1) == 0; v >>= 1)
697
    i++;
698
  return i;
699
#endif
700
1.35M
}
deflate_compress.c:bsf64
Line
Count
Source
685
1.35M
{
686
1.35M
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll)
687
1.35M
  return __builtin_ctzll(v);
688
#elif defined(_MSC_VER) && defined(_WIN64)
689
  unsigned long i;
690
691
  _BitScanForward64(&i, v);
692
  return i;
693
#else
694
  unsigned i = 0;
695
696
  for (; (v & 1) == 0; v >>= 1)
697
    i++;
698
  return i;
699
#endif
700
1.35M
}
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
701
702
static forceinline unsigned
703
bsfw(machine_word_t v)
704
1.35M
{
705
1.35M
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
706
1.35M
  if (WORDBITS == 32)
707
0
    return bsf32(v);
708
1.35M
  else
709
1.35M
    return bsf64(v);
710
1.35M
}
deflate_compress.c:bsfw
Line
Count
Source
704
1.35M
{
705
1.35M
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
706
1.35M
  if (WORDBITS == 32)
707
0
    return bsf32(v);
708
1.35M
  else
709
1.35M
    return bsf64(v);
710
1.35M
}
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
711
712
/*
713
 * rbit32(v): reverse the bits in a 32-bit integer.  This doesn't have a
714
 * fallback implementation; use '#ifdef rbit32' to check if this is available.
715
 */
716
#undef rbit32
717
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \
718
  (__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__)))
719
static forceinline u32
720
rbit32(u32 v)
721
{
722
  __asm__("rbit %0, %1" : "=r" (v) : "r" (v));
723
  return v;
724
}
725
#define rbit32 rbit32
726
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64)
727
static forceinline u32
728
rbit32(u32 v)
729
{
730
  __asm__("rbit %w0, %w1" : "=r" (v) : "r" (v));
731
  return v;
732
}
733
#define rbit32 rbit32
734
#endif
735
736
#endif /* COMMON_DEFS_H */