simdutf
7.3.5
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
#ifndef SIMDUTF_DLLIMPORTEXPORT
127
#if defined(SIMDUTF_VISUAL_STUDIO)
// Visual Studio
143
#if SIMDUTF_BUILDING_WINDOWS_DYNAMIC_LIBRARY
144
145
// We set SIMDUTF_BUILDING_WINDOWS_DYNAMIC_LIBRARY when we build a DLL
146
// under Windows. It should never happen that both
147
// SIMDUTF_BUILDING_WINDOWS_DYNAMIC_LIBRARY and
148
// SIMDUTF_USING_WINDOWS_DYNAMIC_LIBRARY are set.
149
#define SIMDUTF_DLLIMPORTEXPORT __declspec(dllexport)
150
#elif SIMDUTF_USING_WINDOWS_DYNAMIC_LIBRARY
151
// Windows user who call a dynamic library should set
152
// SIMDUTF_USING_WINDOWS_DYNAMIC_LIBRARY to 1.
153
154
#define SIMDUTF_DLLIMPORTEXPORT __declspec(dllimport)
155
#else
156
// We assume by default static linkage
157
#define SIMDUTF_DLLIMPORTEXPORT
158
#endif
159
#else
// defined(SIMDUTF_VISUAL_STUDIO)
160
// Non-Windows systems do not have this complexity.
161
#define SIMDUTF_DLLIMPORTEXPORT
162
#endif
// defined(SIMDUTF_VISUAL_STUDIO)
163
#endif
164
165
#if SIMDUTF_MAYBE_UNUSED_AVAILABLE
166
#define simdutf_maybe_unused [[maybe_unused]]
167
#else
168
#define simdutf_maybe_unused
169
#endif
170
171
#endif
// SIMDUTF_COMMON_DEFS_H
include
simdutf
common_defs.h
Generated by
1.9.8