From 901d2a75ccc5f73a0879ade742f43f8e23564a5b Mon Sep 17 00:00:00 2001 From: Bodo Martin Date: Sun, 25 Jul 2021 13:30:04 +0200 Subject: [PATCH 1/2] exclude fallback functions when FMT_BUILTIN_CLZ(LL) is not defined Signed-off-by: Bodo Martin --- include/fmt/format.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/fmt/format.h b/include/fmt/format.h index a364f850..7fbe4993 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -918,6 +918,7 @@ FMT_CONSTEXPR inline auto count_digits(uint128_t n) -> int { // It is a separate function rather than a part of count_digits to workaround // the lack of static constexpr in constexpr functions. +#ifdef FMT_BUILTIN_CLZLL inline auto do_count_digits(uint64_t n) -> int { // This has comparable performance to the version by Kendall Willets // (https://github.com/fmtlib/format-benchmark/blob/master/digits10) @@ -934,6 +935,7 @@ inline auto do_count_digits(uint64_t n) -> int { 10000000000000000000ULL}; return t - (n < zero_or_powers_of_10[t]); } +#endif // Returns the number of decimal digits in n. Leading zeros are not counted // except for n == 0 in which case count_digits returns 1. @@ -964,6 +966,7 @@ template <> auto count_digits<4>(detail::fallback_uintptr n) -> int; // It is a separate function rather than a part of count_digits to workaround // the lack of static constexpr in constexpr functions. +#ifdef FMT_BUILTIN_CLZ FMT_INLINE auto do_count_digits(uint32_t n) -> int { // An optimization by Kendall Willets from https://bit.ly/3uOIQrB. // This increments the upper 32 bits (log10(T) - 1) when >= T is added. @@ -984,6 +987,7 @@ FMT_INLINE auto do_count_digits(uint32_t n) -> int { auto inc = table[FMT_BUILTIN_CLZ(n | 1) ^ 31]; return static_cast((n + inc) >> 32); } +#endif // Optional version of count_digits for better performance on 32-bit platforms. FMT_CONSTEXPR20 inline auto count_digits(uint32_t n) -> int { From ebbbea6c3fce4225faa29fa987c151b77279cf25 Mon Sep 17 00:00:00 2001 From: Bodo Martin Date: Sun, 25 Jul 2021 17:14:32 +0200 Subject: [PATCH 2/2] moved ifdefs before function comments Signed-off-by: Bodo Martin --- include/fmt/format.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 7fbe4993..7b78200c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -916,9 +916,9 @@ FMT_CONSTEXPR inline auto count_digits(uint128_t n) -> int { } #endif +#ifdef FMT_BUILTIN_CLZLL // It is a separate function rather than a part of count_digits to workaround // the lack of static constexpr in constexpr functions. -#ifdef FMT_BUILTIN_CLZLL inline auto do_count_digits(uint64_t n) -> int { // This has comparable performance to the version by Kendall Willets // (https://github.com/fmtlib/format-benchmark/blob/master/digits10) @@ -964,9 +964,9 @@ FMT_CONSTEXPR auto count_digits(UInt n) -> int { template <> auto count_digits<4>(detail::fallback_uintptr n) -> int; +#ifdef FMT_BUILTIN_CLZ // It is a separate function rather than a part of count_digits to workaround // the lack of static constexpr in constexpr functions. -#ifdef FMT_BUILTIN_CLZ FMT_INLINE auto do_count_digits(uint32_t n) -> int { // An optimization by Kendall Willets from https://bit.ly/3uOIQrB. // This increments the upper 32 bits (log10(T) - 1) when >= T is added.