simdutf
8.0.0
Unicode at GB/s.
Loading...
Searching...
No Matches
common_defs.h
1
#ifndef SIMDUTF_COMMON_DEFS_H
2
#define SIMDUTF_COMMON_DEFS_H
3
4
#include "simdutf/portability.h"
5
#include "simdutf/avx512.h"
6
7
// Sometimes logging is useful, but we want it disabled by default
8
// and free of any logging code in release builds.
9
#ifdef SIMDUTF_LOGGING
10
#include <iostream>
11
#define simdutf_log(msg) \
12
std::cout << "[" << __FUNCTION__ << "]: " << msg << std::endl \
13
<< "\t" << __FILE__ << ":" << __LINE__ << std::endl;
14
#define simdutf_log_assert(cond, msg) \
15
do { \
16
if (!(cond)) { \
17
std::cerr << "[" << __FUNCTION__ << "]: " << msg << std::endl \
18
<< "\t" << __FILE__ << ":" << __LINE__ << std::endl; \
19
std::abort(); \
20
} \
21
} while (0)
22
#else
23
#define simdutf_log(msg)
24
#define simdutf_log_assert(cond, msg)
25
#endif
26
27
#if defined(SIMDUTF_REGULAR_VISUAL_STUDIO)
28
#define SIMDUTF_DEPRECATED __declspec(deprecated)
29
30
#define simdutf_really_inline __forceinline
// really inline in release mode
31
#define simdutf_always_inline __forceinline
// always inline, no matter what
32
#define simdutf_never_inline __declspec(noinline)
33
34
#define simdutf_unused
35
#define simdutf_warn_unused
36
37
#ifndef simdutf_likely
38
#define simdutf_likely(x) x
39
#endif
40
#ifndef simdutf_unlikely
41
#define simdutf_unlikely(x) x
42
#endif
43
44
#define SIMDUTF_PUSH_DISABLE_WARNINGS __pragma(warning(push))
45
#define SIMDUTF_PUSH_DISABLE_ALL_WARNINGS __pragma(warning(push, 0))
46
#define SIMDUTF_DISABLE_VS_WARNING(WARNING_NUMBER) \
47
__pragma(warning(disable : WARNING_NUMBER))
48
// Get rid of Intellisense-only warnings (Code Analysis)
49
// Though __has_include is C++17, it is supported in Visual Studio 2017 or
50
// better (_MSC_VER>=1910).
51
#ifdef __has_include
52
#if __has_include(<CppCoreCheck\Warnings.h>)
53
#include <CppCoreCheck\Warnings.h>
54
#define SIMDUTF_DISABLE_UNDESIRED_WARNINGS \
55
SIMDUTF_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
56
#endif
57
#endif
58
59
#ifndef SIMDUTF_DISABLE_UNDESIRED_WARNINGS
60
#define SIMDUTF_DISABLE_UNDESIRED_WARNINGS
61
#endif
62
63
#define SIMDUTF_DISABLE_DEPRECATED_WARNING SIMDUTF_DISABLE_VS_WARNING(4996)
64
#define SIMDUTF_DISABLE_STRICT_OVERFLOW_WARNING
65
#define SIMDUTF_POP_DISABLE_WARNINGS __pragma(warning(pop))
66
#define SIMDUTF_DISABLE_UNUSED_WARNING
67
#else
// SIMDUTF_REGULAR_VISUAL_STUDIO
68
#if defined(__OPTIMIZE__) || defined(NDEBUG)
69
#define simdutf_really_inline inline __attribute__((always_inline))
70
#else
71
#define simdutf_really_inline inline
72
#endif
73
#define simdutf_always_inline \
74
inline __attribute__((always_inline))
// always inline, no matter what
75
#define SIMDUTF_DEPRECATED __attribute__((deprecated))
76
#define simdutf_never_inline inline __attribute__((noinline))
77
78
#define simdutf_unused __attribute__((unused))
79
#define simdutf_warn_unused __attribute__((warn_unused_result))
80
81
#ifndef simdutf_likely
82
#define simdutf_likely(x) __builtin_expect(!!(x), 1)
83
#endif
84
#ifndef simdutf_unlikely
85
#define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
86
#endif
87
// clang-format off
88
#define SIMDUTF_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
89
// gcc doesn't seem to disable all warnings with all and extra, add warnings
90
// here as necessary
91
#define SIMDUTF_PUSH_DISABLE_ALL_WARNINGS \
92
SIMDUTF_PUSH_DISABLE_WARNINGS \
93
SIMDUTF_DISABLE_GCC_WARNING(-Weffc++) \
94
SIMDUTF_DISABLE_GCC_WARNING(-Wall) \
95
SIMDUTF_DISABLE_GCC_WARNING(-Wconversion) \
96
SIMDUTF_DISABLE_GCC_WARNING(-Wextra) \
97
SIMDUTF_DISABLE_GCC_WARNING(-Wattributes) \
98
SIMDUTF_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
99
SIMDUTF_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
100
SIMDUTF_DISABLE_GCC_WARNING(-Wreturn-type) \
101
SIMDUTF_DISABLE_GCC_WARNING(-Wshadow) \
102
SIMDUTF_DISABLE_GCC_WARNING(-Wunused-parameter) \
103
SIMDUTF_DISABLE_GCC_WARNING(-Wunused-variable)
104
#define SIMDUTF_PRAGMA(P) _Pragma(#P)
105
#define SIMDUTF_DISABLE_GCC_WARNING(WARNING) \
106
SIMDUTF_PRAGMA(GCC diagnostic ignored #WARNING)
107
#if defined(SIMDUTF_CLANG_VISUAL_STUDIO)
108
#define SIMDUTF_DISABLE_UNDESIRED_WARNINGS \
109
SIMDUTF_DISABLE_GCC_WARNING(-Wmicrosoft-include)
110
#else
111
#define SIMDUTF_DISABLE_UNDESIRED_WARNINGS
112
#endif
113
#define SIMDUTF_DISABLE_DEPRECATED_WARNING \
114
SIMDUTF_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
115
#define SIMDUTF_DISABLE_STRICT_OVERFLOW_WARNING \
116
SIMDUTF_DISABLE_GCC_WARNING(-Wstrict-overflow)
117
#define SIMDUTF_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")
118
#define SIMDUTF_DISABLE_UNUSED_WARNING \
119
SIMDUTF_PUSH_DISABLE_WARNINGS \
120
SIMDUTF_DISABLE_GCC_WARNING(-Wunused-function) \
121
SIMDUTF_DISABLE_GCC_WARNING(-Wunused-const-variable)
122
// clang-format on
123
124
#endif
// MSC_VER
125
126
// Conditional constexpr macro: expands to constexpr for C++17+, empty otherwise
127
#if SIMDUTF_CPLUSPLUS17
128
#define simdutf_constexpr constexpr
129
#else
130
#define simdutf_constexpr
131
#endif
132
133
// Will evaluate to constexpr in C++23 or later. This makes it possible to mark
134
// functions constexpr if the "if consteval" feature is available to use.
135
#if SIMDUTF_CPLUSPLUS23
136
#define simdutf_constexpr23 constexpr
137
#else
138
#define simdutf_constexpr23
139
#endif
140
141
#ifndef SIMDUTF_DLLIMPORTEXPORT
142
#if defined(SIMDUTF_VISUAL_STUDIO)
// Visual Studio
158
#if SIMDUTF_BUILDING_WINDOWS_DYNAMIC_LIBRARY
159
160
// We set SIMDUTF_BUILDING_WINDOWS_DYNAMIC_LIBRARY when we build a DLL
161
// under Windows. It should never happen that both
162
// SIMDUTF_BUILDING_WINDOWS_DYNAMIC_LIBRARY and
163
// SIMDUTF_USING_WINDOWS_DYNAMIC_LIBRARY are set.
164
#define SIMDUTF_DLLIMPORTEXPORT __declspec(dllexport)
165
#elif SIMDUTF_USING_WINDOWS_DYNAMIC_LIBRARY
166
// Windows user who call a dynamic library should set
167
// SIMDUTF_USING_WINDOWS_DYNAMIC_LIBRARY to 1.
168
169
#define SIMDUTF_DLLIMPORTEXPORT __declspec(dllimport)
170
#else
171
// We assume by default static linkage
172
#define SIMDUTF_DLLIMPORTEXPORT
173
#endif
174
#else
// defined(SIMDUTF_VISUAL_STUDIO)
175
// Non-Windows systems do not have this complexity.
176
#define SIMDUTF_DLLIMPORTEXPORT
177
#endif
// defined(SIMDUTF_VISUAL_STUDIO)
178
#endif
179
180
#if SIMDUTF_MAYBE_UNUSED_AVAILABLE
181
#define simdutf_maybe_unused [[maybe_unused]]
182
#else
183
#define simdutf_maybe_unused
184
#endif
185
186
#endif
// SIMDUTF_COMMON_DEFS_H
include
simdutf
common_defs.h
Generated by
1.9.8