]> git.proxmox.com Git - mirror_edk2.git/blame - 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
CommitLineData
36ff6d80
SB
1/* Copyright 2016 Google Inc. All Rights Reserved.\r
2\r
3 Distributed under MIT license.\r
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r
5*/\r
6\r
7/* Macros for compiler / platform specific features and build options. */\r
8\r
9#ifndef BROTLI_COMMON_PORT_H_\r
10#define BROTLI_COMMON_PORT_H_\r
11\r
12/* Compatibility with non-clang compilers. */\r
13#ifndef __has_builtin\r
14#define __has_builtin(x) 0\r
15#endif\r
16\r
17#ifndef __has_attribute\r
18#define __has_attribute(x) 0\r
19#endif\r
20\r
21#ifndef __has_feature\r
22#define __has_feature(x) 0\r
23#endif\r
24\r
25#if defined(__GNUC__) && defined(__GNUC_MINOR__)\r
26#define BROTLI_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)\r
27#else\r
28#define BROTLI_GCC_VERSION 0\r
29#endif\r
30\r
31#if defined(__ICC)\r
32#define BROTLI_ICC_VERSION __ICC\r
33#else\r
34#define BROTLI_ICC_VERSION 0\r
35#endif\r
36\r
37#if defined(BROTLI_BUILD_MODERN_COMPILER)\r
38#define BROTLI_MODERN_COMPILER 1\r
39#elif BROTLI_GCC_VERSION > 300 || BROTLI_ICC_VERSION >= 1600\r
40#define BROTLI_MODERN_COMPILER 1\r
41#else\r
42#define BROTLI_MODERN_COMPILER 0\r
43#endif\r
44\r
45/* Define "PREDICT_TRUE" and "PREDICT_FALSE" macros for capable compilers.\r
46\r
47To apply compiler hint, enclose the branching condition into macros, like this:\r
48\r
49 if (PREDICT_TRUE(zero == 0)) {\r
50 // main execution path\r
51 } else {\r
52 // compiler should place this code outside of main execution path\r
53 }\r
54\r
55OR:\r
56\r
57 if (PREDICT_FALSE(something_rare_or_unexpected_happens)) {\r
58 // compiler should place this code outside of main execution path\r
59 }\r
60\r
61*/\r
62#if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_expect)\r
63#define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))\r
64#define PREDICT_FALSE(x) (__builtin_expect(x, 0))\r
65#else\r
66#define PREDICT_FALSE(x) (x)\r
67#define PREDICT_TRUE(x) (x)\r
68#endif\r
69\r
70#if BROTLI_MODERN_COMPILER || __has_attribute(always_inline)\r
71#define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))\r
72#else\r
73#define ATTRIBUTE_ALWAYS_INLINE\r
74#endif\r
75\r
76#if defined(_WIN32) || defined(__CYGWIN__)\r
77#define ATTRIBUTE_VISIBILITY_HIDDEN\r
78#elif BROTLI_MODERN_COMPILER || __has_attribute(visibility)\r
79#define ATTRIBUTE_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))\r
80#else\r
81#define ATTRIBUTE_VISIBILITY_HIDDEN\r
82#endif\r
83\r
84#ifndef BROTLI_INTERNAL\r
85#define BROTLI_INTERNAL ATTRIBUTE_VISIBILITY_HIDDEN\r
86#endif\r
87\r
88#ifndef _MSC_VER\r
89#if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \\r
90 __STDC_VERSION__ >= 199901L\r
91#define BROTLI_INLINE inline ATTRIBUTE_ALWAYS_INLINE\r
92#else\r
93#define BROTLI_INLINE\r
94#endif\r
95#else /* _MSC_VER */\r
96#define BROTLI_INLINE __forceinline\r
97#endif /* _MSC_VER */\r
98\r
99#if BROTLI_MODERN_COMPILER || __has_attribute(noinline)\r
100#define BROTLI_NOINLINE __attribute__((noinline))\r
101#else\r
102#define BROTLI_NOINLINE\r
103#endif\r
104\r
105#define BROTLI_UNUSED(X) (void)(X)\r
106\r
107#endif /* BROTLI_COMMON_PORT_H_ */\r