simdutf 9.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 SIMDUTF_CPLUSPLUS17
28 #define simdutf_unused [[maybe_unused]]
29#endif // SIMDUTF_CPLUSPLUS17
30
31#if defined(SIMDUTF_REGULAR_VISUAL_STUDIO)
32 #define SIMDUTF_DEPRECATED __declspec(deprecated)
33
34 #define simdutf_really_inline __forceinline // really inline in release mode
35 #define simdutf_always_inline __forceinline // always inline, no matter what
36 #define simdutf_never_inline __declspec(noinline)
37
38 #ifndef simdutf_unused
39 #define simdutf_unused
40 #endif // simdutf_unused
41 #define simdutf_warn_unused
42
43 #ifndef simdutf_likely
44 #define simdutf_likely(x) x
45 #endif
46 #ifndef simdutf_unlikely
47 #define simdutf_unlikely(x) x
48 #endif
49
50 #define SIMDUTF_PUSH_DISABLE_WARNINGS __pragma(warning(push))
51 #define SIMDUTF_PUSH_DISABLE_ALL_WARNINGS __pragma(warning(push, 0))
52 #define SIMDUTF_DISABLE_VS_WARNING(WARNING_NUMBER) \
53 __pragma(warning(disable : WARNING_NUMBER))
54 // Get rid of Intellisense-only warnings (Code Analysis)
55 // Though __has_include is C++17, it is supported in Visual Studio 2017 or
56 // better (_MSC_VER>=1910).
57 #ifdef __has_include
58 #if __has_include(<CppCoreCheck\Warnings.h>)
59 #include <CppCoreCheck\Warnings.h>
60 #define SIMDUTF_DISABLE_UNDESIRED_WARNINGS \
61 SIMDUTF_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
62 #endif
63 #endif
64
65 #ifndef SIMDUTF_DISABLE_UNDESIRED_WARNINGS
66 #define SIMDUTF_DISABLE_UNDESIRED_WARNINGS
67 #endif
68
69 #define SIMDUTF_DISABLE_DEPRECATED_WARNING SIMDUTF_DISABLE_VS_WARNING(4996)
70 #define SIMDUTF_DISABLE_STRICT_OVERFLOW_WARNING
71 #define SIMDUTF_POP_DISABLE_WARNINGS __pragma(warning(pop))
72 #define SIMDUTF_DISABLE_UNUSED_WARNING
73#else // SIMDUTF_REGULAR_VISUAL_STUDIO
74 #if defined(__OPTIMIZE__) || defined(NDEBUG)
75 #define simdutf_really_inline inline __attribute__((always_inline))
76 #else
77 #define simdutf_really_inline inline
78 #endif
79 #define simdutf_always_inline \
80 inline __attribute__((always_inline)) // always inline, no matter what
81 #define SIMDUTF_DEPRECATED __attribute__((deprecated))
82 #define simdutf_never_inline inline __attribute__((noinline))
83 #ifndef simdutf_unused
84 #define simdutf_unused __attribute__((unused))
85 #endif // simdutf_unused
86 #define simdutf_warn_unused __attribute__((warn_unused_result))
87
88 #ifndef simdutf_likely
89 #define simdutf_likely(x) __builtin_expect(!!(x), 1)
90 #endif
91 #ifndef simdutf_unlikely
92 #define simdutf_unlikely(x) __builtin_expect(!!(x), 0)
93 #endif
94 // clang-format off
95 #define SIMDUTF_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
96 // gcc doesn't seem to disable all warnings with all and extra, add warnings
97 // here as necessary
98 #define SIMDUTF_PUSH_DISABLE_ALL_WARNINGS \
99 SIMDUTF_PUSH_DISABLE_WARNINGS \
100 SIMDUTF_DISABLE_GCC_WARNING(-Weffc++) \
101 SIMDUTF_DISABLE_GCC_WARNING(-Wall) \
102 SIMDUTF_DISABLE_GCC_WARNING(-Wconversion) \
103 SIMDUTF_DISABLE_GCC_WARNING(-Wextra) \
104 SIMDUTF_DISABLE_GCC_WARNING(-Wattributes) \
105 SIMDUTF_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
106 SIMDUTF_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
107 SIMDUTF_DISABLE_GCC_WARNING(-Wreturn-type) \
108 SIMDUTF_DISABLE_GCC_WARNING(-Wshadow) \
109 SIMDUTF_DISABLE_GCC_WARNING(-Wunused-parameter) \
110 SIMDUTF_DISABLE_GCC_WARNING(-Wunused-variable)
111 #define SIMDUTF_PRAGMA(P) _Pragma(#P)
112 #define SIMDUTF_DISABLE_GCC_WARNING(WARNING) \
113 SIMDUTF_PRAGMA(GCC diagnostic ignored #WARNING)
114 #if defined(SIMDUTF_CLANG_VISUAL_STUDIO)
115 #define SIMDUTF_DISABLE_UNDESIRED_WARNINGS \
116 SIMDUTF_DISABLE_GCC_WARNING(-Wmicrosoft-include)
117 #else
118 #define SIMDUTF_DISABLE_UNDESIRED_WARNINGS
119 #endif
120 #define SIMDUTF_DISABLE_DEPRECATED_WARNING \
121 SIMDUTF_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
122 #define SIMDUTF_DISABLE_STRICT_OVERFLOW_WARNING \
123 SIMDUTF_DISABLE_GCC_WARNING(-Wstrict-overflow)
124 #define SIMDUTF_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")
125 #define SIMDUTF_DISABLE_UNUSED_WARNING \
126 SIMDUTF_PUSH_DISABLE_WARNINGS \
127 SIMDUTF_DISABLE_GCC_WARNING(-Wunused-function) \
128 SIMDUTF_DISABLE_GCC_WARNING(-Wunused-const-variable)
129 // clang-format on
130
131#endif // MSC_VER
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
143 /**
144 * Windows users need to do some extra work when building
145 * or using a dynamic library (DLL). When building, we need
146 * to set SIMDUTF_DLLIMPORTEXPORT to __declspec(dllexport).
147 * When *using* the DLL, the user needs to set
148 * SIMDUTF_DLLIMPORTEXPORT __declspec(dllimport).
149 *
150 * Static libraries not need require such work.
151 *
152 * It does not matter here whether you are using
153 * the regular visual studio or clang under visual
154 * studio, you still need to handle these issues.
155 *
156 * Non-Windows systems do not have this complexity.
157 */
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