]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/BrotliCustomDecompressLib/common/port.h
1 /* Copyright 2016 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. */
9 #ifndef BROTLI_COMMON_PORT_H_
10 #define BROTLI_COMMON_PORT_H_
12 /* Compatibility with non-clang compilers. */
14 #define __has_builtin(x) 0
17 #ifndef __has_attribute
18 #define __has_attribute(x) 0
22 #define __has_feature(x) 0
25 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
26 #define BROTLI_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
28 #define BROTLI_GCC_VERSION 0
32 #define BROTLI_ICC_VERSION __ICC
34 #define BROTLI_ICC_VERSION 0
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
42 #define BROTLI_MODERN_COMPILER 0
45 /* Define "PREDICT_TRUE" and "PREDICT_FALSE" macros for capable compilers.
47 To apply compiler hint, enclose the branching condition into macros, like this:
49 if (PREDICT_TRUE(zero == 0)) {
50 // main execution path
52 // compiler should place this code outside of main execution path
57 if (PREDICT_FALSE(something_rare_or_unexpected_happens)) {
58 // compiler should place this code outside of main execution path
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))
66 #define PREDICT_FALSE(x) (x)
67 #define PREDICT_TRUE(x) (x)
70 #if BROTLI_MODERN_COMPILER || __has_attribute(always_inline)
71 #define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
73 #define ATTRIBUTE_ALWAYS_INLINE
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")))
81 #define ATTRIBUTE_VISIBILITY_HIDDEN
84 #ifndef BROTLI_INTERNAL
85 #define BROTLI_INTERNAL ATTRIBUTE_VISIBILITY_HIDDEN
89 #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
90 __STDC_VERSION__ >= 199901L
91 #define BROTLI_INLINE inline ATTRIBUTE_ALWAYS_INLINE
96 #define BROTLI_INLINE __forceinline
99 #if BROTLI_MODERN_COMPILER || __has_attribute(noinline)
100 #define BROTLI_NOINLINE __attribute__((noinline))
102 #define BROTLI_NOINLINE
105 #define BROTLI_UNUSED(X) (void)(X)
107 #endif /* BROTLI_COMMON_PORT_H_ */