1#ifndef SIMDJSON_COMMON_DEFS_H
2#define SIMDJSON_COMMON_DEFS_H
5#include "simdjson/compiler_check.h"
6#include "simdjson/portability.h"
26enum :
size_t { to_chars_buffer_size = 40 };
37char *to_chars(
char *first,
const char *last,
double value);
43double from_chars(
const char *first)
noexcept;
44double from_chars(
const char *first,
const char* end)
noexcept;
50float from_chars_float(
const char *first)
noexcept;
53#ifndef SIMDJSON_EXCEPTIONS
54#if defined(__cpp_exceptions) || defined(_CPPUNWIND)
55#define SIMDJSON_EXCEPTIONS 1
57#define SIMDJSON_EXCEPTIONS 0
61#ifndef SIMDJSON_ENABLE_NAN_INF
62#define SIMDJSON_ENABLE_NAN_INF 0
69 #define SIMDJSON_BEGIN_DEBUG_BLOCK(name) __asm volatile("# LLVM-MCA-BEGIN " #name);
70 #define SIMDJSON_END_DEBUG_BLOCK(name) __asm volatile("# LLVM-MCA-END " #name);
71 #define SIMDJSON_DEBUG_BLOCK(name, block) BEGIN_DEBUG_BLOCK(name); block; END_DEBUG_BLOCK(name);
73 #define SIMDJSON_BEGIN_DEBUG_BLOCK(name)
74 #define SIMDJSON_END_DEBUG_BLOCK(name)
75 #define SIMDJSON_DEBUG_BLOCK(name, block)
79#define SIMDJSON_ROUNDUP_N(a, n) (((a) + ((n)-1)) & ~((n)-1))
81#if SIMDJSON_REGULAR_VISUAL_STUDIO
83 #define simdjson_deprecated __declspec(deprecated)
85 #define simdjson_really_inline __forceinline
86 #define simdjson_never_inline inline __declspec(noinline)
87 #define simdjson_really_flatten [[msvc::flatten]]
89 #define simdjson_unused
90 #define simdjson_warn_unused
92 #ifndef simdjson_likely
93 #define simdjson_likely(x) x
95 #ifndef simdjson_unlikely
96 #define simdjson_unlikely(x) x
99 #define SIMDJSON_PUSH_DISABLE_WARNINGS __pragma(warning( push ))
100 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS __pragma(warning( push, 0 ))
101 #define SIMDJSON_DISABLE_VS_WARNING(WARNING_NUMBER) __pragma(warning( disable : WARNING_NUMBER ))
105 #if __has_include(<CppCoreCheck\Warnings.h>)
106 #include <CppCoreCheck\Warnings.h>
107 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_VS_WARNING(ALL_CPPCORECHECK_WARNINGS)
111 #ifndef SIMDJSON_DISABLE_UNDESIRED_WARNINGS
112 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
115 #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_VS_WARNING(4996)
116 #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING
117 #define SIMDJSON_POP_DISABLE_WARNINGS __pragma(warning( pop ))
119 #define SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS
120 #define SIMDJSON_POP_DISABLE_UNUSED_WARNINGS
124 #define simdjson_deprecated __attribute__((deprecated))
126 #define simdjson_really_inline inline __attribute__((always_inline))
127 #define simdjson_never_inline inline __attribute__((noinline))
128 #define simdjson_really_flatten [[gnu::flatten]]
130 #define simdjson_unused __attribute__((unused))
131 #define simdjson_warn_unused __attribute__((warn_unused_result))
133 #ifndef simdjson_likely
134 #define simdjson_likely(x) __builtin_expect(!!(x), 1)
136 #ifndef simdjson_unlikely
137 #define simdjson_unlikely(x) __builtin_expect(!!(x), 0)
140 #define SIMDJSON_PUSH_DISABLE_WARNINGS _Pragma("GCC diagnostic push")
145 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
146 SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
147 SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
148 SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
149 SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
150 SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
151 SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
152 SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
153 SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
154 SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
155 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
156 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable)
158 #define SIMDJSON_PUSH_DISABLE_ALL_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
159 SIMDJSON_DISABLE_GCC_WARNING(-Weffc++) \
160 SIMDJSON_DISABLE_GCC_WARNING(-Wall) \
161 SIMDJSON_DISABLE_GCC_WARNING(-Wconversion) \
162 SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
163 SIMDJSON_DISABLE_GCC_WARNING(-Wattributes) \
164 SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \
165 SIMDJSON_DISABLE_GCC_WARNING(-Wnon-virtual-dtor) \
166 SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) \
167 SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
168 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
169 SIMDJSON_DISABLE_GCC_WARNING(-Wunused-variable) \
170 SIMDJSON_DISABLE_GCC_WARNING(-Wmaybe-uninitialized) \
171 SIMDJSON_DISABLE_GCC_WARNING(-Wformat-security)
174 #define SIMDJSON_PRAGMA(P) _Pragma(#P)
175 #define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
176 #if SIMDJSON_CLANG_VISUAL_STUDIO
177 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS SIMDJSON_DISABLE_GCC_WARNING(-Wmicrosoft-include)
179 #define SIMDJSON_DISABLE_UNDESIRED_WARNINGS
181 #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
182 #define SIMDJSON_DISABLE_STRICT_OVERFLOW_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wstrict-overflow)
183 #define SIMDJSON_POP_DISABLE_WARNINGS _Pragma("GCC diagnostic pop")
185 #define SIMDJSON_PUSH_DISABLE_UNUSED_WARNINGS SIMDJSON_PUSH_DISABLE_WARNINGS \
186 SIMDJSON_DISABLE_GCC_WARNING(-Wunused)
187 #define SIMDJSON_POP_DISABLE_UNUSED_WARNINGS SIMDJSON_POP_DISABLE_WARNINGS
193#if defined(simdjson_inline)
195#elif defined(__GNUC__) && !defined(__OPTIMIZE__)
199 #define simdjson_inline inline
202 #define simdjson_inline simdjson_really_inline
205#if defined(simdjson_flatten)
207#elif (defined(__GNUC__) && !defined(__OPTIMIZE__)) || (defined(_DEBUG) && _MSC_VER )
209 #define simdjson_flatten
211 #define simdjson_flatten simdjson_really_flatten
214#if SIMDJSON_VISUAL_STUDIO
230 #if SIMDJSON_BUILDING_WINDOWS_DYNAMIC_LIBRARY
234 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllexport)
235 #elif SIMDJSON_USING_WINDOWS_DYNAMIC_LIBRARY
237 #define SIMDJSON_DLLIMPORTEXPORT __declspec(dllimport)
240 #define SIMDJSON_DLLIMPORTEXPORT
243 #define SIMDJSON_DLLIMPORTEXPORT
247#if SIMDJSON_CPLUSPLUS17
248#define SIMDJSON_HAS_STRING_VIEW
249#include <string_view>
256#ifdef __cpp_lib_string_view
257#define SIMDJSON_HAS_STRING_VIEW
258#include <string_view>
266#ifndef SIMDJSON_HAS_STRING_VIEW
267#if defined __has_include
269#if __has_include (<string_view>)
271#include <string_view>
272#if defined(_LIBCPP_STRING_VIEW)
276#define SIMDJSON_HAS_STRING_VIEW
290#ifndef SIMDJSON_HAS_STRING_VIEW
291SIMDJSON_PUSH_DISABLE_ALL_WARNINGS
292#include "simdjson/nonstd/string_view.hpp"
293SIMDJSON_POP_DISABLE_WARNINGS
296 using string_view = nonstd::string_view;
299#undef SIMDJSON_HAS_STRING_VIEW
302#define SIMDJSON_TRY(EXPR) { auto _err = (EXPR); if (_err) { return _err; } }
319#ifndef SIMDJSON_DEVELOPMENT_CHECKS
324#if defined(_DEBUG) && !defined(NDEBUG)
325#define SIMDJSON_DEVELOPMENT_CHECKS 1
334#if ((!defined(__OPTIMIZE__) || defined(_DEBUG)) && !defined(NDEBUG))
335#define SIMDJSON_DEVELOPMENT_CHECKS 1
343#if SIMDJSON_CPLUSPLUS17
345# define simdjson_fallthrough [[fallthrough]]
347#elif defined(__has_attribute)
349#if __has_attribute(__fallthrough__)
351# define simdjson_fallthrough __attribute__((__fallthrough__))
355#ifndef simdjson_fallthrough
356# define simdjson_fallthrough do {} while (0)
359#if SIMDJSON_DEVELOPMENT_CHECKS
360#define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { assert ((expr)); } while (0)
362#define SIMDJSON_DEVELOPMENT_ASSERT(expr) do { } while (0)
365#ifndef SIMDJSON_UTF8VALIDATION
366#define SIMDJSON_UTF8VALIDATION 1
372#if __has_include(<avx512vbmi2intrin.h>)
373#define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
381#define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
386#ifndef SIMDJSON_AVX512_ALLOWED
387#define SIMDJSON_AVX512_ALLOWED 1
391#ifndef __has_cpp_attribute
392#define simdjson_lifetime_bound
393#elif __has_cpp_attribute(msvc::lifetimebound)
394#define simdjson_lifetime_bound [[msvc::lifetimebound]]
395#elif __has_cpp_attribute(clang::lifetimebound)
396#define simdjson_lifetime_bound [[clang::lifetimebound]]
397#elif __has_cpp_attribute(lifetimebound)
398#define simdjson_lifetime_bound [[lifetimebound]]
400#define simdjson_lifetime_bound
The top level simdjson namespace, containing everything the library provides.