Commit cbc46d9e authored by Victor Zverovich's avatar Victor Zverovich

Use __builtin_clz whenever it is available

parent e87a2463
...@@ -581,13 +581,6 @@ inline unsigned count_digits(uint64_t n) { ...@@ -581,13 +581,6 @@ inline unsigned count_digits(uint64_t n) {
unsigned t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12; unsigned t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12;
return t - (n < Data::POWERS_OF_10_64[t]) + 1; return t - (n < Data::POWERS_OF_10_64[t]) + 1;
} }
# ifdef FMT_BUILTIN_CLZ
// Optional version of count_digits for better performance on 32-bit platforms.
inline unsigned count_digits(uint32_t n) {
uint32_t t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12;
return t - (n < Data::POWERS_OF_10_32[t]) + 1;
}
# endif
#else #else
// Fallback version of count_digits used when __builtin_clz is not available. // Fallback version of count_digits used when __builtin_clz is not available.
inline unsigned count_digits(uint64_t n) { inline unsigned count_digits(uint64_t n) {
...@@ -606,6 +599,14 @@ inline unsigned count_digits(uint64_t n) { ...@@ -606,6 +599,14 @@ inline unsigned count_digits(uint64_t n) {
} }
#endif #endif
#ifdef FMT_BUILTIN_CLZ
// Optional version of count_digits for better performance on 32-bit platforms.
inline unsigned count_digits(uint32_t n) {
uint32_t t = (32 - FMT_BUILTIN_CLZ(n | 1)) * 1233 >> 12;
return t - (n < Data::POWERS_OF_10_32[t]) + 1;
}
#endif
// Formats a decimal unsigned integer value writing into buffer. // Formats a decimal unsigned integer value writing into buffer.
template <typename UInt, typename Char> template <typename UInt, typename Char>
inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) { inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment