diff --git a/include/simdjson.h b/include/simdjson.h index 2aa311ed..63e90c9a 100644 --- a/include/simdjson.h +++ b/include/simdjson.h @@ -34,30 +34,7 @@ } */ -#include "simdjson/compiler_check.h" -#include "simdjson/common_defs.h" - -SIMDJSON_PUSH_DISABLE_WARNINGS -SIMDJSON_DISABLE_UNDESIRED_WARNINGS - -// Public API -#include "simdjson/simdjson_version.h" -#include "simdjson/error.h" -#include "simdjson/minify.h" -#include "simdjson/padded_string.h" -#include "simdjson/padded_string_view.h" -#include "simdjson/implementation.h" - -// Inline functions -#include "simdjson/error-inl.h" -#include "simdjson/padded_string-inl.h" -#include "simdjson/padded_string_view-inl.h" - -// DOM #include "simdjson/dom.h" -// Implementations -#include "simdjson/implementations.h" - -SIMDJSON_POP_DISABLE_WARNINGS +#include "simdjson/builtin.h" #endif // SIMDJSON_H diff --git a/include/simdjson/arm64.h b/include/simdjson/arm64.h index 907dd972..81ad9e85 100644 --- a/include/simdjson/arm64.h +++ b/include/simdjson/arm64.h @@ -1,22 +1,7 @@ #ifndef SIMDJSON_ARM64_H #define SIMDJSON_ARM64_H -#ifdef SIMDJSON_FALLBACK_H -#error "arm64.h must be included before fallback.h" -#endif - -#include "simdjson/portability.h" - -#ifndef SIMDJSON_IMPLEMENTATION_ARM64 -#define SIMDJSON_IMPLEMENTATION_ARM64 (SIMDJSON_IS_ARM64) -#endif -#define SIMDJSON_CAN_ALWAYS_RUN_ARM64 SIMDJSON_IMPLEMENTATION_ARM64 && SIMDJSON_IS_ARM64 - - -#include "simdjson/internal/isadetection.h" -#include "simdjson/internal/jsoncharutils_tables.h" -#include "simdjson/internal/numberparsing_tables.h" -#include "simdjson/internal/simdprune_tables.h" +#include "simdjson/implementation-base.h" #if SIMDJSON_IMPLEMENTATION_ARM64 @@ -42,12 +27,6 @@ namespace arm64 { #include "simdjson/generic/atomparsing.h" #include "simdjson/arm64/stringparsing.h" #include "simdjson/arm64/numberparsing.h" -#include "simdjson/generic/implementation_simdjson_result_base.h" -#include "simdjson/generic/ondemand.h" - -// Inline definitions -#include "simdjson/generic/implementation_simdjson_result_base-inl.h" -#include "simdjson/generic/ondemand-inl.h" #include "simdjson/arm64/end.h" #endif // SIMDJSON_IMPLEMENTATION_ARM64 diff --git a/include/simdjson/arm64/implementation.h b/include/simdjson/arm64/implementation.h index 2e498ff4..7214011a 100644 --- a/include/simdjson/arm64/implementation.h +++ b/include/simdjson/arm64/implementation.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_ARM64_IMPLEMENTATION_H #define SIMDJSON_ARM64_IMPLEMENTATION_H -#include "simdjson.h" +#include "simdjson/base.h" #include "simdjson/internal/isadetection.h" namespace simdjson { diff --git a/include/simdjson/arm64/intrinsics.h b/include/simdjson/arm64/intrinsics.h index ceebaf24..6f6ac4e2 100644 --- a/include/simdjson/arm64/intrinsics.h +++ b/include/simdjson/arm64/intrinsics.h @@ -1,8 +1,6 @@ #ifndef SIMDJSON_ARM64_INTRINSICS_H #define SIMDJSON_ARM64_INTRINSICS_H -#include "simdjson.h" - // This should be the correct header whether // you use visual studio or other compilers. #include diff --git a/include/simdjson/arm64/simd.h b/include/simdjson/arm64/simd.h index 64a3a7e1..81764cf9 100644 --- a/include/simdjson/arm64/simd.h +++ b/include/simdjson/arm64/simd.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_ARM64_SIMD_H #define SIMDJSON_ARM64_SIMD_H -#include "simdjson.h" +#include "simdjson/base.h" #include "simdjson/internal/simdprune_tables.h" #include "simdjson/arm64/bitmanipulation.h" #include diff --git a/include/simdjson/arm64/stringparsing.h b/include/simdjson/arm64/stringparsing.h index e1c3b4d9..08c65487 100644 --- a/include/simdjson/arm64/stringparsing.h +++ b/include/simdjson/arm64/stringparsing.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_ARM64_STRINGPARSING_H #define SIMDJSON_ARM64_STRINGPARSING_H -#include "simdjson.h" +#include "simdjson/base.h" #include "simdjson/arm64/simd.h" #include "simdjson/arm64/bitmanipulation.h" diff --git a/include/simdjson/base.h b/include/simdjson/base.h new file mode 100644 index 00000000..c142f4a3 --- /dev/null +++ b/include/simdjson/base.h @@ -0,0 +1,26 @@ +#ifndef SIMDJSON_BASE_H +#define SIMDJSON_BASE_H + +#include "simdjson/compiler_check.h" +#include "simdjson/common_defs.h" +#include "simdjson/portability.h" + +SIMDJSON_PUSH_DISABLE_WARNINGS +SIMDJSON_DISABLE_UNDESIRED_WARNINGS + +// Public API +#include "simdjson/simdjson_version.h" +#include "simdjson/error.h" +#include "simdjson/minify.h" +#include "simdjson/padded_string.h" +#include "simdjson/padded_string_view.h" +#include "simdjson/implementation.h" + +// Inline functions +#include "simdjson/error-inl.h" +#include "simdjson/padded_string-inl.h" +#include "simdjson/padded_string_view-inl.h" + +SIMDJSON_POP_DISABLE_WARNINGS + +#endif // SIMDJSON_BASE_H \ No newline at end of file diff --git a/include/simdjson/builtin.h b/include/simdjson/builtin.h index 9353d90c..2e0e1456 100644 --- a/include/simdjson/builtin.h +++ b/include/simdjson/builtin.h @@ -1,8 +1,9 @@ #ifndef SIMDJSON_BUILTIN_H #define SIMDJSON_BUILTIN_H -#include "simdjson/portability.h" +#include "simdjson/implementations.h" +// Determine the best builtin implementation #ifndef SIMDJSON_BUILTIN_IMPLEMENTATION #if SIMDJSON_CAN_ALWAYS_RUN_HASWELL #define SIMDJSON_BUILTIN_IMPLEMENTATION haswell @@ -19,6 +20,20 @@ #endif #endif // SIMDJSON_BUILTIN_IMPLEMENTATION +#define SIMDJSON_IMPLEMENTATION SIMDJSON_BUILTIN_IMPLEMENTATION + +// ondemand is only compiled as part of the builtin implementation at present + +// Interface declarations +#include "simdjson/generic/implementation_simdjson_result_base.h" +#include "simdjson/generic/ondemand.h" + +// Inline definitions +#include "simdjson/generic/implementation_simdjson_result_base-inl.h" +#include "simdjson/generic/ondemand-inl.h" + +#undef SIMDJSON_IMPLEMENTATION + namespace simdjson { /** * Represents the best statically linked simdjson implementation that can be used by the compiling @@ -32,7 +47,7 @@ namespace simdjson { */ namespace builtin = SIMDJSON_BUILTIN_IMPLEMENTATION; /** - * @overload simdjson::SIMDJSON_BUILTIN_IMPLEMENTATION::ondemand + * @copydoc simdjson::SIMDJSON_BUILTIN_IMPLEMENTATION::ondemand */ namespace ondemand = SIMDJSON_BUILTIN_IMPLEMENTATION::ondemand; /** diff --git a/include/simdjson/dom.h b/include/simdjson/dom.h index eba36013..b23745c5 100644 --- a/include/simdjson/dom.h +++ b/include/simdjson/dom.h @@ -1,6 +1,11 @@ #ifndef SIMDJSON_DOM_H #define SIMDJSON_DOM_H +#include "simdjson/base.h" + +SIMDJSON_PUSH_DISABLE_WARNINGS +SIMDJSON_DISABLE_UNDESIRED_WARNINGS + #include "simdjson/dom/array.h" #include "simdjson/dom/document_stream.h" #include "simdjson/dom/document.h" @@ -25,4 +30,6 @@ #include "simdjson/internal/tape_ref-inl.h" #include "simdjson/dom/serialization-inl.h" +SIMDJSON_POP_DISABLE_WARNINGS + #endif // SIMDJSON_DOM_H diff --git a/include/simdjson/fallback.h b/include/simdjson/fallback.h index bea92154..26a01c0d 100644 --- a/include/simdjson/fallback.h +++ b/include/simdjson/fallback.h @@ -1,13 +1,7 @@ #ifndef SIMDJSON_FALLBACK_H #define SIMDJSON_FALLBACK_H -#include "simdjson/portability.h" - -// Default Fallback to on unless a builtin implementation has already been selected. -#ifndef SIMDJSON_IMPLEMENTATION_FALLBACK -#define SIMDJSON_IMPLEMENTATION_FALLBACK 1 // (!SIMDJSON_CAN_ALWAYS_RUN_ARM64 && !SIMDJSON_CAN_ALWAYS_RUN_HASWELL && !SIMDJSON_CAN_ALWAYS_RUN_WESTMERE && !SIMDJSON_CAN_ALWAYS_RUN_PPC64) -#endif -#define SIMDJSON_CAN_ALWAYS_RUN_FALLBACK SIMDJSON_IMPLEMENTATION_FALLBACK +#include "simdjson/implementation-base.h" #if SIMDJSON_IMPLEMENTATION_FALLBACK @@ -30,13 +24,6 @@ namespace fallback { #include "simdjson/generic/atomparsing.h" #include "simdjson/fallback/stringparsing.h" #include "simdjson/fallback/numberparsing.h" -#include "simdjson/generic/implementation_simdjson_result_base.h" -#include "simdjson/generic/ondemand.h" - -// Inline definitions -#include "simdjson/generic/implementation_simdjson_result_base-inl.h" -#include "simdjson/generic/ondemand-inl.h" - #include "simdjson/fallback/end.h" #endif // SIMDJSON_IMPLEMENTATION_FALLBACK diff --git a/include/simdjson/fallback/bitmanipulation.h b/include/simdjson/fallback/bitmanipulation.h index 59117ef8..c4dae452 100644 --- a/include/simdjson/fallback/bitmanipulation.h +++ b/include/simdjson/fallback/bitmanipulation.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_FALLBACK_BITMANIPULATION_H #define SIMDJSON_FALLBACK_BITMANIPULATION_H -#include "simdjson.h" +#include "simdjson/base.h" #include namespace simdjson { diff --git a/include/simdjson/fallback/stringparsing.h b/include/simdjson/fallback/stringparsing.h index 97f04fd3..8a0951ef 100644 --- a/include/simdjson/fallback/stringparsing.h +++ b/include/simdjson/fallback/stringparsing.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_FALLBACK_STRINGPARSING_H #define SIMDJSON_FALLBACK_STRINGPARSING_H -#include "simdjson.h" +#include "simdjson/base.h" namespace simdjson { namespace SIMDJSON_IMPLEMENTATION { diff --git a/include/simdjson/generic/dom_parser_implementation.h b/include/simdjson/generic/dom_parser_implementation.h index ab0672c6..6b8eea32 100644 --- a/include/simdjson/generic/dom_parser_implementation.h +++ b/include/simdjson/generic/dom_parser_implementation.h @@ -1,4 +1,4 @@ -#include "simdjson.h" +#include "simdjson/base.h" #include "simdjson/internal/isadetection.h" namespace simdjson { diff --git a/include/simdjson/haswell.h b/include/simdjson/haswell.h index cc93482d..48db97a0 100644 --- a/include/simdjson/haswell.h +++ b/include/simdjson/haswell.h @@ -1,27 +1,17 @@ #ifndef SIMDJSON_HASWELL_H #define SIMDJSON_HASWELL_H -#ifdef SIMDJSON_WESTMERE_H -#error "haswell.h must be included before westmere.h" -#endif -#ifdef SIMDJSON_FALLBACK_H -#error "haswell.h must be included before fallback.h" -#endif - -#include "simdjson/portability.h" - -// Default Haswell to on if this is x86-64. Even if we're not compiled for it, it could be selected -// at runtime. -#ifndef SIMDJSON_IMPLEMENTATION_HASWELL -#define SIMDJSON_IMPLEMENTATION_HASWELL (SIMDJSON_IS_X86_64) -#endif -// To see why (__BMI__) && (__PCLMUL__) && (__LZCNT__) are not part of this next line, see -// https://github.com/simdjson/simdjson/issues/1247 -#define SIMDJSON_CAN_ALWAYS_RUN_HASWELL ((SIMDJSON_IMPLEMENTATION_HASWELL) && (SIMDJSON_IS_X86_64) && (__AVX2__)) +#include "simdjson/implementation-base.h" #if SIMDJSON_IMPLEMENTATION_HASWELL +#if SIMDJSON_CAN_ALWAYS_RUN_HASWELL +#define SIMDJSON_TARGET_HASWELL +#define SIMDJSON_UNTARGET_HASWELL +#else #define SIMDJSON_TARGET_HASWELL SIMDJSON_TARGET_REGION("avx2,bmi,pclmul,lzcnt") +#define SIMDJSON_UNTARGET_HASWELL SIMDJSON_UNTARGET_REGION +#endif namespace simdjson { /** @@ -32,7 +22,7 @@ namespace haswell { } // namespace simdjson // -// These two need to be included outside SIMDJSON_TARGET_REGION +// These two need to be included outside SIMDJSON_TARGET_HASWELL // #include "simdjson/haswell/implementation.h" #include "simdjson/haswell/intrinsics.h" @@ -51,13 +41,6 @@ namespace haswell { #include "simdjson/generic/atomparsing.h" #include "simdjson/haswell/stringparsing.h" #include "simdjson/haswell/numberparsing.h" -#include "simdjson/generic/implementation_simdjson_result_base.h" -#include "simdjson/generic/ondemand.h" - -// Inline definitions -#include "simdjson/generic/implementation_simdjson_result_base-inl.h" -#include "simdjson/generic/ondemand-inl.h" - #include "simdjson/haswell/end.h" #endif // SIMDJSON_IMPLEMENTATION_HASWELL diff --git a/include/simdjson/haswell/end.h b/include/simdjson/haswell/end.h index e1e5634d..d90f3fdb 100644 --- a/include/simdjson/haswell/end.h +++ b/include/simdjson/haswell/end.h @@ -1,2 +1,2 @@ -SIMDJSON_UNTARGET_REGION +SIMDJSON_UNTARGET_HASWELL #undef SIMDJSON_IMPLEMENTATION diff --git a/include/simdjson/haswell/implementation.h b/include/simdjson/haswell/implementation.h index 90c28830..99b7c97e 100644 --- a/include/simdjson/haswell/implementation.h +++ b/include/simdjson/haswell/implementation.h @@ -3,7 +3,7 @@ #include "simdjson/implementation.h" -// The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION +// The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_HASWELL namespace simdjson { namespace haswell { diff --git a/include/simdjson/haswell/intrinsics.h b/include/simdjson/haswell/intrinsics.h index e118c2c7..80146123 100644 --- a/include/simdjson/haswell/intrinsics.h +++ b/include/simdjson/haswell/intrinsics.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_HASWELL_INTRINSICS_H #define SIMDJSON_HASWELL_INTRINSICS_H -#include "simdjson.h" +#include "simdjson/base.h" #ifdef SIMDJSON_VISUAL_STUDIO // under clang within visual studio, this will include @@ -45,7 +45,7 @@ SIMDJSON_TARGET_HASWELL static simdjson_really_inline uint64_t _blsr_u64(uint64_t n) { return (n - 1) & n; } -SIMDJSON_UNTARGET_REGION +SIMDJSON_UNTARGET_HASWELL #endif // _blsr_u64 #endif // SIMDJSON_CLANG_VISUAL_STUDIO diff --git a/include/simdjson/haswell/stringparsing.h b/include/simdjson/haswell/stringparsing.h index 0141c780..ec56bc59 100644 --- a/include/simdjson/haswell/stringparsing.h +++ b/include/simdjson/haswell/stringparsing.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_HASWELL_STRINGPARSING_H #define SIMDJSON_HASWELL_STRINGPARSING_H -#include "simdjson.h" +#include "simdjson/base.h" #include "simdjson/haswell/simd.h" #include "simdjson/haswell/bitmanipulation.h" diff --git a/include/simdjson/implementation-base.h b/include/simdjson/implementation-base.h new file mode 100644 index 00000000..3d560750 --- /dev/null +++ b/include/simdjson/implementation-base.h @@ -0,0 +1,22 @@ +#ifndef SIMDJSON_IMPLEMENTATION_BASE_H +#define SIMDJSON_IMPLEMENTATION_BASE_H + +/** + * @file + * + * Includes common stuff needed for implementations. + */ + +#include "simdjson/base.h" +#include "simdjson/implementation.h" + +// Implementation-internal files (must be included before the implementations themselves, to keep +// amalgamation working--otherwise, the first time a file is included, it might be put inside the +// #ifdef SIMDJSON_IMPLEMENTATION_ARM64/FALLBACK/etc., which means the other implementations can't +// compile unless that implementation is turned on). +#include "simdjson/internal/isadetection.h" +#include "simdjson/internal/jsoncharutils_tables.h" +#include "simdjson/internal/numberparsing_tables.h" +#include "simdjson/internal/simdprune_tables.h" + +#endif // SIMDJSON_IMPLEMENTATION_BASE_H \ No newline at end of file diff --git a/include/simdjson/implementations.h b/include/simdjson/implementations.h index 666262e4..5a1d8230 100644 --- a/include/simdjson/implementations.h +++ b/include/simdjson/implementations.h @@ -1,21 +1,57 @@ #ifndef SIMDJSON_IMPLEMENTATIONS_H #define SIMDJSON_IMPLEMENTATIONS_H -// Implementation-internal files (must be included before the implementations themselves, to keep -// amalgamation working--otherwise, the first time a file is included, it might be put inside the -// #ifdef SIMDJSON_IMPLEMENTATION_ARM64/FALLBACK/etc., which means the other implementations can't -// compile unless that implementation is turned on). -#include "simdjson/internal/isadetection.h" -#include "simdjson/internal/jsoncharutils_tables.h" -#include "simdjson/internal/numberparsing_tables.h" -#include "simdjson/internal/simdprune_tables.h" +#include "simdjson/implementation-base.h" + +// +// First, figure out which implementations can be run. Doing it here makes it so we don't have to worry about the order +// in which we include them. +// + +#ifndef SIMDJSON_IMPLEMENTATION_ARM64 +#define SIMDJSON_IMPLEMENTATION_ARM64 (SIMDJSON_IS_ARM64) +#endif +#define SIMDJSON_CAN_ALWAYS_RUN_ARM64 SIMDJSON_IMPLEMENTATION_ARM64 && SIMDJSON_IS_ARM64 + +// Default Haswell to on if this is x86-64. Even if we're not compiled for it, it could be selected +// at runtime. +#ifndef SIMDJSON_IMPLEMENTATION_HASWELL +#define SIMDJSON_IMPLEMENTATION_HASWELL (SIMDJSON_IS_X86_64) +#endif +// To see why (__BMI__) && (__PCLMUL__) && (__LZCNT__) are not part of this next line, see +// https://github.com/simdjson/simdjson/issues/1247 +#define SIMDJSON_CAN_ALWAYS_RUN_HASWELL ((SIMDJSON_IMPLEMENTATION_HASWELL) && (SIMDJSON_IS_X86_64) && (__AVX2__)) + +// Default Westmere to on if this is x86-64, unless we'll always select Haswell. +#ifndef SIMDJSON_IMPLEMENTATION_WESTMERE +#define SIMDJSON_IMPLEMENTATION_WESTMERE (SIMDJSON_IS_X86_64 && !SIMDJSON_REQUIRES_HASWELL) +#endif +#define SIMDJSON_CAN_ALWAYS_RUN_WESTMERE (SIMDJSON_IMPLEMENTATION_WESTMERE && SIMDJSON_IS_X86_64 && __SSE4_2__ && __PCLMUL__) + +#ifndef SIMDJSON_IMPLEMENTATION_PPC64 +#define SIMDJSON_IMPLEMENTATION_PPC64 (SIMDJSON_IS_PPC64) +#endif +#define SIMDJSON_CAN_ALWAYS_RUN_PPC64 SIMDJSON_IMPLEMENTATION_PPC64 && SIMDJSON_IS_PPC64 + +// Default Fallback to on unless a builtin implementation has already been selected. +#ifndef SIMDJSON_IMPLEMENTATION_FALLBACK +#define SIMDJSON_IMPLEMENTATION_FALLBACK 1 // (!SIMDJSON_CAN_ALWAYS_RUN_ARM64 && !SIMDJSON_CAN_ALWAYS_RUN_HASWELL && !SIMDJSON_CAN_ALWAYS_RUN_WESTMERE && !SIMDJSON_CAN_ALWAYS_RUN_PPC64) +#endif +#define SIMDJSON_CAN_ALWAYS_RUN_FALLBACK SIMDJSON_IMPLEMENTATION_FALLBACK + +SIMDJSON_PUSH_DISABLE_WARNINGS +SIMDJSON_DISABLE_UNDESIRED_WARNINGS // Implementations #include "simdjson/arm64.h" -#include "simdjson/haswell.h" -#include "simdjson/westmere.h" -#include "simdjson/ppc64.h" #include "simdjson/fallback.h" +#include "simdjson/haswell.h" +#include "simdjson/ppc64.h" +#include "simdjson/westmere.h" + +// Builtin implementation #include "simdjson/builtin.h" +SIMDJSON_POP_DISABLE_WARNINGS + #endif // SIMDJSON_IMPLEMENTATIONS_H \ No newline at end of file diff --git a/include/simdjson/internal/jsoncharutils_tables.h b/include/simdjson/internal/jsoncharutils_tables.h index a53551cc..bc412b86 100644 --- a/include/simdjson/internal/jsoncharutils_tables.h +++ b/include/simdjson/internal/jsoncharutils_tables.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_INTERNAL_JSONCHARUTILS_TABLES_H #define SIMDJSON_INTERNAL_JSONCHARUTILS_TABLES_H -#include "simdjson.h" +#include "simdjson/common_defs.h" #ifdef JSON_TEST_STRINGS void found_string(const uint8_t *buf, const uint8_t *parsed_begin, diff --git a/include/simdjson/internal/numberparsing_tables.h b/include/simdjson/internal/numberparsing_tables.h index 9f66b685..1762056f 100644 --- a/include/simdjson/internal/numberparsing_tables.h +++ b/include/simdjson/internal/numberparsing_tables.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_INTERNAL_NUMBERPARSING_TABLES_H #define SIMDJSON_INTERNAL_NUMBERPARSING_TABLES_H -#include "simdjson.h" +#include "simdjson/base.h" namespace simdjson { namespace internal { diff --git a/include/simdjson/ppc64.h b/include/simdjson/ppc64.h index 181cad21..363c2af9 100644 --- a/include/simdjson/ppc64.h +++ b/include/simdjson/ppc64.h @@ -1,22 +1,7 @@ #ifndef SIMDJSON_PPC64_H #define SIMDJSON_PPC64_H -#ifdef SIMDJSON_FALLBACK_H -#error "ppc64.h must be included before fallback.h" -#endif - -#include "simdjson/portability.h" - -#ifndef SIMDJSON_IMPLEMENTATION_PPC64 -#define SIMDJSON_IMPLEMENTATION_PPC64 (SIMDJSON_IS_PPC64) -#endif -#define SIMDJSON_CAN_ALWAYS_RUN_PPC64 SIMDJSON_IMPLEMENTATION_PPC64 && SIMDJSON_IS_PPC64 - - -#include "simdjson/internal/isadetection.h" -#include "simdjson/internal/jsoncharutils_tables.h" -#include "simdjson/internal/numberparsing_tables.h" -#include "simdjson/internal/simdprune_tables.h" +#include "simdjson/implementation-base.h" #if SIMDJSON_IMPLEMENTATION_PPC64 @@ -42,12 +27,6 @@ namespace ppc64 { #include "simdjson/generic/atomparsing.h" #include "simdjson/ppc64/stringparsing.h" #include "simdjson/ppc64/numberparsing.h" -#include "simdjson/generic/implementation_simdjson_result_base.h" -#include "simdjson/generic/ondemand.h" - -// Inline definitions -#include "simdjson/generic/implementation_simdjson_result_base-inl.h" -#include "simdjson/generic/ondemand-inl.h" #include "simdjson/ppc64/end.h" #endif // SIMDJSON_IMPLEMENTATION_PPC64 diff --git a/include/simdjson/ppc64/implementation.h b/include/simdjson/ppc64/implementation.h index 0620f3cc..77b0e830 100644 --- a/include/simdjson/ppc64/implementation.h +++ b/include/simdjson/ppc64/implementation.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_PPC64_IMPLEMENTATION_H #define SIMDJSON_PPC64_IMPLEMENTATION_H -#include "simdjson.h" +#include "simdjson/base.h" #include "simdjson/internal/isadetection.h" namespace simdjson { diff --git a/include/simdjson/ppc64/intrinsics.h b/include/simdjson/ppc64/intrinsics.h index ab86ed84..00dc79c1 100644 --- a/include/simdjson/ppc64/intrinsics.h +++ b/include/simdjson/ppc64/intrinsics.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_PPC64_INTRINSICS_H #define SIMDJSON_PPC64_INTRINSICS_H -#include "simdjson.h" +#include "simdjson/base.h" // This should be the correct header whether // you use visual studio or other compilers. diff --git a/include/simdjson/ppc64/simd.h b/include/simdjson/ppc64/simd.h index 6ebecf1e..47a7b9a3 100644 --- a/include/simdjson/ppc64/simd.h +++ b/include/simdjson/ppc64/simd.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_PPC64_SIMD_H #define SIMDJSON_PPC64_SIMD_H -#include "simdjson.h" +#include "simdjson/base.h" #include "simdjson/internal/simdprune_tables.h" #include "simdjson/ppc64/bitmanipulation.h" #include diff --git a/include/simdjson/ppc64/stringparsing.h b/include/simdjson/ppc64/stringparsing.h index ca78df50..6654d3ff 100644 --- a/include/simdjson/ppc64/stringparsing.h +++ b/include/simdjson/ppc64/stringparsing.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_PPC64_STRINGPARSING_H #define SIMDJSON_PPC64_STRINGPARSING_H -#include "simdjson.h" +#include "simdjson/base.h" #include "simdjson/ppc64/bitmanipulation.h" #include "simdjson/ppc64/simd.h" diff --git a/include/simdjson/westmere.h b/include/simdjson/westmere.h index 2f202c71..4419b012 100644 --- a/include/simdjson/westmere.h +++ b/include/simdjson/westmere.h @@ -1,21 +1,17 @@ #ifndef SIMDJSON_WESTMERE_H #define SIMDJSON_WESTMERE_H -#ifdef SIMDJSON_FALLBACK_H -#error "westmere.h must be included before fallback.h" -#endif - -#include "simdjson/portability.h" - -// Default Westmere to on if this is x86-64, unless we'll always select Haswell. -#ifndef SIMDJSON_IMPLEMENTATION_WESTMERE -#define SIMDJSON_IMPLEMENTATION_WESTMERE (SIMDJSON_IS_X86_64 && !SIMDJSON_REQUIRES_HASWELL) -#endif -#define SIMDJSON_CAN_ALWAYS_RUN_WESTMERE (SIMDJSON_IMPLEMENTATION_WESTMERE && SIMDJSON_IS_X86_64 && __SSE4_2__ && __PCLMUL__) +#include "simdjson/implementation-base.h" #if SIMDJSON_IMPLEMENTATION_WESTMERE +#if SIMDJSON_CAN_ALWAYS_RUN_WESTMERE +#define SIMDJSON_TARGET_WESTMERE +#define SIMDJSON_UNTARGET_WESTMERE +#else #define SIMDJSON_TARGET_WESTMERE SIMDJSON_TARGET_REGION("sse4.2,pclmul") +#define SIMDJSON_UNTARGET_WESTMERE SIMDJSON_UNTARGET_REGION +#endif namespace simdjson { /** @@ -26,7 +22,7 @@ namespace westmere { } // namespace simdjson // -// These two need to be included outside SIMDJSON_TARGET_REGION +// These two need to be included outside SIMDJSON_TARGET_WESTMERE // #include "simdjson/westmere/implementation.h" #include "simdjson/westmere/intrinsics.h" @@ -45,13 +41,6 @@ namespace westmere { #include "simdjson/generic/atomparsing.h" #include "simdjson/westmere/stringparsing.h" #include "simdjson/westmere/numberparsing.h" -#include "simdjson/generic/implementation_simdjson_result_base.h" -#include "simdjson/generic/ondemand.h" - -// Inline definitions -#include "simdjson/generic/implementation_simdjson_result_base-inl.h" -#include "simdjson/generic/ondemand-inl.h" - #include "simdjson/westmere/end.h" #endif // SIMDJSON_IMPLEMENTATION_WESTMERE diff --git a/include/simdjson/westmere/end.h b/include/simdjson/westmere/end.h index e1e5634d..4af0dc54 100644 --- a/include/simdjson/westmere/end.h +++ b/include/simdjson/westmere/end.h @@ -1,2 +1,2 @@ -SIMDJSON_UNTARGET_REGION +SIMDJSON_UNTARGET_WESTMERE #undef SIMDJSON_IMPLEMENTATION diff --git a/include/simdjson/westmere/implementation.h b/include/simdjson/westmere/implementation.h index c4573adc..42bc7657 100644 --- a/include/simdjson/westmere/implementation.h +++ b/include/simdjson/westmere/implementation.h @@ -3,7 +3,7 @@ #include "simdjson/implementation.h" -// The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION +// The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_WESTMERE namespace simdjson { namespace westmere { diff --git a/singleheader/amalgamate.py b/singleheader/amalgamate.py index d1c746fc..6691efec 100755 --- a/singleheader/amalgamate.py +++ b/singleheader/amalgamate.py @@ -83,7 +83,8 @@ def dofile(fid, prepath, filename): # Last lines are always ignored. Files should end by an empty lines. print(f"/* begin file {RELFILE} */", file=fid) includepattern = re.compile('^#include "(.*)"') - redefines_simdjson_implementation = re.compile('^#define SIMDJSON_IMPLEMENTATION (.*)') + redefines_simdjson_implementation = re.compile('^#define\s+SIMDJSON_IMPLEMENTATION\s+(.*)') + undefines_simdjson_implementation = re.compile('^#undef\s+SIMDJSON_IMPLEMENTATION\s*$') uses_simdjson_implementation = re.compile('SIMDJSON_IMPLEMENTATION([^_a-zA-Z0-9]|$)') with open(file, 'r') as fid2: for line in fid2: @@ -106,6 +107,9 @@ def dofile(fid, prepath, filename): if s: current_implementation=s.group(1) print(f"// redefining SIMDJSON_IMPLEMENTATION to \"{current_implementation}\"\n// {line}", file=fid) + elif undefines_simdjson_implementation.search(line): + # Don't include #undef SIMDJSON_IMPLEMENTATION since we're handling it ourselves + print(f"// {line}") else: # copy the line, with SIMDJSON_IMPLEMENTATION replace to what it is currently defined to print(uses_simdjson_implementation.sub(current_implementation+"\\1",line), file=fid) diff --git a/src/implementation.cpp b/src/implementation.cpp index 4301b324..4c0017a4 100644 --- a/src/implementation.cpp +++ b/src/implementation.cpp @@ -1,4 +1,4 @@ -#include "simdjson.h" +#include "simdjson/base.h" #include namespace simdjson { @@ -155,6 +155,7 @@ simdjson_warn_unused bool validate_utf8(const char *buf, size_t len) noexcept { const implementation * builtin_implementation() { static const implementation * builtin_impl = available_implementations[STRINGIFY(SIMDJSON_BUILTIN_IMPLEMENTATION)]; + assert(builtin_impl); return builtin_impl; } diff --git a/src/internal/error_tables.cpp b/src/internal/error_tables.cpp index ce7da7bc..e8792603 100644 --- a/src/internal/error_tables.cpp +++ b/src/internal/error_tables.cpp @@ -1,4 +1,4 @@ -#include "simdjson.h" +#include "simdjson/base.h" namespace simdjson { namespace internal { diff --git a/src/internal/jsoncharutils_tables.cpp b/src/internal/jsoncharutils_tables.cpp index 2cbe1199..deae5489 100644 --- a/src/internal/jsoncharutils_tables.cpp +++ b/src/internal/jsoncharutils_tables.cpp @@ -1,4 +1,4 @@ -#include "simdjson.h" +#include "simdjson/base.h" namespace simdjson { namespace internal { diff --git a/src/internal/numberparsing_tables.cpp b/src/internal/numberparsing_tables.cpp index 4c98607c..4db818b4 100644 --- a/src/internal/numberparsing_tables.cpp +++ b/src/internal/numberparsing_tables.cpp @@ -1,4 +1,4 @@ -#include "simdjson.h" +#include "simdjson/base.h" namespace simdjson { namespace internal {