Merge pull request #16809 from kitaisreal/read-float-8digits-unroll-performance-improvement

ReadFloat 8digits unroll performance improvement
This commit is contained in:
alexey-milovidov 2020-12-14 23:03:21 +03:00 committed by GitHub
commit 91be7a6f27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -249,6 +249,19 @@ ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf)
} }
// credit: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/
static inline bool is_made_of_eight_digits_fast(uint64_t val) noexcept
{
return (((val & 0xF0F0F0F0F0F0F0F0) | (((val + 0x0606060606060606) & 0xF0F0F0F0F0F0F0F0) >> 4)) == 0x3333333333333333);
}
static inline bool is_made_of_eight_digits_fast(const char * chars) noexcept
{
uint64_t val;
::memcpy(&val, chars, 8);
return is_made_of_eight_digits_fast(val);
}
template <size_t N, typename T> template <size_t N, typename T>
static inline void readUIntTextUpToNSignificantDigits(T & x, ReadBuffer & buf) static inline void readUIntTextUpToNSignificantDigits(T & x, ReadBuffer & buf)
{ {
@ -266,9 +279,6 @@ static inline void readUIntTextUpToNSignificantDigits(T & x, ReadBuffer & buf)
else else
return; return;
} }
while (!buf.eof() && isNumericASCII(*buf.position()))
++buf.position();
} }
else else
{ {
@ -283,10 +293,16 @@ static inline void readUIntTextUpToNSignificantDigits(T & x, ReadBuffer & buf)
else else
return; return;
} }
while (!buf.eof() && isNumericASCII(*buf.position()))
++buf.position();
} }
while (!buf.eof() && (buf.position() + 8 <= buf.buffer().end()) &&
is_made_of_eight_digits_fast(buf.position()))
{
buf.position() += 8;
}
while (!buf.eof() && isNumericASCII(*buf.position()))
++buf.position();
} }
@ -319,7 +335,6 @@ ReturnType readFloatTextFastImpl(T & x, ReadBuffer & in)
++in.position(); ++in.position();
} }
auto count_after_sign = in.count(); auto count_after_sign = in.count();
constexpr int significant_digits = std::numeric_limits<UInt64>::digits10; constexpr int significant_digits = std::numeric_limits<UInt64>::digits10;