Merge accumulator into int128_fallback

This commit is contained in:
Victor Zverovich
2022-02-17 21:24:10 -08:00
parent d38f72aff2
commit 4ddab8901c
3 changed files with 15 additions and 48 deletions

View File

@@ -346,8 +346,12 @@ class uint128_fallback {
public:
constexpr uint128_fallback(uint64_t value = 0) : lo_(value), hi_(0) {}
explicit operator int() const { return static_cast<int>(lo_); }
explicit operator uint64_t() const { return lo_; }
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
constexpr explicit operator T() const {
return static_cast<T>(lo_);
}
friend auto operator==(const uint128_fallback& lhs,
const uint128_fallback& rhs) -> bool {
return lhs.hi_ == rhs.hi_ && lhs.lo_ == rhs.lo_;
@@ -361,14 +365,19 @@ class uint128_fallback {
FMT_ASSERT(lhs.lo_ >= rhs, "");
return {lhs.hi_, lhs.lo_ - rhs};
}
auto operator>>(int shift) const -> uint128_fallback {
FMT_CONSTEXPR auto operator>>(int shift) const -> uint128_fallback {
if (shift == 64) return {0, hi_};
return {hi_ >> shift, (hi_ << (64 - shift)) | (lo_ >> shift)};
}
auto operator<<(int shift) const -> uint128_fallback {
FMT_CONSTEXPR auto operator<<(int shift) const -> uint128_fallback {
if (shift == 64) return {lo_, 0};
return {hi_ << shift | (lo_ >> (64 - shift)), (lo_ << shift)};
}
FMT_CONSTEXPR void operator>>=(int shift) { *this = *this >> shift; }
FMT_CONSTEXPR void operator+=(uint64_t n) {
lo_ += n;
if (lo_ < n) ++hi_;
}
};
using uint128_t = conditional_t<FMT_USE_INT128, uint128_opt, uint128_fallback>;