diff options
author | thegeorg <[email protected]> | 2023-08-20 23:36:15 +0300 |
---|---|---|
committer | thegeorg <[email protected]> | 2023-08-21 00:54:32 +0300 |
commit | 4ffd2d398873ff2e3f1c28fbb1d647d26a9600d1 (patch) | |
tree | f023ac7871845812356d6ace5e07d059bdf270b4 /contrib/restricted/abseil-cpp-tstring/y_absl/numeric | |
parent | d619e9fffe040fe2f8b4940b1a72cc1757538c8c (diff) |
Update contrib/restricted/abseil-cpp-tstring to 20230802.0
Diffstat (limited to 'contrib/restricted/abseil-cpp-tstring/y_absl/numeric')
5 files changed, 107 insertions, 84 deletions
diff --git a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/bits.h b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/bits.h index 501c756da5e..2d20293c904 100644 --- a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/bits.h +++ b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/bits.h @@ -38,19 +38,19 @@ #include <limits> #include <type_traits> -#if (defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L) || \ - (defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) +#include "y_absl/base/config.h" + +#if Y_ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L #include <bit> #endif #include "y_absl/base/attributes.h" -#include "y_absl/base/config.h" #include "y_absl/numeric/internal/bits.h" namespace y_absl { Y_ABSL_NAMESPACE_BEGIN - #if !(defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) + // rotating template <class T> Y_ABSL_MUST_USE_RESULT constexpr diff --git a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128.cc b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128.cc index a054aad2c10..fa62f6ad502 100644 --- a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128.cc +++ b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128.cc @@ -111,7 +111,7 @@ uint128 MakeUint128FromFloat(T v) { return MakeUint128(0, static_cast<uint64_t>(v)); } -#if defined(__clang__) && !defined(__SSE3__) +#if defined(__clang__) && (__clang_major__ < 9) && !defined(__SSE3__) // Workaround for clang bug: https://bugs.llvm.org/show_bug.cgi?id=38289 // Casting from long double to uint64_t is miscompiled and drops bits. // It is more work, so only use when we need the workaround. @@ -131,7 +131,7 @@ uint128 MakeUint128FromFloat(long double v) { return (static_cast<uint128>(w0) << 100) | (static_cast<uint128>(w1) << 50) | static_cast<uint128>(w2); } -#endif // __clang__ && !__SSE3__ +#endif // __clang__ && (__clang_major__ < 9) && !__SSE3__ } // namespace uint128::uint128(float v) : uint128(MakeUint128FromFloat(v)) {} @@ -202,6 +202,10 @@ TString Uint128ToFormattedString(uint128 v, std::ios_base::fmtflags flags) { } // namespace +TString uint128::ToString() const { + return Uint128ToFormattedString(*this, std::ios_base::dec); +} + std::ostream& operator<<(std::ostream& os, uint128 v) { std::ios_base::fmtflags flags = os.flags(); TString rep = Uint128ToFormattedString(v, flags); @@ -216,9 +220,9 @@ std::ostream& operator<<(std::ostream& os, uint128 v) { } else if (adjustfield == std::ios::internal && (flags & std::ios::showbase) && (flags & std::ios::basefield) == std::ios::hex && v != 0) { - rep.insert((size_t)2, count, os.fill()); + rep.insert(size_t{2}, count, os.fill()); } else { - rep.insert((size_t)0, count, os.fill()); + rep.insert(size_t{0}, count, os.fill()); } } @@ -285,6 +289,14 @@ int128 operator%(int128 lhs, int128 rhs) { } #endif // Y_ABSL_HAVE_INTRINSIC_INT128 +TString int128::ToString() const { + TString rep; + if (Int128High64(*this) < 0) rep = "-"; + rep.append(Uint128ToFormattedString(UnsignedAbsoluteValue(*this), + std::ios_base::dec)); + return rep; +} + std::ostream& operator<<(std::ostream& os, int128 v) { std::ios_base::fmtflags flags = os.flags(); TString rep; @@ -314,16 +326,16 @@ std::ostream& operator<<(std::ostream& os, int128 v) { break; case std::ios::internal: if (print_as_decimal && (rep[0] == '+' || rep[0] == '-')) { - rep.insert(1u, count, os.fill()); + rep.insert(size_t{1}, count, os.fill()); } else if ((flags & std::ios::basefield) == std::ios::hex && (flags & std::ios::showbase) && v != 0) { - rep.insert((size_t)2, count, os.fill()); + rep.insert(size_t{2}, count, os.fill()); } else { - rep.insert((size_t)0, count, os.fill()); + rep.insert(size_t{0}, count, os.fill()); } break; default: // std::ios::right - rep.insert((size_t)0, count, os.fill()); + rep.insert(size_t{0}, count, os.fill()); break; } } diff --git a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128.h b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128.h index 34c920a032f..d90efdaece0 100644 --- a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128.h +++ b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128.h @@ -32,6 +32,7 @@ #include <cstring> #include <iosfwd> #include <limits> +#include <util/generic/string.h> #include <utility> #include "y_absl/base/config.h" @@ -119,8 +120,8 @@ class #ifdef Y_ABSL_HAVE_INTRINSIC_INT128 constexpr uint128(__int128 v); // NOLINT(runtime/explicit) constexpr uint128(unsigned __int128 v); // NOLINT(runtime/explicit) -#endif // Y_ABSL_HAVE_INTRINSIC_INT128 - constexpr uint128(int128 v); // NOLINT(runtime/explicit) +#endif // Y_ABSL_HAVE_INTRINSIC_INT128 + constexpr uint128(int128 v); // NOLINT(runtime/explicit) explicit uint128(float v); explicit uint128(double v); explicit uint128(long double v); @@ -217,9 +218,17 @@ class return H::combine(std::move(h), Uint128High64(v), Uint128Low64(v)); } + // Support for y_absl::StrCat() etc. + template <typename Sink> + friend void AbslStringify(Sink& sink, uint128 v) { + sink.Append(v.ToString()); + } + private: constexpr uint128(uint64_t high, uint64_t low); + TString ToString() const; + // TODO(strel) Update implementation to use __int128 once all users of // uint128 are fixed to not depend on alignof(uint128) == 8. Also add // alignas(16) to class definition to keep alignment consistent across @@ -286,9 +295,9 @@ class numeric_limits<y_absl::uint128> { #endif // Y_ABSL_HAVE_INTRINSIC_INT128 static constexpr bool tinyness_before = false; - static constexpr y_absl::uint128 (min)() { return 0; } + static constexpr y_absl::uint128(min)() { return 0; } static constexpr y_absl::uint128 lowest() { return 0; } - static constexpr y_absl::uint128 (max)() { return y_absl::Uint128Max(); } + static constexpr y_absl::uint128(max)() { return y_absl::Uint128Max(); } static constexpr y_absl::uint128 epsilon() { return 0; } static constexpr y_absl::uint128 round_error() { return 0; } static constexpr y_absl::uint128 infinity() { return 0; } @@ -454,9 +463,17 @@ class int128 { return H::combine(std::move(h), Int128High64(v), Int128Low64(v)); } + // Support for y_absl::StrCat() etc. + template <typename Sink> + friend void AbslStringify(Sink& sink, int128 v) { + sink.Append(v.ToString()); + } + private: constexpr int128(int64_t high, uint64_t low); + TString ToString() const; + #if defined(Y_ABSL_HAVE_INTRINSIC_INT128) __int128 v_; #else // Y_ABSL_HAVE_INTRINSIC_INT128 @@ -521,9 +538,9 @@ class numeric_limits<y_absl::int128> { #endif // Y_ABSL_HAVE_INTRINSIC_INT128 static constexpr bool tinyness_before = false; - static constexpr y_absl::int128 (min)() { return y_absl::Int128Min(); } + static constexpr y_absl::int128(min)() { return y_absl::Int128Min(); } static constexpr y_absl::int128 lowest() { return y_absl::Int128Min(); } - static constexpr y_absl::int128 (max)() { return y_absl::Int128Max(); } + static constexpr y_absl::int128(max)() { return y_absl::Int128Max(); } static constexpr y_absl::int128 epsilon() { return 0; } static constexpr y_absl::int128 round_error() { return 0; } static constexpr y_absl::int128 infinity() { return 0; } @@ -561,9 +578,7 @@ inline uint128& uint128::operator=(unsigned long v) { } // NOLINTNEXTLINE(runtime/int) -inline uint128& uint128::operator=(long long v) { - return *this = uint128(v); -} +inline uint128& uint128::operator=(long long v) { return *this = uint128(v); } // NOLINTNEXTLINE(runtime/int) inline uint128& uint128::operator=(unsigned long long v) { @@ -571,18 +586,14 @@ inline uint128& uint128::operator=(unsigned long long v) { } #ifdef Y_ABSL_HAVE_INTRINSIC_INT128 -inline uint128& uint128::operator=(__int128 v) { - return *this = uint128(v); -} +inline uint128& uint128::operator=(__int128 v) { return *this = uint128(v); } inline uint128& uint128::operator=(unsigned __int128 v) { return *this = uint128(v); } #endif // Y_ABSL_HAVE_INTRINSIC_INT128 -inline uint128& uint128::operator=(int128 v) { - return *this = uint128(v); -} +inline uint128& uint128::operator=(int128 v) { return *this = uint128(v); } // Arithmetic operators. @@ -637,8 +648,7 @@ constexpr uint64_t Uint128High64(uint128 v) { return v.hi_; } #if defined(Y_ABSL_IS_LITTLE_ENDIAN) -constexpr uint128::uint128(uint64_t high, uint64_t low) - : lo_{low}, hi_{high} {} +constexpr uint128::uint128(uint64_t high, uint64_t low) : lo_{low}, hi_{high} {} constexpr uint128::uint128(int v) : lo_{static_cast<uint64_t>(v)}, @@ -670,8 +680,7 @@ constexpr uint128::uint128(int128 v) #elif defined(Y_ABSL_IS_BIG_ENDIAN) -constexpr uint128::uint128(uint64_t high, uint64_t low) - : hi_{high}, lo_{low} {} +constexpr uint128::uint128(uint64_t high, uint64_t low) : hi_{high}, lo_{low} {} constexpr uint128::uint128(int v) : hi_{v < 0 ? (std::numeric_limits<uint64_t>::max)() : 0}, @@ -817,13 +826,9 @@ constexpr bool operator>=(uint128 lhs, uint128 rhs) { return !(lhs < rhs); } // Unary operators. -constexpr inline uint128 operator+(uint128 val) { - return val; -} +constexpr inline uint128 operator+(uint128 val) { return val; } -constexpr inline int128 operator+(int128 val) { - return val; -} +constexpr inline int128 operator+(int128 val) { return val; } constexpr uint128 operator-(uint128 val) { #if defined(Y_ABSL_HAVE_INTRINSIC_INT128) @@ -906,7 +911,7 @@ constexpr uint128 operator<<(uint128 lhs, int amount) { #else // uint64_t shifts of >= 64 are undefined, so we will need some // special-casing. - return amount >= 64 ? MakeUint128(Uint128Low64(lhs) << (amount - 64), 0) + return amount >= 64 ? MakeUint128(Uint128Low64(lhs) << (amount - 64), 0) : amount == 0 ? lhs : MakeUint128((Uint128High64(lhs) << amount) | (Uint128Low64(lhs) >> (64 - amount)), @@ -920,7 +925,7 @@ constexpr uint128 operator>>(uint128 lhs, int amount) { #else // uint64_t shifts of >= 64 are undefined, so we will need some // special-casing. - return amount >= 64 ? MakeUint128(0, Uint128High64(lhs) >> (amount - 64)) + return amount >= 64 ? MakeUint128(0, Uint128High64(lhs) >> (amount - 64)) : amount == 0 ? lhs : MakeUint128(Uint128High64(lhs) >> amount, (Uint128Low64(lhs) >> amount) | @@ -1042,27 +1047,19 @@ constexpr int128 MakeInt128(int64_t high, uint64_t low) { } // Assignment from integer types. -inline int128& int128::operator=(int v) { - return *this = int128(v); -} +inline int128& int128::operator=(int v) { return *this = int128(v); } -inline int128& int128::operator=(unsigned int v) { - return *this = int128(v); -} +inline int128& int128::operator=(unsigned int v) { return *this = int128(v); } inline int128& int128::operator=(long v) { // NOLINT(runtime/int) return *this = int128(v); } // NOLINTNEXTLINE(runtime/int) -inline int128& int128::operator=(unsigned long v) { - return *this = int128(v); -} +inline int128& int128::operator=(unsigned long v) { return *this = int128(v); } // NOLINTNEXTLINE(runtime/int) -inline int128& int128::operator=(long long v) { - return *this = int128(v); -} +inline int128& int128::operator=(long long v) { return *this = int128(v); } // NOLINTNEXTLINE(runtime/int) inline int128& int128::operator=(unsigned long long v) { diff --git a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128_have_intrinsic.inc b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128_have_intrinsic.inc index 55f20267851..7133611d8f0 100644 --- a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128_have_intrinsic.inc +++ b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128_have_intrinsic.inc @@ -162,9 +162,6 @@ inline int128::operator long double() const { } #else // Clang on PowerPC -// Forward declaration for conversion operators to floating point types. -constexpr int128 operator-(int128 v); -constexpr bool operator!=(int128 lhs, int128 rhs); inline int128::operator float() const { // We must convert the absolute value and then negate as needed, because diff --git a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128_no_intrinsic.inc b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128_no_intrinsic.inc index 8354bd56159..e41d2a55e6d 100644 --- a/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128_no_intrinsic.inc +++ b/contrib/restricted/abseil-cpp-tstring/y_absl/numeric/int128_no_intrinsic.inc @@ -23,8 +23,7 @@ constexpr int64_t Int128High64(int128 v) { return v.hi_; } #if defined(Y_ABSL_IS_LITTLE_ENDIAN) -constexpr int128::int128(int64_t high, uint64_t low) : - lo_(low), hi_(high) {} +constexpr int128::int128(int64_t high, uint64_t low) : lo_(low), hi_(high) {} constexpr int128::int128(int v) : lo_{static_cast<uint64_t>(v)}, hi_{v < 0 ? ~int64_t{0} : 0} {} @@ -44,8 +43,7 @@ constexpr int128::int128(uint128 v) #elif defined(Y_ABSL_IS_BIG_ENDIAN) -constexpr int128::int128(int64_t high, uint64_t low) : - hi_{high}, lo_{low} {} +constexpr int128::int128(int64_t high, uint64_t low) : hi_{high}, lo_{low} {} constexpr int128::int128(int v) : hi_{v < 0 ? ~int64_t{0} : 0}, lo_{static_cast<uint64_t>(v)} {} @@ -279,33 +277,52 @@ constexpr int128 operator^(int128 lhs, int128 rhs) { } constexpr int128 operator<<(int128 lhs, int amount) { - // int64_t shifts of >= 64 are undefined, so we need some special-casing. - return amount >= 64 - ? MakeInt128( - static_cast<int64_t>(Int128Low64(lhs) << (amount - 64)), 0) - : amount == 0 - ? lhs - : MakeInt128( - (Int128High64(lhs) << amount) | - static_cast<int64_t>(Int128Low64(lhs) >> (64 - amount)), - Int128Low64(lhs) << amount); + // int64_t shifts of >= 63 are undefined, so we need some special-casing. + assert(amount >= 0 && amount < 127); + if (amount <= 0) { + return lhs; + } else if (amount < 63) { + return MakeInt128( + (Int128High64(lhs) << amount) | + static_cast<int64_t>(Int128Low64(lhs) >> (64 - amount)), + Int128Low64(lhs) << amount); + } else if (amount == 63) { + return MakeInt128(((Int128High64(lhs) << 32) << 31) | + static_cast<int64_t>(Int128Low64(lhs) >> 1), + (Int128Low64(lhs) << 32) << 31); + } else if (amount == 127) { + return MakeInt128(static_cast<int64_t>(Int128Low64(lhs) << 63), 0); + } else if (amount > 127) { + return MakeInt128(0, 0); + } else { + // amount >= 64 && amount < 127 + return MakeInt128(static_cast<int64_t>(Int128Low64(lhs) << (amount - 64)), + 0); + } } constexpr int128 operator>>(int128 lhs, int amount) { - // int64_t shifts of >= 64 are undefined, so we need some special-casing. - // The (Int128High64(lhs) >> 32) >> 32 "trick" causes the the most significant - // int64 to be inititialized with all zeros or all ones correctly. It takes - // into account whether the number is negative or positive, and whether the - // current architecture does arithmetic or logical right shifts for negative - // numbers. - return amount >= 64 - ? MakeInt128( - (Int128High64(lhs) >> 32) >> 32, - static_cast<uint64_t>(Int128High64(lhs) >> (amount - 64))) - : amount == 0 - ? lhs - : MakeInt128(Int128High64(lhs) >> amount, - (Int128Low64(lhs) >> amount) | - (static_cast<uint64_t>(Int128High64(lhs)) - << (64 - amount))); + // int64_t shifts of >= 63 are undefined, so we need some special-casing. + assert(amount >= 0 && amount < 127); + if (amount <= 0) { + return lhs; + } else if (amount < 63) { + return MakeInt128( + Int128High64(lhs) >> amount, + Int128Low64(lhs) >> amount | static_cast<uint64_t>(Int128High64(lhs)) + << (64 - amount)); + } else if (amount == 63) { + return MakeInt128((Int128High64(lhs) >> 32) >> 31, + static_cast<uint64_t>(Int128High64(lhs) << 1) | + (Int128Low64(lhs) >> 32) >> 31); + + } else if (amount >= 127) { + return MakeInt128((Int128High64(lhs) >> 32) >> 31, + static_cast<uint64_t>((Int128High64(lhs) >> 32) >> 31)); + } else { + // amount >= 64 && amount < 127 + return MakeInt128( + (Int128High64(lhs) >> 32) >> 31, + static_cast<uint64_t>(Int128High64(lhs) >> (amount - 64))); + } } |