From b8163709f51df3b3bdbeff796ff7b6c7e3030551 Mon Sep 17 00:00:00 2001 From: IRainman Date: Mon, 10 Nov 2025 02:41:26 +0300 Subject: [PATCH] * type usage fix for better performance in any hardware. --- include/fast_float/bigint.h | 4 ++-- include/fast_float/fast_float.h | 10 +++++----- include/fast_float/float_common.h | 16 ++++++++-------- include/fast_float/parse_number.h | 22 +++++++++++----------- tests/basictest.cpp | 14 +++++++------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/include/fast_float/bigint.h b/include/fast_float/bigint.h index 5b21015..f3f61ec 100644 --- a/include/fast_float/bigint.h +++ b/include/fast_float/bigint.h @@ -369,7 +369,7 @@ FASTFLOAT_CONSTEXPR20 bool large_mul(stackvec &x, limb_span y) noexcept { } template struct pow5_tables { - static constexpr uint8_t large_step = 135; + static constexpr uint_fast8_t large_step = 135; static constexpr uint64_t small_power_of_5[] = { 1UL, 5UL, @@ -413,7 +413,7 @@ template struct pow5_tables { #if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE -template constexpr uint8_t pow5_tables::large_step; +template constexpr uint_fast8_t pow5_tables::large_step; template constexpr uint64_t pow5_tables::small_power_of_5[]; diff --git a/include/fast_float/fast_float.h b/include/fast_float/fast_float.h index 7e72120..0d70a8d 100644 --- a/include/fast_float/fast_float.h +++ b/include/fast_float/fast_float.h @@ -60,10 +60,10 @@ from_chars_advanced(UC const *first, UC const *last, T &value, */ FASTFLOAT_CONSTEXPR20 inline double integer_times_pow10(uint64_t const mantissa, - int16_t const decimal_exponent) noexcept; + int_fast16_t const decimal_exponent) noexcept; FASTFLOAT_CONSTEXPR20 inline double integer_times_pow10(int64_t const mantissa, - int16_t const decimal_exponent) noexcept; + int_fast16_t const decimal_exponent) noexcept; /** * This function is a template overload of `integer_times_pow10()` @@ -74,12 +74,12 @@ template FASTFLOAT_CONSTEXPR20 typename std::enable_if::value, T>::type integer_times_pow10(uint64_t const mantissa, - int16_t const decimal_exponent) noexcept; + int_fast16_t const decimal_exponent) noexcept; template FASTFLOAT_CONSTEXPR20 typename std::enable_if::value, T>::type integer_times_pow10(int64_t const mantissa, - int16_t const decimal_exponent) noexcept; + int_fast16_t const decimal_exponent) noexcept; /** * from_chars for integer types. @@ -88,7 +88,7 @@ template ::value)> FASTFLOAT_CONSTEXPR20 from_chars_result_t from_chars(UC const *first, UC const *last, T &value, - int const base = 10) noexcept; + uint_fast8_t const base = 10) noexcept; } // namespace fast_float diff --git a/include/fast_float/float_common.h b/include/fast_float/float_common.h index d80bb2a..733d7e9 100644 --- a/include/fast_float/float_common.h +++ b/include/fast_float/float_common.h @@ -287,8 +287,8 @@ struct is_supported_char_type template inline FASTFLOAT_CONSTEXPR14 bool fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase, - uint8_t const length) noexcept { - for (uint8_t i = 0; i++ != length;) { + uint_fast8_t const length) noexcept { + for (uint_fast8_t i = 0; i++ != length;) { UC const actual = actual_mixedcase[i]; if ((actual < 256 ? actual | 32 : actual) != expected_lowercase[i]) { return false; @@ -1059,7 +1059,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float( #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN template struct space_lut { - static constexpr uint8_t value[] = { + static constexpr uint_fast8_t value[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 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, 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, @@ -1075,12 +1075,12 @@ template struct space_lut { #if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE -template constexpr uint8_t space_lut::value[]; +template constexpr uint_fast8_t space_lut::value[]; #endif template constexpr bool is_space(UC c) { - return c < 256 && space_lut<>::value[uint8_t(c)]; + return c < 256 && space_lut<>::value[uint_fast8_t(c)]; } #endif @@ -1166,7 +1166,7 @@ template struct int_luts { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; - static constexpr uint8_t maxdigits_u64[] = { + static constexpr uint_fast8_t maxdigits_u64[] = { 64, 41, 32, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 16, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13}; @@ -1187,9 +1187,9 @@ template struct int_luts { #if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE -template constexpr uint8_t int_luts::chdigit[]; +template constexpr uint_fast8_t int_luts::chdigit[]; -template constexpr uint8_t int_luts::maxdigits_u64[]; +template constexpr uint_fast8_t int_luts::maxdigits_u64[]; template constexpr uint64_t int_luts::min_safe_u64[]; diff --git a/include/fast_float/parse_number.h b/include/fast_float/parse_number.h index f3d5e3a..0a324f6 100644 --- a/include/fast_float/parse_number.h +++ b/include/fast_float/parse_number.h @@ -374,15 +374,15 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value, template FASTFLOAT_CONSTEXPR20 from_chars_result_t -from_chars(UC const *first, UC const *last, T &value, int const base) noexcept { +from_chars(UC const *first, UC const *last, T &value, + uint_fast8_t const base) noexcept { static_assert(is_supported_integer_type::value, "only integer types are supported"); static_assert(is_supported_char_type::value, "only char, wchar_t, char16_t and char32_t are supported"); - parse_options_t const options(chars_format::general, UC('.'), - static_cast(base)); + parse_options_t const options(chars_format::general, UC('.'), base); return from_chars_advanced(first, last, value, options); } @@ -390,7 +390,7 @@ template FASTFLOAT_CONSTEXPR20 typename std::enable_if::value, T>::type integer_times_pow10(uint64_t const mantissa, - int16_t const decimal_exponent) noexcept { + int_fast16_t const decimal_exponent) noexcept { T value; if (clinger_fast_path_impl(mantissa, decimal_exponent, #ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN @@ -413,7 +413,7 @@ template FASTFLOAT_CONSTEXPR20 typename std::enable_if::value, T>::type integer_times_pow10(int64_t const mantissa, - int16_t const decimal_exponent) noexcept { + int_fast16_t const decimal_exponent) noexcept { #ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN FASTFLOAT_ASSUME(mantissa > 0); const am_mant_t m = static_cast(mantissa); @@ -442,13 +442,13 @@ FASTFLOAT_CONSTEXPR20 FASTFLOAT_CONSTEXPR20 inline double integer_times_pow10(uint64_t const mantissa, - int16_t const decimal_exponent) noexcept { + int_fast16_t const decimal_exponent) noexcept { return integer_times_pow10(mantissa, decimal_exponent); } FASTFLOAT_CONSTEXPR20 inline double integer_times_pow10(int64_t const mantissa, - int16_t const decimal_exponent) noexcept { + int_fast16_t const decimal_exponent) noexcept { return integer_times_pow10(mantissa, decimal_exponent); } @@ -460,7 +460,7 @@ FASTFLOAT_CONSTEXPR20 std::is_integral::value && !std::is_signed::value, T>::type - integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept { + integer_times_pow10(Int mantissa, int_fast16_t decimal_exponent) noexcept { return integer_times_pow10(static_cast(mantissa), decimal_exponent); } @@ -471,7 +471,7 @@ FASTFLOAT_CONSTEXPR20 std::is_integral::value && std::is_signed::value, T>::type - integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept { + integer_times_pow10(Int mantissa, int_fast16_t decimal_exponent) noexcept { return integer_times_pow10(static_cast(mantissa), decimal_exponent); } @@ -479,14 +479,14 @@ FASTFLOAT_CONSTEXPR20 template FASTFLOAT_CONSTEXPR20 typename std::enable_if< std::is_integral::value && !std::is_signed::value, double>::type -integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept { +integer_times_pow10(Int mantissa, int_fast16_t decimal_exponent) noexcept { return integer_times_pow10(static_cast(mantissa), decimal_exponent); } template FASTFLOAT_CONSTEXPR20 typename std::enable_if< std::is_integral::value && std::is_signed::value, double>::type -integer_times_pow10(Int mantissa, int16_t decimal_exponent) noexcept { +integer_times_pow10(Int mantissa, int_fast16_t decimal_exponent) noexcept { return integer_times_pow10(static_cast(mantissa), decimal_exponent); } diff --git a/tests/basictest.cpp b/tests/basictest.cpp index 92908b1..514f526 100644 --- a/tests/basictest.cpp +++ b/tests/basictest.cpp @@ -2127,7 +2127,7 @@ TEST_CASE("bfloat16.general") { template void verify_integer_times_pow10_result(Int const mantissa, - int16_t const decimal_exponent, + int_fast16_t const decimal_exponent, T const actual, U const expected) { static_assert(std::is_same::value, "expected and actual types must match"); @@ -2146,7 +2146,7 @@ void verify_integer_times_pow10_result(Int const mantissa, template T calculate_integer_times_pow10_expected_result( - Int const mantissa, int16_t const decimal_exponent) { + Int const mantissa, int_fast16_t const decimal_exponent) { std::string constructed_string = std::to_string(mantissa) + "e" + std::to_string(decimal_exponent); T expected_result; @@ -2160,7 +2160,7 @@ T calculate_integer_times_pow10_expected_result( template void verify_integer_times_pow10_dflt(Int const mantissa, - int16_t const decimal_exponent, + int_fast16_t const decimal_exponent, double const expected) { static_assert(std::is_integral::value); @@ -2174,7 +2174,7 @@ void verify_integer_times_pow10_dflt(Int const mantissa, template void verify_integer_times_pow10_dflt(Int const mantissa, - int16_t const decimal_exponent) { + int_fast16_t const decimal_exponent) { static_assert(std::is_integral::value); const auto expected_result = @@ -2186,7 +2186,7 @@ void verify_integer_times_pow10_dflt(Int const mantissa, template void verify_integer_times_pow10(Int const mantissa, - int16_t const decimal_exponent, + int_fast16_t const decimal_exponent, T const expected) { static_assert(std::is_floating_point::value); static_assert(std::is_integral::value); @@ -2201,7 +2201,7 @@ void verify_integer_times_pow10(Int const mantissa, template void verify_integer_times_pow10(Int const mantissa, - int16_t const decimal_exponent) { + int_fast16_t const decimal_exponent) { static_assert(std::is_floating_point::value); static_assert(std::is_integral::value); @@ -2214,7 +2214,7 @@ void verify_integer_times_pow10(Int const mantissa, namespace all_supported_types { template void verify_integer_times_pow10(Int const mantissa, - int16_t const decimal_exponent) { + int_fast16_t const decimal_exponent) { static_assert(std::is_integral::value); // verify the "default" overload