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_deprecated __declspec(deprecated)
56 #define simdjson_really_inline __forceinline
57 #define simdjson_never_inline __declspec(noinline)
59 #define simdjson_unused
60 #define simdjson_warn_unused
62 #ifndef simdjson_likely
63 #define simdjson_likely(x) x
65 #ifndef simdjson_unlikely
66 #define simdjson_unlikely(x) x
69 #define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push ))
70 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
71 #define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
75 #if __has_include(<CppCoreCheck\Warnings.h>)
76 #include <CppCoreCheck\Warnings.h>
77 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
81 #ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
82 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
85 #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
86 #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
87 #define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
89 #define SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS
90 #define SIMDJSON_POP_DISABLE_UNUSED_WARNINGS
94 #define simdjson_deprecated __attribute__((deprecated))
96 #define simdjson_really_inline inline __attribute__((always_inline))
97 #define simdjson_never_inline inline __attribute__((noinline))
99 #define simdjson_unused __attribute__((unused))
100 #define simdjson_warn_unused __attribute__((warn_unused_result))
102 #ifndef simdjson_likely
103 #define simdjson_likely(x) __builtin_expect(!!(x), 1)
105 #ifndef simdjson_unlikely
106 #define simdjson_unlikely(x) __builtin_expect(!!(x), 0)
109 #define SIMDJSON_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
114 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
115 SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
116 SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
117 SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
118 SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
119 SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
120 SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
121 SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
122 SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
123 SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
124 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
125 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable)
127 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
128 SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
129 SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
130 SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
131 SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
132 SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
133 SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
134 SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
135 SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
136 SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
137 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
138 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable) \
139 SIMDJSON_DISABLE_GCC_WARNING(-Wmaybe-uninitialized) \
140 SIMDJSON_DISABLE_GCC_WARNING(-Wformat-security)
143 #define SIMDJSON_PRAGMA(P) _Pragma(#P)
144 #define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
145 #if SIMDJSON_CLANG_VISUAL_STUDIO
146 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
148 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
150 #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
151 #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wstrict-overflow)
152 #define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")
154 #define SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
155 SIMDJSON_DISABLE_GCC_WARNING(-Wunused)
156 #define SIMDJSON_POP_DISABLE_UNUSED_WARNINGS SIMDJSON_POP_DISABLE_WARNINGS
162 #if defined(simdjson_inline)
164 #elif defined(__GNUC__) && !defined(__OPTIMIZE__)
168 #define simdjson_inline inline
171 #define simdjson_inline simdjson_really_inline
174 #if SIMDJSON_VISUAL_STUDIO
190 #if SIMDJSON_BUILDING_WINDOWS_DYNAMIC_LIBRARY
194 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllexport)
195 #elif SIMDJSON_USING_WINDOWS_DYNAMIC_LIBRARY
197 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllimport)
200 #define SIMDJSON_DLLIMPORTEXPORT
207 #if SIMDJSON_USING_LIBRARY
208 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllimport)
214 #define SIMDJSON_DLLIMPORTEXPORT
218 #if SIMDJSON_CPLUSPLUS17
219 #define SIMDJSON_HAS_STRING_VIEW
220 #include <string_view>
227 #ifdef __cpp_lib_string_view
228 #define SIMDJSON_HAS_STRING_VIEW
235 #ifndef SIMDJSON_HAS_STRING_VIEW
236 #if defined __has_include
238 #if __has_include (<string_view>)
240 #include <string_view>
241 #if defined(_LIBCPP_STRING_VIEW)
245 #define SIMDJSON_HAS_STRING_VIEW
258 #ifndef SIMDJSON_HAS_STRING_VIEW
259 SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
260 #include "simdjson/nonstd/string_view.hpp"
261 SIMDJSON_POP_DISABLE_WARNINGS
264 using string_view = nonstd::string_view;
267 #undef SIMDJSON_HAS_STRING_VIEW
270 #define SIMDJSON_TRY(EXPR) { auto _err = (EXPR); if (_err) { return _err; } }
282 #ifndef SIMDJSON_DEVELOPMENT_CHECKS
286 #define SIMDJSON_DEVELOPMENT_CHECKS 1
292 #define SIMDJSON_DEVELOPMENT_CHECKS 1
300 #if SIMDJSON_CPLUSPLUS17
302 # define simdjson_fallthrough [[fallthrough]]
304 #elif defined(__has_attribute)
306 #if __has_attribute(__fallthrough__)
308 # define simdjson_fallthrough __attribute__((__fallthrough__))
312 #ifndef simdjson_fallthrough
313 # define simdjson_fallthrough do {} while (0)
316 #if SIMDJSON_DEVELOPMENT_CHECKS
317 #define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { assert ((expr)); } while (0)
319 #define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { } while (0)
322 #ifndef SIMDJSON_UTF8VALIDATION
323 #define SIMDJSON_UTF8VALIDATION 1
329 #if __has_include(<avx512vbmi2intrin.h>)
330 #define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
338 #define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
343 #ifndef SIMDJSON_AVX512_ALLOWED
344 #define SIMDJSON_AVX512_ALLOWED 1
The top level simdjson namespace, containing everything the library provides.