Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: third_party/brotli/dec/port.h

Issue 1915823002: Update brotli from 722f89 (Feb 19, 2016) to 510131 (Apr 22, 2016) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/brotli/dec/huffman.c ('k') | third_party/brotli/dec/state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright 2015 Google Inc. All Rights Reserved. 1 /* Copyright 2015 Google Inc. All Rights Reserved.
2 2
3 Distributed under MIT license. 3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */ 5 */
6 6
7 /* Macros for compiler / platform specific features and build options. 7 /* Macros for compiler / platform specific features and build options.
8 8
9 Build options are: 9 Build options are:
10 * BROTLI_BUILD_32_BIT disables 64-bit optimizations 10 * BROTLI_BUILD_32_BIT disables 64-bit optimizations
11 * BROTLI_BUILD_64_BIT forces to use 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 12 * BROTLI_BUILD_BIG_ENDIAN forces to use big-endian optimizations
13 * BROTLI_BUILD_ENDIAN_NEUTRAL disables endian-aware optimizations 13 * BROTLI_BUILD_ENDIAN_NEUTRAL disables endian-aware optimizations
14 * BROTLI_BUILD_LITTLE_ENDIAN forces to use little-endian optimizations 14 * BROTLI_BUILD_LITTLE_ENDIAN forces to use little-endian optimizations
15 * BROTLI_BUILD_MODERN_COMPILER forces to use modern compilers built-ins, 15 * BROTLI_BUILD_MODERN_COMPILER forces to use modern compilers built-ins,
16 features and attributes 16 features and attributes
17 * BROTLI_BUILD_PORTABLE disables dangerous optimizations, like unaligned 17 * BROTLI_BUILD_PORTABLE disables dangerous optimizations, like unaligned
18 read and overlapping memcpy; this reduces decompression speed by 5% 18 read and overlapping memcpy; this reduces decompression speed by 5%
19 * BROTLI_DEBUG dumps file name and line number when decoder detects stream 19 * BROTLI_DEBUG dumps file name and line number when decoder detects stream
20 or memory error 20 or memory error
21 * BROTLI_DECODE_DEBUG enables asserts and dumps various state information 21 * BROTLI_ENABLE_LOG enables asserts and dumps various state information
22 */ 22 */
23 23
24 #ifndef BROTLI_DEC_PORT_H_ 24 #ifndef BROTLI_DEC_PORT_H_
25 #define BROTLI_DEC_PORT_H_ 25 #define BROTLI_DEC_PORT_H_
26 26
27 #if defined(BROTLI_ENABLE_LOG) || defined(BROTLI_DEBUG)
27 #include <assert.h> 28 #include <assert.h>
29 #include <stdio.h>
30 #endif
28 31
29 /* Compatibility with non-clang compilers. */ 32 /* Compatibility with non-clang compilers. */
30 #ifndef __has_builtin 33 #ifndef __has_builtin
31 #define __has_builtin(x) 0 34 #define __has_builtin(x) 0
32 #endif 35 #endif
33 36
34 #ifndef __has_attribute 37 #ifndef __has_attribute
35 #define __has_attribute(x) 0 38 #define __has_attribute(x) 0
36 #endif 39 #endif
37 40
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 80
78 #if defined(BROTLI_BUILD_MODERN_COMPILER) 81 #if defined(BROTLI_BUILD_MODERN_COMPILER)
79 #define BROTLI_MODERN_COMPILER 1 82 #define BROTLI_MODERN_COMPILER 1
80 #elif (BROTLI_GCC_VERSION > 300) || (BROTLI_ICC_VERSION >= 1600) 83 #elif (BROTLI_GCC_VERSION > 300) || (BROTLI_ICC_VERSION >= 1600)
81 #define BROTLI_MODERN_COMPILER 1 84 #define BROTLI_MODERN_COMPILER 1
82 #else 85 #else
83 #define BROTLI_MODERN_COMPILER 0 86 #define BROTLI_MODERN_COMPILER 0
84 #endif 87 #endif
85 88
86 #ifdef BROTLI_BUILD_PORTABLE 89 #ifdef BROTLI_BUILD_PORTABLE
87 #define BROTLI_ALIGNED_READ 1 90 #define BROTLI_ALIGNED_READ (!!1)
88 #elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \ 91 #elif defined(BROTLI_TARGET_X86) || defined(BROTLI_TARGET_X64) || \
89 defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8) 92 defined(BROTLI_TARGET_ARMV7) || defined(BROTLI_TARGET_ARMV8)
90 #define BROTLI_ALIGNED_READ 0 /* Allow unaligned access on whitelisted CPUs. */ 93 /* Allow unaligned read only for whitelisted CPUs. */
94 #define BROTLI_ALIGNED_READ (!!0)
91 #else 95 #else
92 #define BROTLI_ALIGNED_READ 1 96 #define BROTLI_ALIGNED_READ (!!1)
93 #endif 97 #endif
94 98
95 /* Define "PREDICT_TRUE" and "PREDICT_FALSE" macros for capable compilers. 99 /* Define "PREDICT_TRUE" and "PREDICT_FALSE" macros for capable compilers.
96 100
97 To apply compiler hint, enclose the branching condition into macros, like this: 101 To apply compiler hint, enclose the branching condition into macros, like this:
98 102
99 if (PREDICT_TRUE(zero == 0)) { 103 if (PREDICT_TRUE(zero == 0)) {
100 // main execution path 104 // main execution path
101 } else { 105 } else {
102 // compiler should place this code outside of main execution path 106 // compiler should place this code outside of main execution path
103 } 107 }
104 108
105 OR: 109 OR:
106 110
107 if (PREDICT_FALSE(something_rare_or_unexpected_happens)) { 111 if (PREDICT_FALSE(something_rare_or_unexpected_happens)) {
108 // compiler should place this code outside of main execution path 112 // compiler should place this code outside of main execution path
109 } 113 }
110 114
111 */ 115 */
112 #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_expect) 116 #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_expect)
113 #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) 117 #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
114 #define PREDICT_FALSE(x) (__builtin_expect(x, 0)) 118 #define PREDICT_FALSE(x) (__builtin_expect(x, 0))
115 #else 119 #else
116 #define PREDICT_FALSE(x) (x) 120 #define PREDICT_FALSE(x) (x)
117 #define PREDICT_TRUE(x) (x) 121 #define PREDICT_TRUE(x) (x)
118 #endif 122 #endif
119 123
120 /* IS_CONSTANT macros returns true for compile-time constant expressions. */ 124 /* IS_CONSTANT macros returns true for compile-time constant expressions. */
121 #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_constant_p) 125 #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_constant_p)
122 #define IS_CONSTANT(x) __builtin_constant_p(x) 126 #define IS_CONSTANT(x) (!!__builtin_constant_p(x))
123 #else 127 #else
124 #define IS_CONSTANT(x) 0 128 #define IS_CONSTANT(x) (!!0)
125 #endif 129 #endif
126 130
127 #if BROTLI_MODERN_COMPILER || __has_attribute(always_inline) 131 #if BROTLI_MODERN_COMPILER || __has_attribute(always_inline)
128 #define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) 132 #define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
129 #else 133 #else
130 #define ATTRIBUTE_ALWAYS_INLINE 134 #define ATTRIBUTE_ALWAYS_INLINE
131 #endif 135 #endif
132 136
137 #if BROTLI_MODERN_COMPILER || __has_attribute(visibility)
138 #define ATTRIBUTE_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))
139 #else
140 #define ATTRIBUTE_VISIBILITY_HIDDEN
141 #endif
142
143 #ifndef BROTLI_INTERNAL
144 #define BROTLI_INTERNAL ATTRIBUTE_VISIBILITY_HIDDEN
145 #endif
146
133 #ifndef _MSC_VER 147 #ifndef _MSC_VER
134 #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \ 148 #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
135 __STDC_VERSION__ >= 199901L 149 __STDC_VERSION__ >= 199901L
136 #define BROTLI_INLINE inline ATTRIBUTE_ALWAYS_INLINE 150 #define BROTLI_INLINE inline ATTRIBUTE_ALWAYS_INLINE
137 #else 151 #else
138 #define BROTLI_INLINE 152 #define BROTLI_INLINE
139 #endif 153 #endif
140 #else /* _MSC_VER */ 154 #else /* _MSC_VER */
141 #define BROTLI_INLINE __forceinline 155 #define BROTLI_INLINE __forceinline
142 #endif /* _MSC_VER */ 156 #endif /* _MSC_VER */
143 157
144 #ifdef BROTLI_DECODE_DEBUG 158 #ifdef BROTLI_ENABLE_LOG
145 #define BROTLI_DCHECK(x) assert(x) 159 #define BROTLI_DCHECK(x) assert(x)
160 #define BROTLI_LOG(x) printf x
146 #else 161 #else
147 #define BROTLI_DCHECK(x) 162 #define BROTLI_DCHECK(x)
163 #define BROTLI_LOG(x)
164 #endif
165
166 #if defined(BROTLI_DEBUG) || defined(BROTLI_ENABLE_LOG)
167 static inline void BrotliDump(const char* f, int l, const char* fn) {
168 fprintf(stderr, "%s:%d (%s)\n", f, l, fn);
169 fflush(stderr);
170 }
171 #define BROTLI_DUMP() BrotliDump(__FILE__, __LINE__, __FUNCTION__)
172 #else
173 #define BROTLI_DUMP() (void)(0)
148 #endif 174 #endif
149 175
150 #if defined(BROTLI_BUILD_64_BIT) 176 #if defined(BROTLI_BUILD_64_BIT)
151 #define BROTLI_64_BITS 1 177 #define BROTLI_64_BITS 1
152 #elif defined(BROTLI_BUILD_32_BIT) 178 #elif defined(BROTLI_BUILD_32_BIT)
153 #define BROTLI_64_BITS 0 179 #define BROTLI_64_BITS 0
154 #elif defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8) || \ 180 #elif defined(BROTLI_TARGET_X64) || defined(BROTLI_TARGET_ARMV8) || \
155 defined(BROTLI_TARGET_POWERPC64) 181 defined(BROTLI_TARGET_POWERPC64)
156 #define BROTLI_64_BITS 1 182 #define BROTLI_64_BITS 1
157 #else 183 #else
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 static BROTLI_INLINE unsigned BrotliRBit(unsigned input) { 226 static BROTLI_INLINE unsigned BrotliRBit(unsigned input) {
201 unsigned output; 227 unsigned output;
202 __asm__("rbit %0, %1\n" : "=r"(output) : "r"(input)); 228 __asm__("rbit %0, %1\n" : "=r"(output) : "r"(input));
203 return output; 229 return output;
204 } 230 }
205 #define BROTLI_RBIT(x) BrotliRBit(x) 231 #define BROTLI_RBIT(x) BrotliRBit(x)
206 #endif /* armv7 */ 232 #endif /* armv7 */
207 #endif /* gcc || clang */ 233 #endif /* gcc || clang */
208 234
209 #if defined(BROTLI_TARGET_ARM) 235 #if defined(BROTLI_TARGET_ARM)
210 #define BROTLI_HAS_UBFX 1 236 #define BROTLI_HAS_UBFX (!!1)
211 #else 237 #else
212 #define BROTLI_HAS_UBFX 0 238 #define BROTLI_HAS_UBFX (!!0)
213 #endif 239 #endif
214 240
215 #define BROTLI_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L) 241 #define BROTLI_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
216 242
217 #define BROTLI_FREE(S, X) { \ 243 #define BROTLI_FREE(S, X) { \
218 S->free_func(S->memory_manager_opaque, X); \ 244 S->free_func(S->memory_manager_opaque, X); \
219 X = NULL; \ 245 X = NULL; \
220 } 246 }
221 247
222 #define BROTLI_UNUSED(X) (void)(X) 248 #define BROTLI_UNUSED(X) (void)(X)
223 249
224 #endif /* BROTLI_DEC_PORT_H_ */ 250 #endif /* BROTLI_DEC_PORT_H_ */
OLDNEW
« no previous file with comments | « third_party/brotli/dec/huffman.c ('k') | third_party/brotli/dec/state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698