diff --git a/include/simdjson/portability.h b/include/simdjson/portability.h index f2f22bc9d..65ad545ee 100644 --- a/include/simdjson/portability.h +++ b/include/simdjson/portability.h @@ -27,16 +27,20 @@ #define TARGET_REGION(T) \ _Pragma("GCC push_options") _Pragma(STRINGIFY(GCC target(T))) #define UNTARGET_REGION _Pragma("GCC pop_options") -#else +#endif // clang then gcc + +#endif // x86 + +// Default target region macros don't do anything. +#ifndef TARGET_REGION #define TARGET_REGION(T) #define UNTARGET_REGION -#endif // clang then gcc +#endif // under GCC and CLANG, we use these two macros #define TARGET_HASWELL TARGET_REGION("avx2,bmi,pclmul") #define TARGET_WESTMERE TARGET_REGION("sse4.2,pclmul") - -#endif // x86 +#define TARGET_ARM64 #ifdef _MSC_VER #include diff --git a/include/simdjson/stage1_find_marks_common.h b/include/simdjson/stage1_find_marks_common.h index b5840cb26..73c05af3c 100644 --- a/include/simdjson/stage1_find_marks_common.h +++ b/include/simdjson/stage1_find_marks_common.h @@ -4,6 +4,10 @@ // "simdjson/stage1_find_marks.h" (this simplifies amalgation) #ifdef TARGETED_ARCHITECTURE +#ifdef TARGETED_REGION + +TARGETED_REGION +namespace simdjson { // return a bitvector indicating where we have characters that end an odd-length // sequence of backslashes (and thus change the behavior of the next character @@ -226,4 +230,12 @@ int find_structural_bits(const uint8_t *buf, size_t len, return check_utf8_errors(utf8_state); } +} // namespace simdjson +UNTARGET_REGION + +#else +#error TARGETED_REGION must be specified before including. +#endif // TARGETED_REGION +#else +#error TARGETED_ARCHITECTURE must be specified before including. #endif // TARGETED_ARCHITECTURE diff --git a/include/simdjson/stage2_build_tape_common.h b/include/simdjson/stage2_build_tape_common.h index 1413491cb..f54206060 100644 --- a/include/simdjson/stage2_build_tape_common.h +++ b/include/simdjson/stage2_build_tape_common.h @@ -4,6 +4,11 @@ // "simdjson/stage2_build_tape.h" (this simplifies amalgation) #ifdef TARGETED_ARCHITECTURE +#ifdef TARGETED_REGION + +TARGETED_REGION +namespace simdjson { + // this macro reads the next structural character, updating idx, i and c. #define UPDATE_CHAR() \ { \ @@ -522,4 +527,12 @@ fail: return pj.error_code; } +} // namespace simdjson +UNTARGET_REGION + +#else +#error TARGETED_REGION must be specified before including. +#endif // TARGETED_REGION +#else +#error TARGETED_ARCHITECTURE must be specified before including. #endif // TARGETED_ARCHITECTURE diff --git a/include/simdjson/stringparsing_arm64.h b/include/simdjson/stringparsing_arm64.h index 5053921c1..3036ff292 100644 --- a/include/simdjson/stringparsing_arm64.h +++ b/include/simdjson/stringparsing_arm64.h @@ -41,10 +41,13 @@ find_bs_bits_and_quote_bits(const uint8_t *src, }; } +} // namespace simdjson + #define TARGETED_ARCHITECTURE Architecture::ARM64 +#define TARGETED_REGION TARGET_ARM64 #include "simdjson/stringparsing_common.h" #undef TARGETED_ARCHITECTURE +#undef TARGETED_REGION -} // namespace simdjson -#endif +#endif // IS_ARM64 #endif diff --git a/include/simdjson/stringparsing_common.h b/include/simdjson/stringparsing_common.h index 2d8914d56..fe497b8fe 100644 --- a/include/simdjson/stringparsing_common.h +++ b/include/simdjson/stringparsing_common.h @@ -4,6 +4,11 @@ // "simdjson/stringparsing.h" (this simplifies amalgation) #ifdef TARGETED_ARCHITECTURE +#ifdef TARGETED_REGION + +TARGETED_REGION +namespace simdjson { + template <> WARN_UNUSED ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER LENIENT_MEM_SANITIZER really_inline bool @@ -88,4 +93,12 @@ WARN_UNUSED ALLOW_SAME_PAGE_BUFFER_OVERRUN_QUALIFIER LENIENT_MEM_SANITIZER return true; } +} // namespace simdjson +UNTARGET_REGION + +#else +#error TARGETED_REGION must be specified before including. +#endif // TARGETED_REGION +#else +#error TARGETED_ARCHITECTURE must be specified before including. #endif // TARGETED_ARCHITECTURE diff --git a/include/simdjson/stringparsing_haswell.h b/include/simdjson/stringparsing_haswell.h index 3f28a2c73..d51b9f551 100644 --- a/include/simdjson/stringparsing_haswell.h +++ b/include/simdjson/stringparsing_haswell.h @@ -24,13 +24,15 @@ find_bs_bits_and_quote_bits(const uint8_t *src, static_cast(_mm256_movemask_epi8(quote_mask)) // quote_bits }; } - -#define TARGETED_ARCHITECTURE Architecture::HASWELL -#include "simdjson/stringparsing_common.h" -#undef TARGETED_ARCHITECTURE - } // namespace simdjson UNTARGET_REGION -#endif + +#define TARGETED_ARCHITECTURE Architecture::HASWELL +#define TARGETED_REGION TARGET_HASWELL +#include "simdjson/stringparsing_common.h" +#undef TARGETED_ARCHITECTURE +#undef TARGETED_REGION + +#endif // IS_X86_64 #endif diff --git a/include/simdjson/stringparsing_westmere.h b/include/simdjson/stringparsing_westmere.h index 1481f1bf0..5dca7bb48 100644 --- a/include/simdjson/stringparsing_westmere.h +++ b/include/simdjson/stringparsing_westmere.h @@ -23,13 +23,15 @@ find_bs_bits_and_quote_bits(const uint8_t *src, static_cast(_mm_movemask_epi8(quote_mask)) // quote_bits }; } - -#define TARGETED_ARCHITECTURE Architecture::WESTMERE -#include "simdjson/stringparsing_common.h" -#undef TARGETED_ARCHITECTURE - } // namespace simdjson UNTARGET_REGION -#endif + +#define TARGETED_ARCHITECTURE Architecture::WESTMERE +#define TARGETED_REGION TARGET_WESTMERE +#include "simdjson/stringparsing_common.h" +#undef TARGETED_ARCHITECTURE +#undef TARGETED_REGION + +#endif // IS_X86_64 #endif diff --git a/src/stage1_find_marks.cpp b/src/stage1_find_marks.cpp index ab1c5eff4..563d764bc 100644 --- a/src/stage1_find_marks.cpp +++ b/src/stage1_find_marks.cpp @@ -2,32 +2,32 @@ #include "simdjson/portability.h" #ifdef IS_X86_64 + #include "simdjson/stage1_find_marks_haswell.h" #include "simdjson/stage1_find_marks_westmere.h" -TARGET_HASWELL -namespace simdjson { #define TARGETED_ARCHITECTURE Architecture::HASWELL +#define TARGETED_REGION TARGET_HASWELL #include "simdjson/stage1_find_marks_common.h" #undef TARGETED_ARCHITECTURE -} // namespace simdjson -UNTARGET_REGION +#undef TARGETED_REGION -TARGET_WESTMERE -namespace simdjson { #define TARGETED_ARCHITECTURE Architecture::WESTMERE +#define TARGETED_REGION TARGET_WESTMERE #include "simdjson/stage1_find_marks_common.h" #undef TARGETED_ARCHITECTURE -} // namespace simdjson -UNTARGET_REGION +#undef TARGETED_REGION #endif // IS_X86_64 #ifdef IS_ARM64 + #include "simdjson/stage1_find_marks_arm64.h" -namespace simdjson { + #define TARGETED_ARCHITECTURE Architecture::ARM64 +#define TARGETED_REGION TARGET_ARM64 #include "simdjson/stage1_find_marks_common.h" #undef TARGETED_ARCHITECTURE -} // namespace simdjson +#undef TARGETED_REGION + #endif // IS_ARM64 diff --git a/src/stage2_build_tape.cpp b/src/stage2_build_tape.cpp index ae831bc7c..2286b0e5d 100644 --- a/src/stage2_build_tape.cpp +++ b/src/stage2_build_tape.cpp @@ -1,27 +1,23 @@ #include "simdjson/stage2_build_tape.h" #ifdef IS_X86_64 -TARGET_HASWELL -namespace simdjson { #define TARGETED_ARCHITECTURE Architecture::HASWELL +#define TARGETED_REGION TARGET_HASWELL #include "simdjson/stage2_build_tape_common.h" #undef TARGETED_ARCHITECTURE -} // namespace simdjson -UNTARGET_REGION +#undef TARGETED_REGION -TARGET_WESTMERE -namespace simdjson { #define TARGETED_ARCHITECTURE Architecture::WESTMERE +#define TARGETED_REGION TARGET_WESTMERE #include "simdjson/stage2_build_tape_common.h" #undef TARGETED_ARCHITECTURE -} // namespace simdjson -UNTARGET_REGION +#undef TARGETED_REGION #endif // IS_X86_64 #ifdef IS_ARM64 -namespace simdjson { #define TARGETED_ARCHITECTURE Architecture::ARM64 +#define TARGETED_REGION TARGET_ARM64 #include "simdjson/stage2_build_tape_common.h" #undef TARGETED_ARCHITECTURE -} // namespace simdjson -#endif +#undef TARGETED_REGION +#endif // IS_ARM64