Coverage Report

Created: 2026-03-31 06:56

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
680k
#define WORDBYTES ((int)sizeof(machine_word_t))
126
127
/* Number of bits in a word */
128
193k
#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(1900)
163
#    error "MSVC versions older than Visual Studio 2015 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
/*
216
 * restrict - hint that writes only occur through the given pointer.
217
 *
218
 * Don't use MSVC's __restrict, since it has nonstandard behavior.
219
 * Standard restrict is okay, if it is supported.
220
 */
221
#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 201112L)
222
#  if defined(__GNUC__) || defined(__clang__)
223
#    define restrict    __restrict__
224
#  else
225
#    define restrict
226
#  endif
227
#endif /* else assume 'restrict' is usable as-is */
228
229
/* likely(expr) - hint that an expression is usually true */
230
#if defined(__GNUC__) || __has_builtin(__builtin_expect)
231
171k
#  define likely(expr)    __builtin_expect(!!(expr), 1)
232
#else
233
#  define likely(expr)    (expr)
234
#endif
235
236
/* unlikely(expr) - hint that an expression is usually false */
237
#if defined(__GNUC__) || __has_builtin(__builtin_expect)
238
769k
#  define unlikely(expr)  __builtin_expect(!!(expr), 0)
239
#else
240
#  define unlikely(expr)  (expr)
241
#endif
242
243
/* prefetchr(addr) - prefetch into L1 cache for read */
244
#undef prefetchr
245
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch)
246
#  define prefetchr(addr) __builtin_prefetch((addr), 0)
247
#elif defined(_MSC_VER)
248
#  if defined(ARCH_X86_32) || defined(ARCH_X86_64)
249
#    define prefetchr(addr) _mm_prefetch((addr), _MM_HINT_T0)
250
#  elif defined(ARCH_ARM64)
251
#    define prefetchr(addr) __prefetch2((addr), 0x00 /* prfop=PLDL1KEEP */)
252
#  elif defined(ARCH_ARM32)
253
#    define prefetchr(addr) __prefetch(addr)
254
#  endif
255
#endif
256
#ifndef prefetchr
257
#  define prefetchr(addr)
258
#endif
259
260
/* prefetchw(addr) - prefetch into L1 cache for write */
261
#undef prefetchw
262
#if defined(__GNUC__) || __has_builtin(__builtin_prefetch)
263
0
#  define prefetchw(addr) __builtin_prefetch((addr), 1)
264
#elif defined(_MSC_VER)
265
#  if defined(ARCH_X86_32) || defined(ARCH_X86_64)
266
#    define prefetchw(addr) _m_prefetchw(addr)
267
#  elif defined(ARCH_ARM64)
268
#    define prefetchw(addr) __prefetch2((addr), 0x10 /* prfop=PSTL1KEEP */)
269
#  elif defined(ARCH_ARM32)
270
#    define prefetchw(addr) __prefetchw(addr)
271
#  endif
272
#endif
273
#ifndef prefetchw
274
#  define prefetchw(addr)
275
#endif
276
277
/*
278
 * _aligned_attribute(n) - declare that the annotated variable, or variables of
279
 * the annotated type, must be aligned on n-byte boundaries.
280
 */
281
#undef _aligned_attribute
282
#if defined(__GNUC__) || __has_attribute(aligned)
283
#  define _aligned_attribute(n) __attribute__((aligned(n)))
284
#elif defined(_MSC_VER)
285
#  define _aligned_attribute(n) __declspec(align(n))
286
#endif
287
288
/*
289
 * _target_attribute(attrs) - override the compilation target for a function.
290
 *
291
 * This accepts one or more comma-separated suffixes to the -m prefix jointly
292
 * forming the name of a machine-dependent option.  On gcc-like compilers, this
293
 * enables codegen for the given targets, including arbitrary compiler-generated
294
 * code as well as the corresponding intrinsics.  On other compilers this macro
295
 * expands to nothing, though MSVC allows intrinsics to be used anywhere anyway.
296
 */
297
#if defined(__GNUC__) || __has_attribute(target)
298
#  define _target_attribute(attrs)  __attribute__((target(attrs)))
299
#else
300
#  define _target_attribute(attrs)
301
#endif
302
303
/* ========================================================================== */
304
/*                          Miscellaneous macros                              */
305
/* ========================================================================== */
306
307
5
#define ARRAY_LEN(A)    (sizeof(A) / sizeof((A)[0]))
308
17.6k
#define MIN(a, b)   ((a) <= (b) ? (a) : (b))
309
0
#define MAX(a, b)   ((a) >= (b) ? (a) : (b))
310
0
#define DIV_ROUND_UP(n, d)  (((n) + (d) - 1) / (d))
311
688k
#define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)]))
312
0
#define ALIGN(n, a)   (((n) + (a) - 1) & ~((a) - 1))
313
#define ROUND_UP(n, d)    ((d) * DIV_ROUND_UP((n), (d)))
314
315
/* ========================================================================== */
316
/*                           Endianness handling                              */
317
/* ========================================================================== */
318
319
/*
320
 * CPU_IS_LITTLE_ENDIAN() - 1 if the CPU is little endian, or 0 if it is big
321
 * endian.  When possible this is a compile-time macro that can be used in
322
 * preprocessor conditionals.  As a fallback, a generic method is used that
323
 * can't be used in preprocessor conditionals but should still be optimized out.
324
 */
325
#if defined(__BYTE_ORDER__) /* gcc v4.6+ and clang */
326
201k
#  define CPU_IS_LITTLE_ENDIAN()  (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
327
#elif defined(_MSC_VER)
328
#  define CPU_IS_LITTLE_ENDIAN()  true
329
#else
330
static forceinline bool CPU_IS_LITTLE_ENDIAN(void)
331
{
332
  union {
333
    u32 w;
334
    u8 b;
335
  } u;
336
337
  u.w = 1;
338
  return u.b;
339
}
340
#endif
341
342
/* bswap16(v) - swap the bytes of a 16-bit integer */
343
static forceinline u16 bswap16(u16 v)
344
4.99k
{
345
4.99k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap16)
346
4.99k
  return __builtin_bswap16(v);
347
#elif defined(_MSC_VER)
348
  return _byteswap_ushort(v);
349
#else
350
  return (v << 8) | (v >> 8);
351
#endif
352
4.99k
}
Unexecuted instantiation: deflate_compress.c:bswap16
Unexecuted instantiation: utils.c:bswap16
Unexecuted instantiation: deflate_decompress.c:bswap16
Unexecuted instantiation: cpu_features.c:bswap16
Unexecuted instantiation: zlib_compress.c:bswap16
Unexecuted instantiation: adler32.c:bswap16
zlib_decompress.c:bswap16
Line
Count
Source
344
4.99k
{
345
4.99k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap16)
346
4.99k
  return __builtin_bswap16(v);
347
#elif defined(_MSC_VER)
348
  return _byteswap_ushort(v);
349
#else
350
  return (v << 8) | (v >> 8);
351
#endif
352
4.99k
}
353
354
/* bswap32(v) - swap the bytes of a 32-bit integer */
355
static forceinline u32 bswap32(u32 v)
356
1.90k
{
357
1.90k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap32)
358
1.90k
  return __builtin_bswap32(v);
359
#elif defined(_MSC_VER)
360
  return _byteswap_ulong(v);
361
#else
362
  return ((v & 0x000000FF) << 24) |
363
         ((v & 0x0000FF00) << 8) |
364
         ((v & 0x00FF0000) >> 8) |
365
         ((v & 0xFF000000) >> 24);
366
#endif
367
1.90k
}
Unexecuted instantiation: deflate_compress.c:bswap32
Unexecuted instantiation: utils.c:bswap32
Unexecuted instantiation: deflate_decompress.c:bswap32
Unexecuted instantiation: cpu_features.c:bswap32
Unexecuted instantiation: zlib_compress.c:bswap32
Unexecuted instantiation: adler32.c:bswap32
zlib_decompress.c:bswap32
Line
Count
Source
356
1.90k
{
357
1.90k
#if defined(__GNUC__) || __has_builtin(__builtin_bswap32)
358
1.90k
  return __builtin_bswap32(v);
359
#elif defined(_MSC_VER)
360
  return _byteswap_ulong(v);
361
#else
362
  return ((v & 0x000000FF) << 24) |
363
         ((v & 0x0000FF00) << 8) |
364
         ((v & 0x00FF0000) >> 8) |
365
         ((v & 0xFF000000) >> 24);
366
#endif
367
1.90k
}
368
369
/* bswap64(v) - swap the bytes of a 64-bit integer */
370
static forceinline u64 bswap64(u64 v)
371
0
{
372
0
#if defined(__GNUC__) || __has_builtin(__builtin_bswap64)
373
0
  return __builtin_bswap64(v);
374
0
#elif defined(_MSC_VER)
375
0
  return _byteswap_uint64(v);
376
0
#else
377
0
  return ((v & 0x00000000000000FF) << 56) |
378
0
         ((v & 0x000000000000FF00) << 40) |
379
0
         ((v & 0x0000000000FF0000) << 24) |
380
0
         ((v & 0x00000000FF000000) << 8) |
381
0
         ((v & 0x000000FF00000000) >> 8) |
382
0
         ((v & 0x0000FF0000000000) >> 24) |
383
0
         ((v & 0x00FF000000000000) >> 40) |
384
0
         ((v & 0xFF00000000000000) >> 56);
385
0
#endif
386
0
}
Unexecuted instantiation: deflate_compress.c:bswap64
Unexecuted instantiation: utils.c:bswap64
Unexecuted instantiation: deflate_decompress.c:bswap64
Unexecuted instantiation: cpu_features.c:bswap64
Unexecuted instantiation: zlib_compress.c:bswap64
Unexecuted instantiation: adler32.c:bswap64
Unexecuted instantiation: zlib_decompress.c:bswap64
387
388
504
#define le16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap16(v))
389
0
#define le32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap32(v))
390
193k
#define le64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? (v) : bswap64(v))
391
4.99k
#define be16_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap16(v) : (v))
392
1.90k
#define be32_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap32(v) : (v))
393
#define be64_bswap(v) (CPU_IS_LITTLE_ENDIAN() ? bswap64(v) : (v))
394
395
/* ========================================================================== */
396
/*                          Unaligned memory accesses                         */
397
/* ========================================================================== */
398
399
/*
400
 * UNALIGNED_ACCESS_IS_FAST() - 1 if unaligned memory accesses can be performed
401
 * efficiently on the target platform, otherwise 0.
402
 */
403
#if (defined(__GNUC__) || defined(__clang__)) && \
404
  (defined(ARCH_X86_64) || defined(ARCH_X86_32) || \
405
   defined(__ARM_FEATURE_UNALIGNED) || \
406
   defined(__powerpc64__) || defined(__powerpc__) || defined(__POWERPC__) || \
407
   defined(__riscv_misaligned_fast) || \
408
   /*
409
    * For all compilation purposes, WebAssembly behaves like any other CPU
410
    * instruction set. Even though WebAssembly engine might be running on
411
    * top of different actual CPU architectures, the WebAssembly spec
412
    * itself permits unaligned access and it will be fast on most of those
413
    * platforms, and simulated at the engine level on others, so it's
414
    * worth treating it as a CPU architecture with fast unaligned access.
415
    */ defined(__wasm__))
416
1.39M
#  define UNALIGNED_ACCESS_IS_FAST  1
417
#elif defined(_MSC_VER)
418
#  define UNALIGNED_ACCESS_IS_FAST  1
419
#else
420
#  define UNALIGNED_ACCESS_IS_FAST  0
421
#endif
422
423
/*
424
 * Implementing unaligned memory accesses using memcpy() is portable, and it
425
 * usually gets optimized appropriately by modern compilers.  I.e., each
426
 * memcpy() of 1, 2, 4, or WORDBYTES bytes gets compiled to a load or store
427
 * instruction, not to an actual function call.
428
 *
429
 * We no longer use the "packed struct" approach to unaligned accesses, as that
430
 * is nonstandard, has unclear semantics, and doesn't receive enough testing
431
 * (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94994).
432
 *
433
 * arm32 with __ARM_FEATURE_UNALIGNED in gcc 5 and earlier is a known exception
434
 * where memcpy() generates inefficient code
435
 * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67366).  However, we no longer
436
 * consider that one case important enough to maintain different code for.
437
 * If you run into it, please just use a newer version of gcc (or use clang).
438
 */
439
440
#ifdef FREESTANDING
441
#  define MEMCOPY __builtin_memcpy
442
#else
443
4.28M
#  define MEMCOPY memcpy
444
#endif
445
446
/* Unaligned loads and stores without endianness conversion */
447
448
#define DEFINE_UNALIGNED_TYPE(type)       \
449
static forceinline type           \
450
2.20M
load_##type##_unaligned(const void *p)        \
451
2.20M
{               \
452
2.20M
  type v;             \
453
2.20M
                \
454
2.20M
  MEMCOPY(&v, p, sizeof(v));       \
455
2.20M
  return v;           \
456
2.20M
}                \
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
deflate_decompress.c:load_u64_unaligned
Line
Count
Source
450
193k
load_##type##_unaligned(const void *p)        \
451
193k
{               \
452
193k
  type v;             \
453
193k
                \
454
193k
  MEMCOPY(&v, p, sizeof(v));       \
455
193k
  return v;           \
456
193k
}                \
deflate_decompress.c:load_u16_unaligned
Line
Count
Source
450
504
load_##type##_unaligned(const void *p)        \
451
504
{               \
452
504
  type v;             \
453
504
                \
454
504
  MEMCOPY(&v, p, sizeof(v));       \
455
504
  return v;           \
456
504
}                \
deflate_decompress.c:load_machine_word_t_unaligned
Line
Count
Source
450
2.00M
load_##type##_unaligned(const void *p)        \
451
2.00M
{               \
452
2.00M
  type v;             \
453
2.00M
                \
454
2.00M
  MEMCOPY(&v, p, sizeof(v));       \
455
2.00M
  return v;           \
456
2.00M
}                \
Unexecuted instantiation: deflate_decompress.c:load_u32_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: 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
450
4.99k
load_##type##_unaligned(const void *p)        \
451
4.99k
{               \
452
4.99k
  type v;             \
453
4.99k
                \
454
4.99k
  MEMCOPY(&v, p, sizeof(v));       \
455
4.99k
  return v;           \
456
4.99k
}                \
zlib_decompress.c:load_u32_unaligned
Line
Count
Source
450
1.90k
load_##type##_unaligned(const void *p)        \
451
1.90k
{               \
452
1.90k
  type v;             \
453
1.90k
                \
454
1.90k
  MEMCOPY(&v, p, sizeof(v));       \
455
1.90k
  return v;           \
456
1.90k
}                \
Unexecuted instantiation: zlib_decompress.c:load_u64_unaligned
Unexecuted instantiation: zlib_decompress.c:load_machine_word_t_unaligned
457
                \
458
static forceinline void           \
459
2.07M
store_##type##_unaligned(type v, void *p)     \
460
2.07M
{               \
461
2.07M
  MEMCOPY(p, &v, sizeof(v));       \
462
2.07M
}
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
deflate_decompress.c:store_machine_word_t_unaligned
Line
Count
Source
459
2.07M
store_##type##_unaligned(type v, void *p)     \
460
2.07M
{               \
461
2.07M
  MEMCOPY(p, &v, sizeof(v));       \
462
2.07M
}
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: 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: 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
463
464
DEFINE_UNALIGNED_TYPE(u16)
465
DEFINE_UNALIGNED_TYPE(u32)
466
DEFINE_UNALIGNED_TYPE(u64)
467
DEFINE_UNALIGNED_TYPE(machine_word_t)
468
469
#undef MEMCOPY
470
471
2.00M
#define load_word_unaligned load_machine_word_t_unaligned
472
2.07M
#define store_word_unaligned  store_machine_word_t_unaligned
473
474
/* Unaligned loads with endianness conversion */
475
476
static forceinline u16
477
get_unaligned_le16(const u8 *p)
478
504
{
479
504
  if (UNALIGNED_ACCESS_IS_FAST)
480
504
    return le16_bswap(load_u16_unaligned(p));
481
0
  else
482
0
    return ((u16)p[1] << 8) | p[0];
483
504
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_le16
Unexecuted instantiation: utils.c:get_unaligned_le16
deflate_decompress.c:get_unaligned_le16
Line
Count
Source
478
504
{
479
504
  if (UNALIGNED_ACCESS_IS_FAST)
480
504
    return le16_bswap(load_u16_unaligned(p));
481
0
  else
482
0
    return ((u16)p[1] << 8) | p[0];
483
504
}
Unexecuted instantiation: cpu_features.c:get_unaligned_le16
Unexecuted instantiation: zlib_compress.c:get_unaligned_le16
Unexecuted instantiation: adler32.c:get_unaligned_le16
Unexecuted instantiation: zlib_decompress.c:get_unaligned_le16
484
485
static forceinline u16
486
get_unaligned_be16(const u8 *p)
487
4.99k
{
488
4.99k
  if (UNALIGNED_ACCESS_IS_FAST)
489
4.99k
    return be16_bswap(load_u16_unaligned(p));
490
0
  else
491
0
    return ((u16)p[0] << 8) | p[1];
492
4.99k
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_be16
Unexecuted instantiation: utils.c:get_unaligned_be16
Unexecuted instantiation: deflate_decompress.c:get_unaligned_be16
Unexecuted instantiation: cpu_features.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
487
4.99k
{
488
4.99k
  if (UNALIGNED_ACCESS_IS_FAST)
489
4.99k
    return be16_bswap(load_u16_unaligned(p));
490
0
  else
491
0
    return ((u16)p[0] << 8) | p[1];
492
4.99k
}
493
494
static forceinline u32
495
get_unaligned_le32(const u8 *p)
496
0
{
497
0
  if (UNALIGNED_ACCESS_IS_FAST)
498
0
    return le32_bswap(load_u32_unaligned(p));
499
0
  else
500
0
    return ((u32)p[3] << 24) | ((u32)p[2] << 16) |
501
0
      ((u32)p[1] << 8) | p[0];
502
0
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_le32
Unexecuted instantiation: utils.c:get_unaligned_le32
Unexecuted instantiation: deflate_decompress.c:get_unaligned_le32
Unexecuted instantiation: cpu_features.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
503
504
static forceinline u32
505
get_unaligned_be32(const u8 *p)
506
1.90k
{
507
1.90k
  if (UNALIGNED_ACCESS_IS_FAST)
508
1.90k
    return be32_bswap(load_u32_unaligned(p));
509
0
  else
510
0
    return ((u32)p[0] << 24) | ((u32)p[1] << 16) |
511
0
      ((u32)p[2] << 8) | p[3];
512
1.90k
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_be32
Unexecuted instantiation: utils.c:get_unaligned_be32
Unexecuted instantiation: deflate_decompress.c:get_unaligned_be32
Unexecuted instantiation: cpu_features.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
506
1.90k
{
507
1.90k
  if (UNALIGNED_ACCESS_IS_FAST)
508
1.90k
    return be32_bswap(load_u32_unaligned(p));
509
0
  else
510
0
    return ((u32)p[0] << 24) | ((u32)p[1] << 16) |
511
0
      ((u32)p[2] << 8) | p[3];
512
1.90k
}
513
514
static forceinline u64
515
get_unaligned_le64(const u8 *p)
516
193k
{
517
193k
  if (UNALIGNED_ACCESS_IS_FAST)
518
193k
    return le64_bswap(load_u64_unaligned(p));
519
0
  else
520
0
    return ((u64)p[7] << 56) | ((u64)p[6] << 48) |
521
0
      ((u64)p[5] << 40) | ((u64)p[4] << 32) |
522
0
      ((u64)p[3] << 24) | ((u64)p[2] << 16) |
523
0
      ((u64)p[1] << 8) | p[0];
524
193k
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_le64
Unexecuted instantiation: utils.c:get_unaligned_le64
deflate_decompress.c:get_unaligned_le64
Line
Count
Source
516
193k
{
517
193k
  if (UNALIGNED_ACCESS_IS_FAST)
518
193k
    return le64_bswap(load_u64_unaligned(p));
519
0
  else
520
0
    return ((u64)p[7] << 56) | ((u64)p[6] << 48) |
521
0
      ((u64)p[5] << 40) | ((u64)p[4] << 32) |
522
0
      ((u64)p[3] << 24) | ((u64)p[2] << 16) |
523
0
      ((u64)p[1] << 8) | p[0];
524
193k
}
Unexecuted instantiation: cpu_features.c:get_unaligned_le64
Unexecuted instantiation: zlib_compress.c:get_unaligned_le64
Unexecuted instantiation: adler32.c:get_unaligned_le64
Unexecuted instantiation: zlib_decompress.c:get_unaligned_le64
525
526
static forceinline machine_word_t
527
get_unaligned_leword(const u8 *p)
528
193k
{
529
193k
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
530
193k
  if (WORDBITS == 32)
531
0
    return get_unaligned_le32(p);
532
193k
  else
533
193k
    return get_unaligned_le64(p);
534
193k
}
Unexecuted instantiation: deflate_compress.c:get_unaligned_leword
Unexecuted instantiation: utils.c:get_unaligned_leword
deflate_decompress.c:get_unaligned_leword
Line
Count
Source
528
193k
{
529
193k
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
530
193k
  if (WORDBITS == 32)
531
0
    return get_unaligned_le32(p);
532
193k
  else
533
193k
    return get_unaligned_le64(p);
534
193k
}
Unexecuted instantiation: cpu_features.c:get_unaligned_leword
Unexecuted instantiation: zlib_compress.c:get_unaligned_leword
Unexecuted instantiation: adler32.c:get_unaligned_leword
Unexecuted instantiation: zlib_decompress.c:get_unaligned_leword
535
536
/* Unaligned stores with endianness conversion */
537
538
static forceinline void
539
put_unaligned_le16(u16 v, u8 *p)
540
0
{
541
0
  if (UNALIGNED_ACCESS_IS_FAST) {
542
0
    store_u16_unaligned(le16_bswap(v), p);
543
0
  } else {
544
0
    p[0] = (u8)(v >> 0);
545
0
    p[1] = (u8)(v >> 8);
546
0
  }
547
0
}
Unexecuted instantiation: deflate_compress.c:put_unaligned_le16
Unexecuted instantiation: utils.c:put_unaligned_le16
Unexecuted instantiation: deflate_decompress.c:put_unaligned_le16
Unexecuted instantiation: cpu_features.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
548
549
static forceinline void
550
put_unaligned_be16(u16 v, u8 *p)
551
0
{
552
0
  if (UNALIGNED_ACCESS_IS_FAST) {
553
0
    store_u16_unaligned(be16_bswap(v), p);
554
0
  } else {
555
0
    p[0] = (u8)(v >> 8);
556
0
    p[1] = (u8)(v >> 0);
557
0
  }
558
0
}
Unexecuted instantiation: deflate_compress.c:put_unaligned_be16
Unexecuted instantiation: utils.c:put_unaligned_be16
Unexecuted instantiation: deflate_decompress.c:put_unaligned_be16
Unexecuted instantiation: cpu_features.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
559
560
static forceinline void
561
put_unaligned_le32(u32 v, u8 *p)
562
0
{
563
0
  if (UNALIGNED_ACCESS_IS_FAST) {
564
0
    store_u32_unaligned(le32_bswap(v), p);
565
0
  } else {
566
0
    p[0] = (u8)(v >> 0);
567
0
    p[1] = (u8)(v >> 8);
568
0
    p[2] = (u8)(v >> 16);
569
0
    p[3] = (u8)(v >> 24);
570
0
  }
571
0
}
Unexecuted instantiation: deflate_compress.c:put_unaligned_le32
Unexecuted instantiation: utils.c:put_unaligned_le32
Unexecuted instantiation: deflate_decompress.c:put_unaligned_le32
Unexecuted instantiation: cpu_features.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
572
573
static forceinline void
574
put_unaligned_be32(u32 v, u8 *p)
575
0
{
576
0
  if (UNALIGNED_ACCESS_IS_FAST) {
577
0
    store_u32_unaligned(be32_bswap(v), p);
578
0
  } else {
579
0
    p[0] = (u8)(v >> 24);
580
0
    p[1] = (u8)(v >> 16);
581
0
    p[2] = (u8)(v >> 8);
582
0
    p[3] = (u8)(v >> 0);
583
0
  }
584
0
}
Unexecuted instantiation: deflate_compress.c:put_unaligned_be32
Unexecuted instantiation: utils.c:put_unaligned_be32
Unexecuted instantiation: deflate_decompress.c:put_unaligned_be32
Unexecuted instantiation: cpu_features.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
585
586
static forceinline void
587
put_unaligned_le64(u64 v, u8 *p)
588
0
{
589
0
  if (UNALIGNED_ACCESS_IS_FAST) {
590
0
    store_u64_unaligned(le64_bswap(v), p);
591
0
  } else {
592
0
    p[0] = (u8)(v >> 0);
593
0
    p[1] = (u8)(v >> 8);
594
0
    p[2] = (u8)(v >> 16);
595
0
    p[3] = (u8)(v >> 24);
596
0
    p[4] = (u8)(v >> 32);
597
0
    p[5] = (u8)(v >> 40);
598
0
    p[6] = (u8)(v >> 48);
599
0
    p[7] = (u8)(v >> 56);
600
0
  }
601
0
}
Unexecuted instantiation: deflate_compress.c:put_unaligned_le64
Unexecuted instantiation: utils.c:put_unaligned_le64
Unexecuted instantiation: deflate_decompress.c:put_unaligned_le64
Unexecuted instantiation: cpu_features.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
602
603
static forceinline void
604
put_unaligned_leword(machine_word_t v, u8 *p)
605
0
{
606
0
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
607
0
  if (WORDBITS == 32)
608
0
    put_unaligned_le32(v, p);
609
0
  else
610
0
    put_unaligned_le64(v, p);
611
0
}
Unexecuted instantiation: deflate_compress.c:put_unaligned_leword
Unexecuted instantiation: utils.c:put_unaligned_leword
Unexecuted instantiation: deflate_decompress.c:put_unaligned_leword
Unexecuted instantiation: cpu_features.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
612
613
/* ========================================================================== */
614
/*                         Bit manipulation functions                         */
615
/* ========================================================================== */
616
617
/*
618
 * Bit Scan Reverse (BSR) - find the 0-based index (relative to the least
619
 * significant end) of the *most* significant 1 bit in the input value.  The
620
 * input value must be nonzero!
621
 */
622
623
static forceinline unsigned
624
bsr32(u32 v)
625
212k
{
626
212k
#if defined(__GNUC__) || __has_builtin(__builtin_clz)
627
212k
  return 31 - __builtin_clz(v);
628
#elif defined(_MSC_VER)
629
  unsigned long i;
630
631
  _BitScanReverse(&i, v);
632
  return i;
633
#else
634
  unsigned i = 0;
635
636
  while ((v >>= 1) != 0)
637
    i++;
638
  return i;
639
#endif
640
212k
}
Unexecuted instantiation: deflate_compress.c:bsr32
Unexecuted instantiation: utils.c:bsr32
deflate_decompress.c:bsr32
Line
Count
Source
625
212k
{
626
212k
#if defined(__GNUC__) || __has_builtin(__builtin_clz)
627
212k
  return 31 - __builtin_clz(v);
628
#elif defined(_MSC_VER)
629
  unsigned long i;
630
631
  _BitScanReverse(&i, v);
632
  return i;
633
#else
634
  unsigned i = 0;
635
636
  while ((v >>= 1) != 0)
637
    i++;
638
  return i;
639
#endif
640
212k
}
Unexecuted instantiation: cpu_features.c:bsr32
Unexecuted instantiation: zlib_compress.c:bsr32
Unexecuted instantiation: adler32.c:bsr32
Unexecuted instantiation: zlib_decompress.c:bsr32
641
642
static forceinline unsigned
643
bsr64(u64 v)
644
0
{
645
0
#if defined(__GNUC__) || __has_builtin(__builtin_clzll)
646
0
  return 63 - __builtin_clzll(v);
647
0
#elif defined(_MSC_VER) && defined(_WIN64)
648
0
  unsigned long i;
649
0
650
0
  _BitScanReverse64(&i, v);
651
0
  return i;
652
0
#else
653
0
  unsigned i = 0;
654
0
655
0
  while ((v >>= 1) != 0)
656
0
    i++;
657
0
  return i;
658
0
#endif
659
0
}
Unexecuted instantiation: deflate_compress.c:bsr64
Unexecuted instantiation: utils.c:bsr64
Unexecuted instantiation: deflate_decompress.c:bsr64
Unexecuted instantiation: cpu_features.c:bsr64
Unexecuted instantiation: zlib_compress.c:bsr64
Unexecuted instantiation: adler32.c:bsr64
Unexecuted instantiation: zlib_decompress.c:bsr64
660
661
static forceinline unsigned
662
bsrw(machine_word_t v)
663
0
{
664
0
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
665
0
  if (WORDBITS == 32)
666
0
    return bsr32(v);
667
0
  else
668
0
    return bsr64(v);
669
0
}
Unexecuted instantiation: deflate_compress.c:bsrw
Unexecuted instantiation: utils.c:bsrw
Unexecuted instantiation: deflate_decompress.c:bsrw
Unexecuted instantiation: cpu_features.c:bsrw
Unexecuted instantiation: zlib_compress.c:bsrw
Unexecuted instantiation: adler32.c:bsrw
Unexecuted instantiation: zlib_decompress.c:bsrw
670
671
/*
672
 * Bit Scan Forward (BSF) - find the 0-based index (relative to the least
673
 * significant end) of the *least* significant 1 bit in the input value.  The
674
 * input value must be nonzero!
675
 */
676
677
static forceinline unsigned
678
bsf32(u32 v)
679
0
{
680
0
#if defined(__GNUC__) || __has_builtin(__builtin_ctz)
681
0
  return __builtin_ctz(v);
682
0
#elif defined(_MSC_VER)
683
0
  unsigned long i;
684
0
685
0
  _BitScanForward(&i, v);
686
0
  return i;
687
0
#else
688
0
  unsigned i = 0;
689
0
690
0
  for (; (v & 1) == 0; v >>= 1)
691
0
    i++;
692
0
  return i;
693
0
#endif
694
0
}
Unexecuted instantiation: deflate_compress.c:bsf32
Unexecuted instantiation: utils.c:bsf32
Unexecuted instantiation: deflate_decompress.c:bsf32
Unexecuted instantiation: cpu_features.c:bsf32
Unexecuted instantiation: zlib_compress.c:bsf32
Unexecuted instantiation: adler32.c:bsf32
Unexecuted instantiation: zlib_decompress.c:bsf32
695
696
static forceinline unsigned
697
bsf64(u64 v)
698
0
{
699
0
#if defined(__GNUC__) || __has_builtin(__builtin_ctzll)
700
0
  return __builtin_ctzll(v);
701
#elif defined(_MSC_VER) && defined(_WIN64)
702
  unsigned long i;
703
704
  _BitScanForward64(&i, v);
705
  return i;
706
#else
707
  unsigned i = 0;
708
709
  for (; (v & 1) == 0; v >>= 1)
710
    i++;
711
  return i;
712
#endif
713
0
}
Unexecuted instantiation: deflate_compress.c:bsf64
Unexecuted instantiation: utils.c:bsf64
Unexecuted instantiation: deflate_decompress.c:bsf64
Unexecuted instantiation: cpu_features.c:bsf64
Unexecuted instantiation: zlib_compress.c:bsf64
Unexecuted instantiation: adler32.c:bsf64
Unexecuted instantiation: zlib_decompress.c:bsf64
714
715
static forceinline unsigned
716
bsfw(machine_word_t v)
717
0
{
718
0
  STATIC_ASSERT(WORDBITS == 32 || WORDBITS == 64);
719
0
  if (WORDBITS == 32)
720
0
    return bsf32(v);
721
0
  else
722
0
    return bsf64(v);
723
0
}
Unexecuted instantiation: deflate_compress.c:bsfw
Unexecuted instantiation: utils.c:bsfw
Unexecuted instantiation: deflate_decompress.c:bsfw
Unexecuted instantiation: cpu_features.c:bsfw
Unexecuted instantiation: zlib_compress.c:bsfw
Unexecuted instantiation: adler32.c:bsfw
Unexecuted instantiation: zlib_decompress.c:bsfw
724
725
/*
726
 * rbit32(v): reverse the bits in a 32-bit integer.  This doesn't have a
727
 * fallback implementation; use '#ifdef rbit32' to check if this is available.
728
 */
729
#undef rbit32
730
#if (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM32) && \
731
  (__ARM_ARCH >= 7 || (__ARM_ARCH == 6 && defined(__ARM_ARCH_6T2__)))
732
static forceinline u32
733
rbit32(u32 v)
734
{
735
  __asm__("rbit %0, %1" : "=r" (v) : "r" (v));
736
  return v;
737
}
738
#define rbit32 rbit32
739
#elif (defined(__GNUC__) || defined(__clang__)) && defined(ARCH_ARM64)
740
static forceinline u32
741
rbit32(u32 v)
742
{
743
  __asm__("rbit %w0, %w1" : "=r" (v) : "r" (v));
744
  return v;
745
}
746
#define rbit32 rbit32
747
#endif
748
749
#endif /* COMMON_DEFS_H */