Target region for entire compilation of an implementation

This commit is contained in:
John Keiser 2020-07-16 12:20:25 -07:00
parent 796588900c
commit af8b52e7e8
37 changed files with 118 additions and 149 deletions

View File

@ -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

View File

@ -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

View File

@ -2,7 +2,6 @@
#define SIMDJSON_ARM64_BITMANIPULATION_H
#include "simdjson.h"
#include "arm64/intrinsics.h"
namespace simdjson {
namespace arm64 {

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1 @@
#undef SIMDJSON_IMPLEMENTATION

View File

@ -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"

View File

@ -3,7 +3,6 @@
#include "simdjson.h"
#include "jsoncharutils.h"
#include "arm64/intrinsics.h"
#include "arm64/bitmanipulation.h"
#include <cmath>
#include <limits>

View File

@ -4,7 +4,6 @@
#include "simdjson.h"
#include "simdprune_tables.h"
#include "arm64/bitmanipulation.h"
#include "arm64/intrinsics.h"
#include <type_traits>

View File

@ -4,7 +4,6 @@
#include "simdjson.h"
#include "jsoncharutils.h"
#include "arm64/simd.h"
#include "arm64/intrinsics.h"
#include "arm64/bitmanipulation.h"
namespace simdjson {

View File

@ -0,0 +1,4 @@
#include "simdjson.h"
#include "fallback/implementation.h"
#define SIMDJSON_IMPLEMENTATION fallback

View File

@ -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"

View File

@ -0,0 +1 @@
#undef SIMDJSON_IMPLEMENTATION

View File

@ -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"

View File

@ -26,7 +26,6 @@ public:
};
} // namespace fallback
} // namespace simdjson
#endif // SIMDJSON_FALLBACK_IMPLEMENTATION_H

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -0,0 +1,2 @@
#undef SIMDJSON_IMPLEMENTATION
SIMDJSON_UNTARGET_REGION

View File

@ -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"

View File

@ -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 {

View File

@ -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

View File

@ -4,7 +4,6 @@
#include "simdjson.h"
#include "jsoncharutils.h"
#include "haswell/intrinsics.h"
#include "haswell/bitmanipulation.h"
#include <cmath>
#include <limits>
@ -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

View File

@ -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

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -0,0 +1,2 @@
#undef SIMDJSON_IMPLEMENTATION
SIMDJSON_UNTARGET_REGION

View File

@ -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"

View File

@ -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 {

View File

@ -3,7 +3,6 @@
#include "simdjson.h"
#include "jsoncharutils.h"
#include "westmere/intrinsics.h"
#include "westmere/bitmanipulation.h"
#include <cmath>
#include <limits>
@ -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

View File

@ -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<typename Child>
@ -333,9 +329,7 @@ namespace simd {
}; // struct simd8x64<T>
} // namespace simd
} // namespace westmere
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
UNTARGET_REGION
#endif // SIMDJSON_WESTMERE_SIMD_INPUT_H

View File

@ -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