]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BrotliCustomDecompressLib/common/port.h
BaseTools: Update Brotli Compress to the latest one 1.0.6
[mirror_edk2.git] / MdeModulePkg / Library / BrotliCustomDecompressLib / common / port.h
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 > 300 || BROTLI_ICC_VERSION >= 1600
40 #define BROTLI_MODERN_COMPILER 1
41 #else
42 #define BROTLI_MODERN_COMPILER 0
43 #endif
44
45 /* Define "PREDICT_TRUE" and "PREDICT_FALSE" macros for capable compilers.
46
47 To apply compiler hint, enclose the branching condition into macros, like this:
48
49 if (PREDICT_TRUE(zero == 0)) {
50 // main execution path
51 } else {
52 // compiler should place this code outside of main execution path
53 }
54
55 OR:
56
57 if (PREDICT_FALSE(something_rare_or_unexpected_happens)) {
58 // compiler should place this code outside of main execution path
59 }
60
61 */
62 #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_expect)
63 #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
64 #define PREDICT_FALSE(x) (__builtin_expect(x, 0))
65 #else
66 #define PREDICT_FALSE(x) (x)
67 #define PREDICT_TRUE(x) (x)
68 #endif
69
70 #if BROTLI_MODERN_COMPILER || __has_attribute(always_inline)
71 #define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
72 #else
73 #define ATTRIBUTE_ALWAYS_INLINE
74 #endif
75
76 #if defined(_WIN32) || defined(__CYGWIN__)
77 #define ATTRIBUTE_VISIBILITY_HIDDEN
78 #elif BROTLI_MODERN_COMPILER || __has_attribute(visibility)
79 #define ATTRIBUTE_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))
80 #else
81 #define ATTRIBUTE_VISIBILITY_HIDDEN
82 #endif
83
84 #ifndef BROTLI_INTERNAL
85 #define BROTLI_INTERNAL ATTRIBUTE_VISIBILITY_HIDDEN
86 #endif
87
88 #ifndef _MSC_VER
89 #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
90 __STDC_VERSION__ >= 199901L
91 #define BROTLI_INLINE inline ATTRIBUTE_ALWAYS_INLINE
92 #else
93 #define BROTLI_INLINE
94 #endif
95 #else /* _MSC_VER */
96 #define BROTLI_INLINE __forceinline
97 #endif /* _MSC_VER */
98
99 #if BROTLI_MODERN_COMPILER || __has_attribute(noinline)
100 #define BROTLI_NOINLINE __attribute__((noinline))
101 #else
102 #define BROTLI_NOINLINE
103 #endif
104
105 #define BROTLI_UNUSED(X) (void)(X)
106
107 #endif /* BROTLI_COMMON_PORT_H_ */