Mark jsonformatutils.h/isadetection.h internal

- Move jsonformatutils.h to internal/jsonformatutils.h (it is used by
document::print_json)
- Move isadetection.h to src/ (it is only used internally)
This commit is contained in:
John Keiser 2020-03-03 15:53:41 -08:00
parent f58a5d534e
commit eb147d9868
13 changed files with 42 additions and 47 deletions

View File

@ -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_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_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_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) 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) ifeq ($(SIMDJSON_TEST_AMALGAMATED_HEADERS),1)
HEADERS=singleheader/simdjson.h HEADERS=singleheader/simdjson.h

View File

@ -8,8 +8,7 @@ set(SIMDJSON_INCLUDE
${SIMDJSON_INCLUDE_DIR}/simdjson/implementation.h ${SIMDJSON_INCLUDE_DIR}/simdjson/implementation.h
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document.h ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document.h
${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_iterator.h ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_iterator.h
${SIMDJSON_INCLUDE_DIR}/simdjson/isadetection.h ${SIMDJSON_INCLUDE_DIR}/simdjson/internal/jsonformatutils.h
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonformatutils.h
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonioutil.h ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonioutil.h
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonminifier.h ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonminifier.h
${SIMDJSON_INCLUDE_DIR}/simdjson/jsonparser.h ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonparser.h

View File

@ -9,7 +9,7 @@
#include <stdexcept> #include <stdexcept>
#include "simdjson/document.h" #include "simdjson/document.h"
#include "simdjson/jsonformatutils.h" #include "simdjson/internal/jsonformatutils.h"
namespace simdjson { namespace simdjson {

View File

@ -1,15 +1,13 @@
#ifndef SIMDJSON_INLINE_DOCUMENT_H #ifndef SIMDJSON_INLINE_DOCUMENT_H
#define SIMDJSON_INLINE_DOCUMENT_H #define SIMDJSON_INLINE_DOCUMENT_H
// Inline implementations go in here.
// 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.
#include "simdjson/document.h" #include "simdjson/document.h"
#include "simdjson/implementation.h" #include "simdjson/implementation.h"
#include "simdjson/jsonformatutils.h" #include "simdjson/internal/jsonformatutils.h"
#include <iostream> #include <iostream>
namespace simdjson { 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 case '"': // we have a string
os << '"'; os << '"';
memcpy(&string_length, string_buf.get() + payload, sizeof(uint32_t)); 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)), (const unsigned char *)(string_buf.get() + payload + sizeof(uint32_t)),
os, string_length); os, string_length);
os << '"'; os << '"';
@ -368,7 +366,7 @@ inline bool document::dump_raw_tape(std::ostream &os) const noexcept {
case '"': // we have a string case '"': // we have a string
os << "string \""; os << "string \"";
memcpy(&string_length, string_buf.get() + payload, sizeof(uint32_t)); 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)), (const unsigned char *)(string_buf.get() + payload + sizeof(uint32_t)),
os, os,
string_length); string_length);

View File

@ -276,7 +276,7 @@ bool document_iterator<max_depth>::print(std::ostream &os, bool escape_strings)
case '"': // we have a string case '"': // we have a string
os << '"'; os << '"';
if (escape_strings) { if (escape_strings) {
print_with_escapes(get_string(), os, get_string_length()); internal::print_with_escapes(get_string(), os, get_string_length());
} else { } else {
// was: os << get_string();, but given that we can include null chars, we // was: os << get_string();, but given that we can include null chars, we
// have to do something crazier: // have to do something crazier:

View File

@ -1,15 +1,13 @@
#ifndef SIMDJSON_JSONFORMATUTILS_H #ifndef SIMDJSON_INTERNAL_JSONFORMATUTILS_H
#define SIMDJSON_JSONFORMATUTILS_H #define SIMDJSON_INTERNAL_JSONFORMATUTILS_H
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
namespace simdjson { namespace simdjson::internal {
// ends with zero char // ends with zero char
static inline void print_with_escapes(const unsigned char *src, static inline void print_with_escapes(const unsigned char *src, std::ostream &os) {
std::ostream &os) {
while (*src) { while (*src) {
switch (*src) { switch (*src) {
case '\b': case '\b':
@ -107,10 +105,10 @@ static inline void print_with_escapes(const char *src, std::ostream &os) {
print_with_escapes(reinterpret_cast<const unsigned char *>(src), os); print_with_escapes(reinterpret_cast<const unsigned char *>(src), os);
} }
static inline void print_with_escapes(const char *src, std::ostream &os, static inline void print_with_escapes(const char *src, std::ostream &os, size_t len) {
size_t len) {
print_with_escapes(reinterpret_cast<const unsigned char *>(src), os, len); print_with_escapes(reinterpret_cast<const unsigned char *>(src), os, len);
} }
} // namespace simdjson
#endif } // namespace simdjson::internal
#endif // SIMDJSON_INTERNAL_JSONFORMATUTILS_H

View File

@ -5,7 +5,6 @@
#include <limits> #include <limits>
#include <stdexcept> #include <stdexcept>
#include <thread> #include <thread>
#include "simdjson/isadetection.h"
#include "simdjson/padded_string.h" #include "simdjson/padded_string.h"
#include "simdjson/simdjson.h" #include "simdjson/simdjson.h"
#include "jsoncharutils.h" #include "jsoncharutils.h"

View File

@ -29,6 +29,7 @@ set(SIMDJSON_SRC
set(SIMDJSON_SRC_HEADERS set(SIMDJSON_SRC_HEADERS
error.cpp error.cpp
implementation.cpp implementation.cpp
isadetection.h
jsoncharutils.h jsoncharutils.h
jsonioutil.cpp jsonioutil.cpp
jsonminifier.cpp jsonminifier.cpp

View File

@ -6,7 +6,7 @@
#ifdef IS_ARM64 #ifdef IS_ARM64
#include "simdjson/implementation.h" #include "simdjson/implementation.h"
#include "simdjson/isadetection.h" #include "isadetection.h"
namespace simdjson::arm64 { namespace simdjson::arm64 {

View File

@ -6,7 +6,7 @@
#ifdef IS_X86_64 #ifdef IS_X86_64
#include "simdjson/implementation.h" #include "simdjson/implementation.h"
#include "simdjson/isadetection.h" #include "isadetection.h"
namespace simdjson::haswell { namespace simdjson::haswell {

View File

@ -1,5 +1,5 @@
#include "simdjson/portability.h" #include "simdjson/portability.h"
#include "simdjson/isadetection.h" #include "isadetection.h"
#include "simdjson/implementation.h" #include "simdjson/implementation.h"
#include <initializer_list> #include <initializer_list>
@ -11,10 +11,10 @@
#include "haswell/implementation.h" #include "haswell/implementation.h"
#include "westmere/implementation.h" #include "westmere/implementation.h"
namespace simdjson { namespace simdjson::internal {
const haswell::implementation haswell_singleton{}; const haswell::implementation haswell_singleton{};
const westmere::implementation westmere_singleton{}; const westmere::implementation westmere_singleton{};
constexpr const std::initializer_list<const implementation *> available_implementation_pointers { &haswell_singleton, &westmere_singleton }; constexpr const std::initializer_list<const implementation *> available_implementation_pointers { &haswell_singleton, &westmere_singleton };
} }
#endif #endif
@ -23,19 +23,20 @@ namespace simdjson {
#include "arm64/implementation.h" #include "arm64/implementation.h"
namespace simdjson { namespace simdjson::internal {
const arm64::implementation arm64_singleton{}; const arm64::implementation arm64_singleton{};
constexpr const std::initializer_list<const implementation *> available_implementation_pointers { &arm64_singleton }; constexpr const std::initializer_list<const implementation *> available_implementation_pointers { &arm64_singleton };
} }
#endif #endif
namespace simdjson {
namespace simdjson::internal {
// So we can return UNSUPPORTED_ARCHITECTURE from the parser when there is no support // So we can return UNSUPPORTED_ARCHITECTURE from the parser when there is no support
class unsupported_implementation final : public implementation { class unsupported_implementation final : public implementation {
public: 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; return UNSUPPORTED_ARCHITECTURE;
} }
WARN_UNUSED error_code stage1(const uint8_t *, size_t, document::parser &, bool) const noexcept final { 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{}; const unsupported_implementation unsupported_singleton{};
namespace internal {
size_t available_implementation_list::size() const noexcept { 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 { 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 { 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 { const implementation *available_implementation_list::detect_best_supported() const noexcept {
// They are prelisted in priority order, so we just go down the list // They are prelisted in priority order, so we just go down the list
uint32_t supported_instruction_sets = detect_supported_architectures(); 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(); uint32_t required_instruction_sets = impl->required_instruction_sets();
if ((supported_instruction_sets & required_instruction_sets) == required_instruction_sets) { return impl; } 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(); return active_implementation = available_implementations.detect_best_supported();
} }
} // namespace simdjson::internal
} // namespace simdjson } // namespace simdjson

View File

@ -55,6 +55,7 @@ POSSIBILITY OF SUCH DAMAGE.
#endif #endif
namespace simdjson { namespace simdjson {
// Can be found on Intel ISA Reference for CPUID // 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_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 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 #endif // end SIMD extension detection code
} // namespace simdjson
#endif } // namespace simdjson::internal
#endif // SIMDJSON_ISADETECTION_H

View File

@ -6,7 +6,7 @@
#ifdef IS_X86_64 #ifdef IS_X86_64
#include "simdjson/implementation.h" #include "simdjson/implementation.h"
#include "simdjson/isadetection.h" #include "isadetection.h"
namespace simdjson::westmere { namespace simdjson::westmere {