From ec5ba794473f0a816004436332d3f489b9f7c838 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 5 Mar 2021 11:48:34 -0800 Subject: [PATCH 1/7] Add base.h to allow src/ to pick and choose includes --- include/simdjson.h | 24 +----------------------- include/simdjson/base.h | 25 +++++++++++++++++++++++++ include/simdjson/builtin.h | 2 +- include/simdjson/dom.h | 5 +++++ include/simdjson/implementations.h | 5 +++++ 5 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 include/simdjson/base.h diff --git a/include/simdjson.h b/include/simdjson.h index 2aa311eda..f09c9f46c 100644 --- a/include/simdjson.h +++ b/include/simdjson.h @@ -34,30 +34,8 @@ } */ -#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/base.h" #include "simdjson/dom.h" -// Implementations #include "simdjson/implementations.h" -SIMDJSON_POP_DISABLE_WARNINGS - #endif // SIMDJSON_H diff --git a/include/simdjson/base.h b/include/simdjson/base.h new file mode 100644 index 000000000..00ce6851b --- /dev/null +++ b/include/simdjson/base.h @@ -0,0 +1,25 @@ +#ifndef SIMDJSON_BASE_H +#define SIMDJSON_BASE_H + +#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" + +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 9353d90c8..594a73a83 100644 --- a/include/simdjson/builtin.h +++ b/include/simdjson/builtin.h @@ -32,7 +32,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 eba360133..5629b2b1a 100644 --- a/include/simdjson/dom.h +++ b/include/simdjson/dom.h @@ -1,6 +1,9 @@ #ifndef SIMDJSON_DOM_H #define SIMDJSON_DOM_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 +28,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/implementations.h b/include/simdjson/implementations.h index 666262e40..8e89efc6f 100644 --- a/include/simdjson/implementations.h +++ b/include/simdjson/implementations.h @@ -1,6 +1,9 @@ #ifndef SIMDJSON_IMPLEMENTATIONS_H #define SIMDJSON_IMPLEMENTATIONS_H +SIMDJSON_PUSH_DISABLE_WARNINGS +SIMDJSON_DISABLE_UNDESIRED_WARNINGS + // 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 @@ -18,4 +21,6 @@ #include "simdjson/fallback.h" #include "simdjson/builtin.h" +SIMDJSON_POP_DISABLE_WARNINGS + #endif // SIMDJSON_IMPLEMENTATIONS_H \ No newline at end of file From cf4e5385368966e7d4fd2da2736282cee949784d Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 5 Mar 2021 11:59:48 -0800 Subject: [PATCH 2/7] Separate builtin implementation from "all implementations" --- include/simdjson.h | 2 +- include/simdjson/arm64.h | 10 ++-------- include/simdjson/base.h | 1 + include/simdjson/builtin.h | 5 +++++ include/simdjson/dom.h | 2 ++ include/simdjson/fallback.h | 2 +- include/simdjson/haswell.h | 4 ++-- include/simdjson/implementation-base.h | 23 +++++++++++++++++++++++ include/simdjson/implementations.h | 10 ---------- include/simdjson/ppc64.h | 10 ++-------- include/simdjson/westmere.h | 4 ++-- 11 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 include/simdjson/implementation-base.h diff --git a/include/simdjson.h b/include/simdjson.h index f09c9f46c..0e2a08e0d 100644 --- a/include/simdjson.h +++ b/include/simdjson.h @@ -34,8 +34,8 @@ } */ -#include "simdjson/base.h" #include "simdjson/dom.h" #include "simdjson/implementations.h" +#include "simdjson/builtin.h" #endif // SIMDJSON_H diff --git a/include/simdjson/arm64.h b/include/simdjson/arm64.h index 907dd972f..72deb2a63 100644 --- a/include/simdjson/arm64.h +++ b/include/simdjson/arm64.h @@ -1,23 +1,17 @@ #ifndef SIMDJSON_ARM64_H #define SIMDJSON_ARM64_H +#include "simdjson/implementation-base.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" - #if SIMDJSON_IMPLEMENTATION_ARM64 namespace simdjson { diff --git a/include/simdjson/base.h b/include/simdjson/base.h index 00ce6851b..c142f4a36 100644 --- a/include/simdjson/base.h +++ b/include/simdjson/base.h @@ -3,6 +3,7 @@ #include "simdjson/compiler_check.h" #include "simdjson/common_defs.h" +#include "simdjson/portability.h" SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_DISABLE_UNDESIRED_WARNINGS diff --git a/include/simdjson/builtin.h b/include/simdjson/builtin.h index 594a73a83..730c9939b 100644 --- a/include/simdjson/builtin.h +++ b/include/simdjson/builtin.h @@ -6,14 +6,19 @@ #ifndef SIMDJSON_BUILTIN_IMPLEMENTATION #if SIMDJSON_CAN_ALWAYS_RUN_HASWELL #define SIMDJSON_BUILTIN_IMPLEMENTATION haswell +#include "simdjson/haswell.h" #elif SIMDJSON_CAN_ALWAYS_RUN_WESTMERE #define SIMDJSON_BUILTIN_IMPLEMENTATION westmere +#include "simdjson/westmere.h" #elif SIMDJSON_CAN_ALWAYS_RUN_ARM64 #define SIMDJSON_BUILTIN_IMPLEMENTATION arm64 +#include "simdjson/arm64.h" #elif SIMDJSON_CAN_ALWAYS_RUN_PPC64 #define SIMDJSON_BUILTIN_IMPLEMENTATION ppc64 +#include "simdjson/ppc64.h" #elif SIMDJSON_CAN_ALWAYS_RUN_FALLBACK #define SIMDJSON_BUILTIN_IMPLEMENTATION fallback +#include "simdjson/fallback.h" #else #error "All possible implementations (including fallback) have been disabled! simdjson will not run." #endif diff --git a/include/simdjson/dom.h b/include/simdjson/dom.h index 5629b2b1a..b23745c58 100644 --- a/include/simdjson/dom.h +++ b/include/simdjson/dom.h @@ -1,6 +1,8 @@ #ifndef SIMDJSON_DOM_H #define SIMDJSON_DOM_H +#include "simdjson/base.h" + SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_DISABLE_UNDESIRED_WARNINGS diff --git a/include/simdjson/fallback.h b/include/simdjson/fallback.h index bea921547..0c85b433a 100644 --- a/include/simdjson/fallback.h +++ b/include/simdjson/fallback.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_FALLBACK_H #define SIMDJSON_FALLBACK_H -#include "simdjson/portability.h" +#include "simdjson/implementation-base.h" // Default Fallback to on unless a builtin implementation has already been selected. #ifndef SIMDJSON_IMPLEMENTATION_FALLBACK diff --git a/include/simdjson/haswell.h b/include/simdjson/haswell.h index cc93482dd..0195d423c 100644 --- a/include/simdjson/haswell.h +++ b/include/simdjson/haswell.h @@ -1,6 +1,8 @@ #ifndef SIMDJSON_HASWELL_H #define SIMDJSON_HASWELL_H +#include "simdjson/implementation-base.h" + #ifdef SIMDJSON_WESTMERE_H #error "haswell.h must be included before westmere.h" #endif @@ -8,8 +10,6 @@ #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 diff --git a/include/simdjson/implementation-base.h b/include/simdjson/implementation-base.h new file mode 100644 index 000000000..7b95fa3d4 --- /dev/null +++ b/include/simdjson/implementation-base.h @@ -0,0 +1,23 @@ +#ifndef SIMDJSON_IMPLEMENTATION_BASE_H +#define SIMDJSON_IMPLEMENTATION_BASE_H + +/** + * @file + * @private + * + * 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 8e89efc6f..2815d1ea4 100644 --- a/include/simdjson/implementations.h +++ b/include/simdjson/implementations.h @@ -4,22 +4,12 @@ SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_DISABLE_UNDESIRED_WARNINGS -// 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" - // Implementations #include "simdjson/arm64.h" #include "simdjson/haswell.h" #include "simdjson/westmere.h" #include "simdjson/ppc64.h" #include "simdjson/fallback.h" -#include "simdjson/builtin.h" SIMDJSON_POP_DISABLE_WARNINGS diff --git a/include/simdjson/ppc64.h b/include/simdjson/ppc64.h index 181cad213..315869be7 100644 --- a/include/simdjson/ppc64.h +++ b/include/simdjson/ppc64.h @@ -1,23 +1,17 @@ #ifndef SIMDJSON_PPC64_H #define SIMDJSON_PPC64_H +#include "simdjson/implementation-base.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" - #if SIMDJSON_IMPLEMENTATION_PPC64 namespace simdjson { diff --git a/include/simdjson/westmere.h b/include/simdjson/westmere.h index 2f202c71a..917031e2b 100644 --- a/include/simdjson/westmere.h +++ b/include/simdjson/westmere.h @@ -1,12 +1,12 @@ #ifndef SIMDJSON_WESTMERE_H #define SIMDJSON_WESTMERE_H +#include "simdjson/implementation-base.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) From f51d50399c2c05e3febbf33b4d58c9cb7b255f01 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Sat, 6 Mar 2021 12:53:01 -0800 Subject: [PATCH 3/7] Only include builtin implementation from header --- include/simdjson.h | 1 - include/simdjson/arm64.h | 11 ------- include/simdjson/arm64/implementation.h | 2 +- include/simdjson/arm64/intrinsics.h | 2 -- include/simdjson/arm64/simd.h | 2 +- include/simdjson/arm64/stringparsing.h | 2 +- include/simdjson/builtin.h | 2 +- include/simdjson/fallback.h | 6 ---- include/simdjson/fallback/bitmanipulation.h | 2 +- include/simdjson/fallback/stringparsing.h | 2 +- .../generic/dom_parser_implementation.h | 2 +- include/simdjson/haswell.h | 16 ---------- include/simdjson/haswell/intrinsics.h | 2 +- include/simdjson/haswell/stringparsing.h | 2 +- include/simdjson/implementation-base.h | 31 +++++++++++++++++++ .../simdjson/internal/jsoncharutils_tables.h | 2 +- .../simdjson/internal/numberparsing_tables.h | 2 +- include/simdjson/ppc64.h | 9 ------ include/simdjson/ppc64/implementation.h | 2 +- include/simdjson/ppc64/intrinsics.h | 2 +- include/simdjson/ppc64/simd.h | 2 +- include/simdjson/ppc64/stringparsing.h | 2 +- include/simdjson/westmere.h | 10 ------ src/implementation.cpp | 2 +- src/internal/error_tables.cpp | 2 +- src/internal/jsoncharutils_tables.cpp | 2 +- src/internal/numberparsing_tables.cpp | 2 +- src/simdjson.cpp | 4 +++ 28 files changed, 54 insertions(+), 74 deletions(-) diff --git a/include/simdjson.h b/include/simdjson.h index 0e2a08e0d..63e90c9a9 100644 --- a/include/simdjson.h +++ b/include/simdjson.h @@ -35,7 +35,6 @@ */ #include "simdjson/dom.h" -#include "simdjson/implementations.h" #include "simdjson/builtin.h" #endif // SIMDJSON_H diff --git a/include/simdjson/arm64.h b/include/simdjson/arm64.h index 72deb2a63..2f49c9630 100644 --- a/include/simdjson/arm64.h +++ b/include/simdjson/arm64.h @@ -3,15 +3,6 @@ #include "simdjson/implementation-base.h" -#ifdef SIMDJSON_FALLBACK_H -#error "arm64.h must be included before fallback.h" -#endif - -#ifndef SIMDJSON_IMPLEMENTATION_ARM64 -#define SIMDJSON_IMPLEMENTATION_ARM64 (SIMDJSON_IS_ARM64) -#endif -#define SIMDJSON_CAN_ALWAYS_RUN_ARM64 SIMDJSON_IMPLEMENTATION_ARM64 && SIMDJSON_IS_ARM64 - #if SIMDJSON_IMPLEMENTATION_ARM64 namespace simdjson { @@ -37,11 +28,9 @@ namespace arm64 { #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 2e498ff49..7214011ae 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 ceebaf24c..6f6ac4e2f 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 64a3a7e1e..81764cf9b 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 e1c3b4d9e..08c654879 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/builtin.h b/include/simdjson/builtin.h index 730c9939b..47e815011 100644 --- a/include/simdjson/builtin.h +++ b/include/simdjson/builtin.h @@ -1,7 +1,7 @@ #ifndef SIMDJSON_BUILTIN_H #define SIMDJSON_BUILTIN_H -#include "simdjson/portability.h" +#include "simdjson/implementation-base.h" #ifndef SIMDJSON_BUILTIN_IMPLEMENTATION #if SIMDJSON_CAN_ALWAYS_RUN_HASWELL diff --git a/include/simdjson/fallback.h b/include/simdjson/fallback.h index 0c85b433a..182fa945a 100644 --- a/include/simdjson/fallback.h +++ b/include/simdjson/fallback.h @@ -3,12 +3,6 @@ #include "simdjson/implementation-base.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 - #if SIMDJSON_IMPLEMENTATION_FALLBACK namespace simdjson { diff --git a/include/simdjson/fallback/bitmanipulation.h b/include/simdjson/fallback/bitmanipulation.h index 59117ef86..c4dae452a 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 97f04fd3f..8a0951ef5 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 258695677..d5ce9a43f 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 0195d423c..38095418d 100644 --- a/include/simdjson/haswell.h +++ b/include/simdjson/haswell.h @@ -3,22 +3,6 @@ #include "simdjson/implementation-base.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 - -// 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__)) - #if SIMDJSON_IMPLEMENTATION_HASWELL #define SIMDJSON_TARGET_HASWELL SIMDJSON_TARGET_REGION("avx2,bmi,pclmul,lzcnt") diff --git a/include/simdjson/haswell/intrinsics.h b/include/simdjson/haswell/intrinsics.h index e118c2c7f..d13836489 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 diff --git a/include/simdjson/haswell/stringparsing.h b/include/simdjson/haswell/stringparsing.h index 0141c780d..ec56bc59c 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 index 7b95fa3d4..bcdf3ee36 100644 --- a/include/simdjson/implementation-base.h +++ b/include/simdjson/implementation-base.h @@ -20,4 +20,35 @@ #include "simdjson/internal/numberparsing_tables.h" #include "simdjson/internal/simdprune_tables.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 + +// 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 + #endif // SIMDJSON_IMPLEMENTATION_BASE_H \ No newline at end of file diff --git a/include/simdjson/internal/jsoncharutils_tables.h b/include/simdjson/internal/jsoncharutils_tables.h index a53551cc8..bc412b865 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 9f66b6851..1762056f7 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 315869be7..c8d76ca3b 100644 --- a/include/simdjson/ppc64.h +++ b/include/simdjson/ppc64.h @@ -3,15 +3,6 @@ #include "simdjson/implementation-base.h" -#ifdef SIMDJSON_FALLBACK_H -#error "ppc64.h must be included before fallback.h" -#endif - -#ifndef SIMDJSON_IMPLEMENTATION_PPC64 -#define SIMDJSON_IMPLEMENTATION_PPC64 (SIMDJSON_IS_PPC64) -#endif -#define SIMDJSON_CAN_ALWAYS_RUN_PPC64 SIMDJSON_IMPLEMENTATION_PPC64 && SIMDJSON_IS_PPC64 - #if SIMDJSON_IMPLEMENTATION_PPC64 namespace simdjson { diff --git a/include/simdjson/ppc64/implementation.h b/include/simdjson/ppc64/implementation.h index 0620f3cc4..77b0e8303 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 ab86ed84b..00dc79c19 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 6ebecf1e5..47a7b9a39 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 ca78df506..6654d3ff7 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 917031e2b..d0a1f25e3 100644 --- a/include/simdjson/westmere.h +++ b/include/simdjson/westmere.h @@ -3,16 +3,6 @@ #include "simdjson/implementation-base.h" -#ifdef SIMDJSON_FALLBACK_H -#error "westmere.h must be included before fallback.h" -#endif - -// 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__) - #if SIMDJSON_IMPLEMENTATION_WESTMERE #define SIMDJSON_TARGET_WESTMERE SIMDJSON_TARGET_REGION("sse4.2,pclmul") diff --git a/src/implementation.cpp b/src/implementation.cpp index 4301b3246..7bd68b784 100644 --- a/src/implementation.cpp +++ b/src/implementation.cpp @@ -1,4 +1,4 @@ -#include "simdjson.h" +#include "simdjson/base.h" #include namespace simdjson { diff --git a/src/internal/error_tables.cpp b/src/internal/error_tables.cpp index ce7da7bc3..e8792603e 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 2cbe11990..deae54891 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 4c98607c6..4db818b4b 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 { diff --git a/src/simdjson.cpp b/src/simdjson.cpp index 8d17791cd..757996336 100644 --- a/src/simdjson.cpp +++ b/src/simdjson.cpp @@ -1,3 +1,7 @@ +// Instead of including simdjson.h, we include the stuff inside so we can get all the +// implementations and not just builtin +#define SIMDJSON_CPP + #include "simdjson.h" SIMDJSON_PUSH_DISABLE_WARNINGS From 633161fe862e1e1daf9c5744f34c82c7b7a6132b Mon Sep 17 00:00:00 2001 From: John Keiser Date: Mon, 8 Mar 2021 08:52:47 -0800 Subject: [PATCH 4/7] Don't include target flags if the compiler already has them on --- include/simdjson/builtin.h | 23 +--------------------- include/simdjson/haswell.h | 8 +++++++- include/simdjson/haswell/end.h | 2 +- include/simdjson/haswell/implementation.h | 2 +- include/simdjson/haswell/intrinsics.h | 2 +- include/simdjson/implementation-base.h | 17 ++++++++++++++++ include/simdjson/westmere.h | 8 +++++++- include/simdjson/westmere/end.h | 2 +- include/simdjson/westmere/implementation.h | 2 +- 9 files changed, 37 insertions(+), 29 deletions(-) diff --git a/include/simdjson/builtin.h b/include/simdjson/builtin.h index 47e815011..3879585ba 100644 --- a/include/simdjson/builtin.h +++ b/include/simdjson/builtin.h @@ -1,28 +1,7 @@ #ifndef SIMDJSON_BUILTIN_H #define SIMDJSON_BUILTIN_H -#include "simdjson/implementation-base.h" - -#ifndef SIMDJSON_BUILTIN_IMPLEMENTATION -#if SIMDJSON_CAN_ALWAYS_RUN_HASWELL -#define SIMDJSON_BUILTIN_IMPLEMENTATION haswell -#include "simdjson/haswell.h" -#elif SIMDJSON_CAN_ALWAYS_RUN_WESTMERE -#define SIMDJSON_BUILTIN_IMPLEMENTATION westmere -#include "simdjson/westmere.h" -#elif SIMDJSON_CAN_ALWAYS_RUN_ARM64 -#define SIMDJSON_BUILTIN_IMPLEMENTATION arm64 -#include "simdjson/arm64.h" -#elif SIMDJSON_CAN_ALWAYS_RUN_PPC64 -#define SIMDJSON_BUILTIN_IMPLEMENTATION ppc64 -#include "simdjson/ppc64.h" -#elif SIMDJSON_CAN_ALWAYS_RUN_FALLBACK -#define SIMDJSON_BUILTIN_IMPLEMENTATION fallback -#include "simdjson/fallback.h" -#else -#error "All possible implementations (including fallback) have been disabled! simdjson will not run." -#endif -#endif // SIMDJSON_BUILTIN_IMPLEMENTATION +#include "simdjson/implementations.h" namespace simdjson { /** diff --git a/include/simdjson/haswell.h b/include/simdjson/haswell.h index 38095418d..fc1541a2e 100644 --- a/include/simdjson/haswell.h +++ b/include/simdjson/haswell.h @@ -5,7 +5,13 @@ #if SIMDJSON_IMPLEMENTATION_HASWELL +#ifndef SIMDJSON_CAN_ALWAYS_RUN_HASWELL #define SIMDJSON_TARGET_HASWELL SIMDJSON_TARGET_REGION("avx2,bmi,pclmul,lzcnt") +#define SIMDJSON_UNTARGET_HASWELL SIMDJSON_UNTARGET_REGION +#else +#define SIMDJSON_TARGET_HASWELL +#define SIMDJSON_UNTARGET_HASWELL +#endif namespace simdjson { /** @@ -16,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" diff --git a/include/simdjson/haswell/end.h b/include/simdjson/haswell/end.h index e1e5634d2..d90f3fdb2 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 90c28830c..99b7c97e1 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 d13836489..801461231 100644 --- a/include/simdjson/haswell/intrinsics.h +++ b/include/simdjson/haswell/intrinsics.h @@ -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/implementation-base.h b/include/simdjson/implementation-base.h index bcdf3ee36..427102236 100644 --- a/include/simdjson/implementation-base.h +++ b/include/simdjson/implementation-base.h @@ -51,4 +51,21 @@ #endif #define SIMDJSON_CAN_ALWAYS_RUN_FALLBACK SIMDJSON_IMPLEMENTATION_FALLBACK +// Determine the best builtin implementation +#ifndef SIMDJSON_BUILTIN_IMPLEMENTATION +#if SIMDJSON_CAN_ALWAYS_RUN_HASWELL +#define SIMDJSON_BUILTIN_IMPLEMENTATION haswell +#elif SIMDJSON_CAN_ALWAYS_RUN_WESTMERE +#define SIMDJSON_BUILTIN_IMPLEMENTATION westmere +#elif SIMDJSON_CAN_ALWAYS_RUN_ARM64 +#define SIMDJSON_BUILTIN_IMPLEMENTATION arm64 +#elif SIMDJSON_CAN_ALWAYS_RUN_PPC64 +#define SIMDJSON_BUILTIN_IMPLEMENTATION ppc64 +#elif SIMDJSON_CAN_ALWAYS_RUN_FALLBACK +#define SIMDJSON_BUILTIN_IMPLEMENTATION fallback +#else +#error "All possible implementations (including fallback) have been disabled! simdjson will not run." +#endif +#endif // SIMDJSON_BUILTIN_IMPLEMENTATION + #endif // SIMDJSON_IMPLEMENTATION_BASE_H \ No newline at end of file diff --git a/include/simdjson/westmere.h b/include/simdjson/westmere.h index d0a1f25e3..3bec30f5a 100644 --- a/include/simdjson/westmere.h +++ b/include/simdjson/westmere.h @@ -5,7 +5,13 @@ #if SIMDJSON_IMPLEMENTATION_WESTMERE +#ifndef SIMDJSON_CAN_ALWAYS_RUN_WESTMERE #define SIMDJSON_TARGET_WESTMERE SIMDJSON_TARGET_REGION("sse4.2,pclmul") +#define SIMDJSON_UNTARGET_WESTMERE SIMDJSON_UNTARGET_REGION +#else +#define SIMDJSON_TARGET_WESTMERE +#define SIMDJSON_UNTARGET_WESTMERE +#endif namespace simdjson { /** @@ -16,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" diff --git a/include/simdjson/westmere/end.h b/include/simdjson/westmere/end.h index e1e5634d2..4af0dc541 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 c4573adce..42bc7657b 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 { From 985dfab2c4ba3fa8328aff831fffbd945e4c5d70 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Mon, 8 Mar 2021 09:53:33 -0800 Subject: [PATCH 5/7] Don't use TARGET unless the target options are *not* specified This eliminates the possibility of inlining target failures for ondemand Also makes it so we always compile common architectures needed by simdjson.cpp in simdjson.h, since amalgamation has no way to reason about whether to include / exclude it. --- include/simdjson/arm64.h | 4 ---- include/simdjson/builtin.h | 31 ++++++++++++++++++++++++++ include/simdjson/fallback.h | 7 ------ include/simdjson/haswell.h | 15 ++++--------- include/simdjson/implementation-base.h | 17 -------------- include/simdjson/implementations.h | 3 +++ include/simdjson/ppc64.h | 6 ----- include/simdjson/westmere.h | 15 ++++--------- singleheader/amalgamate.py | 6 ++++- src/implementation.cpp | 1 + 10 files changed, 48 insertions(+), 57 deletions(-) diff --git a/include/simdjson/arm64.h b/include/simdjson/arm64.h index 2f49c9630..81ad9e859 100644 --- a/include/simdjson/arm64.h +++ b/include/simdjson/arm64.h @@ -27,10 +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" - -// Inline definitions -#include "simdjson/generic/implementation_simdjson_result_base-inl.h" #include "simdjson/arm64/end.h" #endif // SIMDJSON_IMPLEMENTATION_ARM64 diff --git a/include/simdjson/builtin.h b/include/simdjson/builtin.h index 3879585ba..2e0e14561 100644 --- a/include/simdjson/builtin.h +++ b/include/simdjson/builtin.h @@ -3,6 +3,37 @@ #include "simdjson/implementations.h" +// Determine the best builtin implementation +#ifndef SIMDJSON_BUILTIN_IMPLEMENTATION +#if SIMDJSON_CAN_ALWAYS_RUN_HASWELL +#define SIMDJSON_BUILTIN_IMPLEMENTATION haswell +#elif SIMDJSON_CAN_ALWAYS_RUN_WESTMERE +#define SIMDJSON_BUILTIN_IMPLEMENTATION westmere +#elif SIMDJSON_CAN_ALWAYS_RUN_ARM64 +#define SIMDJSON_BUILTIN_IMPLEMENTATION arm64 +#elif SIMDJSON_CAN_ALWAYS_RUN_PPC64 +#define SIMDJSON_BUILTIN_IMPLEMENTATION ppc64 +#elif SIMDJSON_CAN_ALWAYS_RUN_FALLBACK +#define SIMDJSON_BUILTIN_IMPLEMENTATION fallback +#else +#error "All possible implementations (including fallback) have been disabled! simdjson will not run." +#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 diff --git a/include/simdjson/fallback.h b/include/simdjson/fallback.h index 182fa945a..26a01c0d1 100644 --- a/include/simdjson/fallback.h +++ b/include/simdjson/fallback.h @@ -24,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/haswell.h b/include/simdjson/haswell.h index fc1541a2e..48db97a0b 100644 --- a/include/simdjson/haswell.h +++ b/include/simdjson/haswell.h @@ -5,12 +5,12 @@ #if SIMDJSON_IMPLEMENTATION_HASWELL -#ifndef SIMDJSON_CAN_ALWAYS_RUN_HASWELL -#define SIMDJSON_TARGET_HASWELL SIMDJSON_TARGET_REGION("avx2,bmi,pclmul,lzcnt") -#define SIMDJSON_UNTARGET_HASWELL SIMDJSON_UNTARGET_REGION -#else +#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 { @@ -41,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/implementation-base.h b/include/simdjson/implementation-base.h index 427102236..bcdf3ee36 100644 --- a/include/simdjson/implementation-base.h +++ b/include/simdjson/implementation-base.h @@ -51,21 +51,4 @@ #endif #define SIMDJSON_CAN_ALWAYS_RUN_FALLBACK SIMDJSON_IMPLEMENTATION_FALLBACK -// Determine the best builtin implementation -#ifndef SIMDJSON_BUILTIN_IMPLEMENTATION -#if SIMDJSON_CAN_ALWAYS_RUN_HASWELL -#define SIMDJSON_BUILTIN_IMPLEMENTATION haswell -#elif SIMDJSON_CAN_ALWAYS_RUN_WESTMERE -#define SIMDJSON_BUILTIN_IMPLEMENTATION westmere -#elif SIMDJSON_CAN_ALWAYS_RUN_ARM64 -#define SIMDJSON_BUILTIN_IMPLEMENTATION arm64 -#elif SIMDJSON_CAN_ALWAYS_RUN_PPC64 -#define SIMDJSON_BUILTIN_IMPLEMENTATION ppc64 -#elif SIMDJSON_CAN_ALWAYS_RUN_FALLBACK -#define SIMDJSON_BUILTIN_IMPLEMENTATION fallback -#else -#error "All possible implementations (including fallback) have been disabled! simdjson will not run." -#endif -#endif // SIMDJSON_BUILTIN_IMPLEMENTATION - #endif // SIMDJSON_IMPLEMENTATION_BASE_H \ No newline at end of file diff --git a/include/simdjson/implementations.h b/include/simdjson/implementations.h index 2815d1ea4..660021b4c 100644 --- a/include/simdjson/implementations.h +++ b/include/simdjson/implementations.h @@ -1,6 +1,8 @@ #ifndef SIMDJSON_IMPLEMENTATIONS_H #define SIMDJSON_IMPLEMENTATIONS_H +#include "simdjson/implementation-base.h" + SIMDJSON_PUSH_DISABLE_WARNINGS SIMDJSON_DISABLE_UNDESIRED_WARNINGS @@ -10,6 +12,7 @@ SIMDJSON_DISABLE_UNDESIRED_WARNINGS #include "simdjson/westmere.h" #include "simdjson/ppc64.h" #include "simdjson/fallback.h" +#include "simdjson/builtin.h" SIMDJSON_POP_DISABLE_WARNINGS diff --git a/include/simdjson/ppc64.h b/include/simdjson/ppc64.h index c8d76ca3b..363c2af94 100644 --- a/include/simdjson/ppc64.h +++ b/include/simdjson/ppc64.h @@ -27,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/westmere.h b/include/simdjson/westmere.h index 3bec30f5a..4419b0129 100644 --- a/include/simdjson/westmere.h +++ b/include/simdjson/westmere.h @@ -5,12 +5,12 @@ #if SIMDJSON_IMPLEMENTATION_WESTMERE -#ifndef SIMDJSON_CAN_ALWAYS_RUN_WESTMERE -#define SIMDJSON_TARGET_WESTMERE SIMDJSON_TARGET_REGION("sse4.2,pclmul") -#define SIMDJSON_UNTARGET_WESTMERE SIMDJSON_UNTARGET_REGION -#else +#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 { @@ -41,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/singleheader/amalgamate.py b/singleheader/amalgamate.py index d1c746fc6..6691efec1 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 7bd68b784..4c0017a4e 100644 --- a/src/implementation.cpp +++ b/src/implementation.cpp @@ -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; } From 751696d7ebf9c4817c67c92c42c96d2e4a5a12cc Mon Sep 17 00:00:00 2001 From: John Keiser Date: Tue, 9 Mar 2021 09:10:08 -0800 Subject: [PATCH 6/7] Move implementation selection to implementations.h --- include/simdjson/implementation-base.h | 32 ------------------- include/simdjson/implementations.h | 44 ++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/include/simdjson/implementation-base.h b/include/simdjson/implementation-base.h index bcdf3ee36..3d560750c 100644 --- a/include/simdjson/implementation-base.h +++ b/include/simdjson/implementation-base.h @@ -3,7 +3,6 @@ /** * @file - * @private * * Includes common stuff needed for implementations. */ @@ -20,35 +19,4 @@ #include "simdjson/internal/numberparsing_tables.h" #include "simdjson/internal/simdprune_tables.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 - -// 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 - #endif // SIMDJSON_IMPLEMENTATION_BASE_H \ No newline at end of file diff --git a/include/simdjson/implementations.h b/include/simdjson/implementations.h index 660021b4c..5a1d82305 100644 --- a/include/simdjson/implementations.h +++ b/include/simdjson/implementations.h @@ -3,15 +3,53 @@ #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 From a9871920400fea6b9c2aa5cd33cd655d938cc7de Mon Sep 17 00:00:00 2001 From: John Keiser Date: Tue, 9 Mar 2021 09:10:27 -0800 Subject: [PATCH 7/7] Remove SIMDJSON_CPP --- src/simdjson.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/simdjson.cpp b/src/simdjson.cpp index 757996336..8d17791cd 100644 --- a/src/simdjson.cpp +++ b/src/simdjson.cpp @@ -1,7 +1,3 @@ -// Instead of including simdjson.h, we include the stuff inside so we can get all the -// implementations and not just builtin -#define SIMDJSON_CPP - #include "simdjson.h" SIMDJSON_PUSH_DISABLE_WARNINGS