/src/brotli/c/common/platform.h
Line | Count | Source |
1 | | /* Copyright 2016 Google Inc. All Rights Reserved. |
2 | | |
3 | | Distributed under MIT license. |
4 | | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
5 | | */ |
6 | | |
7 | | /* Macros for compiler / platform specific features and build options. |
8 | | |
9 | | Build options are: |
10 | | * BROTLI_BUILD_32_BIT disables 64-bit optimizations |
11 | | * BROTLI_BUILD_64_BIT forces to use 64-bit optimizations |
12 | | * BROTLI_BUILD_BIG_ENDIAN forces to use big-endian optimizations |
13 | | * BROTLI_BUILD_ENDIAN_NEUTRAL disables endian-aware optimizations |
14 | | * BROTLI_BUILD_LITTLE_ENDIAN forces to use little-endian optimizations |
15 | | * BROTLI_BUILD_NO_RBIT disables "rbit" optimization for ARM CPUs |
16 | | * BROTLI_BUILD_NO_UNALIGNED_READ_FAST forces off the fast-unaligned-read |
17 | | optimizations (mainly for testing purposes) |
18 | | * BROTLI_DEBUG dumps file name and line number when decoder detects stream |
19 | | or memory error |
20 | | * BROTLI_ENABLE_LOG enables asserts and dumps various state information |
21 | | * BROTLI_ENABLE_DUMP overrides default "dump" behaviour |
22 | | */ |
23 | | |
24 | | #ifndef BROTLI_COMMON_PLATFORM_H_ |
25 | | #define BROTLI_COMMON_PLATFORM_H_ |
26 | | |
27 | | #include <limits.h> |
28 | | #include <string.h> /* IWYU pragma: export memcmp, memcpy, memset */ |
29 | | #include <stdlib.h> /* IWYU pragma: export exit, free, malloc */ |
30 | | #include <sys/types.h> /* should include endian.h for us */ |
31 | | |
32 | | #include <brotli/port.h> /* IWYU pragma: export */ |
33 | | #include <brotli/types.h> /* IWYU pragma: export */ |
34 | | |
35 | | #if BROTLI_MSVC_VERSION_CHECK(18, 0, 0) |
36 | | #include <intrin.h> |
37 | | #endif |
38 | | |
39 | | #if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG) |
40 | | #include <assert.h> |
41 | | #include <stdio.h> |
42 | | #endif |
43 | | |
44 | | /* The following macros were borrowed from https://github.com/nemequ/hedley |
45 | | * with permission of original author - Evan Nemerson <evan@nemerson.com> */ |
46 | | |
47 | | /* >>> >>> >>> hedley macros */ |
48 | | |
49 | | /* Define "BROTLI_PREDICT_TRUE" and "BROTLI_PREDICT_FALSE" macros for capable |
50 | | compilers. |
51 | | |
52 | | To apply compiler hint, enclose the branching condition into macros, like this: |
53 | | |
54 | | if (BROTLI_PREDICT_TRUE(zero == 0)) { |
55 | | // main execution path |
56 | | } else { |
57 | | // compiler should place this code outside of main execution path |
58 | | } |
59 | | |
60 | | OR: |
61 | | |
62 | | if (BROTLI_PREDICT_FALSE(something_rare_or_unexpected_happens)) { |
63 | | // compiler should place this code outside of main execution path |
64 | | } |
65 | | |
66 | | */ |
67 | | #if BROTLI_GNUC_HAS_BUILTIN(__builtin_expect, 3, 0, 0) || \ |
68 | | BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \ |
69 | | BROTLI_SUNPRO_VERSION_CHECK(5, 15, 0) || \ |
70 | | BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \ |
71 | | BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \ |
72 | | BROTLI_TI_VERSION_CHECK(7, 3, 0) || \ |
73 | | BROTLI_TINYC_VERSION_CHECK(0, 9, 27) |
74 | 0 | #define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) |
75 | 0 | #define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0)) |
76 | | #else |
77 | | #define BROTLI_PREDICT_FALSE(x) (x) |
78 | | #define BROTLI_PREDICT_TRUE(x) (x) |
79 | | #endif |
80 | | |
81 | | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ |
82 | | !defined(__cplusplus) |
83 | | #define BROTLI_RESTRICT restrict |
84 | | #elif BROTLI_GNUC_VERSION_CHECK(3, 1, 0) || \ |
85 | | BROTLI_MSVC_VERSION_CHECK(14, 0, 0) || \ |
86 | | BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \ |
87 | | BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \ |
88 | | BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \ |
89 | | BROTLI_PGI_VERSION_CHECK(17, 10, 0) || \ |
90 | | BROTLI_TI_VERSION_CHECK(8, 0, 0) || \ |
91 | | BROTLI_IAR_VERSION_CHECK(8, 0, 0) || \ |
92 | | (BROTLI_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus)) |
93 | | #define BROTLI_RESTRICT __restrict |
94 | | #elif BROTLI_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus) |
95 | | #define BROTLI_RESTRICT _Restrict |
96 | | #else |
97 | | #define BROTLI_RESTRICT |
98 | | #endif |
99 | | |
100 | | #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ |
101 | | (defined(__cplusplus) && (__cplusplus >= 199711L)) |
102 | | #define BROTLI_MAYBE_INLINE inline |
103 | | #elif defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__) || \ |
104 | | BROTLI_ARM_VERSION_CHECK(6, 2, 0) |
105 | | #define BROTLI_MAYBE_INLINE __inline__ |
106 | | #elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0) || \ |
107 | | BROTLI_ARM_VERSION_CHECK(4, 1, 0) || BROTLI_TI_VERSION_CHECK(8, 0, 0) |
108 | | #define BROTLI_MAYBE_INLINE __inline |
109 | | #else |
110 | | #define BROTLI_MAYBE_INLINE |
111 | | #endif |
112 | | |
113 | | #if BROTLI_GNUC_HAS_ATTRIBUTE(always_inline, 4, 0, 0) || \ |
114 | | BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \ |
115 | | BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \ |
116 | | BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \ |
117 | | BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \ |
118 | | BROTLI_TI_VERSION_CHECK(8, 0, 0) || \ |
119 | | (BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) |
120 | | #define BROTLI_INLINE BROTLI_MAYBE_INLINE __attribute__((__always_inline__)) |
121 | | #elif BROTLI_MSVC_VERSION_CHECK(12, 0, 0) |
122 | | #define BROTLI_INLINE BROTLI_MAYBE_INLINE __forceinline |
123 | | #elif BROTLI_TI_VERSION_CHECK(7, 0, 0) && defined(__cplusplus) |
124 | | #define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("FUNC_ALWAYS_INLINE;") |
125 | | #elif BROTLI_IAR_VERSION_CHECK(8, 0, 0) |
126 | | #define BROTLI_INLINE BROTLI_MAYBE_INLINE _Pragma("inline=forced") |
127 | | #else |
128 | | #define BROTLI_INLINE BROTLI_MAYBE_INLINE |
129 | | #endif |
130 | | |
131 | | #if BROTLI_GNUC_HAS_ATTRIBUTE(noinline, 4, 0, 0) || \ |
132 | | BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \ |
133 | | BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \ |
134 | | BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \ |
135 | | BROTLI_IBM_VERSION_CHECK(10, 1, 0) || \ |
136 | | BROTLI_TI_VERSION_CHECK(8, 0, 0) || \ |
137 | | (BROTLI_TI_VERSION_CHECK(7, 3, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) |
138 | | #define BROTLI_NOINLINE __attribute__((__noinline__)) |
139 | | #elif BROTLI_MSVC_VERSION_CHECK(13, 10, 0) |
140 | | #define BROTLI_NOINLINE __declspec(noinline) |
141 | | #elif BROTLI_PGI_VERSION_CHECK(10, 2, 0) |
142 | | #define BROTLI_NOINLINE _Pragma("noinline") |
143 | | #elif BROTLI_TI_VERSION_CHECK(6, 0, 0) && defined(__cplusplus) |
144 | | #define BROTLI_NOINLINE _Pragma("FUNC_CANNOT_INLINE;") |
145 | | #elif BROTLI_IAR_VERSION_CHECK(8, 0, 0) |
146 | | #define BROTLI_NOINLINE _Pragma("inline=never") |
147 | | #else |
148 | | #define BROTLI_NOINLINE |
149 | | #endif |
150 | | |
151 | | /* <<< <<< <<< end of hedley macros. */ |
152 | | |
153 | | #if BROTLI_GNUC_HAS_ATTRIBUTE(unused, 2, 7, 0) || \ |
154 | | BROTLI_INTEL_VERSION_CHECK(16, 0, 0) |
155 | | #define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE __attribute__ ((unused)) |
156 | | #else |
157 | | #define BROTLI_UNUSED_FUNCTION static BROTLI_INLINE |
158 | | #endif |
159 | | |
160 | | #if BROTLI_GNUC_HAS_ATTRIBUTE(aligned, 2, 7, 0) |
161 | | #define BROTLI_ALIGNED(N) __attribute__((aligned(N))) |
162 | | #else |
163 | | #define BROTLI_ALIGNED(N) |
164 | | #endif |
165 | | |
166 | | #if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \ |
167 | | (defined(M_ARM) && (M_ARM == 7)) |
168 | | #define BROTLI_TARGET_ARMV7 |
169 | | #endif /* ARMv7 */ |
170 | | |
171 | | #if (defined(__ARM_ARCH) && (__ARM_ARCH == 8)) || \ |
172 | | defined(__aarch64__) || defined(__ARM64_ARCH_8__) |
173 | | #define BROTLI_TARGET_ARMV8_ANY |
174 | | |
175 | | #if defined(__ARM_32BIT_STATE) |
176 | | #define BROTLI_TARGET_ARMV8_32 |
177 | | #elif defined(__ARM_64BIT_STATE) |
178 | | #define BROTLI_TARGET_ARMV8_64 |
179 | | #endif |
180 | | |
181 | | #endif /* ARMv8 */ |
182 | | |
183 | | #if defined(__ARM_NEON__) || defined(__ARM_NEON) |
184 | | #define BROTLI_TARGET_NEON |
185 | | #endif |
186 | | |
187 | | #if defined(__i386) || defined(_M_IX86) |
188 | | #define BROTLI_TARGET_X86 |
189 | | #endif |
190 | | |
191 | | #if defined(__x86_64__) || defined(_M_X64) |
192 | | #define BROTLI_TARGET_X64 |
193 | | #endif |
194 | | |
195 | | #if defined(__PPC64__) |
196 | | #define BROTLI_TARGET_POWERPC64 |
197 | | #endif |
198 | | |
199 | | #if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64 |
200 | | #define BROTLI_TARGET_RISCV64 |
201 | | #endif |
202 | | |
203 | | #if defined(__loongarch_lp64) |
204 | | #define BROTLI_TARGET_LOONGARCH64 |
205 | | #endif |
206 | | |
207 | | /* This does not seem to be an indicator of z/Architecture (64-bit); neither |
208 | | that allows to use unaligned loads. */ |
209 | | #if defined(__s390x__) |
210 | | #define BROTLI_TARGET_S390X |
211 | | #endif |
212 | | |
213 | | #if defined(__mips64) |
214 | | #define BROTLI_TARGET_MIPS64 |
215 | | #endif |
216 | | |
217 | | #if defined(__ia64__) || defined(_M_IA64) |
218 | | #define BROTLI_TARGET_IA64 |
219 | | #endif |
220 | | |
221 | | #if defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8_64) || \ |
222 | | defined(BROTLI_TARGET_POWERPC64) || defined(BROTLI_TARGET_RISCV64) || \ |
223 | | defined(BROTLI_TARGET_LOONGARCH64) || defined(BROTLI_TARGET_MIPS64) |
224 | 0 | #define BROTLI_TARGET_64_BITS 1 |
225 | | #else |
226 | | #define BROTLI_TARGET_64_BITS 0 |
227 | | #endif |
228 | | |
229 | | #if defined(BROTLI_BUILD_64_BIT) |
230 | | #define BROTLI_64_BITS 1 |
231 | | #elif defined(BROTLI_BUILD_32_BIT) |
232 | | #define BROTLI_64_BITS 0 |
233 | | #else |
234 | 0 | #define BROTLI_64_BITS BROTLI_TARGET_64_BITS |
235 | | #endif |
236 | | |
237 | | #if (BROTLI_64_BITS) |
238 | 0 | #define brotli_reg_t uint64_t |
239 | | #else |
240 | | #define brotli_reg_t uint32_t |
241 | | #endif |
242 | | |
243 | | #if defined(BROTLI_BUILD_BIG_ENDIAN) |
244 | | #define BROTLI_BIG_ENDIAN 1 |
245 | | #elif defined(BROTLI_BUILD_LITTLE_ENDIAN) |
246 | | #define BROTLI_LITTLE_ENDIAN 1 |
247 | | #elif defined(BROTLI_BUILD_ENDIAN_NEUTRAL) |
248 | | /* Just break elif chain. */ |
249 | | #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
250 | | #define BROTLI_LITTLE_ENDIAN 1 |
251 | | #elif defined(_WIN32) || defined(BROTLI_TARGET_X64) |
252 | | /* Win32 & x64 can currently always be assumed to be little endian */ |
253 | | #define BROTLI_LITTLE_ENDIAN 1 |
254 | | #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) |
255 | | #define BROTLI_BIG_ENDIAN 1 |
256 | | /* Likely target platform is iOS / OSX. */ |
257 | | #elif defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN) |
258 | | #define BROTLI_LITTLE_ENDIAN 1 |
259 | | #elif defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN) |
260 | | #define BROTLI_BIG_ENDIAN 1 |
261 | | #endif |
262 | | |
263 | | #if !defined(BROTLI_LITTLE_ENDIAN) |
264 | | #define BROTLI_LITTLE_ENDIAN 0 |
265 | | #endif |
266 | | |
267 | | #if !defined(BROTLI_BIG_ENDIAN) |
268 | | #define BROTLI_BIG_ENDIAN 0 |
269 | | #endif |
270 | | |
271 | | #if defined(BROTLI_BUILD_NO_UNALIGNED_READ_FAST) |
272 | | #define BROTLI_UNALIGNED_READ_FAST (!!0) |
273 | | #elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \ |
274 | | defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY) || \ |
275 | | defined(BROTLI_TARGET_RISCV64) || defined(BROTLI_TARGET_LOONGARCH64) |
276 | | /* These targets are known to generate efficient code for unaligned reads |
277 | | * (e.g. a single instruction, not multiple 1-byte loads, shifted and or'd |
278 | | * together). */ |
279 | 0 | #define BROTLI_UNALIGNED_READ_FAST (!!1) |
280 | | #else |
281 | | #define BROTLI_UNALIGNED_READ_FAST (!!0) |
282 | | #endif |
283 | | |
284 | | /* Portable unaligned memory access: read / write values via memcpy. */ |
285 | | #if !defined(BROTLI_USE_PACKED_FOR_UNALIGNED) |
286 | | #if defined(__mips__) && (!defined(__mips_isa_rev) || __mips_isa_rev < 6) |
287 | | #define BROTLI_USE_PACKED_FOR_UNALIGNED 1 |
288 | | #else |
289 | | #define BROTLI_USE_PACKED_FOR_UNALIGNED 0 |
290 | | #endif |
291 | | #endif /* defined(BROTLI_USE_PACKED_FOR_UNALIGNED) */ |
292 | | |
293 | | #if BROTLI_USE_PACKED_FOR_UNALIGNED |
294 | | |
295 | | typedef union BrotliPackedValue { |
296 | | uint16_t u16; |
297 | | uint32_t u32; |
298 | | uint64_t u64; |
299 | | size_t szt; |
300 | | } __attribute__ ((packed)) BrotliPackedValue; |
301 | | |
302 | | static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) { |
303 | | const BrotliPackedValue* address = (const BrotliPackedValue*)p; |
304 | | return address->u16; |
305 | | } |
306 | | static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) { |
307 | | const BrotliPackedValue* address = (const BrotliPackedValue*)p; |
308 | | return address->u32; |
309 | | } |
310 | | static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) { |
311 | | const BrotliPackedValue* address = (const BrotliPackedValue*)p; |
312 | | return address->u64; |
313 | | } |
314 | | static BROTLI_INLINE size_t BrotliUnalignedReadSizeT(const void* p) { |
315 | | const BrotliPackedValue* address = (const BrotliPackedValue*)p; |
316 | | return address->szt; |
317 | | } |
318 | | static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) { |
319 | | BrotliPackedValue* address = (BrotliPackedValue*)p; |
320 | | address->u64 = v; |
321 | | } |
322 | | |
323 | | #else /* not BROTLI_USE_PACKED_FOR_UNALIGNED */ |
324 | | |
325 | 0 | static BROTLI_INLINE uint16_t BrotliUnalignedRead16(const void* p) { |
326 | 0 | uint16_t t; |
327 | 0 | memcpy(&t, p, sizeof t); |
328 | 0 | return t; |
329 | 0 | } Unexecuted instantiation: decode.c:BrotliUnalignedRead16 Unexecuted instantiation: huffman.c:BrotliUnalignedRead16 Unexecuted instantiation: prefix.c:BrotliUnalignedRead16 Unexecuted instantiation: state.c:BrotliUnalignedRead16 Unexecuted instantiation: static_init.c:BrotliUnalignedRead16 Unexecuted instantiation: bit_reader.c:BrotliUnalignedRead16 Unexecuted instantiation: constants.c:BrotliUnalignedRead16 Unexecuted instantiation: context.c:BrotliUnalignedRead16 Unexecuted instantiation: platform.c:BrotliUnalignedRead16 Unexecuted instantiation: shared_dictionary.c:BrotliUnalignedRead16 Unexecuted instantiation: transform.c:BrotliUnalignedRead16 Unexecuted instantiation: dictionary.c:BrotliUnalignedRead16 |
330 | 0 | static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) { |
331 | 0 | uint32_t t; |
332 | 0 | memcpy(&t, p, sizeof t); |
333 | 0 | return t; |
334 | 0 | } Unexecuted instantiation: decode.c:BrotliUnalignedRead32 Unexecuted instantiation: huffman.c:BrotliUnalignedRead32 Unexecuted instantiation: prefix.c:BrotliUnalignedRead32 Unexecuted instantiation: state.c:BrotliUnalignedRead32 Unexecuted instantiation: static_init.c:BrotliUnalignedRead32 Unexecuted instantiation: bit_reader.c:BrotliUnalignedRead32 Unexecuted instantiation: constants.c:BrotliUnalignedRead32 Unexecuted instantiation: context.c:BrotliUnalignedRead32 Unexecuted instantiation: platform.c:BrotliUnalignedRead32 Unexecuted instantiation: shared_dictionary.c:BrotliUnalignedRead32 Unexecuted instantiation: transform.c:BrotliUnalignedRead32 Unexecuted instantiation: dictionary.c:BrotliUnalignedRead32 |
335 | 0 | static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) { |
336 | 0 | uint64_t t; |
337 | 0 | memcpy(&t, p, sizeof t); |
338 | 0 | return t; |
339 | 0 | } Unexecuted instantiation: decode.c:BrotliUnalignedRead64 Unexecuted instantiation: huffman.c:BrotliUnalignedRead64 Unexecuted instantiation: prefix.c:BrotliUnalignedRead64 Unexecuted instantiation: state.c:BrotliUnalignedRead64 Unexecuted instantiation: static_init.c:BrotliUnalignedRead64 Unexecuted instantiation: bit_reader.c:BrotliUnalignedRead64 Unexecuted instantiation: constants.c:BrotliUnalignedRead64 Unexecuted instantiation: context.c:BrotliUnalignedRead64 Unexecuted instantiation: platform.c:BrotliUnalignedRead64 Unexecuted instantiation: shared_dictionary.c:BrotliUnalignedRead64 Unexecuted instantiation: transform.c:BrotliUnalignedRead64 Unexecuted instantiation: dictionary.c:BrotliUnalignedRead64 |
340 | 0 | static BROTLI_INLINE size_t BrotliUnalignedReadSizeT(const void* p) { |
341 | 0 | size_t t; |
342 | 0 | memcpy(&t, p, sizeof t); |
343 | 0 | return t; |
344 | 0 | } Unexecuted instantiation: decode.c:BrotliUnalignedReadSizeT Unexecuted instantiation: huffman.c:BrotliUnalignedReadSizeT Unexecuted instantiation: prefix.c:BrotliUnalignedReadSizeT Unexecuted instantiation: state.c:BrotliUnalignedReadSizeT Unexecuted instantiation: static_init.c:BrotliUnalignedReadSizeT Unexecuted instantiation: bit_reader.c:BrotliUnalignedReadSizeT Unexecuted instantiation: constants.c:BrotliUnalignedReadSizeT Unexecuted instantiation: context.c:BrotliUnalignedReadSizeT Unexecuted instantiation: platform.c:BrotliUnalignedReadSizeT Unexecuted instantiation: shared_dictionary.c:BrotliUnalignedReadSizeT Unexecuted instantiation: transform.c:BrotliUnalignedReadSizeT Unexecuted instantiation: dictionary.c:BrotliUnalignedReadSizeT |
345 | 0 | static BROTLI_INLINE void BrotliUnalignedWrite64(void* p, uint64_t v) { |
346 | 0 | memcpy(p, &v, sizeof v); |
347 | 0 | } Unexecuted instantiation: decode.c:BrotliUnalignedWrite64 Unexecuted instantiation: huffman.c:BrotliUnalignedWrite64 Unexecuted instantiation: prefix.c:BrotliUnalignedWrite64 Unexecuted instantiation: state.c:BrotliUnalignedWrite64 Unexecuted instantiation: static_init.c:BrotliUnalignedWrite64 Unexecuted instantiation: bit_reader.c:BrotliUnalignedWrite64 Unexecuted instantiation: constants.c:BrotliUnalignedWrite64 Unexecuted instantiation: context.c:BrotliUnalignedWrite64 Unexecuted instantiation: platform.c:BrotliUnalignedWrite64 Unexecuted instantiation: shared_dictionary.c:BrotliUnalignedWrite64 Unexecuted instantiation: transform.c:BrotliUnalignedWrite64 Unexecuted instantiation: dictionary.c:BrotliUnalignedWrite64 |
348 | | |
349 | | #endif /* BROTLI_USE_PACKED_FOR_UNALIGNED */ |
350 | | |
351 | | #if BROTLI_GNUC_HAS_BUILTIN(__builtin_bswap16, 4, 3, 0) |
352 | | #define BROTLI_BSWAP16(V) ((uint16_t)__builtin_bswap16(V)) |
353 | | #else |
354 | | #define BROTLI_BSWAP16(V) ((uint16_t)( \ |
355 | | (((V) & 0xFFU) << 8) | \ |
356 | | (((V) >> 8) & 0xFFU))) |
357 | | #endif |
358 | | |
359 | | #if BROTLI_GNUC_HAS_BUILTIN(__builtin_bswap32, 4, 3, 0) |
360 | | #define BROTLI_BSWAP32(V) ((uint32_t)__builtin_bswap32(V)) |
361 | | #else |
362 | | #define BROTLI_BSWAP32(V) ((uint32_t)( \ |
363 | | (((V) & 0xFFU) << 24) | (((V) & 0xFF00U) << 8) | \ |
364 | | (((V) >> 8) & 0xFF00U) | (((V) >> 24) & 0xFFU))) |
365 | | #endif |
366 | | |
367 | | #if BROTLI_GNUC_HAS_BUILTIN(__builtin_bswap64, 4, 3, 0) |
368 | | #define BROTLI_BSWAP64(V) ((uint64_t)__builtin_bswap64(V)) |
369 | | #else |
370 | | #define BROTLI_BSWAP64(V) ((uint64_t)( \ |
371 | | (((V) & 0xFFU) << 56) | (((V) & 0xFF00U) << 40) | \ |
372 | | (((V) & 0xFF0000U) << 24) | (((V) & 0xFF000000U) << 8) | \ |
373 | | (((V) >> 8) & 0xFF000000U) | (((V) >> 24) & 0xFF0000U) | \ |
374 | | (((V) >> 40) & 0xFF00U) | (((V) >> 56) & 0xFFU))) |
375 | | #endif |
376 | | |
377 | | #if BROTLI_LITTLE_ENDIAN |
378 | | /* Straight endianness. Just read / write values. */ |
379 | | #define BROTLI_UNALIGNED_LOAD16LE BrotliUnalignedRead16 |
380 | 0 | #define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32 |
381 | 0 | #define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64 |
382 | | #define BROTLI_UNALIGNED_STORE64LE BrotliUnalignedWrite64 |
383 | | #elif BROTLI_BIG_ENDIAN /* BROTLI_LITTLE_ENDIAN */ |
384 | | static BROTLI_INLINE uint16_t BROTLI_UNALIGNED_LOAD16LE(const void* p) { |
385 | | uint16_t value = BrotliUnalignedRead16(p); |
386 | | return BROTLI_BSWAP16(value); |
387 | | } |
388 | | static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32LE(const void* p) { |
389 | | uint32_t value = BrotliUnalignedRead32(p); |
390 | | return BROTLI_BSWAP32(value); |
391 | | } |
392 | | static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void* p) { |
393 | | uint64_t value = BrotliUnalignedRead64(p); |
394 | | return BROTLI_BSWAP64(value); |
395 | | } |
396 | | static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) { |
397 | | uint64_t value = BROTLI_BSWAP64(v); |
398 | | BrotliUnalignedWrite64(p, value); |
399 | | } |
400 | | #else /* BROTLI_LITTLE_ENDIAN */ |
401 | | /* Read / store values byte-wise; hopefully compiler will understand. */ |
402 | | static BROTLI_INLINE uint16_t BROTLI_UNALIGNED_LOAD16LE(const void* p) { |
403 | | const uint8_t* in = (const uint8_t*)p; |
404 | | return (uint16_t)(in[0] | (in[1] << 8)); |
405 | | } |
406 | | static BROTLI_INLINE uint32_t BROTLI_UNALIGNED_LOAD32LE(const void* p) { |
407 | | const uint8_t* in = (const uint8_t*)p; |
408 | | uint32_t value = (uint32_t)(in[0]); |
409 | | value |= (uint32_t)(in[1]) << 8; |
410 | | value |= (uint32_t)(in[2]) << 16; |
411 | | value |= (uint32_t)(in[3]) << 24; |
412 | | return value; |
413 | | } |
414 | | static BROTLI_INLINE uint64_t BROTLI_UNALIGNED_LOAD64LE(const void* p) { |
415 | | const uint8_t* in = (const uint8_t*)p; |
416 | | uint64_t value = (uint64_t)(in[0]); |
417 | | value |= (uint64_t)(in[1]) << 8; |
418 | | value |= (uint64_t)(in[2]) << 16; |
419 | | value |= (uint64_t)(in[3]) << 24; |
420 | | value |= (uint64_t)(in[4]) << 32; |
421 | | value |= (uint64_t)(in[5]) << 40; |
422 | | value |= (uint64_t)(in[6]) << 48; |
423 | | value |= (uint64_t)(in[7]) << 56; |
424 | | return value; |
425 | | } |
426 | | static BROTLI_INLINE void BROTLI_UNALIGNED_STORE64LE(void* p, uint64_t v) { |
427 | | uint8_t* out = (uint8_t*)p; |
428 | | out[0] = (uint8_t)v; |
429 | | out[1] = (uint8_t)(v >> 8); |
430 | | out[2] = (uint8_t)(v >> 16); |
431 | | out[3] = (uint8_t)(v >> 24); |
432 | | out[4] = (uint8_t)(v >> 32); |
433 | | out[5] = (uint8_t)(v >> 40); |
434 | | out[6] = (uint8_t)(v >> 48); |
435 | | out[7] = (uint8_t)(v >> 56); |
436 | | } |
437 | | #endif /* BROTLI_LITTLE_ENDIAN */ |
438 | | |
439 | 0 | static BROTLI_INLINE void* BROTLI_UNALIGNED_LOAD_PTR(const void* p) { |
440 | 0 | void* v; |
441 | 0 | memcpy(&v, p, sizeof(void*)); |
442 | 0 | return v; |
443 | 0 | } Unexecuted instantiation: decode.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: huffman.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: prefix.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: state.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: static_init.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: bit_reader.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: constants.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: context.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: platform.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: shared_dictionary.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: transform.c:BROTLI_UNALIGNED_LOAD_PTR Unexecuted instantiation: dictionary.c:BROTLI_UNALIGNED_LOAD_PTR |
444 | | |
445 | 0 | static BROTLI_INLINE void BROTLI_UNALIGNED_STORE_PTR(void* p, const void* v) { |
446 | 0 | memcpy(p, &v, sizeof(void*)); |
447 | 0 | } Unexecuted instantiation: decode.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: huffman.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: prefix.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: state.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: static_init.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: bit_reader.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: constants.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: context.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: platform.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: shared_dictionary.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: transform.c:BROTLI_UNALIGNED_STORE_PTR Unexecuted instantiation: dictionary.c:BROTLI_UNALIGNED_STORE_PTR |
448 | | |
449 | | /* BROTLI_IS_CONSTANT macros returns true for compile-time constants. */ |
450 | | #if BROTLI_GNUC_HAS_BUILTIN(__builtin_constant_p, 3, 0, 1) || \ |
451 | | BROTLI_INTEL_VERSION_CHECK(16, 0, 0) |
452 | 0 | #define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x)) |
453 | | #else |
454 | | #define BROTLI_IS_CONSTANT(x) (!!0) |
455 | | #endif |
456 | | |
457 | | #if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY) |
458 | | #define BROTLI_HAS_UBFX (!!1) |
459 | | #else |
460 | | #define BROTLI_HAS_UBFX (!!0) |
461 | | #endif |
462 | | |
463 | | #if defined(BROTLI_ENABLE_LOG) |
464 | | #define BROTLI_LOG(x) printf x |
465 | | #else |
466 | | #define BROTLI_LOG(x) |
467 | | #endif |
468 | | |
469 | | #if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG) |
470 | | #define BROTLI_ENABLE_DUMP_DEFAULT 1 |
471 | | #define BROTLI_DCHECK(x) assert(x) |
472 | | #else |
473 | | #define BROTLI_ENABLE_DUMP_DEFAULT 0 |
474 | | #define BROTLI_DCHECK(x) |
475 | | #endif |
476 | | |
477 | | #if !defined(BROTLI_ENABLE_DUMP) |
478 | | #define BROTLI_ENABLE_DUMP BROTLI_ENABLE_DUMP_DEFAULT |
479 | | #endif |
480 | | |
481 | | #if BROTLI_ENABLE_DUMP |
482 | | static BROTLI_INLINE void BrotliDump(const char* f, int l, const char* fn) { |
483 | | fprintf(stderr, "%s:%d (%s)\n", f, l, fn); |
484 | | fflush(stderr); |
485 | | } |
486 | | #define BROTLI_DUMP() BrotliDump(__FILE__, __LINE__, __FUNCTION__) |
487 | | #else |
488 | 0 | #define BROTLI_DUMP() (void)(0) |
489 | | #endif |
490 | | |
491 | | /* BrotliRBit assumes brotli_reg_t fits native CPU register type. */ |
492 | | #if (BROTLI_64_BITS == BROTLI_TARGET_64_BITS) |
493 | | /* TODO(eustas): add appropriate icc/sunpro/arm/ibm/ti checks. */ |
494 | | #if (BROTLI_GNUC_VERSION_CHECK(3, 0, 0) || defined(__llvm__)) && \ |
495 | | !defined(BROTLI_BUILD_NO_RBIT) |
496 | | #if defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8_ANY) |
497 | | /* TODO(eustas): detect ARMv6T2 and enable this code for it. */ |
498 | | static BROTLI_INLINE brotli_reg_t BrotliRBit(brotli_reg_t input) { |
499 | | brotli_reg_t output; |
500 | | __asm__("rbit %0, %1\n" : "=r"(output) : "r"(input)); |
501 | | return output; |
502 | | } |
503 | | #define BROTLI_RBIT(x) BrotliRBit(x) |
504 | | #endif /* armv7 / armv8 */ |
505 | | #endif /* gcc || clang */ |
506 | | #endif /* brotli_reg_t is native */ |
507 | | #if !defined(BROTLI_RBIT) |
508 | 0 | static BROTLI_INLINE void BrotliRBit(void) { /* Should break build if used. */ }Unexecuted instantiation: decode.c:BrotliRBit Unexecuted instantiation: huffman.c:BrotliRBit Unexecuted instantiation: prefix.c:BrotliRBit Unexecuted instantiation: state.c:BrotliRBit Unexecuted instantiation: static_init.c:BrotliRBit Unexecuted instantiation: bit_reader.c:BrotliRBit Unexecuted instantiation: constants.c:BrotliRBit Unexecuted instantiation: context.c:BrotliRBit Unexecuted instantiation: platform.c:BrotliRBit Unexecuted instantiation: shared_dictionary.c:BrotliRBit Unexecuted instantiation: transform.c:BrotliRBit Unexecuted instantiation: dictionary.c:BrotliRBit |
509 | | #endif /* BROTLI_RBIT */ |
510 | | |
511 | 0 | #define BROTLI_REPEAT_4(X) {X; X; X; X;} |
512 | 0 | #define BROTLI_REPEAT_5(X) {X; X; X; X; X;} |
513 | 0 | #define BROTLI_REPEAT_6(X) {X; X; X; X; X; X;} |
514 | | |
515 | 0 | #define BROTLI_UNUSED(X) (void)(X) |
516 | | |
517 | | #define BROTLI_MIN_MAX(T) \ |
518 | 0 | static BROTLI_INLINE T brotli_min_ ## T (T a, T b) { return a < b ? a : b; } \Unexecuted instantiation: decode.c:brotli_min_double Unexecuted instantiation: decode.c:brotli_min_float Unexecuted instantiation: decode.c:brotli_min_int Unexecuted instantiation: decode.c:brotli_min_size_t Unexecuted instantiation: decode.c:brotli_min_uint32_t Unexecuted instantiation: decode.c:brotli_min_uint8_t Unexecuted instantiation: huffman.c:brotli_min_double Unexecuted instantiation: huffman.c:brotli_min_float Unexecuted instantiation: huffman.c:brotli_min_int Unexecuted instantiation: huffman.c:brotli_min_size_t Unexecuted instantiation: huffman.c:brotli_min_uint32_t Unexecuted instantiation: huffman.c:brotli_min_uint8_t Unexecuted instantiation: prefix.c:brotli_min_double Unexecuted instantiation: prefix.c:brotli_min_float Unexecuted instantiation: prefix.c:brotli_min_int Unexecuted instantiation: prefix.c:brotli_min_size_t Unexecuted instantiation: prefix.c:brotli_min_uint32_t Unexecuted instantiation: prefix.c:brotli_min_uint8_t Unexecuted instantiation: state.c:brotli_min_double Unexecuted instantiation: state.c:brotli_min_float Unexecuted instantiation: state.c:brotli_min_int Unexecuted instantiation: state.c:brotli_min_size_t Unexecuted instantiation: state.c:brotli_min_uint32_t Unexecuted instantiation: state.c:brotli_min_uint8_t Unexecuted instantiation: static_init.c:brotli_min_double Unexecuted instantiation: static_init.c:brotli_min_float Unexecuted instantiation: static_init.c:brotli_min_int Unexecuted instantiation: static_init.c:brotli_min_size_t Unexecuted instantiation: static_init.c:brotli_min_uint32_t Unexecuted instantiation: static_init.c:brotli_min_uint8_t Unexecuted instantiation: bit_reader.c:brotli_min_double Unexecuted instantiation: bit_reader.c:brotli_min_float Unexecuted instantiation: bit_reader.c:brotli_min_int Unexecuted instantiation: bit_reader.c:brotli_min_size_t Unexecuted instantiation: bit_reader.c:brotli_min_uint32_t Unexecuted instantiation: bit_reader.c:brotli_min_uint8_t Unexecuted instantiation: constants.c:brotli_min_double Unexecuted instantiation: constants.c:brotli_min_float Unexecuted instantiation: constants.c:brotli_min_int Unexecuted instantiation: constants.c:brotli_min_size_t Unexecuted instantiation: constants.c:brotli_min_uint32_t Unexecuted instantiation: constants.c:brotli_min_uint8_t Unexecuted instantiation: context.c:brotli_min_double Unexecuted instantiation: context.c:brotli_min_float Unexecuted instantiation: context.c:brotli_min_int Unexecuted instantiation: context.c:brotli_min_size_t Unexecuted instantiation: context.c:brotli_min_uint32_t Unexecuted instantiation: context.c:brotli_min_uint8_t Unexecuted instantiation: platform.c:brotli_min_double Unexecuted instantiation: platform.c:brotli_min_float Unexecuted instantiation: platform.c:brotli_min_int Unexecuted instantiation: platform.c:brotli_min_size_t Unexecuted instantiation: platform.c:brotli_min_uint32_t Unexecuted instantiation: platform.c:brotli_min_uint8_t Unexecuted instantiation: shared_dictionary.c:brotli_min_double Unexecuted instantiation: shared_dictionary.c:brotli_min_float Unexecuted instantiation: shared_dictionary.c:brotli_min_int Unexecuted instantiation: shared_dictionary.c:brotli_min_size_t Unexecuted instantiation: shared_dictionary.c:brotli_min_uint32_t Unexecuted instantiation: shared_dictionary.c:brotli_min_uint8_t Unexecuted instantiation: transform.c:brotli_min_double Unexecuted instantiation: transform.c:brotli_min_float Unexecuted instantiation: transform.c:brotli_min_int Unexecuted instantiation: transform.c:brotli_min_size_t Unexecuted instantiation: transform.c:brotli_min_uint32_t Unexecuted instantiation: transform.c:brotli_min_uint8_t Unexecuted instantiation: dictionary.c:brotli_min_double Unexecuted instantiation: dictionary.c:brotli_min_float Unexecuted instantiation: dictionary.c:brotli_min_int Unexecuted instantiation: dictionary.c:brotli_min_size_t Unexecuted instantiation: dictionary.c:brotli_min_uint32_t Unexecuted instantiation: dictionary.c:brotli_min_uint8_t |
519 | 0 | static BROTLI_INLINE T brotli_max_ ## T (T a, T b) { return a > b ? a : b; }Unexecuted instantiation: decode.c:brotli_max_double Unexecuted instantiation: decode.c:brotli_max_float Unexecuted instantiation: decode.c:brotli_max_int Unexecuted instantiation: decode.c:brotli_max_size_t Unexecuted instantiation: decode.c:brotli_max_uint32_t Unexecuted instantiation: decode.c:brotli_max_uint8_t Unexecuted instantiation: huffman.c:brotli_max_double Unexecuted instantiation: huffman.c:brotli_max_float Unexecuted instantiation: huffman.c:brotli_max_int Unexecuted instantiation: huffman.c:brotli_max_size_t Unexecuted instantiation: huffman.c:brotli_max_uint32_t Unexecuted instantiation: huffman.c:brotli_max_uint8_t Unexecuted instantiation: prefix.c:brotli_max_double Unexecuted instantiation: prefix.c:brotli_max_float Unexecuted instantiation: prefix.c:brotli_max_int Unexecuted instantiation: prefix.c:brotli_max_size_t Unexecuted instantiation: prefix.c:brotli_max_uint32_t Unexecuted instantiation: prefix.c:brotli_max_uint8_t Unexecuted instantiation: state.c:brotli_max_double Unexecuted instantiation: state.c:brotli_max_float Unexecuted instantiation: state.c:brotli_max_int Unexecuted instantiation: state.c:brotli_max_size_t Unexecuted instantiation: state.c:brotli_max_uint32_t Unexecuted instantiation: state.c:brotli_max_uint8_t Unexecuted instantiation: static_init.c:brotli_max_double Unexecuted instantiation: static_init.c:brotli_max_float Unexecuted instantiation: static_init.c:brotli_max_int Unexecuted instantiation: static_init.c:brotli_max_size_t Unexecuted instantiation: static_init.c:brotli_max_uint32_t Unexecuted instantiation: static_init.c:brotli_max_uint8_t Unexecuted instantiation: bit_reader.c:brotli_max_double Unexecuted instantiation: bit_reader.c:brotli_max_float Unexecuted instantiation: bit_reader.c:brotli_max_int Unexecuted instantiation: bit_reader.c:brotli_max_size_t Unexecuted instantiation: bit_reader.c:brotli_max_uint32_t Unexecuted instantiation: bit_reader.c:brotli_max_uint8_t Unexecuted instantiation: constants.c:brotli_max_double Unexecuted instantiation: constants.c:brotli_max_float Unexecuted instantiation: constants.c:brotli_max_int Unexecuted instantiation: constants.c:brotli_max_size_t Unexecuted instantiation: constants.c:brotli_max_uint32_t Unexecuted instantiation: constants.c:brotli_max_uint8_t Unexecuted instantiation: context.c:brotli_max_double Unexecuted instantiation: context.c:brotli_max_float Unexecuted instantiation: context.c:brotli_max_int Unexecuted instantiation: context.c:brotli_max_size_t Unexecuted instantiation: context.c:brotli_max_uint32_t Unexecuted instantiation: context.c:brotli_max_uint8_t Unexecuted instantiation: platform.c:brotli_max_double Unexecuted instantiation: platform.c:brotli_max_float Unexecuted instantiation: platform.c:brotli_max_int Unexecuted instantiation: platform.c:brotli_max_size_t Unexecuted instantiation: platform.c:brotli_max_uint32_t Unexecuted instantiation: platform.c:brotli_max_uint8_t Unexecuted instantiation: shared_dictionary.c:brotli_max_double Unexecuted instantiation: shared_dictionary.c:brotli_max_float Unexecuted instantiation: shared_dictionary.c:brotli_max_int Unexecuted instantiation: shared_dictionary.c:brotli_max_size_t Unexecuted instantiation: shared_dictionary.c:brotli_max_uint32_t Unexecuted instantiation: shared_dictionary.c:brotli_max_uint8_t Unexecuted instantiation: transform.c:brotli_max_double Unexecuted instantiation: transform.c:brotli_max_float Unexecuted instantiation: transform.c:brotli_max_int Unexecuted instantiation: transform.c:brotli_max_size_t Unexecuted instantiation: transform.c:brotli_max_uint32_t Unexecuted instantiation: transform.c:brotli_max_uint8_t Unexecuted instantiation: dictionary.c:brotli_max_double Unexecuted instantiation: dictionary.c:brotli_max_float Unexecuted instantiation: dictionary.c:brotli_max_int Unexecuted instantiation: dictionary.c:brotli_max_size_t Unexecuted instantiation: dictionary.c:brotli_max_uint32_t Unexecuted instantiation: dictionary.c:brotli_max_uint8_t |
520 | | BROTLI_MIN_MAX(double) BROTLI_MIN_MAX(float) BROTLI_MIN_MAX(int) |
521 | | BROTLI_MIN_MAX(size_t) BROTLI_MIN_MAX(uint32_t) BROTLI_MIN_MAX(uint8_t) |
522 | | #undef BROTLI_MIN_MAX |
523 | | #define BROTLI_MIN(T, A, B) (brotli_min_ ## T((A), (B))) |
524 | | #define BROTLI_MAX(T, A, B) (brotli_max_ ## T((A), (B))) |
525 | | |
526 | 0 | static BROTLI_INLINE int brotli_safe_add_int(int a, int b, int* result) { |
527 | 0 | if (b > 0 && a > INT_MAX - b) return 0; |
528 | 0 | if (b < 0 && a < INT_MIN - b) return 0; |
529 | 0 | *result = a + b; |
530 | 0 | return 1; |
531 | 0 | } Unexecuted instantiation: decode.c:brotli_safe_add_int Unexecuted instantiation: huffman.c:brotli_safe_add_int Unexecuted instantiation: prefix.c:brotli_safe_add_int Unexecuted instantiation: state.c:brotli_safe_add_int Unexecuted instantiation: static_init.c:brotli_safe_add_int Unexecuted instantiation: bit_reader.c:brotli_safe_add_int Unexecuted instantiation: constants.c:brotli_safe_add_int Unexecuted instantiation: context.c:brotli_safe_add_int Unexecuted instantiation: platform.c:brotli_safe_add_int Unexecuted instantiation: shared_dictionary.c:brotli_safe_add_int Unexecuted instantiation: transform.c:brotli_safe_add_int Unexecuted instantiation: dictionary.c:brotli_safe_add_int |
532 | 0 | #define BROTLI_SAFE_ADD(T, A, B, R) (brotli_safe_add_ ## T((A), (B), (R))) |
533 | | |
534 | | #define BROTLI_SWAP(T, A, I, J) { \ |
535 | | T __brotli_swap_tmp = (A)[(I)]; \ |
536 | | (A)[(I)] = (A)[(J)]; \ |
537 | | (A)[(J)] = __brotli_swap_tmp; \ |
538 | | } |
539 | | |
540 | | #if BROTLI_64_BITS |
541 | | #if BROTLI_GNUC_HAS_BUILTIN(__builtin_ctzll, 3, 4, 0) || \ |
542 | | BROTLI_INTEL_VERSION_CHECK(16, 0, 0) |
543 | | #define BROTLI_TZCNT64 __builtin_ctzll |
544 | | #elif BROTLI_MSVC_VERSION_CHECK(18, 0, 0) |
545 | | #if defined(BROTLI_TARGET_X64) && !defined(_M_ARM64EC) |
546 | | #define BROTLI_TZCNT64 _tzcnt_u64 |
547 | | #else /* BROTLI_TARGET_X64 */ |
548 | | static BROTLI_INLINE uint32_t BrotliBsf64Msvc(uint64_t x) { |
549 | | uint32_t lsb; |
550 | | _BitScanForward64(&lsb, x); |
551 | | return lsb; |
552 | | } |
553 | | #define BROTLI_TZCNT64 BrotliBsf64Msvc |
554 | | #endif /* BROTLI_TARGET_X64 */ |
555 | | #endif /* __builtin_ctzll */ |
556 | | #endif /* BROTLI_64_BITS */ |
557 | | |
558 | | #if BROTLI_GNUC_HAS_BUILTIN(__builtin_clz, 3, 4, 0) || \ |
559 | | BROTLI_INTEL_VERSION_CHECK(16, 0, 0) |
560 | | #define BROTLI_BSR32(x) (31u ^ (uint32_t)__builtin_clz(x)) |
561 | | #elif BROTLI_MSVC_VERSION_CHECK(18, 0, 0) |
562 | | static BROTLI_INLINE uint32_t BrotliBsr32Msvc(uint32_t x) { |
563 | | unsigned long msb; |
564 | | _BitScanReverse(&msb, x); |
565 | | return (uint32_t)msb; |
566 | | } |
567 | | #define BROTLI_BSR32 BrotliBsr32Msvc |
568 | | #endif /* __builtin_clz */ |
569 | | |
570 | | /* Default brotli_alloc_func */ |
571 | | BROTLI_COMMON_API void* BrotliDefaultAllocFunc(void* opaque, size_t size); |
572 | | |
573 | | /* Default brotli_free_func */ |
574 | | BROTLI_COMMON_API void BrotliDefaultFreeFunc(void* opaque, void* address); |
575 | | |
576 | | /* Circular logical rotates. */ |
577 | | static BROTLI_INLINE uint16_t BrotliRotateRight16(uint16_t const value, |
578 | 0 | size_t count) { |
579 | 0 | count &= 0x0F; /* for fickle pattern recognition */ |
580 | 0 | return (value >> count) | (uint16_t)(value << ((0U - count) & 0x0F)); |
581 | 0 | } Unexecuted instantiation: decode.c:BrotliRotateRight16 Unexecuted instantiation: huffman.c:BrotliRotateRight16 Unexecuted instantiation: prefix.c:BrotliRotateRight16 Unexecuted instantiation: state.c:BrotliRotateRight16 Unexecuted instantiation: static_init.c:BrotliRotateRight16 Unexecuted instantiation: bit_reader.c:BrotliRotateRight16 Unexecuted instantiation: constants.c:BrotliRotateRight16 Unexecuted instantiation: context.c:BrotliRotateRight16 Unexecuted instantiation: platform.c:BrotliRotateRight16 Unexecuted instantiation: shared_dictionary.c:BrotliRotateRight16 Unexecuted instantiation: transform.c:BrotliRotateRight16 Unexecuted instantiation: dictionary.c:BrotliRotateRight16 |
582 | | static BROTLI_INLINE uint32_t BrotliRotateRight32(uint32_t const value, |
583 | 0 | size_t count) { |
584 | 0 | count &= 0x1F; /* for fickle pattern recognition */ |
585 | 0 | return (value >> count) | (uint32_t)(value << ((0U - count) & 0x1F)); |
586 | 0 | } Unexecuted instantiation: decode.c:BrotliRotateRight32 Unexecuted instantiation: huffman.c:BrotliRotateRight32 Unexecuted instantiation: prefix.c:BrotliRotateRight32 Unexecuted instantiation: state.c:BrotliRotateRight32 Unexecuted instantiation: static_init.c:BrotliRotateRight32 Unexecuted instantiation: bit_reader.c:BrotliRotateRight32 Unexecuted instantiation: constants.c:BrotliRotateRight32 Unexecuted instantiation: context.c:BrotliRotateRight32 Unexecuted instantiation: platform.c:BrotliRotateRight32 Unexecuted instantiation: shared_dictionary.c:BrotliRotateRight32 Unexecuted instantiation: transform.c:BrotliRotateRight32 Unexecuted instantiation: dictionary.c:BrotliRotateRight32 |
587 | | static BROTLI_INLINE uint64_t BrotliRotateRight64(uint64_t const value, |
588 | 0 | size_t count) { |
589 | 0 | count &= 0x3F; /* for fickle pattern recognition */ |
590 | 0 | return (value >> count) | (uint64_t)(value << ((0U - count) & 0x3F)); |
591 | 0 | } Unexecuted instantiation: decode.c:BrotliRotateRight64 Unexecuted instantiation: huffman.c:BrotliRotateRight64 Unexecuted instantiation: prefix.c:BrotliRotateRight64 Unexecuted instantiation: state.c:BrotliRotateRight64 Unexecuted instantiation: static_init.c:BrotliRotateRight64 Unexecuted instantiation: bit_reader.c:BrotliRotateRight64 Unexecuted instantiation: constants.c:BrotliRotateRight64 Unexecuted instantiation: context.c:BrotliRotateRight64 Unexecuted instantiation: platform.c:BrotliRotateRight64 Unexecuted instantiation: shared_dictionary.c:BrotliRotateRight64 Unexecuted instantiation: transform.c:BrotliRotateRight64 Unexecuted instantiation: dictionary.c:BrotliRotateRight64 |
592 | | |
593 | 0 | BROTLI_UNUSED_FUNCTION void BrotliSuppressUnusedFunctions(void) { |
594 | 0 | BROTLI_UNUSED(&BrotliSuppressUnusedFunctions); |
595 | 0 | BROTLI_UNUSED(&BrotliUnalignedRead16); |
596 | 0 | BROTLI_UNUSED(&BrotliUnalignedRead32); |
597 | 0 | BROTLI_UNUSED(&BrotliUnalignedRead64); |
598 | 0 | BROTLI_UNUSED(&BrotliUnalignedReadSizeT); |
599 | 0 | BROTLI_UNUSED(&BrotliUnalignedWrite64); |
600 | 0 | BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD16LE); |
601 | 0 | BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD32LE); |
602 | 0 | BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD64LE); |
603 | 0 | BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE64LE); |
604 | 0 | BROTLI_UNUSED(&BROTLI_UNALIGNED_LOAD_PTR); |
605 | 0 | BROTLI_UNUSED(&BROTLI_UNALIGNED_STORE_PTR); |
606 | 0 | BROTLI_UNUSED(&BrotliRBit); |
607 | 0 | BROTLI_UNUSED(&brotli_min_double); |
608 | 0 | BROTLI_UNUSED(&brotli_max_double); |
609 | 0 | BROTLI_UNUSED(&brotli_min_float); |
610 | 0 | BROTLI_UNUSED(&brotli_max_float); |
611 | 0 | BROTLI_UNUSED(&brotli_min_int); |
612 | 0 | BROTLI_UNUSED(&brotli_max_int); |
613 | 0 | BROTLI_UNUSED(&brotli_min_size_t); |
614 | 0 | BROTLI_UNUSED(&brotli_max_size_t); |
615 | 0 | BROTLI_UNUSED(&brotli_min_uint32_t); |
616 | 0 | BROTLI_UNUSED(&brotli_max_uint32_t); |
617 | 0 | BROTLI_UNUSED(&brotli_min_uint8_t); |
618 | 0 | BROTLI_UNUSED(&brotli_max_uint8_t); |
619 | 0 | BROTLI_UNUSED(&brotli_safe_add_int); |
620 | 0 | BROTLI_UNUSED(&BrotliDefaultAllocFunc); |
621 | 0 | BROTLI_UNUSED(&BrotliDefaultFreeFunc); |
622 | 0 | BROTLI_UNUSED(&BrotliRotateRight16); |
623 | 0 | BROTLI_UNUSED(&BrotliRotateRight32); |
624 | 0 | BROTLI_UNUSED(&BrotliRotateRight64); |
625 | 0 | #if BROTLI_ENABLE_DUMP |
626 | 0 | BROTLI_UNUSED(&BrotliDump); |
627 | 0 | #endif |
628 | 0 | } Unexecuted instantiation: decode.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: huffman.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: prefix.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: state.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: static_init.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: bit_reader.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: constants.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: context.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: platform.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: shared_dictionary.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: transform.c:BrotliSuppressUnusedFunctions Unexecuted instantiation: dictionary.c:BrotliSuppressUnusedFunctions |
629 | | |
630 | | #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) && \ |
631 | | !defined(_M_ARM64EC) |
632 | | /* _mm_prefetch() is not defined outside of x86/x64 */ |
633 | | /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */ |
634 | | #include <mmintrin.h> |
635 | | #define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0) |
636 | | #define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1) |
637 | | #elif BROTLI_GNUC_HAS_BUILTIN(__builtin_prefetch, 3, 1, 0) |
638 | | #define PREFETCH_L1(ptr) \ |
639 | | __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */) |
640 | | #define PREFETCH_L2(ptr) \ |
641 | | __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */) |
642 | | #elif defined(__aarch64__) |
643 | | #define PREFETCH_L1(ptr) \ |
644 | | do { \ |
645 | | __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr))); \ |
646 | | } while (0) |
647 | | #define PREFETCH_L2(ptr) \ |
648 | | do { \ |
649 | | __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr))); \ |
650 | | } while (0) |
651 | | #else |
652 | | #define PREFETCH_L1(ptr) \ |
653 | | do { \ |
654 | | (void)(ptr); \ |
655 | | } while (0) /* disabled */ |
656 | | #define PREFETCH_L2(ptr) \ |
657 | | do { \ |
658 | | (void)(ptr); \ |
659 | | } while (0) /* disabled */ |
660 | | #endif |
661 | | |
662 | | /* The SIMD matchers are only faster at certain quality levels. */ |
663 | | #if defined(_M_X64) && defined(BROTLI_TZCNT64) |
664 | | #define BROTLI_MAX_SIMD_QUALITY 7 |
665 | | #elif defined(BROTLI_TZCNT64) |
666 | | #define BROTLI_MAX_SIMD_QUALITY 6 |
667 | | #endif |
668 | | |
669 | | #if defined(_MSC_VER) |
670 | | #define BROTLI_CRASH() __debugbreak(), (void)abort() |
671 | | #elif BROTLI_GNUC_HAS_BUILTIN(__builtin_trap, 3, 0, 0) |
672 | | #define BROTLI_CRASH() (void)__builtin_trap() |
673 | | #else |
674 | | #define BROTLI_CRASH() (void)abort() |
675 | | #endif |
676 | | |
677 | | /* Make BROTLI_TEST=0 act same as undefined. */ |
678 | | #if defined(BROTLI_TEST) && ((1-BROTLI_TEST-1) == 0) |
679 | | #undef BROTLI_TEST |
680 | | #endif |
681 | | |
682 | | #if !defined(BROTLI_MODEL) && BROTLI_GNUC_HAS_ATTRIBUTE(model, 3, 0, 3) && \ |
683 | | !defined(BROTLI_TARGET_IA64) && !defined(BROTLI_TARGET_LOONGARCH64) |
684 | | #define BROTLI_MODEL(M) __attribute__((model(M))) |
685 | | #else |
686 | | #define BROTLI_MODEL(M) /* M */ |
687 | | #endif |
688 | | |
689 | | #if !defined(BROTLI_COLD) && BROTLI_GNUC_HAS_ATTRIBUTE(cold, 4, 3, 0) |
690 | | #define BROTLI_COLD __attribute__((cold)) |
691 | | #else |
692 | | #define BROTLI_COLD /* cold */ |
693 | | #endif |
694 | | |
695 | | #endif /* BROTLI_COMMON_PLATFORM_H_ */ |