114 template <typename T>
115 constexpr
Uint128(T v) noexcept;
123 explicit
Uint128(uint64_t high, uint64_t low) noexcept;
125#if defined(__SIZEOF_INT128__)
135 explicit operator __uint128_t() const noexcept;
272 Uint128 operator<<(
int shift) const noexcept;
285 Uint128 operator>>(
int shift) const noexcept;
317 Uint128& operator<<=(
int shift) noexcept;
325 Uint128& operator>>=(
int shift) noexcept;
333 [[nodiscard]]
bool operator==(const
Uint128& other) const noexcept;
341 [[nodiscard]]
bool operator!=(const
Uint128& other) const noexcept;
352 [[nodiscard]]
bool operator<(const
Uint128& other) const noexcept;
360 [[nodiscard]]
bool operator>(const
Uint128& other) const noexcept;
368 [[nodiscard]]
bool operator<=(const
Uint128& other) const noexcept;
376 [[nodiscard]]
bool operator>=(const
Uint128& other) const noexcept;
386 Uint128& operator++() noexcept;
393 Uint128 operator++(
int) noexcept;
403 Uint128& operator--() noexcept;
410 Uint128 operator--(
int) noexcept;
417 [[nodiscard]] uint64_t
get_high() const noexcept;
424 [[nodiscard]] uint64_t
get_low() const noexcept;
438 VLINK_EXPORT static
void mul_64_128(uint64_t a, uint64_t b, uint64_t& hi, uint64_t& lo) noexcept;
440 VLINK_EXPORT static uint64_t add64_carry(uint64_t a, uint64_t b, uint64_t& carry_out) noexcept;
442 VLINK_EXPORT static
void add_128_with64(uint64_t& high, uint64_t& low, uint64_t add_low,
443 uint64_t add_high = 0) noexcept;
461#if defined(__SIZEOF_INT128__)
462inline Uint128::operator __uint128_t() const noexcept {
return (
static_cast<__uint128_t
>(high_) << 64) | low_; }
491 uint64_t old_low = low_;
495 uint64_t carry = (low_ < old_low) ? 1 : 0;
497 high_ += other.high_ + carry;
503 uint64_t borrow = (low_ < other.low_) ? 1 : 0;
506 high_ = high_ - other.high_ - borrow;
512#if defined(__SIZEOF_INT128__)
513 __uint128_t lhs = (
static_cast<__uint128_t
>(high_) << 64) | low_;
514 __uint128_t rhs = (
static_cast<__uint128_t
>(other.high_) << 64) | other.low_;
515 __uint128_t res = lhs * rhs;
517 high_ =
static_cast<uint64_t
>(res >> 64);
518 low_ =
static_cast<uint64_t
>(res);
520 Uint128 r = mul_u128_fallback(*
this, other);
529 auto qr = u128_divmod(*
this, other);
531 high_ = qr.first.high_;
532 low_ = qr.first.low_;
538 auto qr = u128_divmod(*
this, other);
540 high_ = qr.second.high_;
541 low_ = qr.second.low_;
547 return Uint128(high_ | other.high_, low_ | other.low_);
551 return Uint128(high_ & other.high_, low_ & other.low_);
555 return Uint128(high_ ^ other.high_, low_ ^ other.low_);
570 return Uint128(low_ << (shift - 64), 0);
573 uint64_t new_high = (high_ << shift) | (low_ >> (64 - shift));
574 uint64_t new_low = low_ << shift;
576 return Uint128(new_high, new_low);
589 return Uint128(0, high_ >> (shift - 64));
592 uint64_t new_low = (low_ >> shift) | (high_ << (64 - shift));
593 uint64_t new_high = high_ >> shift;
595 return Uint128(new_high, new_low);
599 high_ |= other.high_;
606 high_ &= other.high_;
613 high_ ^= other.high_;
632 high_ = (low_ << (shift - 64));
635 uint64_t nh = (high_ << shift) | (low_ >> (64 - shift));
636 uint64_t nl = low_ << shift;
657 low_ = (high_ >> (shift - 64));
660 uint64_t nl = (low_ >> shift) | (high_ << (64 - shift));
661 uint64_t nh = high_ >> shift;
671 return high_ == other.high_ && low_ == other.low_;
677 return (high_ < other.high_) || (high_ == other.high_ && low_ < other.low_);
687 uint64_t old_low = low_;
691 if (low_ < old_low) {
707 uint64_t old_low = low_;
733#if defined(__SIZEOF_INT128__)
734 if constexpr (std::is_same_v<__uint128_t, T>) {
735 high_ =
static_cast<uint64_t
>(v >> 64);
736 low_ =
static_cast<uint64_t
>(v);
742 if constexpr (std::is_constructible_v<uint64_t, T>) {
128-bit unsigned integer stored as two 64-bit halves with full operator support.
定义 uint128.h:95
Uint128 operator>>(int shift) const noexcept
Returns *this shifted right by shift bits (logical, zero-fill).
定义 uint128.h:579
Uint128 & operator*=(const Uint128 &other) noexcept
Multiplies *this by other in-place.
定义 uint128.h:511
Uint128 operator-(const Uint128 &other) const noexcept
Returns the difference of *this and other.
定义 uint128.h:472
bool operator<(const Uint128 &other) const noexcept
Returns true if *this is less than other.
定义 uint128.h:676
Uint128 operator+(const Uint128 &other) const noexcept
Returns the sum of *this and other.
定义 uint128.h:465
Uint128 & operator--() noexcept
Pre-decrement: decrements the value by one and returns *this.
定义 uint128.h:706
Uint128 & operator|=(const Uint128 &other) noexcept
Applies bitwise OR with other in-place.
定义 uint128.h:598
uint64_t get_low() const noexcept
Returns the lower 64 bits of the 128-bit value.
定义 uint128.h:727
Uint128 & operator%=(const Uint128 &other)
Computes *this modulo other in-place.
定义 uint128.h:537
bool operator!=(const Uint128 &other) const noexcept
Returns true if *this does not equal other.
定义 uint128.h:674
Uint128 operator/(const Uint128 &other) const
Returns the quotient of *this divided by other.
定义 uint128.h:486
Uint128 & operator-=(const Uint128 &other) noexcept
Subtracts other from *this in-place with borrow propagation.
定义 uint128.h:502
Uint128 & operator+=(const Uint128 &other) noexcept
Adds other to *this in-place with carry propagation.
定义 uint128.h:490
bool operator>=(const Uint128 &other) const noexcept
Returns true if *this is greater than or equal to other.
定义 uint128.h:684
Uint128 operator*(const Uint128 &other) const noexcept
Returns the product of *this and other.
定义 uint128.h:479
bool operator==(const Uint128 &other) const noexcept
Returns true if *this equals other.
定义 uint128.h:670
Uint128 & operator>>=(int shift) noexcept
Shifts *this right by shift bits in-place (logical, zero-fill).
定义 uint128.h:645
Uint128 operator%(const Uint128 &other) const
Returns the remainder of *this divided by other.
定义 uint128.h:488
uint64_t get_high() const noexcept
Returns the upper 64 bits of the 128-bit value.
定义 uint128.h:725
Uint128 operator&(const Uint128 &other) const noexcept
Returns the bitwise AND of *this and other.
定义 uint128.h:550
bool operator<=(const Uint128 &other) const noexcept
Returns true if *this is less than or equal to other.
定义 uint128.h:682
Uint128 & operator/=(const Uint128 &other)
Divides *this by other in-place.
定义 uint128.h:528
Uint128 operator~() const noexcept
Returns the bitwise NOT (complement) of *this.
定义 uint128.h:558
Uint128 operator<<(int shift) const noexcept
Returns *this shifted left by shift bits.
定义 uint128.h:560
Uint128 & operator++() noexcept
Pre-increment: increments the value by one and returns *this.
定义 uint128.h:686
Uint128 & operator^=(const Uint128 &other) noexcept
Applies bitwise XOR with other in-place.
定义 uint128.h:612
bool operator>(const Uint128 &other) const noexcept
Returns true if *this is greater than other.
定义 uint128.h:680
Uint128 operator^(const Uint128 &other) const noexcept
Returns the bitwise XOR of *this and other.
定义 uint128.h:554
Uint128 & operator&=(const Uint128 &other) noexcept
Applies bitwise AND with other in-place.
定义 uint128.h:605
Uint128 & operator<<=(int shift) noexcept
Shifts *this left by shift bits in-place.
定义 uint128.h:619
Uint128() noexcept=default
Default-constructs a zero-valued Uint128.
Uint128 operator|(const Uint128 &other) const noexcept
Returns the bitwise OR of *this and other.
定义 uint128.h:546
Platform-independent macro definitions for the VLink library.
#define VLINK_EXPORT
定义 macros.h:85
Uint128 uint128_t
定义 uint128.h:453
VLINK_EXPORT size_t operator()(const vlink::Uint128 &value) const noexcept
Computes the hash of value.