• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BROTLI_COMMON_PORT_H_
10 #define BROTLI_COMMON_PORT_H_
11 
12 /* Compatibility with non-clang compilers. */
13 #ifndef __has_builtin
14 #define __has_builtin(x) 0
15 #endif
16 
17 #ifndef __has_attribute
18 #define __has_attribute(x) 0
19 #endif
20 
21 #ifndef __has_feature
22 #define __has_feature(x) 0
23 #endif
24 
25 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
26 #define BROTLI_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
27 #else
28 #define BROTLI_GCC_VERSION 0
29 #endif
30 
31 #if defined(__ICC)
32 #define BROTLI_ICC_VERSION __ICC
33 #else
34 #define BROTLI_ICC_VERSION 0
35 #endif
36 
37 #if defined(BROTLI_BUILD_MODERN_COMPILER)
38 #define BROTLI_MODERN_COMPILER 1
39 #elif BROTLI_GCC_VERSION >= 304 || BROTLI_ICC_VERSION >= 1600
40 #define BROTLI_MODERN_COMPILER 1
41 #else
42 #define BROTLI_MODERN_COMPILER 0
43 #endif
44 
45 /* Define "BROTLI_PREDICT_TRUE" and "BROTLI_PREDICT_FALSE" macros for capable
46    compilers.
47 
48 To apply compiler hint, enclose the branching condition into macros, like this:
49 
50   if (BROTLI_PREDICT_TRUE(zero == 0)) {
51     // main execution path
52   } else {
53     // compiler should place this code outside of main execution path
54   }
55 
56 OR:
57 
58   if (BROTLI_PREDICT_FALSE(something_rare_or_unexpected_happens)) {
59     // compiler should place this code outside of main execution path
60   }
61 
62 */
63 #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_expect)
64 #define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
65 #define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
66 #else
67 #define BROTLI_PREDICT_FALSE(x) (x)
68 #define BROTLI_PREDICT_TRUE(x) (x)
69 #endif
70 
71 #if BROTLI_MODERN_COMPILER || __has_attribute(always_inline)
72 #define BROTLI_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
73 #else
74 #define BROTLI_ATTRIBUTE_ALWAYS_INLINE
75 #endif
76 
77 #if defined(_WIN32) || defined(__CYGWIN__)
78 #define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN
79 #elif BROTLI_MODERN_COMPILER || __has_attribute(visibility)
80 #define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN \
81     __attribute__ ((visibility ("hidden")))
82 #else
83 #define BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN
84 #endif
85 
86 #ifndef BROTLI_INTERNAL
87 #define BROTLI_INTERNAL BROTLI_ATTRIBUTE_VISIBILITY_HIDDEN
88 #endif
89 
90 #if defined(BROTLI_SHARED_COMPILATION) && defined(_WIN32)
91 #if defined(BROTLICOMMON_SHARED_COMPILATION)
92 #define BROTLI_COMMON_API __declspec(dllexport)
93 #else
94 #define BROTLI_COMMON_API __declspec(dllimport)
95 #endif  /* BROTLICOMMON_SHARED_COMPILATION */
96 #if defined(BROTLIDEC_SHARED_COMPILATION)
97 #define BROTLI_DEC_API __declspec(dllexport)
98 #else
99 #define BROTLI_DEC_API __declspec(dllimport)
100 #endif  /* BROTLIDEC_SHARED_COMPILATION */
101 #if defined(BROTLIENC_SHARED_COMPILATION)
102 #define BROTLI_ENC_API __declspec(dllexport)
103 #else
104 #define BROTLI_ENC_API __declspec(dllimport)
105 #endif  /* BROTLIENC_SHARED_COMPILATION */
106 #else  /* BROTLI_SHARED_COMPILATION && _WIN32 */
107 #define BROTLI_COMMON_API
108 #define BROTLI_DEC_API
109 #define BROTLI_ENC_API
110 #endif
111 
112 #ifndef _MSC_VER
113 #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
114     (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
115 #define BROTLI_INLINE inline BROTLI_ATTRIBUTE_ALWAYS_INLINE
116 #else
117 #define BROTLI_INLINE
118 #endif
119 #else  /* _MSC_VER */
120 #define BROTLI_INLINE __forceinline
121 #endif  /* _MSC_VER */
122 
123 #if !defined(__cplusplus) && !defined(c_plusplus) && \
124     (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
125 #define BROTLI_RESTRICT restrict
126 #elif BROTLI_GCC_VERSION > 295 || defined(__llvm__)
127 #define BROTLI_RESTRICT __restrict
128 #else
129 #define BROTLI_RESTRICT
130 #endif
131 
132 #if BROTLI_MODERN_COMPILER || __has_attribute(noinline)
133 #define BROTLI_NOINLINE __attribute__((noinline))
134 #else
135 #define BROTLI_NOINLINE
136 #endif
137 
138 #if BROTLI_MODERN_COMPILER || __has_attribute(deprecated)
139 #define BROTLI_DEPRECATED __attribute__((deprecated))
140 #else
141 #define BROTLI_DEPRECATED
142 #endif
143 
144 #define BROTLI_UNUSED(X) (void)(X)
145 
146 #endif  /* BROTLI_COMMON_PORT_H_ */
147