-
Notifications
You must be signed in to change notification settings - Fork 29
/
compile_optimize.h
191 lines (169 loc) · 5.08 KB
/
compile_optimize.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#pragma once
// ================ branch prediction information ================
#ifndef likely
#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
#else
#define likely(x) !!(x)
#endif
#endif
#ifndef unlikely
#ifdef __GNUC__
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define unlikely(x) !!(x)
#endif
#endif
#ifndef unreachable
#ifdef __GNUC__
#ifdef __clang__
#if __has_builtin(__builtin_unreachable)
#define unreachable() __builtin_unreachable()
#else
#define unreachable() abort()
#endif
#else
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define unreachable() __builtin_unreachable()
#else
#define unreachable() abort()
#endif
#endif
#else
#define unreachable() abort()
#endif
#endif
// ---------------- branch prediction information ----------------
// ================ import/export ================
// @see https://gcc.gnu.org/wiki/Visibility
// @see http://releases.llvm.org/9.0.0/tools/clang/docs/AttributeReference.html
// 不支持 borland/sunpro_cc/xlcpp
// ================ import/export: for compilers ================
#if defined(__GNUC__) && !defined(__ibmxl__)
// GNU C++/Clang
//
// Dynamic shared object (DSO) and dynamic-link library (DLL) support
//
#if __GNUC__ >= 4
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
// All Win32 development environments, including 64-bit Windows and MinGW, define
// _WIN32 or one of its variant spellings. Note that Cygwin is a POSIX environment,
// so does not define _WIN32 or its variants.
#ifndef UTIL_SYMBOL_EXPORT
#define UTIL_SYMBOL_EXPORT __attribute__((__dllexport__))
#endif
#ifndef UTIL_SYMBOL_IMPORT
#define UTIL_SYMBOL_IMPORT __attribute__((__dllimport__))
#endif
#else
#ifndef UTIL_SYMBOL_EXPORT
#define UTIL_SYMBOL_EXPORT __attribute__((visibility("default")))
#endif
#ifndef UTIL_SYMBOL_IMPORT
#define UTIL_SYMBOL_IMPORT __attribute__((visibility("default")))
#endif
#ifndef UTIL_SYMBOL_VISIBLE
#define UTIL_SYMBOL_VISIBLE __attribute__((visibility("default")))
#endif
#ifndef UTIL_SYMBOL_LOCAL
#define UTIL_SYMBOL_LOCAL __attribute__((visibility("hidden")))
#endif
#endif
#else
// config/platform/win32.hpp will define UTIL_SYMBOL_EXPORT, etc., unless already defined
#ifndef UTIL_SYMBOL_EXPORT
#define UTIL_SYMBOL_EXPORT
#endif
#ifndef UTIL_SYMBOL_IMPORT
#define UTIL_SYMBOL_IMPORT
#endif
#ifndef UTIL_SYMBOL_VISIBLE
#define UTIL_SYMBOL_VISIBLE
#endif
#ifndef UTIL_SYMBOL_LOCAL
#define UTIL_SYMBOL_LOCAL
#endif
#endif
#elif defined(_MSC_VER)
// Microsoft Visual C++
//
// Must remain the last #elif since some other vendors (Metrowerks, for
// example) also #define _MSC_VER
#else
#endif
// ---------------- import/export: for compilers ----------------
// ================ import/export: for platform ================
// Default defines for UTIL_SYMBOL_EXPORT and UTIL_SYMBOL_IMPORT
// If a compiler doesn't support __declspec(dllexport)/__declspec(dllimport),
// its boost/config/compiler/ file must define UTIL_SYMBOL_EXPORT and
// UTIL_SYMBOL_IMPORT
#if !defined(UTIL_SYMBOL_EXPORT) && (defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__))
#ifndef UTIL_SYMBOL_EXPORT
#define UTIL_SYMBOL_EXPORT __declspec(dllexport)
#endif
#ifndef UTIL_SYMBOL_IMPORT
#define UTIL_SYMBOL_IMPORT __declspec(dllimport)
#endif
#endif
// ---------------- import/export: for platform ----------------
#ifndef UTIL_SYMBOL_EXPORT
#define UTIL_SYMBOL_EXPORT
#endif
#ifndef UTIL_SYMBOL_IMPORT
#define UTIL_SYMBOL_IMPORT
#endif
#ifndef UTIL_SYMBOL_VISIBLE
#define UTIL_SYMBOL_VISIBLE
#endif
#ifndef UTIL_SYMBOL_LOCAL
#define UTIL_SYMBOL_LOCAL
#endif
#ifndef UTIL_SYMBOL_NONE
#define UTIL_SYMBOL_NONE
#endif
// ---------------- import/export ----------------
// ================ __cdecl ================
#if defined(__GNUC__) || defined(__GNUG__)
#ifndef __cdecl
// see https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html
// Intel x86 architecture specific calling conventions
#ifdef _M_IX86
#define __cdecl __attribute__((__cdecl__))
#else
#define __cdecl
#endif
#endif
#endif
// ---------------- __cdecl ----------------
// ================ always inline ================
#ifndef UTIL_FORCEINLINE
#if defined(__clang__)
#if __has_attribute(always_inline)
#define UTIL_FORCEINLINE __attribute__((always_inline))
#else
#define UTIL_FORCEINLINE inline
#endif
#elif defined(__GNUC__) && __GNUC__ > 3
#define UTIL_FORCEINLINE __attribute__((always_inline))
#elif defined(_MSC_VER)
#define UTIL_FORCEINLINE __forceinline
#else
#define UTIL_FORCEINLINE inline
#endif
#endif
#ifndef UTIL_NOINLINE
#if defined(_MSC_VER)
#define UTIL_NOINLINE __declspec(noinline)
#elif defined(__GNUC__) && __GNUC__ > 3
// Clang also defines __GNUC__ (as 4)
#if defined(__CUDACC__)
// nvcc doesn't always parse __noinline__,
// see: https://svn.boost.org/trac/boost/ticket/9392
#define UTIL_NOINLINE __attribute__((noinline))
#else
#define UTIL_NOINLINE __attribute__((__noinline__))
#endif
#else
#define UTIL_NOINLINE
#endif
#endif