mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-11 05:30:05 +00:00
Use __builtin_clz whenever it is available
This commit is contained in:
parent
e87a24633b
commit
cbc46d9e78
15
format.h
15
format.h
@ -581,13 +581,6 @@ inline unsigned count_digits(uint64_t n) {
|
||||
unsigned t = (64 - FMT_BUILTIN_CLZLL(n | 1)) * 1233 >> 12;
|
||||
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
|
||||
// Fallback version of count_digits used when __builtin_clz is not available.
|
||||
inline unsigned count_digits(uint64_t n) {
|
||||
@ -606,6 +599,14 @@ inline unsigned count_digits(uint64_t n) {
|
||||
}
|
||||
#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.
|
||||
template <typename UInt, typename Char>
|
||||
inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
|
||||
|
Loading…
Reference in New Issue
Block a user