Skip to content

Commit

Permalink
Exclude fallback functions when FMT_BUILTIN_CLZ(LL) is not defined (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
brm authored and PoetaKodu committed Nov 11, 2021
1 parent 2a0c9b6 commit 50f4e39
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ 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.
inline auto do_count_digits(uint64_t n) -> int {
Expand All @@ -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.
Expand Down Expand Up @@ -962,6 +964,7 @@ 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.
FMT_INLINE auto do_count_digits(uint32_t n) -> int {
Expand All @@ -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<int>((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 {
Expand Down

0 comments on commit 50f4e39

Please sign in to comment.