diff --git a/include/simdjson/arm64.h b/include/simdjson/arm64.h index 2f49c963..81ad9e85 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 3879585b..2e0e1456 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 182fa945..26a01c0d 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 fc1541a2..48db97a0 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 42710223..bcdf3ee3 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 2815d1ea..660021b4 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 c8d76ca3..363c2af9 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 3bec30f5..4419b012 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 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 7bd68b78..4c0017a4 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; }