diff --git a/include/simdjson.h b/include/simdjson.h index 0e2a08e0..63e90c9a 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 72deb2a6..2f49c963 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 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/builtin.h b/include/simdjson/builtin.h index 730c9939..47e81501 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 0c85b433..182fa945 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 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 25869567..d5ce9a43 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 0195d423..38095418 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 e118c2c7..d1383648 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 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 index 7b95fa3d..bcdf3ee3 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 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 315869be..c8d76ca3 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 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 917031e2..d0a1f25e 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 4301b324..7bd68b78 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 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 { diff --git a/src/simdjson.cpp b/src/simdjson.cpp index 8d17791c..75799633 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