Merge pull request #1065 from simdjson/jkeiser/anonymous-namespace

[1/3] Wrap simdjson kernels in anonymous namespaces
This commit is contained in:
John Keiser 2020-08-02 11:37:11 -07:00 committed by GitHub
commit 9cc7a94a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
56 changed files with 224 additions and 309 deletions

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_ARM64_BITMANIPULATION_H
#define SIMDJSON_ARM64_BITMANIPULATION_H
namespace simdjson {
namespace {
namespace arm64 {
// We sometimes call trailing_zero on inputs that are zero,
@ -55,16 +55,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *resu
#endif
}
really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
*result = value1 * value2;
return !!__umulh(value1, value2);
#else
return __builtin_umulll_overflow(value1, value2, (unsigned long long *)result);
#endif
}
} // namespace arm64
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_ARM64_BITMANIPULATION_H

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_ARM64_BITMASK_H
#define SIMDJSON_ARM64_BITMASK_H
namespace simdjson {
namespace {
namespace arm64 {
//

View File

@ -5,7 +5,7 @@
//
// Stage 1
//
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
using namespace simd;
@ -80,7 +80,7 @@ really_inline bool is_ascii(const simd8x64<uint8_t>& input) {
return bits.max() < 0b10000000u;
}
really_inline simd8<bool> must_be_continuation(const simd8<uint8_t> prev1, const simd8<uint8_t> prev2, const simd8<uint8_t> prev3) {
UNUSED really_inline simd8<bool> must_be_continuation(const simd8<uint8_t> prev1, const simd8<uint8_t> prev2, const simd8<uint8_t> prev3) {
simd8<bool> is_second_byte = prev1 >= uint8_t(0b11000000u);
simd8<bool> is_third_byte = prev2 >= uint8_t(0b11100000u);
simd8<bool> is_fourth_byte = prev3 >= uint8_t(0b11110000u);
@ -99,7 +99,7 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "generic/stage1/utf8_lookup4_algorithm.h"
#include "generic/stage1/json_structural_indexer.h"
@ -116,9 +116,8 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
//
// Implementation-specific overrides
//
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) {
@ -141,7 +140,24 @@ 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);
return arm64::stage1::generic_validate_utf8(buf,len);
}
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
error_code result = stage2::parse_structurals<false>(*this, _doc);
if (result) { return result; }
// If we didn't make it to the end, it's an error
if ( next_structural_index != n_structural_indexes ) {
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
return error = TAPE_ERROR;
}
return SUCCESS;
}
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
return stage2::parse_structurals<true>(*this, _doc);
}
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {
@ -151,6 +167,6 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "arm64/end_implementation.h"

View File

@ -1,7 +1,7 @@
#include "arm64/begin_implementation.h"
#include "arm64/dom_parser_implementation.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
WARN_UNUSED error_code implementation::create_dom_parser_implementation(
@ -17,6 +17,6 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation(
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "arm64/end_implementation.h"

View File

@ -4,9 +4,10 @@
#include "simdjson.h"
#include "isadetection.h"
namespace simdjson {
namespace {
namespace arm64 {
using namespace simdjson;
using namespace simdjson::dom;
class implementation final : public simdjson::implementation {
@ -22,6 +23,6 @@ public:
};
} // namespace arm64
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_ARM64_IMPLEMENTATION_H

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_ARM64_NUMBERPARSING_H
#define SIMDJSON_ARM64_NUMBERPARSING_H
namespace simdjson {
namespace {
namespace arm64 {
// we don't have SSE, so let us use a scalar function
@ -15,7 +15,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars)
}
} // namespace arm64
} // namespace simdjson
} // namespace {
#define SWAR_NUMBER_PARSING

View File

@ -7,7 +7,7 @@
#include <type_traits>
namespace simdjson {
namespace {
namespace arm64 {
namespace simd {
@ -495,6 +495,6 @@ really_inline int8x16_t make_int8x16_t(int8_t x1, int8_t x2, int8_t x3, int8_
} // namespace simd
} // namespace arm64
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_ARM64_SIMD_H

View File

@ -5,7 +5,7 @@
#include "arm64/simd.h"
#include "arm64/bitmanipulation.h"
namespace simdjson {
namespace {
namespace arm64 {
using namespace simd;
@ -44,7 +44,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8
}
} // namespace arm64
} // namespace simdjson
} // namespace {
#include "generic/stage2/stringparsing.h"

View File

@ -4,7 +4,7 @@
#include "simdjson.h"
#include <limits>
namespace simdjson {
namespace {
namespace fallback {
#if defined(_MSC_VER) && !defined(_M_ARM64) && !defined(_M_X64)
@ -24,27 +24,6 @@ static unsigned char _BitScanReverse64(unsigned long* ret, uint64_t x) {
}
#endif
// We sometimes call trailing_zero on inputs that are zero,
// but the algorithms do not end up using the returned value.
// Sadly, sanitizers are not smart enough to figure it out.
NO_SANITIZE_UNDEFINED
really_inline int trailing_zeroes(uint64_t input_num) {
#ifdef _MSC_VER
unsigned long ret;
// Search the mask data from least significant bit (LSB)
// to the most significant bit (MSB) for a set bit (1).
_BitScanForward64(&ret, input_num);
return (int)ret;
#else // _MSC_VER
return __builtin_ctzll(input_num);
#endif // _MSC_VER
}
/* result might be undefined when input_num is zero */
really_inline uint64_t clear_lowest_bit(uint64_t input_num) {
return input_num & (input_num-1);
}
/* result might be undefined when input_num is zero */
really_inline int leading_zeroes(uint64_t input_num) {
#ifdef _MSC_VER
@ -60,18 +39,7 @@ really_inline int leading_zeroes(uint64_t input_num) {
#endif// _MSC_VER
}
really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
*result = value1 + value2;
return *result < value1;
}
really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
*result = value1 * value2;
// TODO there must be a faster way
return value2 > 0 && value1 > std::numeric_limits<uint64_t>::max() / value2;
}
} // namespace fallback
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_FALLBACK_BITMANIPULATION_H

View File

@ -7,7 +7,7 @@
//
#include "generic/stage1/find_next_document_index.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
@ -308,7 +308,7 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
//
// Stage 2
@ -317,9 +317,26 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
#include "fallback/numberparsing.h"
#include "generic/stage2/structural_parser.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
error_code result = stage2::parse_structurals<false>(*this, _doc);
if (result) { return result; }
// If we didn't make it to the end, it's an error
if ( next_structural_index != n_structural_indexes ) {
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
return error = TAPE_ERROR;
}
return SUCCESS;
}
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
return stage2::parse_structurals<true>(*this, _doc);
}
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {
error_code err = stage1(_buf, _len, false);
if (err) { return err; }
@ -327,6 +344,6 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "fallback/end_implementation.h"

View File

@ -1,7 +1,7 @@
#include "fallback/begin_implementation.h"
#include "fallback/dom_parser_implementation.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
WARN_UNUSED error_code implementation::create_dom_parser_implementation(
@ -17,6 +17,6 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation(
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "fallback/end_implementation.h"

View File

@ -4,9 +4,10 @@
#include "simdjson.h"
#include "isadetection.h"
namespace simdjson {
namespace {
namespace fallback {
using namespace simdjson;
using namespace simdjson::dom;
class implementation final : public simdjson::implementation {
@ -26,6 +27,6 @@ public:
};
} // namespace fallback
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_FALLBACK_IMPLEMENTATION_H

View File

@ -8,7 +8,7 @@ void found_unsigned_integer(uint64_t result, const uint8_t *buf);
void found_float(double result, const uint8_t *buf);
#endif
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
static really_inline uint32_t parse_eight_digits_unrolled(const char *chars) {
uint32_t result = 0;
@ -22,7 +22,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars)
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#define SWAR_NUMBER_PARSING
#include "generic/stage2/numberparsing.h"

View File

@ -3,7 +3,7 @@
#include "simdjson.h"
namespace simdjson {
namespace {
namespace fallback {
// Holds backslashes and quotes locations.
@ -27,7 +27,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8
}
} // namespace fallback
} // namespace simdjson
} // namespace {
#include "generic/stage2/stringparsing.h"

View File

@ -1,7 +1,7 @@
#include "simdjson.h"
#include "isadetection.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
// expectation: sizeof(scope_descriptor) = 64/8.
@ -45,12 +45,12 @@ public:
};
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "generic/stage1/allocate.h"
#include "generic/stage2/allocate.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
really_inline dom_parser_implementation::dom_parser_implementation() {}
@ -71,4 +71,4 @@ WARN_UNUSED error_code dom_parser_implementation::set_max_depth(size_t max_depth
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
namespace allocate {
@ -18,4 +18,4 @@ really_inline error_code set_capacity(internal::dom_parser_implementation &parse
} // namespace allocate
} // namespace stage1
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
// Walks through a buffer in block-sized increments, loading the last part with spaces
@ -86,4 +86,4 @@ really_inline void buf_block_reader<STEP_SIZE>::advance() {
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
/**
@ -67,26 +67,5 @@ really_inline uint32_t find_next_document_index(dom_parser_implementation &parse
return 0;
}
// Skip the last character if it is partial
really_inline size_t trim_partial_utf8(const uint8_t *buf, size_t len) {
if (unlikely(len < 3)) {
switch (len) {
case 2:
if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left
if (buf[len-2] >= 0b11100000) { return len-2; } // 3- and 4-byte characters with only 2 bytes left
return len;
case 1:
if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left
return len;
case 0:
return len;
}
}
if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left
if (buf[len-2] >= 0b11100000) { return len-2; } // 3- and 4-byte characters with only 1 byte left
if (buf[len-3] >= 0b11110000) { return len-3; } // 4-byte characters with only 3 bytes left
return len;
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -3,7 +3,7 @@
// We assume the file in which it is included already includes
// "simdjson/stage1.h" (this simplifies amalgation)
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
@ -78,4 +78,4 @@ error_code json_minifier::minify(const uint8_t *buf, size_t len, uint8_t *dst, s
} // namespace stage1
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
@ -75,19 +75,6 @@ really_inline uint64_t follows(const uint64_t match, uint64_t &overflow) {
return result;
}
//
// Check if the current character follows a matching character, with possible "filler" between.
// For example, this checks for empty curly braces, e.g.
//
// in.eq('}') & follows(in.eq('['), in.eq(' '), prev_empty_array) // { <whitespace>* }
//
really_inline uint64_t follows(const uint64_t match, const uint64_t filler, uint64_t &overflow) {
uint64_t follows_match = follows(match, overflow);
uint64_t result;
overflow |= uint64_t(add_overflow(follows_match, filler, &result));
return result;
}
really_inline json_block json_scanner::next(const simd::simd8x64<uint8_t>& in) {
json_string_block strings = string_scanner.next(in);
json_character_block characters = json_character_block::classify(in);
@ -105,4 +92,4 @@ really_inline error_code json_scanner::finish(bool streaming) {
} // namespace stage1
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
@ -140,4 +140,4 @@ really_inline error_code json_string_scanner::finish(bool streaming) {
} // namespace stage1
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -9,7 +9,7 @@
#include "generic/stage1/json_minifier.h"
#include "generic/stage1/find_next_document_index.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
@ -91,6 +91,27 @@ private:
really_inline json_structural_indexer::json_structural_indexer(uint32_t *structural_indexes) : indexer{structural_indexes} {}
// Skip the last character if it is partial
really_inline size_t trim_partial_utf8(const uint8_t *buf, size_t len) {
if (unlikely(len < 3)) {
switch (len) {
case 2:
if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left
if (buf[len-2] >= 0b11100000) { return len-2; } // 3- and 4-byte characters with only 2 bytes left
return len;
case 1:
if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left
return len;
case 0:
return len;
}
}
if (buf[len-1] >= 0b11000000) { return len-1; } // 2-, 3- and 4-byte characters with only 1 byte left
if (buf[len-2] >= 0b11100000) { return len-2; } // 3- and 4-byte characters with only 1 byte left
if (buf[len-3] >= 0b11110000) { return len-3; } // 4-byte characters with only 3 bytes left
return len;
}
//
// PERF NOTES:
// We pipe 2 inputs through these stages:
@ -205,4 +226,4 @@ really_inline error_code json_structural_indexer::finish(dom_parser_implementati
} // namespace stage1
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -181,4 +181,4 @@ struct utf8_checker {
}; // struct utf8_checker
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,5 +1,6 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace utf8_validation {
//
// Detect Unicode errors.
@ -66,7 +67,6 @@ namespace SIMDJSON_IMPLEMENTATION {
//
using namespace simd;
namespace utf8_validation {
// For a detailed description of the lookup2 algorithm, see the file HACKING.md under "UTF-8 validation (lookup2)".
//
@ -216,7 +216,8 @@ namespace utf8_validation {
}
}; // struct utf8_checker
}
} // namespace utf8_validation
} // namespace {
using utf8_validation::utf8_checker;

View File

@ -1,5 +1,6 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace utf8_validation {
//
// Detect Unicode errors.
@ -66,7 +67,6 @@ namespace SIMDJSON_IMPLEMENTATION {
//
using namespace simd;
namespace utf8_validation {
// For a detailed description of the lookup2 algorithm, see the file HACKING.md under "UTF-8 validation (lookup2)".
//
@ -236,7 +236,8 @@ namespace utf8_validation {
}
}; // struct utf8_checker
}
} // namespace utf8_validation
} // namespace {
using utf8_validation::utf8_checker;

View File

@ -1,6 +1,5 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace utf8_validation {
using namespace simd;
@ -179,4 +178,4 @@ using namespace simd;
using utf8_validation::utf8_checker;
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,5 +1,6 @@
namespace simdjson {
namespace SIMDJSON_IMPLEMENTATION {
namespace utf8_validation {
//
// Detect Unicode errors.
@ -66,10 +67,6 @@ namespace SIMDJSON_IMPLEMENTATION {
//
using namespace simd;
namespace utf8_validation {
} // namespace utf8_validation
struct utf8_checker {
// If this is nonzero, there has been a UTF-8 error.
simd8<uint8_t> error;
@ -301,5 +298,6 @@ struct utf8_checker {
}; // struct utf8_checker
} // namespace utf8_validation
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -183,4 +183,4 @@ struct utf8_checker {
}; // struct utf8_checker
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
@ -28,4 +28,4 @@ bool generic_validate_utf8(const char * input, size_t length) {
} // namespace stage1
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -362,4 +362,4 @@ struct utf8_checker {
}; // struct utf8_checker
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage2 {
namespace allocate {
@ -19,4 +19,4 @@ really_inline error_code set_max_depth(dom_parser_implementation &parser, size_t
} // namespace allocate
} // namespace stage2
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,9 +1,8 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage2 {
namespace atomparsing {
namespace{
// The string_to_uint32 is exclusively used to map literal strings to 32-bit values.
// We use memcpy instead of a pointer cast to avoid undefined behaviors since we cannot
// be certain that the character pointer will be properly aligned.
@ -22,7 +21,6 @@ really_inline uint32_t str4ncmp(const uint8_t *src, const char* atom) {
std::memcpy(&srcval, src, sizeof(uint32_t));
return srcval ^ string_to_uint32(atom);
}
} // anonymous namespace
WARN_UNUSED
really_inline bool is_valid_true_atom(const uint8_t *src) {
@ -63,4 +61,4 @@ really_inline bool is_valid_null_atom(const uint8_t *src, size_t len) {
} // namespace atomparsing
} // namespace stage2
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,23 +1,13 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage2 {
// return non-zero if not a structural or whitespace char
// zero otherwise
really_inline uint32_t is_not_structural_or_whitespace_or_null(uint8_t c) {
return structural_or_whitespace_or_null_negated[c];
}
// return non-zero if not a structural or whitespace char
// zero otherwise
really_inline uint32_t is_not_structural_or_whitespace(uint8_t c) {
return structural_or_whitespace_negated[c];
}
really_inline uint32_t is_structural_or_whitespace_or_null(uint8_t c) {
return structural_or_whitespace_or_null[c];
}
really_inline uint32_t is_structural_or_whitespace(uint8_t c) {
return structural_or_whitespace[c];
}
@ -116,4 +106,4 @@ really_inline value128 full_multiplication(uint64_t value1, uint64_t value2) {
} // namespace stage2
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,8 +1,9 @@
// This is for an internal-only stage 2 specific logger.
// Set LOG_ENABLED = true to log what stage 2 is doing!
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace logger {
static constexpr const char * DASHES = "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------";
static constexpr const bool LOG_ENABLED = false;
@ -62,6 +63,7 @@ namespace logger {
printf("|\n");
}
}
} // namespace logger
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,7 +1,7 @@
#include <cmath>
#include <limits>
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage2 {
namespace numberparsing {
@ -505,4 +505,4 @@ really_inline bool parse_number(const uint8_t *const src, W &writer) {
} // namespace numberparsing
} // namespace stage2
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,7 +1,7 @@
// This file contains the common code every implementation uses
// It is intended to be included multiple times and compiled multiple times
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage2 {
namespace stringparsing {
@ -122,4 +122,4 @@ WARN_UNUSED really_inline uint8_t *parse_string(const uint8_t *src, uint8_t *dst
} // namespace stringparsing
} // namespace stage2
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage2 {
@ -47,4 +47,4 @@ public:
} // namespace stage2
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -8,12 +8,10 @@
#include "generic/stage2/atomparsing.h"
#include "generic/stage2/structural_iterator.h"
namespace simdjson {
namespace { // Make everything here private
namespace SIMDJSON_IMPLEMENTATION {
namespace stage2 {
namespace { // Make everything here private
#ifdef SIMDJSON_USE_COMPUTED_GOTO
#define INIT_ADDRESSES() { &&array_begin, &&array_continue, &&error, &&finish, &&object_begin, &&object_continue }
#define GOTO(address) { goto *(address); }
@ -468,33 +466,6 @@ error:
return parser.error();
}
} // namespace {}
} // namespace stage2
/************
* The JSON is parsed to a tape, see the accompanying tape.md file
* for documentation.
***********/
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
error_code result = stage2::parse_structurals<false>(*this, _doc);
if (result) { return result; }
// If we didn't make it to the end, it's an error
if ( next_structural_index != n_structural_indexes ) {
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
return error = TAPE_ERROR;
}
return SUCCESS;
}
/************
* The JSON is parsed to a tape, see the accompanying tape.md file
* for documentation.
***********/
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
return stage2::parse_structurals<true>(*this, _doc);
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,4 +1,4 @@
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage2 {
@ -100,4 +100,4 @@ really_inline void tape_writer::write(uint64_t &tape_loc, uint64_t val, internal
} // namespace stage2
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_HASWELL_BITMANIPULATION_H
#define SIMDJSON_HASWELL_BITMANIPULATION_H
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
// We sometimes call trailing_zero on inputs that are zero,
@ -53,22 +53,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
#endif
}
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
#pragma intrinsic(_umul128)
#endif
really_inline bool mul_overflow(uint64_t value1, uint64_t value2,
uint64_t *result) {
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
uint64_t high;
*result = _umul128(value1, value2, &high);
return high;
#else
return __builtin_umulll_overflow(value1, value2,
(unsigned long long *)result);
#endif
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_HASWELL_BITMANIPULATION_H

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_HASWELL_BITMASK_H
#define SIMDJSON_HASWELL_BITMASK_H
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
//
@ -18,6 +18,6 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) {
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_HASWELL_BITMASK_H

View File

@ -6,7 +6,7 @@
// Stage 1
//
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
using namespace simd;
@ -49,7 +49,7 @@ really_inline bool is_ascii(const simd8x64<uint8_t>& input) {
return input.reduce_or().is_ascii();
}
really_inline simd8<bool> must_be_continuation(const simd8<uint8_t> prev1, const simd8<uint8_t> prev2, const simd8<uint8_t> prev3) {
UNUSED really_inline simd8<bool> must_be_continuation(const simd8<uint8_t> prev1, const simd8<uint8_t> prev2, const simd8<uint8_t> prev3) {
simd8<uint8_t> is_second_byte = prev1.saturating_sub(0b11000000u-1); // Only 11______ will be > 0
simd8<uint8_t> is_third_byte = prev2.saturating_sub(0b11100000u-1); // Only 111_____ will be > 0
simd8<uint8_t> is_fourth_byte = prev3.saturating_sub(0b11110000u-1); // Only 1111____ will be > 0
@ -65,7 +65,7 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "generic/stage1/utf8_lookup4_algorithm.h"
#include "generic/stage1/json_structural_indexer.h"
@ -81,9 +81,8 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
//
// Implementation-specific overrides
//
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) {
@ -104,7 +103,24 @@ 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);
return haswell::stage1::generic_validate_utf8(buf,len);
}
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
error_code result = stage2::parse_structurals<false>(*this, _doc);
if (result) { return result; }
// If we didn't make it to the end, it's an error
if ( next_structural_index != n_structural_indexes ) {
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
return error = TAPE_ERROR;
}
return SUCCESS;
}
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
return stage2::parse_structurals<true>(*this, _doc);
}
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {
@ -114,6 +130,6 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "haswell/end_implementation.h"

View File

@ -1,7 +1,7 @@
#include "haswell/begin_implementation.h"
#include "haswell/dom_parser_implementation.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
WARN_UNUSED error_code implementation::create_dom_parser_implementation(
@ -17,7 +17,7 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation(
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "haswell/end_implementation.h"

View File

@ -5,9 +5,11 @@
#include "isadetection.h"
// The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION
namespace simdjson {
namespace {
namespace haswell {
using namespace simdjson;
class implementation final : public simdjson::implementation {
public:
really_inline implementation() : simdjson::implementation(
@ -25,6 +27,6 @@ public:
};
} // namespace haswell
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_HASWELL_IMPLEMENTATION_H

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_HASWELL_NUMBERPARSING_H
#define SIMDJSON_HASWELL_NUMBERPARSING_H
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) {
@ -23,7 +23,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars)
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#define SWAR_NUMBER_PARSING

View File

@ -3,7 +3,7 @@
#include "simdprune_tables.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace simd {
@ -349,6 +349,6 @@ namespace simd {
} // namespace simd
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_HASWELL_SIMD_H

View File

@ -5,7 +5,7 @@
#include "haswell/simd.h"
#include "haswell/bitmanipulation.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
using namespace simd;
@ -39,7 +39,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "generic/stage2/stringparsing.h"

View File

@ -15,25 +15,6 @@ namespace simdjson {
// we are also interested in the four whitespace characters
// space 0x20, linefeed 0x0a, horizontal tab 0x09 and carriage return 0x0d
// these are the chars that can follow a true/false/null or number atom
// and nothing else
const uint32_t structural_or_whitespace_or_null_negated[256] = {
0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
const uint32_t structural_or_whitespace_negated[256] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -51,19 +32,6 @@ const uint32_t structural_or_whitespace_negated[256] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
const uint32_t structural_or_whitespace_or_null[256] = {
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const uint32_t structural_or_whitespace[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_WESTMERE_BITMANIPULATION_H
#define SIMDJSON_WESTMERE_BITMANIPULATION_H
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
// We sometimes call trailing_zero on inputs that are zero,
@ -62,22 +62,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2,
#endif
}
#if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS)
#pragma intrinsic(_umul128)
#endif
really_inline bool mul_overflow(uint64_t value1, uint64_t value2,
uint64_t *result) {
#ifdef SIMDJSON_REGULAR_VISUAL_STUDIO
uint64_t high;
*result = _umul128(value1, value2, &high);
return high;
#else
return __builtin_umulll_overflow(value1, value2,
(unsigned long long *)result);
#endif
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_WESTMERE_BITMANIPULATION_H

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_WESTMERE_BITMASK_H
#define SIMDJSON_WESTMERE_BITMASK_H
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
//
@ -18,6 +18,6 @@ really_inline uint64_t prefix_xor(const uint64_t bitmask) {
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_WESTMERE_BITMASK_H

View File

@ -6,7 +6,7 @@
// Stage 1
//
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
using namespace simd;
@ -54,7 +54,7 @@ really_inline bool is_ascii(const simd8x64<uint8_t>& input) {
return input.reduce_or().is_ascii();
}
really_inline simd8<bool> must_be_continuation(const simd8<uint8_t> prev1, const simd8<uint8_t> prev2, const simd8<uint8_t> prev3) {
UNUSED really_inline simd8<bool> must_be_continuation(const simd8<uint8_t> prev1, const simd8<uint8_t> prev2, const simd8<uint8_t> prev3) {
simd8<uint8_t> is_second_byte = prev1.saturating_sub(0b11000000u-1); // Only 11______ will be > 0
simd8<uint8_t> is_third_byte = prev2.saturating_sub(0b11100000u-1); // Only 111_____ will be > 0
simd8<uint8_t> is_fourth_byte = prev3.saturating_sub(0b11110000u-1); // Only 1111____ will be > 0
@ -70,7 +70,7 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "generic/stage1/utf8_lookup4_algorithm.h"
#include "generic/stage1/json_structural_indexer.h"
@ -86,9 +86,9 @@ really_inline simd8<bool> must_be_2_3_continuation(const simd8<uint8_t> prev2, c
//
// Implementation-specific overrides
//
namespace simdjson {
namespace SIMDJSON_IMPLEMENTATION {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace stage1 {
really_inline uint64_t json_string_scanner::find_escaped(uint64_t backslash) {
@ -109,7 +109,24 @@ 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);
return westmere::stage1::generic_validate_utf8(buf,len);
}
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
error_code result = stage2::parse_structurals<false>(*this, _doc);
if (result) { return result; }
// If we didn't make it to the end, it's an error
if ( next_structural_index != n_structural_indexes ) {
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
return error = TAPE_ERROR;
}
return SUCCESS;
}
WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_doc) noexcept {
return stage2::parse_structurals<true>(*this, _doc);
}
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {
@ -119,6 +136,6 @@ WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, siz
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "westmere/end_implementation.h"

View File

@ -1,7 +1,7 @@
#include "westmere/begin_implementation.h"
#include "westmere/dom_parser_implementation.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
WARN_UNUSED error_code implementation::create_dom_parser_implementation(
@ -17,6 +17,6 @@ WARN_UNUSED error_code implementation::create_dom_parser_implementation(
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "westmere/end_implementation.h"

View File

@ -6,9 +6,10 @@
#include "isadetection.h"
// The constructor may be executed on any host, so we take care not to use SIMDJSON_TARGET_REGION
namespace simdjson {
namespace {
namespace westmere {
using namespace simdjson;
using namespace simdjson::dom;
class implementation final : public simdjson::implementation {
@ -24,6 +25,6 @@ public:
};
} // namespace westmere
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_WESTMERE_IMPLEMENTATION_H

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_WESTMERE_NUMBERPARSING_H
#define SIMDJSON_WESTMERE_NUMBERPARSING_H
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars) {
@ -23,7 +23,7 @@ static really_inline uint32_t parse_eight_digits_unrolled(const uint8_t *chars)
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#define SWAR_NUMBER_PARSING

View File

@ -3,7 +3,7 @@
#include "simdprune_tables.h"
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
namespace simd {
@ -328,6 +328,6 @@ namespace simd {
} // namespace simd
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#endif // SIMDJSON_WESTMERE_SIMD_INPUT_H

View File

@ -1,7 +1,7 @@
#ifndef SIMDJSON_WESTMERE_STRINGPARSING_H
#define SIMDJSON_WESTMERE_STRINGPARSING_H
namespace simdjson {
namespace {
namespace SIMDJSON_IMPLEMENTATION {
using namespace simd;
@ -37,7 +37,7 @@ really_inline backslash_and_quote backslash_and_quote::copy_and_find(const uint8
}
} // namespace SIMDJSON_IMPLEMENTATION
} // namespace simdjson
} // namespace {
#include "generic/stage2/stringparsing.h"