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