diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 030fd07..8cd7980 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -509,7 +509,7 @@ parse_int_string(UC const *p, UC const *pend, T &value, UC const *const start_digits = p; - if constexpr (std::is_same_v) { + FASTFLOAT_IF_CONSTEXPR17(std::is_same::value) { const size_t len = (size_t)(pend - p); if (len == 0) { if (has_leading_zeros) { @@ -550,7 +550,7 @@ parse_int_string(UC const *p, UC const *pend, T &value, uint32_t magic = ((digits.as_int + 0x46464646u) | (digits.as_int - 0x30303030u)) & 0x80808080u; - uint32_t tz = (uint32_t)std::__countr_zero(magic); // 7, 15, 23, 31, or 32 + uint32_t tz = (uint32_t)countr_zero_32(magic); // 7, 15, 23, 31, or 32 uint32_t nd = (tz == 32) ? 4 : (tz >> 3); nd = (uint32_t)std::min((size_t)nd, len); if (nd == 0) { diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index 18484a6..ab95e1d 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -362,6 +362,52 @@ leading_zeroes(uint64_t input_num) { #endif } +/* Helper C++14 constexpr generic implementation of countr_zero for 32-bit */ +fastfloat_really_inline FASTFLOAT_CONSTEXPR14 int +countr_zero_generic_32(uint32_t input_num) { + if (input_num == 0) { + return 32; + } + int last_bit = 0; + if (!(input_num & 0x0000FFFF)) { + input_num >>= 16; + last_bit |= 16; + } + if (!(input_num & 0x00FF)) { + input_num >>= 8; + last_bit |= 8; + } + if (!(input_num & 0x0F)) { + input_num >>= 4; + last_bit |= 4; + } + if (!(input_num & 0x3)) { + input_num >>= 2; + last_bit |= 2; + } + if (!(input_num & 0x1)) { + last_bit |= 1; + } + return last_bit; +} + +/* count trailing zeroes for 32-bit integers */ +fastfloat_really_inline FASTFLOAT_CONSTEXPR20 int +countr_zero_32(uint32_t input_num) { + if (cpp20_and_in_constexpr()) { + return countr_zero_generic_32(input_num); + } +#ifdef FASTFLOAT_VISUAL_STUDIO + unsigned long trailing_zero = 0; + if (_BitScanForward(&trailing_zero, input_num)) { + return (int)trailing_zero; + } + return 32; +#else + return input_num == 0 ? 32 : __builtin_ctz(input_num); +#endif +} + // slow emulation routine for 32-bit fastfloat_really_inline constexpr uint64_t emulu(uint32_t x, uint32_t y) { return x * (uint64_t)y;