From af8b52e7e81f646d392470c7f42aedea552cd764 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 16 Jul 2020 12:20:25 -0700 Subject: [PATCH] Target region for entire compilation of an implementation --- include/simdjson/portability.h | 21 ++++++++------------- src/arm64/begin_implementation.h | 5 +++++ src/arm64/bitmanipulation.h | 1 - src/arm64/bitmask.h | 4 +--- src/arm64/dom_parser_implementation.cpp | 14 ++++++++------ src/arm64/end_implementation.h | 1 + src/arm64/implementation.cpp | 11 ++++------- src/arm64/numberparsing.h | 1 - src/arm64/simd.h | 1 - src/arm64/stringparsing.h | 1 - src/fallback/begin_implementation.h | 4 ++++ src/fallback/dom_parser_implementation.cpp | 14 ++++++++------ src/fallback/end_implementation.h | 1 + src/fallback/implementation.cpp | 11 ++++------- src/fallback/implementation.h | 1 - src/haswell/begin_implementation.h | 6 ++++++ src/haswell/bitmanipulation.h | 8 ++------ src/haswell/bitmask.h | 9 ++------- src/haswell/dom_parser_implementation.cpp | 18 ++++++++---------- src/haswell/dom_parser_implementation.h | 4 ++-- src/haswell/end_implementation.h | 2 ++ src/haswell/implementation.cpp | 12 +++++------- src/haswell/implementation.h | 1 + src/haswell/intrinsics.h | 11 +++++++---- src/haswell/numberparsing.h | 9 +++------ src/haswell/simd.h | 7 ++----- src/haswell/stringparsing.h | 7 ++----- src/westmere/begin_implementation.h | 6 ++++++ src/westmere/bitmanipulation.h | 8 ++------ src/westmere/bitmask.h | 8 ++------ src/westmere/dom_parser_implementation.cpp | 19 ++++++++----------- src/westmere/end_implementation.h | 2 ++ src/westmere/implementation.cpp | 11 ++++------- src/westmere/implementation.h | 1 + src/westmere/numberparsing.h | 10 +++------- src/westmere/simd.h | 10 ++-------- src/westmere/stringparsing.h | 7 ++----- 37 files changed, 118 insertions(+), 149 deletions(-) create mode 100644 src/arm64/begin_implementation.h create mode 100644 src/arm64/end_implementation.h create mode 100644 src/fallback/begin_implementation.h create mode 100644 src/fallback/end_implementation.h create mode 100644 src/haswell/begin_implementation.h create mode 100644 src/haswell/end_implementation.h create mode 100644 src/westmere/begin_implementation.h create mode 100644 src/westmere/end_implementation.h diff --git a/include/simdjson/portability.h b/include/simdjson/portability.h index e91a2423..d6a1b8d7 100644 --- a/include/simdjson/portability.h +++ b/include/simdjson/portability.h @@ -103,32 +103,27 @@ use a 64-bit target such as x64 or 64-bit ARM.") #ifdef __clang__ // clang does not have GCC push pop // warning: clang attribute push can't be used within a namespace in clang up -// til 8.0 so TARGET_REGION and UNTARGET_REGION must be *outside* of a +// til 8.0 so SIMDJSON_TARGET_REGION and SIMDJSON_UNTARGET_REGION must be *outside* of a // namespace. -#define TARGET_REGION(T) \ +#define SIMDJSON_TARGET_REGION(T) \ _Pragma(STRINGIFY( \ clang attribute push(__attribute__((target(T))), apply_to = function))) -#define UNTARGET_REGION _Pragma("clang attribute pop") +#define SIMDJSON_UNTARGET_REGION _Pragma("clang attribute pop") #elif defined(__GNUC__) // GCC is easier -#define TARGET_REGION(T) \ +#define SIMDJSON_TARGET_REGION(T) \ _Pragma("GCC push_options") _Pragma(STRINGIFY(GCC target(T))) -#define UNTARGET_REGION _Pragma("GCC pop_options") +#define SIMDJSON_UNTARGET_REGION _Pragma("GCC pop_options") #endif // clang then gcc #endif // x86 // Default target region macros don't do anything. -#ifndef TARGET_REGION -#define TARGET_REGION(T) -#define UNTARGET_REGION +#ifndef SIMDJSON_TARGET_REGION +#define SIMDJSON_TARGET_REGION(T) +#define SIMDJSON_UNTARGET_REGION #endif -// under GCC and CLANG, we use these two macros -#define TARGET_HASWELL TARGET_REGION("avx2,bmi,pclmul,lzcnt") -#define TARGET_WESTMERE TARGET_REGION("sse4.2,pclmul") -#define TARGET_ARM64 - // Is threading enabled? #if defined(BOOST_HAS_THREADS) || defined(_REENTRANT) || defined(_MT) #ifndef SIMDJSON_THREADS_ENABLED diff --git a/src/arm64/begin_implementation.h b/src/arm64/begin_implementation.h new file mode 100644 index 00000000..aba32298 --- /dev/null +++ b/src/arm64/begin_implementation.h @@ -0,0 +1,5 @@ +#include "simdjson.h" +#include "arm64/implementation.h" +#include "arm64/intrinsics.h" // Generally need to be included outside SIMDJSON_TARGET_REGION + +#define SIMDJSON_IMPLEMENTATION arm64 diff --git a/src/arm64/bitmanipulation.h b/src/arm64/bitmanipulation.h index fe002043..7cab8016 100644 --- a/src/arm64/bitmanipulation.h +++ b/src/arm64/bitmanipulation.h @@ -2,7 +2,6 @@ #define SIMDJSON_ARM64_BITMANIPULATION_H #include "simdjson.h" -#include "arm64/intrinsics.h" namespace simdjson { namespace arm64 { diff --git a/src/arm64/bitmask.h b/src/arm64/bitmask.h index 3c8ceed9..fbaf6aa9 100644 --- a/src/arm64/bitmask.h +++ b/src/arm64/bitmask.h @@ -3,8 +3,6 @@ #include "simdjson.h" -#include "arm64/intrinsics.h" - namespace simdjson { namespace arm64 { @@ -38,6 +36,6 @@ really_inline uint64_t prefix_xor(uint64_t bitmask) { } // namespace arm64 } // namespace simdjson -UNTARGET_REGION +SIMDJSON_UNTARGET_REGION #endif diff --git a/src/arm64/dom_parser_implementation.cpp b/src/arm64/dom_parser_implementation.cpp index 5ac421d4..e7debac2 100644 --- a/src/arm64/dom_parser_implementation.cpp +++ b/src/arm64/dom_parser_implementation.cpp @@ -1,5 +1,4 @@ -#include "simdjson.h" -#include "arm64/implementation.h" +#include "arm64/begin_implementation.h" #include "arm64/dom_parser_implementation.h" // @@ -10,7 +9,7 @@ #include "arm64/bitmanipulation.h" namespace simdjson { -namespace arm64 { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -132,7 +131,8 @@ WARN_UNUSED error_code dom_parser_implementation::stage1(const uint8_t *_buf, si WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) const noexcept { return simdjson::arm64::stage1::generic_validate_utf8(buf,len); } -} // namespace arm64 + +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson // @@ -143,7 +143,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons #include "arm64/numberparsing.h" namespace simdjson { -namespace arm64 { +namespace SIMDJSON_IMPLEMENTATION { #include "generic/stage2/logger.h" #include "generic/stage2/atomparsing.h" @@ -156,5 +156,7 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz return stage2(_doc); } -} // namespace arm64 +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson + +#include "arm64/end_implementation.h" \ No newline at end of file diff --git a/src/arm64/end_implementation.h b/src/arm64/end_implementation.h new file mode 100644 index 00000000..69c9f4b8 --- /dev/null +++ b/src/arm64/end_implementation.h @@ -0,0 +1 @@ +#undef SIMDJSON_IMPLEMENTATION diff --git a/src/arm64/implementation.cpp b/src/arm64/implementation.cpp index 7276aa29..a4b8958d 100644 --- a/src/arm64/implementation.cpp +++ b/src/arm64/implementation.cpp @@ -1,11 +1,8 @@ -#include "simdjson.h" -#include "arm64/implementation.h" +#include "arm64/begin_implementation.h" #include "arm64/dom_parser_implementation.h" -TARGET_HASWELL - namespace simdjson { -namespace arm64 { +namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -19,7 +16,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } -} // namespace arm64 +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION +#include "arm64/end_implementation.h" \ No newline at end of file diff --git a/src/arm64/numberparsing.h b/src/arm64/numberparsing.h index 7355c687..0854b469 100644 --- a/src/arm64/numberparsing.h +++ b/src/arm64/numberparsing.h @@ -3,7 +3,6 @@ #include "simdjson.h" #include "jsoncharutils.h" -#include "arm64/intrinsics.h" #include "arm64/bitmanipulation.h" #include #include diff --git a/src/arm64/simd.h b/src/arm64/simd.h index c00ae99e..e3665427 100644 --- a/src/arm64/simd.h +++ b/src/arm64/simd.h @@ -4,7 +4,6 @@ #include "simdjson.h" #include "simdprune_tables.h" #include "arm64/bitmanipulation.h" -#include "arm64/intrinsics.h" #include diff --git a/src/arm64/stringparsing.h b/src/arm64/stringparsing.h index 0673e04c..98decef2 100644 --- a/src/arm64/stringparsing.h +++ b/src/arm64/stringparsing.h @@ -4,7 +4,6 @@ #include "simdjson.h" #include "jsoncharutils.h" #include "arm64/simd.h" -#include "arm64/intrinsics.h" #include "arm64/bitmanipulation.h" namespace simdjson { diff --git a/src/fallback/begin_implementation.h b/src/fallback/begin_implementation.h new file mode 100644 index 00000000..f0ad486e --- /dev/null +++ b/src/fallback/begin_implementation.h @@ -0,0 +1,4 @@ +#include "simdjson.h" +#include "fallback/implementation.h" + +#define SIMDJSON_IMPLEMENTATION fallback diff --git a/src/fallback/dom_parser_implementation.cpp b/src/fallback/dom_parser_implementation.cpp index a474b68f..44e98b4e 100644 --- a/src/fallback/dom_parser_implementation.cpp +++ b/src/fallback/dom_parser_implementation.cpp @@ -1,12 +1,12 @@ -#include "simdjson.h" -#include "fallback/implementation.h" +#include "fallback/begin_implementation.h" #include "fallback/dom_parser_implementation.h" // // Stage 1 // namespace simdjson { -namespace fallback { +namespace SIMDJSON_IMPLEMENTATION { + namespace stage1 { #include "generic/stage1/find_next_document_index.h" @@ -308,7 +308,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons return true; } -} // namespace fallback +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson // @@ -318,7 +318,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons #include "fallback/numberparsing.h" namespace simdjson { -namespace fallback { +namespace SIMDJSON_IMPLEMENTATION { #include "generic/stage2/logger.h" #include "generic/stage2/atomparsing.h" @@ -331,5 +331,7 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz return stage2(_doc); } -} // namespace fallback +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson + +#include "fallback/end_implementation.h" \ No newline at end of file diff --git a/src/fallback/end_implementation.h b/src/fallback/end_implementation.h new file mode 100644 index 00000000..69c9f4b8 --- /dev/null +++ b/src/fallback/end_implementation.h @@ -0,0 +1 @@ +#undef SIMDJSON_IMPLEMENTATION diff --git a/src/fallback/implementation.cpp b/src/fallback/implementation.cpp index 3981f222..305e040c 100644 --- a/src/fallback/implementation.cpp +++ b/src/fallback/implementation.cpp @@ -1,11 +1,8 @@ -#include "simdjson.h" -#include "fallback/implementation.h" +#include "fallback/begin_implementation.h" #include "fallback/dom_parser_implementation.h" -TARGET_HASWELL - namespace simdjson { -namespace fallback { +namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -19,7 +16,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } -} // namespace fallback +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION +#include "fallback/end_implementation.h" \ No newline at end of file diff --git a/src/fallback/implementation.h b/src/fallback/implementation.h index 5d92d385..5b99218c 100644 --- a/src/fallback/implementation.h +++ b/src/fallback/implementation.h @@ -26,7 +26,6 @@ public: }; } // namespace fallback - } // namespace simdjson #endif // SIMDJSON_FALLBACK_IMPLEMENTATION_H \ No newline at end of file diff --git a/src/haswell/begin_implementation.h b/src/haswell/begin_implementation.h new file mode 100644 index 00000000..bfa87e29 --- /dev/null +++ b/src/haswell/begin_implementation.h @@ -0,0 +1,6 @@ +#include "simdjson.h" +#include "haswell/implementation.h" +#include "haswell/intrinsics.h" // Generally need to be included outside SIMDJSON_TARGET_REGION + +#define SIMDJSON_IMPLEMENTATION haswell +SIMDJSON_TARGET_REGION("avx2,bmi,pclmul,lzcnt") diff --git a/src/haswell/bitmanipulation.h b/src/haswell/bitmanipulation.h index f6b8fc72..24042649 100644 --- a/src/haswell/bitmanipulation.h +++ b/src/haswell/bitmanipulation.h @@ -3,11 +3,8 @@ #include "simdjson.h" -#include "haswell/intrinsics.h" - -TARGET_HASWELL namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. @@ -73,8 +70,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, #endif } -} // namespace haswell +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_HASWELL_BITMANIPULATION_H diff --git a/src/haswell/bitmask.h b/src/haswell/bitmask.h index c9ed2e0e..9661f7ef 100644 --- a/src/haswell/bitmask.h +++ b/src/haswell/bitmask.h @@ -3,11 +3,8 @@ #include "simdjson.h" -#include "haswell/intrinsics.h" - -TARGET_HASWELL namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { // // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. @@ -22,9 +19,7 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) { return _mm_cvtsi128_si64(result); } -} // namespace haswell - +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_HASWELL_BITMASK_H diff --git a/src/haswell/dom_parser_implementation.cpp b/src/haswell/dom_parser_implementation.cpp index 2a1f1891..b104754e 100644 --- a/src/haswell/dom_parser_implementation.cpp +++ b/src/haswell/dom_parser_implementation.cpp @@ -1,5 +1,4 @@ -#include "simdjson.h" -#include "haswell/implementation.h" +#include "haswell/begin_implementation.h" #include "haswell/dom_parser_implementation.h" // @@ -9,9 +8,8 @@ #include "haswell/simd.h" #include "haswell/bitmanipulation.h" -TARGET_HASWELL namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -97,9 +95,9 @@ WARN_UNUSED error_code dom_parser_implementation::stage1(const uint8_t *_buf, si WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) const noexcept { return simdjson::haswell::stage1::generic_validate_utf8(buf,len); } -} // namespace haswell + +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION // // Stage 2 @@ -107,9 +105,8 @@ UNTARGET_REGION #include "haswell/stringparsing.h" #include "haswell/numberparsing.h" -TARGET_HASWELL namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { #include "generic/stage2/logger.h" #include "generic/stage2/atomparsing.h" @@ -122,6 +119,7 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz return stage2(_doc); } -} // namespace haswell +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION + +#include "haswell/end_implementation.h" diff --git a/src/haswell/dom_parser_implementation.h b/src/haswell/dom_parser_implementation.h index fdf7d2b0..180be00a 100644 --- a/src/haswell/dom_parser_implementation.h +++ b/src/haswell/dom_parser_implementation.h @@ -5,11 +5,11 @@ #include "isadetection.h" namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { #include "generic/dom_parser_implementation.h" -} // namespace haswell +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson #endif // SIMDJSON_HASWELL_DOM_PARSER_IMPLEMENTATION_H \ No newline at end of file diff --git a/src/haswell/end_implementation.h b/src/haswell/end_implementation.h new file mode 100644 index 00000000..cf78b56c --- /dev/null +++ b/src/haswell/end_implementation.h @@ -0,0 +1,2 @@ +#undef SIMDJSON_IMPLEMENTATION +SIMDJSON_UNTARGET_REGION diff --git a/src/haswell/implementation.cpp b/src/haswell/implementation.cpp index 53daa182..09c38aba 100644 --- a/src/haswell/implementation.cpp +++ b/src/haswell/implementation.cpp @@ -1,11 +1,8 @@ -#include "simdjson.h" -#include "haswell/implementation.h" +#include "haswell/begin_implementation.h" #include "haswell/dom_parser_implementation.h" -TARGET_HASWELL - namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -19,7 +16,8 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } -} // namespace haswell +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION +#include "haswell/end_implementation.h" + diff --git a/src/haswell/implementation.h b/src/haswell/implementation.h index 36e5f389..efd20e30 100644 --- a/src/haswell/implementation.h +++ b/src/haswell/implementation.h @@ -4,6 +4,7 @@ #include "simdjson.h" #include "isadetection.h" +// The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION namespace simdjson { namespace haswell { diff --git a/src/haswell/intrinsics.h b/src/haswell/intrinsics.h index 5abc48c7..69df3d36 100644 --- a/src/haswell/intrinsics.h +++ b/src/haswell/intrinsics.h @@ -41,12 +41,15 @@ // has it as a macro. #ifndef _blsr_u64 // we roll our own -TARGET_HASWELL -static really_inline uint64_t simdjson_blsr_u64(uint64_t n) { +#include "haswell/begin_implementation.h" +namespace simdjson { +namespace SIMDJSON_IMPLEMENTATION { +static really_inline uint64_t _blsr_u64(uint64_t n) { return (n - 1) & n; } -UNTARGET_REGION -#define _blsr_u64(a) (simdjson_blsr_u64((a))) +} // namespace SIMDJSON_IMPLEMENTATION +} // namespace simdjson +#include "haswell/end_implementation.h" #endif // _blsr_u64 #endif diff --git a/src/haswell/numberparsing.h b/src/haswell/numberparsing.h index 6f7e242e..472b62d0 100644 --- a/src/haswell/numberparsing.h +++ b/src/haswell/numberparsing.h @@ -4,7 +4,6 @@ #include "simdjson.h" #include "jsoncharutils.h" -#include "haswell/intrinsics.h" #include "haswell/bitmanipulation.h" #include #include @@ -16,9 +15,9 @@ void found_unsigned_integer(uint64_t result, const uint8_t *buf); void found_float(double result, const uint8_t *buf); #endif -TARGET_HASWELL namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { + static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) { // this actually computes *16* values so we are being wasteful. const __m128i ascii0 = _mm_set1_epi8('0'); @@ -41,9 +40,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) #include "generic/stage2/numberparsing.h" -} // namespace haswell - +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_HASWELL_NUMBERPARSING_H diff --git a/src/haswell/simd.h b/src/haswell/simd.h index c95f01df..f2410842 100644 --- a/src/haswell/simd.h +++ b/src/haswell/simd.h @@ -4,11 +4,9 @@ #include "simdjson.h" #include "simdprune_tables.h" #include "haswell/bitmanipulation.h" -#include "haswell/intrinsics.h" -TARGET_HASWELL namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { namespace simd { // Forward-declared so they can be used by splat and friends. @@ -352,8 +350,7 @@ namespace simd { } // namespace simd -} // namespace haswell +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_HASWELL_SIMD_H diff --git a/src/haswell/stringparsing.h b/src/haswell/stringparsing.h index a8d7728b..a7b52495 100644 --- a/src/haswell/stringparsing.h +++ b/src/haswell/stringparsing.h @@ -4,12 +4,10 @@ #include "simdjson.h" #include "jsoncharutils.h" #include "haswell/simd.h" -#include "haswell/intrinsics.h" #include "haswell/bitmanipulation.h" -TARGET_HASWELL namespace simdjson { -namespace haswell { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -43,8 +41,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 #include "generic/stage2/stringparsing.h" -} // namespace haswell +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_HASWELL_STRINGPARSING_H diff --git a/src/westmere/begin_implementation.h b/src/westmere/begin_implementation.h new file mode 100644 index 00000000..8c7bfd16 --- /dev/null +++ b/src/westmere/begin_implementation.h @@ -0,0 +1,6 @@ +#include "simdjson.h" +#include "westmere/intrinsics.h" // Generally need to be included outside SIMDJSON_TARGET_REGION +#include "westmere/implementation.h" + +#define SIMDJSON_IMPLEMENTATION westmere +SIMDJSON_TARGET_REGION("sse4.2,pclmul") diff --git a/src/westmere/bitmanipulation.h b/src/westmere/bitmanipulation.h index 29a8623a..3cf20323 100644 --- a/src/westmere/bitmanipulation.h +++ b/src/westmere/bitmanipulation.h @@ -2,11 +2,9 @@ #define SIMDJSON_WESTMERE_BITMANIPULATION_H #include "simdjson.h" -#include "westmere/intrinsics.h" -TARGET_WESTMERE namespace simdjson { -namespace westmere { +namespace SIMDJSON_IMPLEMENTATION { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. @@ -81,9 +79,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, #endif } -} // namespace westmere - +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_WESTMERE_BITMANIPULATION_H diff --git a/src/westmere/bitmask.h b/src/westmere/bitmask.h index 32bab6da..d1da0eb1 100644 --- a/src/westmere/bitmask.h +++ b/src/westmere/bitmask.h @@ -2,11 +2,9 @@ #define SIMDJSON_WESTMERE_BITMASK_H #include "simdjson.h" -#include "westmere/intrinsics.h" -TARGET_WESTMERE namespace simdjson { -namespace westmere { +namespace SIMDJSON_IMPLEMENTATION { // // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered. @@ -21,9 +19,7 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) { return _mm_cvtsi128_si64(result); } -} // namespace westmere - +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_WESTMERE_BITMASK_H diff --git a/src/westmere/dom_parser_implementation.cpp b/src/westmere/dom_parser_implementation.cpp index c665e76c..ff156970 100644 --- a/src/westmere/dom_parser_implementation.cpp +++ b/src/westmere/dom_parser_implementation.cpp @@ -1,6 +1,4 @@ -#include "simdjson.h" -#include "westmere/implementation.h" -#include "westmere/dom_parser_implementation.h" +#include "westmere/begin_implementation.h" // // Stage 1 @@ -10,9 +8,8 @@ #include "westmere/bitmanipulation.h" #include "westmere/implementation.h" -TARGET_WESTMERE namespace simdjson { -namespace westmere { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -103,9 +100,9 @@ WARN_UNUSED error_code dom_parser_implementation::stage1(const uint8_t *_buf, si WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) const noexcept { return simdjson::westmere::stage1::generic_validate_utf8(buf,len); } -} // namespace westmere + +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION // // Stage 2 @@ -113,9 +110,8 @@ UNTARGET_REGION #include "westmere/stringparsing.h" #include "westmere/numberparsing.h" -TARGET_WESTMERE namespace simdjson { -namespace westmere { +namespace SIMDJSON_IMPLEMENTATION { #include "generic/stage2/logger.h" #include "generic/stage2/atomparsing.h" @@ -128,6 +124,7 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz return stage2(_doc); } -} // namespace westmere +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION + +#include "westmere/end_implementation.h" diff --git a/src/westmere/end_implementation.h b/src/westmere/end_implementation.h new file mode 100644 index 00000000..cf78b56c --- /dev/null +++ b/src/westmere/end_implementation.h @@ -0,0 +1,2 @@ +#undef SIMDJSON_IMPLEMENTATION +SIMDJSON_UNTARGET_REGION diff --git a/src/westmere/implementation.cpp b/src/westmere/implementation.cpp index 56792a8c..e166210b 100644 --- a/src/westmere/implementation.cpp +++ b/src/westmere/implementation.cpp @@ -1,11 +1,8 @@ -#include "simdjson.h" -#include "westmere/implementation.h" +#include "westmere/begin_implementation.h" #include "westmere/dom_parser_implementation.h" -TARGET_HASWELL - namespace simdjson { -namespace westmere { +namespace SIMDJSON_IMPLEMENTATION { WARN_UNUSED error_code implementation::create_dom_parser_implementation( size_t capacity, @@ -19,7 +16,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation( return SUCCESS; } -} // namespace westmere +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION +#include "westmere/end_implementation.h" \ No newline at end of file diff --git a/src/westmere/implementation.h b/src/westmere/implementation.h index 69dceb20..3fe8e6ac 100644 --- a/src/westmere/implementation.h +++ b/src/westmere/implementation.h @@ -5,6 +5,7 @@ #include "simdjson/implementation.h" #include "isadetection.h" +// The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION namespace simdjson { namespace westmere { diff --git a/src/westmere/numberparsing.h b/src/westmere/numberparsing.h index fa856e00..f10fc77c 100644 --- a/src/westmere/numberparsing.h +++ b/src/westmere/numberparsing.h @@ -3,7 +3,6 @@ #include "simdjson.h" #include "jsoncharutils.h" -#include "westmere/intrinsics.h" #include "westmere/bitmanipulation.h" #include #include @@ -16,10 +15,9 @@ void found_unsigned_integer(uint64_t result, const uint8_t *buf); void found_float(double result, const uint8_t *buf); #endif - -TARGET_WESTMERE namespace simdjson { -namespace westmere { +namespace SIMDJSON_IMPLEMENTATION { + static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) { // this actually computes *16* values so we are being wasteful. const __m128i ascii0 = _mm_set1_epi8('0'); @@ -42,9 +40,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) #include "generic/stage2/numberparsing.h" -} // namespace westmere - +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_WESTMERE_NUMBERPARSING_H diff --git a/src/westmere/simd.h b/src/westmere/simd.h index efbe508b..597e2fce 100644 --- a/src/westmere/simd.h +++ b/src/westmere/simd.h @@ -4,13 +4,9 @@ #include "simdjson.h" #include "simdprune_tables.h" #include "westmere/bitmanipulation.h" -#include "westmere/intrinsics.h" - - -TARGET_WESTMERE namespace simdjson { -namespace westmere { +namespace SIMDJSON_IMPLEMENTATION { namespace simd { template @@ -333,9 +329,7 @@ namespace simd { }; // struct simd8x64 } // namespace simd - -} // namespace westmere +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_WESTMERE_SIMD_INPUT_H diff --git a/src/westmere/stringparsing.h b/src/westmere/stringparsing.h index e2b0a4ac..09f34318 100644 --- a/src/westmere/stringparsing.h +++ b/src/westmere/stringparsing.h @@ -4,12 +4,10 @@ #include "simdjson.h" #include "jsoncharutils.h" #include "westmere/simd.h" -#include "westmere/intrinsics.h" #include "westmere/bitmanipulation.h" -TARGET_WESTMERE namespace simdjson { -namespace westmere { +namespace SIMDJSON_IMPLEMENTATION { using namespace simd; @@ -45,8 +43,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8 #include "generic/stage2/stringparsing.h" -} // namespace westmere +} // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -UNTARGET_REGION #endif // SIMDJSON_WESTMERE_STRINGPARSING_H