-
Notifications
You must be signed in to change notification settings - Fork 4
/
global.hpp
223 lines (172 loc) · 6.07 KB
/
global.hpp
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Copyright 2019-2022 Laurynas Biveinis
#ifndef UNODB_DETAIL_GLOBAL_HPP
#define UNODB_DETAIL_GLOBAL_HPP
// Defines that must precede includes
#ifdef UNODB_DETAIL_STANDALONE
#if !defined(NDEBUG) && !defined(__clang__)
#ifndef _GLIBCXX_DEBUG
#define _GLIBCXX_DEBUG
#endif
#ifndef _GLIBCXX_DEBUG_PEDANTIC
#define _GLIBCXX_DEBUG_PEDANTIC
#endif
#endif // !defined(NDEBUG) && !defined(__clang__)
#if defined(__has_feature) && !defined(__clang__)
#if __has_feature(address_sanitizer)
#define _GLIBCXX_SANITIZE_VECTOR 1
#endif
#elif defined(__SANITIZE_ADDRESS__)
#define _GLIBCXX_SANITIZE_VECTOR 1
#endif
#endif // UNODB_DETAIL_STANDALONE
#ifdef _MSC_VER
#define NOMINMAX
#if !defined(NDEBUG) && defined(__SANITIZE_ADDRESS__)
// Workaround bug of _aligned_free not being hooked for ASan under MSVC debug
// build -
// https://developercommunity.visualstudio.com/t/asan-check-failed-using-aligned-free-in-debug-buil/1406956
#undef _CRTDBG_MAP_ALLOC
#endif
#endif
// Architecture
#if defined(_MSC_VER) && defined(_M_X64)
#define UNODB_DETAIL_MSVC_X86_64
#endif
#if defined(__x86_64) || defined(UNODB_DETAIL_MSVC_X86_64)
#define UNODB_DETAIL_X86_64
#endif
#ifdef UNODB_DETAIL_X86_64
#ifdef __AVX2__
#define UNODB_DETAIL_AVX2
#else
#define UNODB_DETAIL_SSE4_2
#endif
#endif
#if defined(UNODB_DETAIL_X86_64) || \
defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define UNODB_DETAIL_LITTLE_ENDIAN
#endif
// Compiler
#if defined(_MSC_VER)
#if !defined(__clang__)
// MSVC with the MSVC frontend, not the LLVM one
#define UNODB_DETAIL_MSVC
#else // #if !defined(__clang__)
#define UNODB_DETAIL_MSVC_CLANG
#endif // #if !defined(__clang__)
#endif // #if defined(_MSC_VER)
#ifndef UNODB_DETAIL_MSVC
#ifdef __clang__
#define UNODB_DETAIL_BUILTIN_ASSUME(x) __builtin_assume(x)
#define UNODB_DETAIL_LIFETIMEBOUND [[clang::lifetimebound]]
#define UNODB_DETAIL_C_STRING_ARG(x)
#else
#define UNODB_DETAIL_BUILTIN_ASSUME(x) \
do { \
if (!(x)) __builtin_unreachable(); \
} while (0)
#define UNODB_DETAIL_LIFETIMEBOUND
#if __GNUG__ >= 14
#define UNODB_DETAIL_C_STRING_ARG(x) \
__attribute__((null_terminated_string_arg(x)))
#else
#define UNODB_DETAIL_C_STRING_ARG(x)
#endif
#endif
#define UNODB_DETAIL_LIKELY(x) __builtin_expect(x, 1)
#define UNODB_DETAIL_UNLIKELY(x) __builtin_expect(x, 0)
#define UNODB_DETAIL_UNUSED [[gnu::unused]]
#define UNODB_DETAIL_FORCE_INLINE __attribute__((always_inline))
#define UNODB_DETAIL_NOINLINE __attribute__((noinline))
#define UNODB_DETAIL_UNREACHABLE() __builtin_unreachable()
#define UNODB_DETAIL_CONSTEXPR_NOT_MSVC constexpr
#else // #ifndef UNODB_DETAIL_MSVC
#define UNODB_DETAIL_BUILTIN_ASSUME(x) __assume(x)
#define UNODB_DETAIL_LIKELY(x) (!!(x))
#define UNODB_DETAIL_UNLIKELY(x) (!!(x))
#define UNODB_DETAIL_UNUSED [[maybe_unused]]
#define UNODB_DETAIL_FORCE_INLINE __forceinline
#define UNODB_DETAIL_NOINLINE __declspec(noinline)
#define UNODB_DETAIL_UNREACHABLE() __assume(0)
#define UNODB_DETAIL_CONSTEXPR_NOT_MSVC inline
#define UNODB_DETAIL_LIFETIMEBOUND
#define UNODB_DETAIL_C_STRING_ARG(x)
#endif // #ifndef UNODB_DETAIL_MSVC
// Sanitizers
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define UNODB_DETAIL_ADDRESS_SANITIZER 1
#endif
#if __has_feature(thread_sanitizer)
#define UNODB_DETAIL_THREAD_SANITIZER 1
#endif
#else
#ifdef __SANITIZE_ADDRESS__
#define UNODB_DETAIL_ADDRESS_SANITIZER 1
#endif
#ifdef __SANITIZE_THREAD__
#define UNODB_DETAIL_THREAD_SANITIZER 1
#endif
#endif
// Warnings
#define UNODB_DETAIL_DO_PRAGMA(x) _Pragma(#x)
#ifndef UNODB_DETAIL_MSVC
#define UNODB_DETAIL_DISABLE_WARNING(x) \
_Pragma("GCC diagnostic push") \
UNODB_DETAIL_DO_PRAGMA(GCC diagnostic ignored x)
#define UNODB_DETAIL_RESTORE_WARNINGS() _Pragma("GCC diagnostic pop")
#define UNODB_DETAIL_DISABLE_MSVC_WARNING(x)
#define UNODB_DETAIL_RESTORE_MSVC_WARNINGS()
#else // #ifndef UNODB_DETAIL_MSVC
#define UNODB_DETAIL_DISABLE_MSVC_WARNING(x) \
_Pragma("warning(push)") UNODB_DETAIL_DO_PRAGMA(warning(disable : x))
#define UNODB_DETAIL_RESTORE_MSVC_WARNINGS() _Pragma("warning(pop)")
#endif // #ifndef UNODB_DETAIL_MSVC
#ifdef __clang__
#define UNODB_DETAIL_DISABLE_CLANG_WARNING(x) UNODB_DETAIL_DISABLE_WARNING(x)
#define UNODB_DETAIL_RESTORE_CLANG_WARNINGS() UNODB_DETAIL_RESTORE_WARNINGS()
#else
#define UNODB_DETAIL_DISABLE_CLANG_WARNING(x)
#define UNODB_DETAIL_RESTORE_CLANG_WARNINGS()
#endif
#if defined(__GNUG__) && !defined(__clang__)
#define UNODB_DETAIL_DISABLE_GCC_WARNING(x) UNODB_DETAIL_DISABLE_WARNING(x)
#define UNODB_DETAIL_RESTORE_GCC_WARNINGS() UNODB_DETAIL_RESTORE_WARNINGS()
#if __GNUG__ == 10
#define UNODB_DETAIL_DISABLE_GCC_10_WARNING(x) UNODB_DETAIL_DISABLE_WARNING(x)
#define UNODB_DETAIL_RESTORE_GCC_10_WARNINGS() UNODB_DETAIL_RESTORE_WARNINGS()
#else // __GNUG__ == 10
#define UNODB_DETAIL_DISABLE_GCC_10_WARNING(x)
#define UNODB_DETAIL_RESTORE_GCC_10_WARNINGS()
#endif // __GNUG__ == 10
#if __GNUG__ >= 11
#define UNODB_DETAIL_DISABLE_GCC_11_WARNING(x) UNODB_DETAIL_DISABLE_WARNING(x)
#define UNODB_DETAIL_RESTORE_GCC_11_WARNINGS() UNODB_DETAIL_RESTORE_WARNINGS()
#else // __GNUG__ >= 11
#define UNODB_DETAIL_DISABLE_GCC_11_WARNING(x)
#define UNODB_DETAIL_RESTORE_GCC_11_WARNINGS()
#endif // __GNUG__ >= 11
#else // defined(__GNUG__) && !defined(__clang__)
#define UNODB_DETAIL_DISABLE_GCC_WARNING(x)
#define UNODB_DETAIL_RESTORE_GCC_WARNINGS()
#define UNODB_DETAIL_DISABLE_GCC_10_WARNING(x)
#define UNODB_DETAIL_RESTORE_GCC_10_WARNINGS()
#define UNODB_DETAIL_DISABLE_GCC_11_WARNING(x)
#define UNODB_DETAIL_RESTORE_GCC_11_WARNINGS()
#endif // defined(__GNUG__) && !defined(__clang__)
// Debug or release build
#ifdef NDEBUG
#define UNODB_DETAIL_RELEASE_CONSTEXPR constexpr
#define UNODB_DETAIL_RELEASE_CONST const
#define UNODB_DETAIL_RELEASE_EXPLICIT explicit
#define UNODB_DETAIL_USED_IN_DEBUG UNODB_DETAIL_UNUSED
#else
#define UNODB_DETAIL_RELEASE_CONSTEXPR
#define UNODB_DETAIL_RELEASE_CONST
#define UNODB_DETAIL_RELEASE_EXPLICIT
#define UNODB_DETAIL_USED_IN_DEBUG
#endif
// Features
#define UNODB_DETAIL_SPINLOCK_LOOP_PAUSE 1
#define UNODB_DETAIL_SPINLOCK_LOOP_EMPTY 2
#endif // UNODB_DETAIL_GLOBAL_HPP