Simplify data handling

This commit is contained in:
Victor Zverovich
2021-04-23 06:52:10 -07:00
parent 54d3b1710e
commit c47f211296
4 changed files with 52 additions and 87 deletions
+1 -53
View File
@@ -897,61 +897,13 @@ using uint32_or_64_or_128_t =
template <typename T>
using uint64_or_128_t = conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>;
// 128-bit integer type used internally
struct FMT_EXTERN_TEMPLATE_API uint128_wrapper {
uint128_wrapper() = default;
#if FMT_USE_INT128
uint128_t internal_;
constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT
: internal_{static_cast<uint128_t>(low) |
(static_cast<uint128_t>(high) << 64)} {}
constexpr uint128_wrapper(uint128_t u) : internal_{u} {}
constexpr uint64_t high() const FMT_NOEXCEPT {
return uint64_t(internal_ >> 64);
}
constexpr uint64_t low() const FMT_NOEXCEPT { return uint64_t(internal_); }
uint128_wrapper& operator+=(uint64_t n) FMT_NOEXCEPT {
internal_ += n;
return *this;
}
#else
uint64_t high_;
uint64_t low_;
constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT
: high_{high},
low_{low} {}
constexpr uint64_t high() const FMT_NOEXCEPT { return high_; }
constexpr uint64_t low() const FMT_NOEXCEPT { return low_; }
uint128_wrapper& operator+=(uint64_t n) FMT_NOEXCEPT {
# if defined(_MSC_VER) && defined(_M_X64)
unsigned char carry = _addcarry_u64(0, low_, n, &low_);
_addcarry_u64(carry, high_, 0, &high_);
return *this;
# else
uint64_t sum = low_ + n;
high_ += (sum < low_ ? 1 : 0);
low_ = sum;
return *this;
# endif
}
#endif
};
#define FMT_POWERS_OF_10(factor) \
factor * 10, (factor)*100, (factor)*1000, (factor)*10000, (factor)*100000, \
(factor)*1000000, (factor)*10000000, (factor)*100000000, \
(factor)*1000000000
// Static data is placed in this class template for the header-only config.
template <typename T = void> struct FMT_EXTERN_TEMPLATE_API basic_data {
template <typename T = void> struct basic_data {
static constexpr const uint32_t zero_or_powers_of_10_32[] = {
0, 0, FMT_POWERS_OF_10(1U)};
@@ -1005,10 +957,6 @@ FMT_INLINE uint16_t bsr2log10(int bsr) {
return data[bsr];
}
#ifndef FMT_EXPORTED
FMT_EXTERN template struct FMT_INSTANTIATION_DECL_API basic_data<void>;
#endif
template <typename T> FMT_CONSTEXPR int count_digits_fallback(T n) {
int count = 1;
for (;;) {