1#ifndef SIMDJSON_COMMON_DEFS_H
2#define SIMDJSON_COMMON_DEFS_H
5#include "simdjson/compiler_check.h"
6#include "simdjson/portability.h"
15char *to_chars(
char *first,
const char *last,
double value);
21double from_chars(
const char *first)
noexcept;
22double from_chars(
const char *first,
const char* end)
noexcept;
25#ifndef SIMDJSON_EXCEPTIONS
26#if defined(__cpp_exceptions) || defined(_CPPUNWIND)
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
203 #define SIMDJSON_DLLIMPORTEXPORT
207#if SIMDJSON_CPLUSPLUS17
208#define SIMDJSON_HAS_STRING_VIEW
209#include <string_view>
216#ifdef __cpp_lib_string_view
217#define SIMDJSON_HAS_STRING_VIEW
218#include <string_view>
226#ifndef SIMDJSON_HAS_STRING_VIEW
227#if defined __has_include
229#if __has_include (<string_view>)
231#include <string_view>
232#if defined(_LIBCPP_STRING_VIEW)
236#define SIMDJSON_HAS_STRING_VIEW
250#ifndef SIMDJSON_HAS_STRING_VIEW
251SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
252#include "simdjson/nonstd/string_view.hpp"
253SIMDJSON_POP_DISABLE_WARNINGS
256 using string_view = nonstd::string_view;
259#undef SIMDJSON_HAS_STRING_VIEW
262#define SIMDJSON_TRY(EXPR) { auto _err = (EXPR); if (_err) { return _err; } }
279#ifndef SIMDJSON_DEVELOPMENT_CHECKS
284#if defined(_DEBUG) && !defined(NDEBUG)
285#define SIMDJSON_DEVELOPMENT_CHECKS 1
292#if !defined(__OPTIMIZE__) && !defined(NDEBUG)
293#define SIMDJSON_DEVELOPMENT_CHECKS 1
301#if SIMDJSON_CPLUSPLUS17
303# define simdjson_fallthrough [[fallthrough]]
305#elif defined(__has_attribute)
307#if __has_attribute(__fallthrough__)
309# define simdjson_fallthrough __attribute__((__fallthrough__))
313#ifndef simdjson_fallthrough
314# define simdjson_fallthrough do {} while (0)
317#if SIMDJSON_DEVELOPMENT_CHECKS
318#define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { assert ((expr)); } while (0)
320#define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { } while (0)
323#ifndef SIMDJSON_UTF8VALIDATION
324#define SIMDJSON_UTF8VALIDATION 1
330#if __has_include(<avx512vbmi2intrin.h>)
331#define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
339#define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
344#ifndef SIMDJSON_AVX512_ALLOWED
345#define SIMDJSON_AVX512_ALLOWED 1
349#ifndef __has_cpp_attribute
350#define simdjson_lifetime_bound
351#elif __has_cpp_attribute(msvc::lifetimebound)
352#define simdjson_lifetime_bound [[msvc::lifetimebound]]
353#elif __has_cpp_attribute(clang::lifetimebound)
354#define simdjson_lifetime_bound [[clang::lifetimebound]]
355#elif __has_cpp_attribute(lifetimebound)
356#define simdjson_lifetime_bound [[lifetimebound]]
358#define simdjson_lifetime_bound
The top level simdjson namespace, containing everything the library provides.