From 04034f79c616ff89eb8898591495f9e64be92cd8 Mon Sep 17 00:00:00 2001 From: RealTimeChris <40668522+RealTimeChris@users.noreply.github.com> Date: Fri, 22 Nov 2024 00:24:47 -0500 Subject: [PATCH] Adding new is_made_of_eight_digits_fast implementation. [skip ci] --- include/fast_float/ascii_number.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index f2484e8..84d85c5 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -137,11 +137,18 @@ parse_eight_digits_unrolled(UC const *chars) noexcept { return parse_eight_digits_unrolled(simd_read8_to_u64(chars)); } -// credit @aqrit +// credit @realtimechris fastfloat_really_inline constexpr bool is_made_of_eight_digits_fast(uint64_t val) noexcept { - return !((((val + 0x4646464646464646) | (val - 0x3030303030303030)) & - 0x8080808080808080)); + constexpr uint64_t byte_mask = ~uint64_t(0) / 255ull; + constexpr uint64_t msb_mask = byte_mask * 128ull; + constexpr uint64_t sub_mask = + byte_mask * (127ull - 10ull) - 0x3030303030303030ull; +#if !defined(__clang__) + return !bool((val + sub_mask | val) & msb_mask); +#else + return ((val + sub_mask | val) & msb_mask) == 0; +#endif } #ifdef FASTFLOAT_HAS_SIMD