]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BrotliCustomDecompressLib/dec/port.h
1 /* Copyright 2015 Google Inc. All Rights Reserved.
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
7 /* Macros for compiler / platform specific features and build options.
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_MODERN_COMPILER forces to use modern compilers built-ins,
16 features and attributes
17 * BROTLI_BUILD_PORTABLE disables dangerous optimizations, like unaligned
18 read and overlapping memcpy; this reduces decompression speed by 5%
19 * BROTLI_DEBUG dumps file name and line number when decoder detects stream
21 * BROTLI_ENABLE_LOG enables asserts and dumps various state information
24 #ifndef BROTLI_DEC_PORT_H_
25 #define BROTLI_DEC_PORT_H_
27 #if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
32 #include "../common/port.h"
34 #if defined(__arm__) || defined(__thumb__) || \
35 defined(_M_ARM) || defined(_M_ARMT)
36 #define BROTLI_TARGET_ARM
37 #if (defined(__ARM_ARCH) && (__ARM_ARCH >= 7)) || \
38 (defined(M_ARM) && (M_ARM >= 7))
39 #define BROTLI_TARGET_ARMV7
41 #if defined(__aarch64__)
42 #define BROTLI_TARGET_ARMV8
46 #if defined(__i386) || defined(_M_IX86)
47 #define BROTLI_TARGET_X86
50 #if defined(__x86_64__) || defined(_M_X64)
51 #define BROTLI_TARGET_X64
54 #if defined(__PPC64__)
55 #define BROTLI_TARGET_POWERPC64
58 #ifdef BROTLI_BUILD_PORTABLE
59 #define BROTLI_ALIGNED_READ (!!1)
60 #elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
61 defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
62 /* Allow unaligned read only for whitelisted CPUs. */
63 #define BROTLI_ALIGNED_READ (!!0)
65 #define BROTLI_ALIGNED_READ (!!1)
68 /* IS_CONSTANT macros returns true for compile-time constant expressions. */
69 #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_constant_p)
70 #define IS_CONSTANT(x) (!!__builtin_constant_p(x))
72 #define IS_CONSTANT(x) (!!0)
75 #ifdef BROTLI_ENABLE_LOG
76 #define BROTLI_DCHECK(x) assert(x)
77 #define BROTLI_LOG(x) printf x
79 #define BROTLI_DCHECK(x)
83 #if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
84 static BROTLI_INLINE
void BrotliDump(const char* f
, int l
, const char* fn
) {
85 fprintf(stderr
, "%s:%d (%s)\n", f
, l
, fn
);
88 #define BROTLI_DUMP() BrotliDump(__FILE__, __LINE__, __FUNCTION__)
90 #define BROTLI_DUMP() (void)(0)
93 #if defined(BROTLI_BUILD_64_BIT)
94 #define BROTLI_64_BITS 1
95 #elif defined(BROTLI_BUILD_32_BIT)
96 #define BROTLI_64_BITS 0
97 #elif defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8) || \
98 defined(BROTLI_TARGET_POWERPC64)
99 #define BROTLI_64_BITS 1
101 #define BROTLI_64_BITS 0
104 #if defined(BROTLI_BUILD_BIG_ENDIAN)
105 #define BROTLI_LITTLE_ENDIAN 0
106 #define BROTLI_BIG_ENDIAN 1
107 #elif defined(BROTLI_BUILD_LITTLE_ENDIAN)
108 #define BROTLI_LITTLE_ENDIAN 1
109 #define BROTLI_BIG_ENDIAN 0
110 #elif defined(BROTLI_BUILD_ENDIAN_NEUTRAL)
111 #define BROTLI_LITTLE_ENDIAN 0
112 #define BROTLI_BIG_ENDIAN 0
113 #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
114 #define BROTLI_LITTLE_ENDIAN 1
115 #define BROTLI_BIG_ENDIAN 0
116 #elif defined(_WIN32)
117 /* Win32 can currently always be assumed to be little endian */
118 #define BROTLI_LITTLE_ENDIAN 1
119 #define BROTLI_BIG_ENDIAN 0
121 #if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
122 #define BROTLI_BIG_ENDIAN 1
124 #define BROTLI_BIG_ENDIAN 0
126 #define BROTLI_LITTLE_ENDIAN 0
129 #define BROTLI_REPEAT(N, X) { \
130 if ((N & 1) != 0) {X;} \
131 if ((N & 2) != 0) {X; X;} \
132 if ((N & 4) != 0) {X; X; X; X;} \
135 #if BROTLI_MODERN_COMPILER || defined(__llvm__)
136 #if defined(BROTLI_TARGET_ARMV7)
137 static BROTLI_INLINE
unsigned BrotliRBit(unsigned input
) {
139 __asm__("rbit %0, %1\n" : "=r"(output
) : "r"(input
));
142 #define BROTLI_RBIT(x) BrotliRBit(x)
144 #endif /* gcc || clang */
146 #if defined(BROTLI_TARGET_ARM)
147 #define BROTLI_HAS_UBFX (!!1)
149 #define BROTLI_HAS_UBFX (!!0)
152 #define BROTLI_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
154 #define BROTLI_FREE(S, X) { \
155 S->free_func(S->memory_manager_opaque, X); \
159 #endif /* BROTLI_DEC_PORT_H_ */