From 4e944a9f3c8a010211c760643952b8527ffb0673 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 24 Jul 2020 17:20:18 -0700 Subject: [PATCH] Eliminate unused functions in fallback --- src/arm64/bitmanipulation.h | 2 ++ src/arm64/dom_parser_implementation.cpp | 2 +- src/fallback/bitmanipulation.h | 10 ++++-- src/generic/stage1/find_next_document_index.h | 21 ------------ src/generic/stage1/json_scanner.h | 13 -------- src/generic/stage1/json_structural_indexer.h | 21 ++++++++++++ src/generic/stage2/jsoncharutils.h | 10 ------ src/haswell/bitmanipulation.h | 2 ++ src/haswell/dom_parser_implementation.cpp | 2 +- src/jsoncharutils_tables.h | 32 ------------------- src/westmere/bitmanipulation.h | 2 ++ src/westmere/dom_parser_implementation.cpp | 2 +- 12 files changed, 37 insertions(+), 82 deletions(-) diff --git a/src/arm64/bitmanipulation.h b/src/arm64/bitmanipulation.h index 4df7d60d8..e0d380e7e 100644 --- a/src/arm64/bitmanipulation.h +++ b/src/arm64/bitmanipulation.h @@ -55,6 +55,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *resu #endif } +#if 0 // Currently unused really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { #ifdef SIMDJSON_REGULAR_VISUAL_STUDIO *result = value1 * value2; @@ -63,6 +64,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu return __builtin_umulll_overflow(value1, value2, (unsigned long long *)result); #endif } +#endif // Currently unused } // namespace arm64 } // namespace { diff --git a/src/arm64/dom_parser_implementation.cpp b/src/arm64/dom_parser_implementation.cpp index 7a964044d..d64103013 100644 --- a/src/arm64/dom_parser_implementation.cpp +++ b/src/arm64/dom_parser_implementation.cpp @@ -80,7 +80,7 @@ really_inline bool is_ascii(const simd8x64& input) { return bits.max() < 0b10000000u; } -really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { +UNUSED really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { simd8 is_second_byte = prev1 >= uint8_t(0b11000000u); simd8 is_third_byte = prev2 >= uint8_t(0b11100000u); simd8 is_fourth_byte = prev3 >= uint8_t(0b11110000u); diff --git a/src/fallback/bitmanipulation.h b/src/fallback/bitmanipulation.h index e1e96d712..ab223bb3f 100644 --- a/src/fallback/bitmanipulation.h +++ b/src/fallback/bitmanipulation.h @@ -24,9 +24,10 @@ 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. +// +// These are currently unused, but one day will be. +// +#if 0 // Currently unused NO_SANITIZE_UNDEFINED really_inline int trailing_zeroes(uint64_t input_num) { #ifdef _MSC_VER @@ -44,6 +45,7 @@ really_inline int trailing_zeroes(uint64_t input_num) { really_inline uint64_t clear_lowest_bit(uint64_t input_num) { return input_num & (input_num-1); } +#endif // Currently unused /* result might be undefined when input_num is zero */ really_inline int leading_zeroes(uint64_t input_num) { @@ -60,6 +62,7 @@ really_inline int leading_zeroes(uint64_t input_num) { #endif// _MSC_VER } +#if 0 // Currently unused really_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { *result = value1 + value2; return *result < value1; @@ -70,6 +73,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, uint64_t *resu // TODO there must be a faster way return value2 > 0 && value1 > std::numeric_limits::max() / value2; } +#endif // Currently unused } // namespace fallback } // namespace { diff --git a/src/generic/stage1/find_next_document_index.h b/src/generic/stage1/find_next_document_index.h index f1b51d63e..176a76a51 100644 --- a/src/generic/stage1/find_next_document_index.h +++ b/src/generic/stage1/find_next_document_index.h @@ -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 { diff --git a/src/generic/stage1/json_scanner.h b/src/generic/stage1/json_scanner.h index a8b0b17ea..3338ab135 100644 --- a/src/generic/stage1/json_scanner.h +++ b/src/generic/stage1/json_scanner.h @@ -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) // { * } -// -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& in) { json_string_block strings = string_scanner.next(in); json_character_block characters = json_character_block::classify(in); diff --git a/src/generic/stage1/json_structural_indexer.h b/src/generic/stage1/json_structural_indexer.h index b887eea41..0a4a2298b 100644 --- a/src/generic/stage1/json_structural_indexer.h +++ b/src/generic/stage1/json_structural_indexer.h @@ -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: diff --git a/src/generic/stage2/jsoncharutils.h b/src/generic/stage2/jsoncharutils.h index 6d7c1167b..1c0419ee6 100644 --- a/src/generic/stage2/jsoncharutils.h +++ b/src/generic/stage2/jsoncharutils.h @@ -2,22 +2,12 @@ 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]; } diff --git a/src/haswell/bitmanipulation.h b/src/haswell/bitmanipulation.h index 8e22b7d8d..e7b0769c4 100644 --- a/src/haswell/bitmanipulation.h +++ b/src/haswell/bitmanipulation.h @@ -53,6 +53,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, #endif } +#if 0 // Currently unused #if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS) #pragma intrinsic(_umul128) #endif @@ -67,6 +68,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, (unsigned long long *)result); #endif } +#endif // Currently unused } // namespace SIMDJSON_IMPLEMENTATION } // namespace { diff --git a/src/haswell/dom_parser_implementation.cpp b/src/haswell/dom_parser_implementation.cpp index 68fa6aa6e..39cafef1e 100644 --- a/src/haswell/dom_parser_implementation.cpp +++ b/src/haswell/dom_parser_implementation.cpp @@ -49,7 +49,7 @@ really_inline bool is_ascii(const simd8x64& input) { return input.reduce_or().is_ascii(); } -really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { +UNUSED really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { simd8 is_second_byte = prev1.saturating_sub(0b11000000u-1); // Only 11______ will be > 0 simd8 is_third_byte = prev2.saturating_sub(0b11100000u-1); // Only 111_____ will be > 0 simd8 is_fourth_byte = prev3.saturating_sub(0b11110000u-1); // Only 1111____ will be > 0 diff --git a/src/jsoncharutils_tables.h b/src/jsoncharutils_tables.h index 365ef4156..afa1ebe51 100644 --- a/src/jsoncharutils_tables.h +++ b/src/jsoncharutils_tables.h @@ -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, diff --git a/src/westmere/bitmanipulation.h b/src/westmere/bitmanipulation.h index 928dbfd18..d221f971b 100644 --- a/src/westmere/bitmanipulation.h +++ b/src/westmere/bitmanipulation.h @@ -62,6 +62,7 @@ really_inline bool add_overflow(uint64_t value1, uint64_t value2, #endif } +#if 0 // Currently unused #if defined(SIMDJSON_REGULAR_VISUAL_STUDIO) || defined(SIMDJSON_IS_32BITS) #pragma intrinsic(_umul128) #endif @@ -76,6 +77,7 @@ really_inline bool mul_overflow(uint64_t value1, uint64_t value2, (unsigned long long *)result); #endif } +#endif // Currently unused } // namespace SIMDJSON_IMPLEMENTATION } // namespace { diff --git a/src/westmere/dom_parser_implementation.cpp b/src/westmere/dom_parser_implementation.cpp index 1f561c216..f15f67234 100644 --- a/src/westmere/dom_parser_implementation.cpp +++ b/src/westmere/dom_parser_implementation.cpp @@ -54,7 +54,7 @@ really_inline bool is_ascii(const simd8x64& input) { return input.reduce_or().is_ascii(); } -really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { +UNUSED really_inline simd8 must_be_continuation(const simd8 prev1, const simd8 prev2, const simd8 prev3) { simd8 is_second_byte = prev1.saturating_sub(0b11000000u-1); // Only 11______ will be > 0 simd8 is_third_byte = prev2.saturating_sub(0b11100000u-1); // Only 111_____ will be > 0 simd8 is_fourth_byte = prev3.saturating_sub(0b11110000u-1); // Only 1111____ will be > 0