diff --git a/Makefile b/Makefile index 5bf05a8a..fd2cfa99 100644 --- a/Makefile +++ b/Makefile @@ -62,10 +62,10 @@ SRCHEADERS_GENERIC=src/generic/numberparsing.h src/generic/stage1_find_marks.h s SRCHEADERS_ARM64= src/arm64/bitmanipulation.h src/arm64/bitmask.h src/arm64/intrinsics.h src/arm64/numberparsing.h src/arm64/simd.h src/arm64/stage1_find_marks.h src/arm64/stage2_build_tape.h src/arm64/stringparsing.h SRCHEADERS_HASWELL= src/haswell/bitmanipulation.h src/haswell/bitmask.h src/haswell/intrinsics.h src/haswell/numberparsing.h src/haswell/simd.h src/haswell/stage1_find_marks.h src/haswell/stage2_build_tape.h src/haswell/stringparsing.h SRCHEADERS_WESTMERE=src/westmere/bitmanipulation.h src/westmere/bitmask.h src/westmere/intrinsics.h src/westmere/numberparsing.h src/westmere/simd.h src/westmere/stage1_find_marks.h src/westmere/stage2_build_tape.h src/westmere/stringparsing.h -SRCHEADERS_SRC=src/jsoncharutils.h src/simdprune_tables.h src/error.cpp src/jsonioutil.cpp src/implementation.cpp src/stage1_find_marks.cpp src/stage2_build_tape.cpp src/inline/document_parser_callbacks.h +SRCHEADERS_SRC=src/isadetection.h src/jsoncharutils.h src/simdprune_tables.h src/error.cpp src/jsonioutil.cpp src/implementation.cpp src/stage1_find_marks.cpp src/stage2_build_tape.cpp src/inline/document_parser_callbacks.h SRCHEADERS=$(SRCHEADERS_SRC) $(SRCHEADERS_GENERIC) $(SRCHEADERS_ARM64) $(SRCHEADERS_HASWELL) $(SRCHEADERS_WESTMERE) -INCLUDEHEADERS=include/simdjson.h include/simdjson/common_defs.h include/simdjson/isadetection.h include/simdjson/jsonformatutils.h include/simdjson/jsonioutil.h include/simdjson/jsonminifier.h include/simdjson/jsonparser.h include/simdjson/padded_string.h include/simdjson/document.h include/simdjson/inline/document.h include/simdjson/document_iterator.h include/simdjson/inline/document_iterator.h include/simdjson/implementation.h include/simdjson/parsedjson.h include/simdjson/jsonstream.h include/simdjson/portability.h include/simdjson/error.h include/simdjson/simdjson.h include/simdjson/simdjson_version.h +INCLUDEHEADERS=include/simdjson.h include/simdjson/common_defs.h include/simdjson/internal/jsonformatutils.h include/simdjson/jsonioutil.h include/simdjson/jsonminifier.h include/simdjson/jsonparser.h include/simdjson/padded_string.h include/simdjson/document.h include/simdjson/inline/document.h include/simdjson/document_iterator.h include/simdjson/inline/document_iterator.h include/simdjson/implementation.h include/simdjson/parsedjson.h include/simdjson/jsonstream.h include/simdjson/portability.h include/simdjson/error.h include/simdjson/simdjson.h include/simdjson/simdjson_version.h ifeq ($(SIMDJSON_TEST_AMALGAMATED_HEADERS),1) HEADERS=singleheader/simdjson.h diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 5413eab1..607e74f4 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -8,8 +8,7 @@ set(SIMDJSON_INCLUDE ${SIMDJSON_INCLUDE_DIR}/simdjson/implementation.h ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document.h ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_iterator.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/isadetection.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonformatutils.h + ${SIMDJSON_INCLUDE_DIR}/simdjson/internal/jsonformatutils.h ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonioutil.h ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonminifier.h ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonparser.h diff --git a/include/simdjson/document_iterator.h b/include/simdjson/document_iterator.h index 18b69752..bf005538 100644 --- a/include/simdjson/document_iterator.h +++ b/include/simdjson/document_iterator.h @@ -9,7 +9,7 @@ #include #include "simdjson/document.h" -#include "simdjson/jsonformatutils.h" +#include "simdjson/internal/jsonformatutils.h" namespace simdjson { diff --git a/include/simdjson/inline/document.h b/include/simdjson/inline/document.h index 1d39ccd1..63938ee1 100644 --- a/include/simdjson/inline/document.h +++ b/include/simdjson/inline/document.h @@ -1,15 +1,13 @@ #ifndef SIMDJSON_INLINE_DOCUMENT_H #define SIMDJSON_INLINE_DOCUMENT_H - -// Inline implementations go in here if they aren't small enough to go in the class itself or if -// there are complex header file dependencies that need to be broken by externalizing the -// implementation. +// Inline implementations go in here. #include "simdjson/document.h" #include "simdjson/implementation.h" -#include "simdjson/jsonformatutils.h" +#include "simdjson/internal/jsonformatutils.h" #include + namespace simdjson { // @@ -278,7 +276,7 @@ inline bool document::print_json(std::ostream &os, size_t max_depth) const noexc case '"': // we have a string os << '"'; memcpy(&string_length, string_buf.get() + payload, sizeof(uint32_t)); - print_with_escapes( + internal::print_with_escapes( (const unsigned char *)(string_buf.get() + payload + sizeof(uint32_t)), os, string_length); os << '"'; @@ -368,7 +366,7 @@ inline bool document::dump_raw_tape(std::ostream &os) const noexcept { case '"': // we have a string os << "string \""; memcpy(&string_length, string_buf.get() + payload, sizeof(uint32_t)); - print_with_escapes( + internal::print_with_escapes( (const unsigned char *)(string_buf.get() + payload + sizeof(uint32_t)), os, string_length); diff --git a/include/simdjson/inline/document_iterator.h b/include/simdjson/inline/document_iterator.h index 9d86ec4f..59734ff2 100644 --- a/include/simdjson/inline/document_iterator.h +++ b/include/simdjson/inline/document_iterator.h @@ -276,7 +276,7 @@ bool document_iterator::print(std::ostream &os, bool escape_strings) case '"': // we have a string os << '"'; if (escape_strings) { - print_with_escapes(get_string(), os, get_string_length()); + internal::print_with_escapes(get_string(), os, get_string_length()); } else { // was: os << get_string();, but given that we can include null chars, we // have to do something crazier: diff --git a/include/simdjson/jsonformatutils.h b/include/simdjson/internal/jsonformatutils.h similarity index 87% rename from include/simdjson/jsonformatutils.h rename to include/simdjson/internal/jsonformatutils.h index 3a5e75e8..8c6187b2 100644 --- a/include/simdjson/jsonformatutils.h +++ b/include/simdjson/internal/jsonformatutils.h @@ -1,15 +1,13 @@ -#ifndef SIMDJSON_JSONFORMATUTILS_H -#define SIMDJSON_JSONFORMATUTILS_H +#ifndef SIMDJSON_INTERNAL_JSONFORMATUTILS_H +#define SIMDJSON_INTERNAL_JSONFORMATUTILS_H #include #include -namespace simdjson { - +namespace simdjson::internal { // ends with zero char -static inline void print_with_escapes(const unsigned char *src, - std::ostream &os) { +static inline void print_with_escapes(const unsigned char *src, std::ostream &os) { while (*src) { switch (*src) { case '\b': @@ -107,10 +105,10 @@ static inline void print_with_escapes(const char *src, std::ostream &os) { print_with_escapes(reinterpret_cast(src), os); } -static inline void print_with_escapes(const char *src, std::ostream &os, - size_t len) { +static inline void print_with_escapes(const char *src, std::ostream &os, size_t len) { print_with_escapes(reinterpret_cast(src), os, len); } -} // namespace simdjson -#endif +} // namespace simdjson::internal + +#endif // SIMDJSON_INTERNAL_JSONFORMATUTILS_H diff --git a/include/simdjson/jsonstream.h b/include/simdjson/jsonstream.h index a8824cbd..d5989c81 100644 --- a/include/simdjson/jsonstream.h +++ b/include/simdjson/jsonstream.h @@ -5,7 +5,6 @@ #include #include #include -#include "simdjson/isadetection.h" #include "simdjson/padded_string.h" #include "simdjson/simdjson.h" #include "jsoncharutils.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26eb2d81..964af7f1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,7 @@ set(SIMDJSON_SRC set(SIMDJSON_SRC_HEADERS error.cpp implementation.cpp + isadetection.h jsoncharutils.h jsonioutil.cpp jsonminifier.cpp diff --git a/src/arm64/implementation.h b/src/arm64/implementation.h index 7380c5d2..0f6d7644 100644 --- a/src/arm64/implementation.h +++ b/src/arm64/implementation.h @@ -6,7 +6,7 @@ #ifdef IS_ARM64 #include "simdjson/implementation.h" -#include "simdjson/isadetection.h" +#include "isadetection.h" namespace simdjson::arm64 { diff --git a/src/haswell/implementation.h b/src/haswell/implementation.h index 55b55599..8bb9f5cd 100644 --- a/src/haswell/implementation.h +++ b/src/haswell/implementation.h @@ -6,7 +6,7 @@ #ifdef IS_X86_64 #include "simdjson/implementation.h" -#include "simdjson/isadetection.h" +#include "isadetection.h" namespace simdjson::haswell { diff --git a/src/implementation.cpp b/src/implementation.cpp index cbba5dee..652c8dcb 100644 --- a/src/implementation.cpp +++ b/src/implementation.cpp @@ -1,5 +1,5 @@ #include "simdjson/portability.h" -#include "simdjson/isadetection.h" +#include "isadetection.h" #include "simdjson/implementation.h" #include @@ -11,10 +11,10 @@ #include "haswell/implementation.h" #include "westmere/implementation.h" -namespace simdjson { - const haswell::implementation haswell_singleton{}; - const westmere::implementation westmere_singleton{}; - constexpr const std::initializer_list available_implementation_pointers { &haswell_singleton, &westmere_singleton }; +namespace simdjson::internal { +const haswell::implementation haswell_singleton{}; +const westmere::implementation westmere_singleton{}; +constexpr const std::initializer_list available_implementation_pointers { &haswell_singleton, &westmere_singleton }; } #endif @@ -23,19 +23,20 @@ namespace simdjson { #include "arm64/implementation.h" -namespace simdjson { - const arm64::implementation arm64_singleton{}; - constexpr const std::initializer_list available_implementation_pointers { &arm64_singleton }; +namespace simdjson::internal { +const arm64::implementation arm64_singleton{}; +constexpr const std::initializer_list available_implementation_pointers { &arm64_singleton }; } #endif -namespace simdjson { + +namespace simdjson::internal { // So we can return UNSUPPORTED_ARCHITECTURE from the parser when there is no support class unsupported_implementation final : public implementation { public: - WARN_UNUSED virtual error_code parse(const uint8_t *, size_t, document::parser &) const noexcept final { + WARN_UNUSED error_code parse(const uint8_t *, size_t, document::parser &) const noexcept final { return UNSUPPORTED_ARCHITECTURE; } WARN_UNUSED error_code stage1(const uint8_t *, size_t, document::parser &, bool) const noexcept final { @@ -53,21 +54,19 @@ public: const unsupported_implementation unsupported_singleton{}; -namespace internal { - size_t available_implementation_list::size() const noexcept { - return available_implementation_pointers.size(); + return internal::available_implementation_pointers.size(); } const implementation * const *available_implementation_list::begin() const noexcept { - return available_implementation_pointers.begin(); + return internal::available_implementation_pointers.begin(); } const implementation * const *available_implementation_list::end() const noexcept { - return available_implementation_pointers.end(); + return internal::available_implementation_pointers.end(); } const implementation *available_implementation_list::detect_best_supported() const noexcept { // They are prelisted in priority order, so we just go down the list uint32_t supported_instruction_sets = detect_supported_architectures(); - for (const implementation *impl : available_implementation_pointers) { + for (const implementation *impl : internal::available_implementation_pointers) { uint32_t required_instruction_sets = impl->required_instruction_sets(); if ((supported_instruction_sets & required_instruction_sets) == required_instruction_sets) { return impl; } } @@ -78,6 +77,4 @@ const implementation *detect_best_supported_implementation_on_first_use::set_bes return active_implementation = available_implementations.detect_best_supported(); } -} // namespace simdjson::internal - } // namespace simdjson diff --git a/include/simdjson/isadetection.h b/src/isadetection.h similarity index 98% rename from include/simdjson/isadetection.h rename to src/isadetection.h index 328df291..c881c85f 100644 --- a/include/simdjson/isadetection.h +++ b/src/isadetection.h @@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE. #endif namespace simdjson { + // Can be found on Intel ISA Reference for CPUID constexpr uint32_t cpuid_avx2_bit = 1 << 5; // Bit 5 of EBX for EAX=0x7 constexpr uint32_t cpuid_bmi1_bit = 1 << 3; // bit 3 of EBX for EAX=0x7 @@ -148,5 +149,7 @@ static inline uint32_t detect_supported_architectures() { } #endif // end SIMD extension detection code -} // namespace simdjson -#endif + +} // namespace simdjson::internal + +#endif // SIMDJSON_ISADETECTION_H diff --git a/src/westmere/implementation.h b/src/westmere/implementation.h index b6b8c681..a992152c 100644 --- a/src/westmere/implementation.h +++ b/src/westmere/implementation.h @@ -6,7 +6,7 @@ #ifdef IS_X86_64 #include "simdjson/implementation.h" -#include "simdjson/isadetection.h" +#include "isadetection.h" namespace simdjson::westmere {