Coverage Report

Created: 2024-07-27 06:04

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