1 #ifndef SIMDJSON_COMMON_DEFS_H
2 #define SIMDJSON_COMMON_DEFS_H
5 #include "simdjson/compiler_check.h"
6 #include "simdjson/portability.h"
15 char *to_chars(
char *first,
const char *last,
double value);
21 double from_chars(
const char *first) noexcept;
22 double from_chars(
const char *first,
const char* end) noexcept;
25 #ifndef SIMDJSON_EXCEPTIONS
27 #define SIMDJSON_EXCEPTIONS 1
29 #define SIMDJSON_EXCEPTIONS 0
37 #define SIMDJSON_BEGIN_DEBUG_BLOCK(name) __asm volatile("# LLVM-MCA-BEGIN " #name);
38 #define SIMDJSON_END_DEBUG_BLOCK(name) __asm volatile("# LLVM-MCA-END " #name);
39 #define SIMDJSON_DEBUG_BLOCK(name, block) BEGIN_DEBUG_BLOCK(name); block; END_DEBUG_BLOCK(name);
41 #define SIMDJSON_BEGIN_DEBUG_BLOCK(name)
42 #define SIMDJSON_END_DEBUG_BLOCK(name)
43 #define SIMDJSON_DEBUG_BLOCK(name, block)
47 #define SIMDJSON_ROUNDUP_N(a, n) (((a) + ((n)-1)) & ~((n)-1))
48 #define SIMDJSON_ROUNDDOWN_N(a, n) ((a) & ~((n)-1))
50 #define SIMDJSON_ISALIGNED_N(ptr, n) (((uintptr_t)(ptr) & ((n)-1)) == 0)
52 #if SIMDJSON_REGULAR_VISUAL_STUDIO
54 #define simdjson_really_inline __forceinline
55 #define simdjson_never_inline __declspec(noinline)
57 #define simdjson_unused
58 #define simdjson_warn_unused
60 #ifndef simdjson_likely
61 #define simdjson_likely(x) x
63 #ifndef simdjson_unlikely
64 #define simdjson_unlikely(x) x
67 #define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push ))
68 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
69 #define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
73 #if __has_include(<CppCoreCheck\Warnings.h>)
74 #include <CppCoreCheck\Warnings.h>
75 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
79 #ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
80 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
83 #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
84 #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
85 #define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
87 #define SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS
88 #define SIMDJSON_POP_DISABLE_UNUSED_WARNINGS
92 #define simdjson_really_inline inline __attribute__((always_inline))
93 #define simdjson_never_inline inline __attribute__((noinline))
95 #define simdjson_unused __attribute__((unused))
96 #define simdjson_warn_unused __attribute__((warn_unused_result))
98 #ifndef simdjson_likely
99 #define simdjson_likely(x) __builtin_expect(!!(x), 1)
101 #ifndef simdjson_unlikely
102 #define simdjson_unlikely(x) __builtin_expect(!!(x), 0)
105 #define SIMDJSON_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
110 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
111 SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
112 SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
113 SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
114 SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
115 SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
116 SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
117 SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
118 SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
119 SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
120 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
121 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable)
123 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
124 SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
125 SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
126 SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
127 SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
128 SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
129 SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
130 SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
131 SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
132 SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
133 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
134 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable) \
135 SIMDJSON_DISABLE_GCC_WARNING(-Wmaybe-uninitialized) \
136 SIMDJSON_DISABLE_GCC_WARNING(-Wformat-security)
139 #define SIMDJSON_PRAGMA(P) _Pragma(#P)
140 #define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
141 #if SIMDJSON_CLANG_VISUAL_STUDIO
142 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
144 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
146 #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
147 #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wstrict-overflow)
148 #define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")
150 #define SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
151 SIMDJSON_DISABLE_GCC_WARNING(-Wunused)
152 #define SIMDJSON_POP_DISABLE_UNUSED_WARNINGS SIMDJSON_POP_DISABLE_WARNINGS
158 #if defined(simdjson_inline)
160 #elif defined(__GNUC__) && !defined(__OPTIMIZE__)
164 #define simdjson_inline inline
167 #define simdjson_inline simdjson_really_inline
170 #if SIMDJSON_VISUAL_STUDIO
186 #if SIMDJSON_BUILDING_WINDOWS_DYNAMIC_LIBRARY
190 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllexport)
191 #elif SIMDJSON_USING_WINDOWS_DYNAMIC_LIBRARY
193 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllimport)
196 #define SIMDJSON_DLLIMPORTEXPORT
203 #if SIMDJSON_USING_LIBRARY
204 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllimport)
210 #define SIMDJSON_DLLIMPORTEXPORT
214 #if SIMDJSON_CPLUSPLUS17
215 #define SIMDJSON_HAS_STRING_VIEW
216 #include <string_view>
223 #ifdef __cpp_lib_string_view
224 #define SIMDJSON_HAS_STRING_VIEW
231 #ifndef SIMDJSON_HAS_STRING_VIEW
232 #if defined __has_include
234 #if __has_include (<string_view>)
236 #include <string_view>
237 #if defined(_LIBCPP_STRING_VIEW)
241 #define SIMDJSON_HAS_STRING_VIEW
254 #ifndef SIMDJSON_HAS_STRING_VIEW
255 SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
256 #include "simdjson/nonstd/string_view.hpp"
257 SIMDJSON_POP_DISABLE_WARNINGS
260 using string_view = nonstd::string_view;
263 #undef SIMDJSON_HAS_STRING_VIEW
266 #define SIMDJSON_TRY(EXPR) { auto _err = (EXPR); if (_err) { return _err; } }
278 #ifndef SIMDJSON_DEVELOPMENT_CHECKS
282 #define SIMDJSON_DEVELOPMENT_CHECKS 1
288 #define SIMDJSON_DEVELOPMENT_CHECKS 1
296 #if SIMDJSON_CPLUSPLUS17
298 # define simdjson_fallthrough [[fallthrough]]
300 #elif defined(__has_attribute)
302 #if __has_attribute(__fallthrough__)
304 # define simdjson_fallthrough __attribute__((__fallthrough__))
308 #ifndef simdjson_fallthrough
309 # define simdjson_fallthrough do {} while (0)
312 #if SIMDJSON_DEVELOPMENT_CHECKS
313 #define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { assert ((expr)); } while (0)
315 #define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { } while (0)
318 #ifndef SIMDJSON_UTF8VALIDATION
319 #define SIMDJSON_UTF8VALIDATION 1
325 #if __has_include(<avx512vbmi2intrin.h>)
326 #define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
334 #define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
339 #ifndef SIMDJSON_AVX512_ALLOWED
340 #define SIMDJSON_AVX512_ALLOWED 1
The top level simdjson namespace, containing everything the library provides.