From 582e4baf37cdfe23f17d4c6ca8fdd912108cfd29 Mon Sep 17 00:00:00 2001 From: Gil Date: Tue, 6 Feb 2018 09:35:10 -0800 Subject: Add StrCat, StrJoin and the rest of //strings from abseil-cpp (#756) From abseil-cpp version bf7fc9986e20f664958fc227547fd8d2fdcf863e --- .../abseil-cpp/absl/numeric/CMakeLists.txt | 62 ++ .../third_party/abseil-cpp/absl/numeric/int128.cc | 206 +++++++ .../third_party/abseil-cpp/absl/numeric/int128.h | 632 +++++++++++++++++++ .../absl/numeric/int128_have_intrinsic.inc | 3 + .../absl/numeric/int128_no_intrinsic.inc | 3 + .../abseil-cpp/absl/numeric/int128_stream_test.cc | 666 +++++++++++++++++++++ .../abseil-cpp/absl/numeric/int128_test.cc | 429 +++++++++++++ 7 files changed, 2001 insertions(+) create mode 100644 Firestore/third_party/abseil-cpp/absl/numeric/CMakeLists.txt create mode 100644 Firestore/third_party/abseil-cpp/absl/numeric/int128.cc create mode 100644 Firestore/third_party/abseil-cpp/absl/numeric/int128.h create mode 100644 Firestore/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc create mode 100644 Firestore/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc create mode 100644 Firestore/third_party/abseil-cpp/absl/numeric/int128_stream_test.cc create mode 100644 Firestore/third_party/abseil-cpp/absl/numeric/int128_test.cc (limited to 'Firestore/third_party/abseil-cpp/absl/numeric') diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/CMakeLists.txt b/Firestore/third_party/abseil-cpp/absl/numeric/CMakeLists.txt new file mode 100644 index 0000000..3360b2e --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/numeric/CMakeLists.txt @@ -0,0 +1,62 @@ +# +# Copyright 2017 The Abseil Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +list(APPEND NUMERIC_PUBLIC_HEADERS + "int128.h" +) + + +# library 128 +list(APPEND INT128_SRC + "int128.cc" + ${NUMERIC_PUBLIC_HEADERS} +) +absl_library( + TARGET + absl_int128 + SOURCES + ${INT128_SRC} + PUBLIC_LIBRARIES + ${INT128_PUBLIC_LIBRARIES} + EXPORT_NAME + int128 +) + + +absl_header_library( + TARGET + absl_numeric + PUBLIC_LIBRARIES + absl::int128 + EXPORT_NAME + numeric +) + +# test int128_test +set(INT128_TEST_SRC "int128_test.cc") +set(INT128_TEST_PUBLIC_LIBRARIES absl::numeric absl::base) + +absl_test( + TARGET + int128_test + SOURCES + ${INT128_TEST_SRC} + PUBLIC_LIBRARIES + ${INT128_TEST_PUBLIC_LIBRARIES} +) + + + diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128.cc b/Firestore/third_party/abseil-cpp/absl/numeric/int128.cc new file mode 100644 index 0000000..00bf7f4 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128.cc @@ -0,0 +1,206 @@ +// Copyright 2017 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/numeric/int128.h" + +#include +#include +#include +#include // NOLINT(readability/streams) +#include +#include + +namespace absl { + +const uint128 kuint128max = MakeUint128(std::numeric_limits::max(), + std::numeric_limits::max()); + +namespace { + +// Returns the 0-based position of the last set bit (i.e., most significant bit) +// in the given uint64_t. The argument may not be 0. +// +// For example: +// Given: 5 (decimal) == 101 (binary) +// Returns: 2 +#define STEP(T, n, pos, sh) \ + do { \ + if ((n) >= (static_cast(1) << (sh))) { \ + (n) = (n) >> (sh); \ + (pos) |= (sh); \ + } \ + } while (0) +static inline int Fls64(uint64_t n) { + assert(n != 0); + int pos = 0; + STEP(uint64_t, n, pos, 0x20); + uint32_t n32 = static_cast(n); + STEP(uint32_t, n32, pos, 0x10); + STEP(uint32_t, n32, pos, 0x08); + STEP(uint32_t, n32, pos, 0x04); + return pos + ((uint64_t{0x3333333322221100} >> (n32 << 2)) & 0x3); +} +#undef STEP + +// Like Fls64() above, but returns the 0-based position of the last set bit +// (i.e., most significant bit) in the given uint128. The argument may not be 0. +static inline int Fls128(uint128 n) { + if (uint64_t hi = Uint128High64(n)) { + return Fls64(hi) + 64; + } + return Fls64(Uint128Low64(n)); +} + +// Long division/modulo for uint128 implemented using the shift-subtract +// division algorithm adapted from: +// http://stackoverflow.com/questions/5386377/division-without-using +void DivModImpl(uint128 dividend, uint128 divisor, uint128* quotient_ret, + uint128* remainder_ret) { + assert(divisor != 0); + + if (divisor > dividend) { + *quotient_ret = 0; + *remainder_ret = dividend; + return; + } + + if (divisor == dividend) { + *quotient_ret = 1; + *remainder_ret = 0; + return; + } + + uint128 denominator = divisor; + uint128 quotient = 0; + + // Left aligns the MSB of the denominator and the dividend. + const int shift = Fls128(dividend) - Fls128(denominator); + denominator <<= shift; + + // Uses shift-subtract algorithm to divide dividend by denominator. The + // remainder will be left in dividend. + for (int i = 0; i <= shift; ++i) { + quotient <<= 1; + if (dividend >= denominator) { + dividend -= denominator; + quotient |= 1; + } + denominator >>= 1; + } + + *quotient_ret = quotient; + *remainder_ret = dividend; +} + +template +uint128 Initialize128FromFloat(T v) { + // Rounding behavior is towards zero, same as for built-in types. + + // Undefined behavior if v is NaN or cannot fit into uint128. + assert(!std::isnan(v) && v > -1 && v < std::ldexp(static_cast(1), 128)); + + if (v >= std::ldexp(static_cast(1), 64)) { + uint64_t hi = static_cast(std::ldexp(v, -64)); + uint64_t lo = static_cast(v - std::ldexp(static_cast(hi), 64)); + return MakeUint128(hi, lo); + } + + return MakeUint128(0, static_cast(v)); +} +} // namespace + +uint128::uint128(float v) : uint128(Initialize128FromFloat(v)) {} +uint128::uint128(double v) : uint128(Initialize128FromFloat(v)) {} +uint128::uint128(long double v) : uint128(Initialize128FromFloat(v)) {} + +uint128& uint128::operator/=(uint128 other) { + uint128 quotient = 0; + uint128 remainder = 0; + DivModImpl(*this, other, "ient, &remainder); + *this = quotient; + return *this; +} +uint128& uint128::operator%=(uint128 other) { + uint128 quotient = 0; + uint128 remainder = 0; + DivModImpl(*this, other, "ient, &remainder); + *this = remainder; + return *this; +} + +std::ostream& operator<<(std::ostream& o, uint128 b) { + std::ios_base::fmtflags flags = o.flags(); + + // Select a divisor which is the largest power of the base < 2^64. + uint128 div; + int div_base_log; + switch (flags & std::ios::basefield) { + case std::ios::hex: + div = 0x1000000000000000; // 16^15 + div_base_log = 15; + break; + case std::ios::oct: + div = 01000000000000000000000; // 8^21 + div_base_log = 21; + break; + default: // std::ios::dec + div = 10000000000000000000u; // 10^19 + div_base_log = 19; + break; + } + + // Now piece together the uint128 representation from three chunks of + // the original value, each less than "div" and therefore representable + // as a uint64_t. + std::ostringstream os; + std::ios_base::fmtflags copy_mask = + std::ios::basefield | std::ios::showbase | std::ios::uppercase; + os.setf(flags & copy_mask, copy_mask); + uint128 high = b; + uint128 low; + DivModImpl(high, div, &high, &low); + uint128 mid; + DivModImpl(high, div, &high, &mid); + if (Uint128Low64(high) != 0) { + os << Uint128Low64(high); + os << std::noshowbase << std::setfill('0') << std::setw(div_base_log); + os << Uint128Low64(mid); + os << std::setw(div_base_log); + } else if (Uint128Low64(mid) != 0) { + os << Uint128Low64(mid); + os << std::noshowbase << std::setfill('0') << std::setw(div_base_log); + } + os << Uint128Low64(low); + std::string rep = os.str(); + + // Add the requisite padding. + std::streamsize width = o.width(0); + if (static_cast(width) > rep.size()) { + std::ios::fmtflags adjustfield = flags & std::ios::adjustfield; + if (adjustfield == std::ios::left) { + rep.append(width - rep.size(), o.fill()); + } else if (adjustfield == std::ios::internal && + (flags & std::ios::showbase) && + (flags & std::ios::basefield) == std::ios::hex && b != 0) { + rep.insert(2, width - rep.size(), o.fill()); + } else { + rep.insert(0, width - rep.size(), o.fill()); + } + } + + // Stream the final representation in a single "<<" call. + return o << rep; +} + +} // namespace absl diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128.h b/Firestore/third_party/abseil-cpp/absl/numeric/int128.h new file mode 100644 index 0000000..d87cbbd --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128.h @@ -0,0 +1,632 @@ +// +// Copyright 2017 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ----------------------------------------------------------------------------- +// File: int128.h +// ----------------------------------------------------------------------------- +// +// This header file defines 128-bit integer types. Currently, this file defines +// `uint128`, an unsigned 128-bit integer; a signed 128-bit integer is +// forthcoming. + +#ifndef ABSL_NUMERIC_INT128_H_ +#define ABSL_NUMERIC_INT128_H_ + +#include +#include +#include +#include +#include +#include + +#include "absl/base/config.h" +#include "absl/base/macros.h" +#include "absl/base/port.h" + +namespace absl { + +// uint128 +// +// An unsigned 128-bit integer type. The API is meant to mimic an intrinsic type +// as closely as is practical, including exhibiting undefined behavior in +// analogous cases (e.g. division by zero). This type is intended to be a +// drop-in replacement once C++ supports an intrinsic `uint128_t` type; when +// that occurs, existing uses of `uint128` will continue to work using that new +// type. +// +// Note: code written with this type will continue to compile once `uint128_t` +// is introduced, provided the replacement helper functions +// `Uint128(Low|High)64()` and `MakeUint128()` are made. +// +// A `uint128` supports the following: +// +// * Implicit construction from integral types +// * Explicit conversion to integral types +// +// Additionally, if your compiler supports `__int128`, `uint128` is +// interoperable with that type. (Abseil checks for this compatibility through +// the `ABSL_HAVE_INTRINSIC_INT128` macro.) +// +// However, a `uint128` differs from intrinsic integral types in the following +// ways: +// +// * Errors on implicit conversions that does not preserve value (such as +// loss of precision when converting to float values). +// * Requires explicit construction from and conversion to floating point +// types. +// * Conversion to integral types requires an explicit static_cast() to +// mimic use of the `-Wnarrowing` compiler flag. +// +// Example: +// +// float y = absl::kuint128max; // Error. uint128 cannot be implicitly +// // converted to float. +// +// absl::uint128 v; +// absl::uint64_t i = v; // Error +// absl::uint64_t i = static_cast(v); // OK +// +class alignas(16) uint128 { + public: + uint128() = default; + + // Constructors from arithmetic types + constexpr uint128(int v); // NOLINT(runtime/explicit) + constexpr uint128(unsigned int v); // NOLINT(runtime/explicit) + constexpr uint128(long v); // NOLINT(runtime/int) + constexpr uint128(unsigned long v); // NOLINT(runtime/int) + constexpr uint128(long long v); // NOLINT(runtime/int) + constexpr uint128(unsigned long long v); // NOLINT(runtime/int) +#ifdef ABSL_HAVE_INTRINSIC_INT128 + constexpr uint128(__int128 v); // NOLINT(runtime/explicit) + constexpr uint128(unsigned __int128 v); // NOLINT(runtime/explicit) +#endif // ABSL_HAVE_INTRINSIC_INT128 + explicit uint128(float v); + explicit uint128(double v); + explicit uint128(long double v); + + // Assignment operators from arithmetic types + uint128& operator=(int v); + uint128& operator=(unsigned int v); + uint128& operator=(long v); // NOLINT(runtime/int) + uint128& operator=(unsigned long v); // NOLINT(runtime/int) + uint128& operator=(long long v); // NOLINT(runtime/int) + uint128& operator=(unsigned long long v); // NOLINT(runtime/int) +#ifdef ABSL_HAVE_INTRINSIC_INT128 + uint128& operator=(__int128 v); + uint128& operator=(unsigned __int128 v); +#endif // ABSL_HAVE_INTRINSIC_INT128 + + // Conversion operators to other arithmetic types + constexpr explicit operator bool() const; + constexpr explicit operator char() const; + constexpr explicit operator signed char() const; + constexpr explicit operator unsigned char() const; + constexpr explicit operator char16_t() const; + constexpr explicit operator char32_t() const; + constexpr explicit operator wchar_t() const; + constexpr explicit operator short() const; // NOLINT(runtime/int) + // NOLINTNEXTLINE(runtime/int) + constexpr explicit operator unsigned short() const; + constexpr explicit operator int() const; + constexpr explicit operator unsigned int() const; + constexpr explicit operator long() const; // NOLINT(runtime/int) + // NOLINTNEXTLINE(runtime/int) + constexpr explicit operator unsigned long() const; + // NOLINTNEXTLINE(runtime/int) + constexpr explicit operator long long() const; + // NOLINTNEXTLINE(runtime/int) + constexpr explicit operator unsigned long long() const; +#ifdef ABSL_HAVE_INTRINSIC_INT128 + constexpr explicit operator __int128() const; + constexpr explicit operator unsigned __int128() const; +#endif // ABSL_HAVE_INTRINSIC_INT128 + explicit operator float() const; + explicit operator double() const; + explicit operator long double() const; + + // Trivial copy constructor, assignment operator and destructor. + + // Arithmetic operators. + uint128& operator+=(uint128 other); + uint128& operator-=(uint128 other); + uint128& operator*=(uint128 other); + // Long division/modulo for uint128. + uint128& operator/=(uint128 other); + uint128& operator%=(uint128 other); + uint128 operator++(int); + uint128 operator--(int); + uint128& operator<<=(int); + uint128& operator>>=(int); + uint128& operator&=(uint128 other); + uint128& operator|=(uint128 other); + uint128& operator^=(uint128 other); + uint128& operator++(); + uint128& operator--(); + + // Uint128Low64() + // + // Returns the lower 64-bit value of a `uint128` value. + friend constexpr uint64_t Uint128Low64(uint128 v); + + // Uint128High64() + // + // Returns the higher 64-bit value of a `uint128` value. + friend constexpr uint64_t Uint128High64(uint128 v); + + // MakeUInt128() + // + // Constructs a `uint128` numeric value from two 64-bit unsigned integers. + // Note that this factory function is the only way to construct a `uint128` + // from integer values greater than 2^64. + // + // Example: + // + // absl::uint128 big = absl::MakeUint128(1, 0); + friend constexpr uint128 MakeUint128(uint64_t top, uint64_t bottom); + + private: + constexpr uint128(uint64_t top, uint64_t bottom); + + // 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 + // platforms. +#if defined(ABSL_IS_LITTLE_ENDIAN) + uint64_t lo_; + uint64_t hi_; +#elif defined(ABSL_IS_BIG_ENDIAN) + uint64_t hi_; + uint64_t lo_; +#else // byte order +#error "Unsupported byte order: must be little-endian or big-endian." +#endif // byte order +}; + +extern const uint128 kuint128max; + +// allow uint128 to be logged +extern std::ostream& operator<<(std::ostream& o, uint128 b); + +// TODO(strel) add operator>>(std::istream&, uint128) + +// TODO(absl-team): Implement signed 128-bit type + +// -------------------------------------------------------------------------- +// Implementation details follow +// -------------------------------------------------------------------------- + +constexpr uint128 MakeUint128(uint64_t top, uint64_t bottom) { + return uint128(top, bottom); +} + +// Assignment from integer types. + +inline uint128& uint128::operator=(int v) { return *this = uint128(v); } + +inline uint128& uint128::operator=(unsigned int v) { + return *this = uint128(v); +} + +inline uint128& uint128::operator=(long v) { // NOLINT(runtime/int) + return *this = uint128(v); +} + +// NOLINTNEXTLINE(runtime/int) +inline uint128& uint128::operator=(unsigned long v) { + return *this = uint128(v); +} + +// NOLINTNEXTLINE(runtime/int) +inline uint128& uint128::operator=(long long v) { + return *this = uint128(v); +} + +// NOLINTNEXTLINE(runtime/int) +inline uint128& uint128::operator=(unsigned long long v) { + return *this = uint128(v); +} + +#ifdef ABSL_HAVE_INTRINSIC_INT128 +inline uint128& uint128::operator=(__int128 v) { + return *this = uint128(v); +} + +inline uint128& uint128::operator=(unsigned __int128 v) { + return *this = uint128(v); +} +#endif // ABSL_HAVE_INTRINSIC_INT128 + +// Shift and arithmetic operators. + +inline uint128 operator<<(uint128 lhs, int amount) { + return uint128(lhs) <<= amount; +} + +inline uint128 operator>>(uint128 lhs, int amount) { + return uint128(lhs) >>= amount; +} + +inline uint128 operator+(uint128 lhs, uint128 rhs) { + return uint128(lhs) += rhs; +} + +inline uint128 operator-(uint128 lhs, uint128 rhs) { + return uint128(lhs) -= rhs; +} + +inline uint128 operator*(uint128 lhs, uint128 rhs) { + return uint128(lhs) *= rhs; +} + +inline uint128 operator/(uint128 lhs, uint128 rhs) { + return uint128(lhs) /= rhs; +} + +inline uint128 operator%(uint128 lhs, uint128 rhs) { + return uint128(lhs) %= rhs; +} + +constexpr uint64_t Uint128Low64(uint128 v) { return v.lo_; } + +constexpr uint64_t Uint128High64(uint128 v) { return v.hi_; } + +// Constructors from integer types. + +#if defined(ABSL_IS_LITTLE_ENDIAN) + +constexpr uint128::uint128(uint64_t top, uint64_t bottom) + : lo_(bottom), hi_(top) {} + +constexpr uint128::uint128(int v) + : lo_(v), hi_(v < 0 ? std::numeric_limits::max() : 0) {} +constexpr uint128::uint128(long v) // NOLINT(runtime/int) + : lo_(v), hi_(v < 0 ? std::numeric_limits::max() : 0) {} +constexpr uint128::uint128(long long v) // NOLINT(runtime/int) + : lo_(v), hi_(v < 0 ? std::numeric_limits::max() : 0) {} + +constexpr uint128::uint128(unsigned int v) : lo_(v), hi_(0) {} +// NOLINTNEXTLINE(runtime/int) +constexpr uint128::uint128(unsigned long v) : lo_(v), hi_(0) {} +// NOLINTNEXTLINE(runtime/int) +constexpr uint128::uint128(unsigned long long v) : lo_(v), hi_(0) {} + +#ifdef ABSL_HAVE_INTRINSIC_INT128 +constexpr uint128::uint128(__int128 v) + : lo_(static_cast(v & ~uint64_t{0})), + hi_(static_cast(static_cast(v) >> 64)) {} +constexpr uint128::uint128(unsigned __int128 v) + : lo_(static_cast(v & ~uint64_t{0})), + hi_(static_cast(v >> 64)) {} +#endif // ABSL_HAVE_INTRINSIC_INT128 + +#elif defined(ABSL_IS_BIG_ENDIAN) + +constexpr uint128::uint128(uint64_t top, uint64_t bottom) + : hi_(top), lo_(bottom) {} + +constexpr uint128::uint128(int v) + : hi_(v < 0 ? std::numeric_limits::max() : 0), lo_(v) {} +constexpr uint128::uint128(long v) // NOLINT(runtime/int) + : hi_(v < 0 ? std::numeric_limits::max() : 0), lo_(v) {} +constexpr uint128::uint128(long long v) // NOLINT(runtime/int) + : hi_(v < 0 ? std::numeric_limits::max() : 0), lo_(v) {} + +constexpr uint128::uint128(unsigned int v) : hi_(0), lo_(v) {} +// NOLINTNEXTLINE(runtime/int) +constexpr uint128::uint128(unsigned long v) : hi_(0), lo_(v) {} +// NOLINTNEXTLINE(runtime/int) +constexpr uint128::uint128(unsigned long long v) : hi_(0), lo_(v) {} + +#ifdef ABSL_HAVE_INTRINSIC_INT128 +constexpr uint128::uint128(__int128 v) + : hi_(static_cast(static_cast(v) >> 64)), + lo_(static_cast(v & ~uint64_t{0})) {} +constexpr uint128::uint128(unsigned __int128 v) + : hi_(static_cast(v >> 64)), + lo_(static_cast(v & ~uint64_t{0})) {} +#endif // ABSL_HAVE_INTRINSIC_INT128 + +#else // byte order +#error "Unsupported byte order: must be little-endian or big-endian." +#endif // byte order + +// Conversion operators to integer types. + +constexpr uint128::operator bool() const { return lo_ || hi_; } + +constexpr uint128::operator char() const { return static_cast(lo_); } + +constexpr uint128::operator signed char() const { + return static_cast(lo_); +} + +constexpr uint128::operator unsigned char() const { + return static_cast(lo_); +} + +constexpr uint128::operator char16_t() const { + return static_cast(lo_); +} + +constexpr uint128::operator char32_t() const { + return static_cast(lo_); +} + +constexpr uint128::operator wchar_t() const { + return static_cast(lo_); +} + +// NOLINTNEXTLINE(runtime/int) +constexpr uint128::operator short() const { return static_cast(lo_); } + +constexpr uint128::operator unsigned short() const { // NOLINT(runtime/int) + return static_cast(lo_); // NOLINT(runtime/int) +} + +constexpr uint128::operator int() const { return static_cast(lo_); } + +constexpr uint128::operator unsigned int() const { + return static_cast(lo_); +} + +// NOLINTNEXTLINE(runtime/int) +constexpr uint128::operator long() const { return static_cast(lo_); } + +constexpr uint128::operator unsigned long() const { // NOLINT(runtime/int) + return static_cast(lo_); // NOLINT(runtime/int) +} + +constexpr uint128::operator long long() const { // NOLINT(runtime/int) + return static_cast(lo_); // NOLINT(runtime/int) +} + +constexpr uint128::operator unsigned long long() const { // NOLINT(runtime/int) + return static_cast(lo_); // NOLINT(runtime/int) +} + +#ifdef ABSL_HAVE_INTRINSIC_INT128 +constexpr uint128::operator __int128() const { + return (static_cast<__int128>(hi_) << 64) + lo_; +} + +constexpr uint128::operator unsigned __int128() const { + return (static_cast(hi_) << 64) + lo_; +} +#endif // ABSL_HAVE_INTRINSIC_INT128 + +// Conversion operators to floating point types. + +inline uint128::operator float() const { + return static_cast(lo_) + std::ldexp(static_cast(hi_), 64); +} + +inline uint128::operator double() const { + return static_cast(lo_) + std::ldexp(static_cast(hi_), 64); +} + +inline uint128::operator long double() const { + return static_cast(lo_) + + std::ldexp(static_cast(hi_), 64); +} + +// Comparison operators. + +inline bool operator==(uint128 lhs, uint128 rhs) { + return (Uint128Low64(lhs) == Uint128Low64(rhs) && + Uint128High64(lhs) == Uint128High64(rhs)); +} + +inline bool operator!=(uint128 lhs, uint128 rhs) { + return !(lhs == rhs); +} + +inline bool operator<(uint128 lhs, uint128 rhs) { + return (Uint128High64(lhs) == Uint128High64(rhs)) + ? (Uint128Low64(lhs) < Uint128Low64(rhs)) + : (Uint128High64(lhs) < Uint128High64(rhs)); +} + +inline bool operator>(uint128 lhs, uint128 rhs) { + return (Uint128High64(lhs) == Uint128High64(rhs)) + ? (Uint128Low64(lhs) > Uint128Low64(rhs)) + : (Uint128High64(lhs) > Uint128High64(rhs)); +} + +inline bool operator<=(uint128 lhs, uint128 rhs) { + return (Uint128High64(lhs) == Uint128High64(rhs)) + ? (Uint128Low64(lhs) <= Uint128Low64(rhs)) + : (Uint128High64(lhs) <= Uint128High64(rhs)); +} + +inline bool operator>=(uint128 lhs, uint128 rhs) { + return (Uint128High64(lhs) == Uint128High64(rhs)) + ? (Uint128Low64(lhs) >= Uint128Low64(rhs)) + : (Uint128High64(lhs) >= Uint128High64(rhs)); +} + +// Unary operators. + +inline uint128 operator-(uint128 val) { + const uint64_t hi_flip = ~Uint128High64(val); + const uint64_t lo_flip = ~Uint128Low64(val); + const uint64_t lo_add = lo_flip + 1; + if (lo_add < lo_flip) { + return MakeUint128(hi_flip + 1, lo_add); + } + return MakeUint128(hi_flip, lo_add); +} + +inline bool operator!(uint128 val) { + return !Uint128High64(val) && !Uint128Low64(val); +} + +// Logical operators. + +inline uint128 operator~(uint128 val) { + return MakeUint128(~Uint128High64(val), ~Uint128Low64(val)); +} + +inline uint128 operator|(uint128 lhs, uint128 rhs) { + return MakeUint128(Uint128High64(lhs) | Uint128High64(rhs), + Uint128Low64(lhs) | Uint128Low64(rhs)); +} + +inline uint128 operator&(uint128 lhs, uint128 rhs) { + return MakeUint128(Uint128High64(lhs) & Uint128High64(rhs), + Uint128Low64(lhs) & Uint128Low64(rhs)); +} + +inline uint128 operator^(uint128 lhs, uint128 rhs) { + return MakeUint128(Uint128High64(lhs) ^ Uint128High64(rhs), + Uint128Low64(lhs) ^ Uint128Low64(rhs)); +} + +inline uint128& uint128::operator|=(uint128 other) { + hi_ |= other.hi_; + lo_ |= other.lo_; + return *this; +} + +inline uint128& uint128::operator&=(uint128 other) { + hi_ &= other.hi_; + lo_ &= other.lo_; + return *this; +} + +inline uint128& uint128::operator^=(uint128 other) { + hi_ ^= other.hi_; + lo_ ^= other.lo_; + return *this; +} + +// Shift and arithmetic assign operators. + +inline uint128& uint128::operator<<=(int amount) { + // Shifts of >= 128 are undefined. + assert(amount < 128); + + // uint64_t shifts of >= 64 are undefined, so we will need some + // special-casing. + if (amount < 64) { + if (amount != 0) { + hi_ = (hi_ << amount) | (lo_ >> (64 - amount)); + lo_ = lo_ << amount; + } + } else { + hi_ = lo_ << (amount - 64); + lo_ = 0; + } + return *this; +} + +inline uint128& uint128::operator>>=(int amount) { + // Shifts of >= 128 are undefined. + assert(amount < 128); + + // uint64_t shifts of >= 64 are undefined, so we will need some + // special-casing. + if (amount < 64) { + if (amount != 0) { + lo_ = (lo_ >> amount) | (hi_ << (64 - amount)); + hi_ = hi_ >> amount; + } + } else { + lo_ = hi_ >> (amount - 64); + hi_ = 0; + } + return *this; +} + +inline uint128& uint128::operator+=(uint128 other) { + hi_ += other.hi_; + uint64_t lolo = lo_ + other.lo_; + if (lolo < lo_) + ++hi_; + lo_ = lolo; + return *this; +} + +inline uint128& uint128::operator-=(uint128 other) { + hi_ -= other.hi_; + if (other.lo_ > lo_) --hi_; + lo_ -= other.lo_; + return *this; +} + +inline uint128& uint128::operator*=(uint128 other) { +#if defined(ABSL_HAVE_INTRINSIC_INT128) + // TODO(strel) Remove once alignment issues are resolved and unsigned __int128 + // can be used for uint128 storage. + *this = static_cast(*this) * + static_cast(other); + return *this; +#else // ABSL_HAVE_INTRINSIC128 + uint64_t a96 = hi_ >> 32; + uint64_t a64 = hi_ & 0xffffffff; + uint64_t a32 = lo_ >> 32; + uint64_t a00 = lo_ & 0xffffffff; + uint64_t b96 = other.hi_ >> 32; + uint64_t b64 = other.hi_ & 0xffffffff; + uint64_t b32 = other.lo_ >> 32; + uint64_t b00 = other.lo_ & 0xffffffff; + // multiply [a96 .. a00] x [b96 .. b00] + // terms higher than c96 disappear off the high side + // terms c96 and c64 are safe to ignore carry bit + uint64_t c96 = a96 * b00 + a64 * b32 + a32 * b64 + a00 * b96; + uint64_t c64 = a64 * b00 + a32 * b32 + a00 * b64; + this->hi_ = (c96 << 32) + c64; + this->lo_ = 0; + // add terms after this one at a time to capture carry + *this += uint128(a32 * b00) << 32; + *this += uint128(a00 * b32) << 32; + *this += a00 * b00; + return *this; +#endif // ABSL_HAVE_INTRINSIC128 +} + +// Increment/decrement operators. + +inline uint128 uint128::operator++(int) { + uint128 tmp(*this); + *this += 1; + return tmp; +} + +inline uint128 uint128::operator--(int) { + uint128 tmp(*this); + *this -= 1; + return tmp; +} + +inline uint128& uint128::operator++() { + *this += 1; + return *this; +} + +inline uint128& uint128::operator--() { + *this -= 1; + return *this; +} + +#if defined(ABSL_HAVE_INTRINSIC_INT128) +#include "absl/numeric/int128_have_intrinsic.inc" +#else // ABSL_HAVE_INTRINSIC_INT128 +#include "absl/numeric/int128_no_intrinsic.inc" +#endif // ABSL_HAVE_INTRINSIC_INT128 + +} // namespace absl + +#endif // ABSL_NUMERIC_INT128_H_ diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc b/Firestore/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc new file mode 100644 index 0000000..49bde07 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc @@ -0,0 +1,3 @@ +// This file will contain :int128 implementation details that depend on internal +// representation when ABSL_HAVE_INTRINSIC_INT128 is defined. This file will be +// included by int128.h. diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc b/Firestore/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc new file mode 100644 index 0000000..2dbff2b --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc @@ -0,0 +1,3 @@ +// This file will contain :int128 implementation details that depend on internal +// representation when ABSL_HAVE_INTRINSIC_INT128 is *not* defined. This file +// will be included by int128.h. diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128_stream_test.cc b/Firestore/third_party/abseil-cpp/absl/numeric/int128_stream_test.cc new file mode 100644 index 0000000..09efaad --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128_stream_test.cc @@ -0,0 +1,666 @@ +// Copyright 2017 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/numeric/int128.h" + +#include +#include + +#include "gtest/gtest.h" + +namespace { + +struct Uint128TestCase { + absl::uint128 value; + std::ios_base::fmtflags flags; + std::streamsize width; + const char* expected; +}; + +constexpr char kFill = '_'; + +std::string StreamFormatToString(std::ios_base::fmtflags flags, + std::streamsize width) { + std::vector flagstr; + switch (flags & std::ios::basefield) { + case std::ios::dec: + flagstr.push_back("std::ios::dec"); + break; + case std::ios::oct: + flagstr.push_back("std::ios::oct"); + break; + case std::ios::hex: + flagstr.push_back("std::ios::hex"); + break; + default: // basefield not specified + break; + } + switch (flags & std::ios::adjustfield) { + case std::ios::left: + flagstr.push_back("std::ios::left"); + break; + case std::ios::internal: + flagstr.push_back("std::ios::internal"); + break; + case std::ios::right: + flagstr.push_back("std::ios::right"); + break; + default: // adjustfield not specified + break; + } + if (flags & std::ios::uppercase) flagstr.push_back("std::ios::uppercase"); + if (flags & std::ios::showbase) flagstr.push_back("std::ios::showbase"); + if (flags & std::ios::showpos) flagstr.push_back("std::ios::showpos"); + + std::ostringstream msg; + msg << "\n StreamFormatToString(test_case.flags, test_case.width)\n " + "flags: "; + if (!flagstr.empty()) { + for (size_t i = 0; i < flagstr.size() - 1; ++i) msg << flagstr[i] << " | "; + msg << flagstr.back(); + } else { + msg << "(default)"; + } + msg << "\n width: " << width << "\n fill: '" << kFill << "'"; + return msg.str(); +} + +void CheckUint128Case(const Uint128TestCase& test_case) { + std::ostringstream os; + os.flags(test_case.flags); + os.width(test_case.width); + os.fill(kFill); + os << test_case.value; + SCOPED_TRACE(StreamFormatToString(test_case.flags, test_case.width)); + EXPECT_EQ(test_case.expected, os.str()); +} + +constexpr std::ios::fmtflags kDec = std::ios::dec; +constexpr std::ios::fmtflags kOct = std::ios::oct; +constexpr std::ios::fmtflags kHex = std::ios::hex; +constexpr std::ios::fmtflags kLeft = std::ios::left; +constexpr std::ios::fmtflags kInt = std::ios::internal; +constexpr std::ios::fmtflags kRight = std::ios::right; +constexpr std::ios::fmtflags kUpper = std::ios::uppercase; +constexpr std::ios::fmtflags kBase = std::ios::showbase; +constexpr std::ios::fmtflags kPos = std::ios::showpos; + +TEST(Uint128, OStreamValueTest) { + CheckUint128Case({1, kDec, /*width = */ 0, "1"}); + CheckUint128Case({1, kOct, /*width = */ 0, "1"}); + CheckUint128Case({1, kHex, /*width = */ 0, "1"}); + CheckUint128Case({9, kDec, /*width = */ 0, "9"}); + CheckUint128Case({9, kOct, /*width = */ 0, "11"}); + CheckUint128Case({9, kHex, /*width = */ 0, "9"}); + CheckUint128Case({12345, kDec, /*width = */ 0, "12345"}); + CheckUint128Case({12345, kOct, /*width = */ 0, "30071"}); + CheckUint128Case({12345, kHex, /*width = */ 0, "3039"}); + CheckUint128Case( + {0x8000000000000000, kDec, /*width = */ 0, "9223372036854775808"}); + CheckUint128Case( + {0x8000000000000000, kOct, /*width = */ 0, "1000000000000000000000"}); + CheckUint128Case( + {0x8000000000000000, kHex, /*width = */ 0, "8000000000000000"}); + CheckUint128Case({std::numeric_limits::max(), kDec, + /*width = */ 0, "18446744073709551615"}); + CheckUint128Case({std::numeric_limits::max(), kOct, + /*width = */ 0, "1777777777777777777777"}); + CheckUint128Case({std::numeric_limits::max(), kHex, + /*width = */ 0, "ffffffffffffffff"}); + CheckUint128Case( + {absl::MakeUint128(1, 0), kDec, /*width = */ 0, "18446744073709551616"}); + CheckUint128Case({absl::MakeUint128(1, 0), kOct, /*width = */ 0, + "2000000000000000000000"}); + CheckUint128Case( + {absl::MakeUint128(1, 0), kHex, /*width = */ 0, "10000000000000000"}); + CheckUint128Case({absl::MakeUint128(0x8000000000000000, 0), kDec, + /*width = */ 0, "170141183460469231731687303715884105728"}); + CheckUint128Case({absl::MakeUint128(0x8000000000000000, 0), kOct, + /*width = */ 0, + "2000000000000000000000000000000000000000000"}); + CheckUint128Case({absl::MakeUint128(0x8000000000000000, 0), kHex, + /*width = */ 0, "80000000000000000000000000000000"}); + CheckUint128Case({absl::kuint128max, kDec, /*width = */ 0, + "340282366920938463463374607431768211455"}); + CheckUint128Case({absl::kuint128max, kOct, /*width = */ 0, + "3777777777777777777777777777777777777777777"}); + CheckUint128Case({absl::kuint128max, kHex, /*width = */ 0, + "ffffffffffffffffffffffffffffffff"}); +} + +std::vector GetUint128FormatCases(); + +TEST(Uint128, OStreamFormatTest) { + for (const Uint128TestCase& test_case : GetUint128FormatCases()) { + CheckUint128Case(test_case); + } +} + +std::vector GetUint128FormatCases() { + return { + {0, std::ios_base::fmtflags(), /*width = */ 0, "0"}, + {0, std::ios_base::fmtflags(), /*width = */ 6, "_____0"}, + {0, kPos, /*width = */ 0, "0"}, + {0, kPos, /*width = */ 6, "_____0"}, + {0, kBase, /*width = */ 0, "0"}, + {0, kBase, /*width = */ 6, "_____0"}, + {0, kBase | kPos, /*width = */ 0, "0"}, + {0, kBase | kPos, /*width = */ 6, "_____0"}, + {0, kUpper, /*width = */ 0, "0"}, + {0, kUpper, /*width = */ 6, "_____0"}, + {0, kUpper | kPos, /*width = */ 0, "0"}, + {0, kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kUpper | kBase, /*width = */ 0, "0"}, + {0, kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kLeft, /*width = */ 0, "0"}, + {0, kLeft, /*width = */ 6, "0_____"}, + {0, kLeft | kPos, /*width = */ 0, "0"}, + {0, kLeft | kPos, /*width = */ 6, "0_____"}, + {0, kLeft | kBase, /*width = */ 0, "0"}, + {0, kLeft | kBase, /*width = */ 6, "0_____"}, + {0, kLeft | kBase | kPos, /*width = */ 0, "0"}, + {0, kLeft | kBase | kPos, /*width = */ 6, "0_____"}, + {0, kLeft | kUpper, /*width = */ 0, "0"}, + {0, kLeft | kUpper, /*width = */ 6, "0_____"}, + {0, kLeft | kUpper | kPos, /*width = */ 0, "0"}, + {0, kLeft | kUpper | kPos, /*width = */ 6, "0_____"}, + {0, kLeft | kUpper | kBase, /*width = */ 0, "0"}, + {0, kLeft | kUpper | kBase, /*width = */ 6, "0_____"}, + {0, kLeft | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kLeft | kUpper | kBase | kPos, /*width = */ 6, "0_____"}, + {0, kInt, /*width = */ 0, "0"}, + {0, kInt, /*width = */ 6, "_____0"}, + {0, kInt | kPos, /*width = */ 0, "0"}, + {0, kInt | kPos, /*width = */ 6, "_____0"}, + {0, kInt | kBase, /*width = */ 0, "0"}, + {0, kInt | kBase, /*width = */ 6, "_____0"}, + {0, kInt | kBase | kPos, /*width = */ 0, "0"}, + {0, kInt | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kInt | kUpper, /*width = */ 0, "0"}, + {0, kInt | kUpper, /*width = */ 6, "_____0"}, + {0, kInt | kUpper | kPos, /*width = */ 0, "0"}, + {0, kInt | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kInt | kUpper | kBase, /*width = */ 0, "0"}, + {0, kInt | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kInt | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kInt | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kRight, /*width = */ 0, "0"}, + {0, kRight, /*width = */ 6, "_____0"}, + {0, kRight | kPos, /*width = */ 0, "0"}, + {0, kRight | kPos, /*width = */ 6, "_____0"}, + {0, kRight | kBase, /*width = */ 0, "0"}, + {0, kRight | kBase, /*width = */ 6, "_____0"}, + {0, kRight | kBase | kPos, /*width = */ 0, "0"}, + {0, kRight | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kRight | kUpper, /*width = */ 0, "0"}, + {0, kRight | kUpper, /*width = */ 6, "_____0"}, + {0, kRight | kUpper | kPos, /*width = */ 0, "0"}, + {0, kRight | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kRight | kUpper | kBase, /*width = */ 0, "0"}, + {0, kRight | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kRight | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kRight | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kDec, /*width = */ 0, "0"}, + {0, kDec, /*width = */ 6, "_____0"}, + {0, kDec | kPos, /*width = */ 0, "0"}, + {0, kDec | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kBase, /*width = */ 0, "0"}, + {0, kDec | kBase, /*width = */ 6, "_____0"}, + {0, kDec | kBase | kPos, /*width = */ 0, "0"}, + {0, kDec | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kUpper, /*width = */ 0, "0"}, + {0, kDec | kUpper, /*width = */ 6, "_____0"}, + {0, kDec | kUpper | kPos, /*width = */ 0, "0"}, + {0, kDec | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kUpper | kBase, /*width = */ 0, "0"}, + {0, kDec | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kDec | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kDec | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kLeft, /*width = */ 0, "0"}, + {0, kDec | kLeft, /*width = */ 6, "0_____"}, + {0, kDec | kLeft | kPos, /*width = */ 0, "0"}, + {0, kDec | kLeft | kPos, /*width = */ 6, "0_____"}, + {0, kDec | kLeft | kBase, /*width = */ 0, "0"}, + {0, kDec | kLeft | kBase, /*width = */ 6, "0_____"}, + {0, kDec | kLeft | kBase | kPos, /*width = */ 0, "0"}, + {0, kDec | kLeft | kBase | kPos, /*width = */ 6, "0_____"}, + {0, kDec | kLeft | kUpper, /*width = */ 0, "0"}, + {0, kDec | kLeft | kUpper, /*width = */ 6, "0_____"}, + {0, kDec | kLeft | kUpper | kPos, /*width = */ 0, "0"}, + {0, kDec | kLeft | kUpper | kPos, /*width = */ 6, "0_____"}, + {0, kDec | kLeft | kUpper | kBase, /*width = */ 0, "0"}, + {0, kDec | kLeft | kUpper | kBase, /*width = */ 6, "0_____"}, + {0, kDec | kLeft | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kDec | kLeft | kUpper | kBase | kPos, /*width = */ 6, "0_____"}, + {0, kDec | kInt, /*width = */ 0, "0"}, + {0, kDec | kInt, /*width = */ 6, "_____0"}, + {0, kDec | kInt | kPos, /*width = */ 0, "0"}, + {0, kDec | kInt | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kInt | kBase, /*width = */ 0, "0"}, + {0, kDec | kInt | kBase, /*width = */ 6, "_____0"}, + {0, kDec | kInt | kBase | kPos, /*width = */ 0, "0"}, + {0, kDec | kInt | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kInt | kUpper, /*width = */ 0, "0"}, + {0, kDec | kInt | kUpper, /*width = */ 6, "_____0"}, + {0, kDec | kInt | kUpper | kPos, /*width = */ 0, "0"}, + {0, kDec | kInt | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kInt | kUpper | kBase, /*width = */ 0, "0"}, + {0, kDec | kInt | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kDec | kInt | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kDec | kInt | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kRight, /*width = */ 0, "0"}, + {0, kDec | kRight, /*width = */ 6, "_____0"}, + {0, kDec | kRight | kPos, /*width = */ 0, "0"}, + {0, kDec | kRight | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kRight | kBase, /*width = */ 0, "0"}, + {0, kDec | kRight | kBase, /*width = */ 6, "_____0"}, + {0, kDec | kRight | kBase | kPos, /*width = */ 0, "0"}, + {0, kDec | kRight | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kRight | kUpper, /*width = */ 0, "0"}, + {0, kDec | kRight | kUpper, /*width = */ 6, "_____0"}, + {0, kDec | kRight | kUpper | kPos, /*width = */ 0, "0"}, + {0, kDec | kRight | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kDec | kRight | kUpper | kBase, /*width = */ 0, "0"}, + {0, kDec | kRight | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kDec | kRight | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kDec | kRight | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kOct, /*width = */ 0, "0"}, + {0, kOct, /*width = */ 6, "_____0"}, + {0, kOct | kPos, /*width = */ 0, "0"}, + {0, kOct | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kBase, /*width = */ 0, "0"}, + {0, kOct | kBase, /*width = */ 6, "_____0"}, + {0, kOct | kBase | kPos, /*width = */ 0, "0"}, + {0, kOct | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kUpper, /*width = */ 0, "0"}, + {0, kOct | kUpper, /*width = */ 6, "_____0"}, + {0, kOct | kUpper | kPos, /*width = */ 0, "0"}, + {0, kOct | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kUpper | kBase, /*width = */ 0, "0"}, + {0, kOct | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kOct | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kOct | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kLeft, /*width = */ 0, "0"}, + {0, kOct | kLeft, /*width = */ 6, "0_____"}, + {0, kOct | kLeft | kPos, /*width = */ 0, "0"}, + {0, kOct | kLeft | kPos, /*width = */ 6, "0_____"}, + {0, kOct | kLeft | kBase, /*width = */ 0, "0"}, + {0, kOct | kLeft | kBase, /*width = */ 6, "0_____"}, + {0, kOct | kLeft | kBase | kPos, /*width = */ 0, "0"}, + {0, kOct | kLeft | kBase | kPos, /*width = */ 6, "0_____"}, + {0, kOct | kLeft | kUpper, /*width = */ 0, "0"}, + {0, kOct | kLeft | kUpper, /*width = */ 6, "0_____"}, + {0, kOct | kLeft | kUpper | kPos, /*width = */ 0, "0"}, + {0, kOct | kLeft | kUpper | kPos, /*width = */ 6, "0_____"}, + {0, kOct | kLeft | kUpper | kBase, /*width = */ 0, "0"}, + {0, kOct | kLeft | kUpper | kBase, /*width = */ 6, "0_____"}, + {0, kOct | kLeft | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kOct | kLeft | kUpper | kBase | kPos, /*width = */ 6, "0_____"}, + {0, kOct | kInt, /*width = */ 0, "0"}, + {0, kOct | kInt, /*width = */ 6, "_____0"}, + {0, kOct | kInt | kPos, /*width = */ 0, "0"}, + {0, kOct | kInt | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kInt | kBase, /*width = */ 0, "0"}, + {0, kOct | kInt | kBase, /*width = */ 6, "_____0"}, + {0, kOct | kInt | kBase | kPos, /*width = */ 0, "0"}, + {0, kOct | kInt | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kInt | kUpper, /*width = */ 0, "0"}, + {0, kOct | kInt | kUpper, /*width = */ 6, "_____0"}, + {0, kOct | kInt | kUpper | kPos, /*width = */ 0, "0"}, + {0, kOct | kInt | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kInt | kUpper | kBase, /*width = */ 0, "0"}, + {0, kOct | kInt | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kOct | kInt | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kOct | kInt | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kRight, /*width = */ 0, "0"}, + {0, kOct | kRight, /*width = */ 6, "_____0"}, + {0, kOct | kRight | kPos, /*width = */ 0, "0"}, + {0, kOct | kRight | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kRight | kBase, /*width = */ 0, "0"}, + {0, kOct | kRight | kBase, /*width = */ 6, "_____0"}, + {0, kOct | kRight | kBase | kPos, /*width = */ 0, "0"}, + {0, kOct | kRight | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kRight | kUpper, /*width = */ 0, "0"}, + {0, kOct | kRight | kUpper, /*width = */ 6, "_____0"}, + {0, kOct | kRight | kUpper | kPos, /*width = */ 0, "0"}, + {0, kOct | kRight | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kOct | kRight | kUpper | kBase, /*width = */ 0, "0"}, + {0, kOct | kRight | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kOct | kRight | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kOct | kRight | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kHex, /*width = */ 0, "0"}, + {0, kHex, /*width = */ 6, "_____0"}, + {0, kHex | kPos, /*width = */ 0, "0"}, + {0, kHex | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kBase, /*width = */ 0, "0"}, + {0, kHex | kBase, /*width = */ 6, "_____0"}, + {0, kHex | kBase | kPos, /*width = */ 0, "0"}, + {0, kHex | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kUpper, /*width = */ 0, "0"}, + {0, kHex | kUpper, /*width = */ 6, "_____0"}, + {0, kHex | kUpper | kPos, /*width = */ 0, "0"}, + {0, kHex | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kUpper | kBase, /*width = */ 0, "0"}, + {0, kHex | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kHex | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kHex | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kLeft, /*width = */ 0, "0"}, + {0, kHex | kLeft, /*width = */ 6, "0_____"}, + {0, kHex | kLeft | kPos, /*width = */ 0, "0"}, + {0, kHex | kLeft | kPos, /*width = */ 6, "0_____"}, + {0, kHex | kLeft | kBase, /*width = */ 0, "0"}, + {0, kHex | kLeft | kBase, /*width = */ 6, "0_____"}, + {0, kHex | kLeft | kBase | kPos, /*width = */ 0, "0"}, + {0, kHex | kLeft | kBase | kPos, /*width = */ 6, "0_____"}, + {0, kHex | kLeft | kUpper, /*width = */ 0, "0"}, + {0, kHex | kLeft | kUpper, /*width = */ 6, "0_____"}, + {0, kHex | kLeft | kUpper | kPos, /*width = */ 0, "0"}, + {0, kHex | kLeft | kUpper | kPos, /*width = */ 6, "0_____"}, + {0, kHex | kLeft | kUpper | kBase, /*width = */ 0, "0"}, + {0, kHex | kLeft | kUpper | kBase, /*width = */ 6, "0_____"}, + {0, kHex | kLeft | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kHex | kLeft | kUpper | kBase | kPos, /*width = */ 6, "0_____"}, + {0, kHex | kInt, /*width = */ 0, "0"}, + {0, kHex | kInt, /*width = */ 6, "_____0"}, + {0, kHex | kInt | kPos, /*width = */ 0, "0"}, + {0, kHex | kInt | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kInt | kBase, /*width = */ 0, "0"}, + {0, kHex | kInt | kBase, /*width = */ 6, "_____0"}, + {0, kHex | kInt | kBase | kPos, /*width = */ 0, "0"}, + {0, kHex | kInt | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kInt | kUpper, /*width = */ 0, "0"}, + {0, kHex | kInt | kUpper, /*width = */ 6, "_____0"}, + {0, kHex | kInt | kUpper | kPos, /*width = */ 0, "0"}, + {0, kHex | kInt | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kInt | kUpper | kBase, /*width = */ 0, "0"}, + {0, kHex | kInt | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kHex | kInt | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kHex | kInt | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kRight, /*width = */ 0, "0"}, + {0, kHex | kRight, /*width = */ 6, "_____0"}, + {0, kHex | kRight | kPos, /*width = */ 0, "0"}, + {0, kHex | kRight | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kRight | kBase, /*width = */ 0, "0"}, + {0, kHex | kRight | kBase, /*width = */ 6, "_____0"}, + {0, kHex | kRight | kBase | kPos, /*width = */ 0, "0"}, + {0, kHex | kRight | kBase | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kRight | kUpper, /*width = */ 0, "0"}, + {0, kHex | kRight | kUpper, /*width = */ 6, "_____0"}, + {0, kHex | kRight | kUpper | kPos, /*width = */ 0, "0"}, + {0, kHex | kRight | kUpper | kPos, /*width = */ 6, "_____0"}, + {0, kHex | kRight | kUpper | kBase, /*width = */ 0, "0"}, + {0, kHex | kRight | kUpper | kBase, /*width = */ 6, "_____0"}, + {0, kHex | kRight | kUpper | kBase | kPos, /*width = */ 0, "0"}, + {0, kHex | kRight | kUpper | kBase | kPos, /*width = */ 6, "_____0"}, + {37, std::ios_base::fmtflags(), /*width = */ 0, "37"}, + {37, std::ios_base::fmtflags(), /*width = */ 6, "____37"}, + {37, kPos, /*width = */ 0, "37"}, + {37, kPos, /*width = */ 6, "____37"}, + {37, kBase, /*width = */ 0, "37"}, + {37, kBase, /*width = */ 6, "____37"}, + {37, kBase | kPos, /*width = */ 0, "37"}, + {37, kBase | kPos, /*width = */ 6, "____37"}, + {37, kUpper, /*width = */ 0, "37"}, + {37, kUpper, /*width = */ 6, "____37"}, + {37, kUpper | kPos, /*width = */ 0, "37"}, + {37, kUpper | kPos, /*width = */ 6, "____37"}, + {37, kUpper | kBase, /*width = */ 0, "37"}, + {37, kUpper | kBase, /*width = */ 6, "____37"}, + {37, kUpper | kBase | kPos, /*width = */ 0, "37"}, + {37, kUpper | kBase | kPos, /*width = */ 6, "____37"}, + {37, kLeft, /*width = */ 0, "37"}, + {37, kLeft, /*width = */ 6, "37____"}, + {37, kLeft | kPos, /*width = */ 0, "37"}, + {37, kLeft | kPos, /*width = */ 6, "37____"}, + {37, kLeft | kBase, /*width = */ 0, "37"}, + {37, kLeft | kBase, /*width = */ 6, "37____"}, + {37, kLeft | kBase | kPos, /*width = */ 0, "37"}, + {37, kLeft | kBase | kPos, /*width = */ 6, "37____"}, + {37, kLeft | kUpper, /*width = */ 0, "37"}, + {37, kLeft | kUpper, /*width = */ 6, "37____"}, + {37, kLeft | kUpper | kPos, /*width = */ 0, "37"}, + {37, kLeft | kUpper | kPos, /*width = */ 6, "37____"}, + {37, kLeft | kUpper | kBase, /*width = */ 0, "37"}, + {37, kLeft | kUpper | kBase, /*width = */ 6, "37____"}, + {37, kLeft | kUpper | kBase | kPos, /*width = */ 0, "37"}, + {37, kLeft | kUpper | kBase | kPos, /*width = */ 6, "37____"}, + {37, kInt, /*width = */ 0, "37"}, + {37, kInt, /*width = */ 6, "____37"}, + {37, kInt | kPos, /*width = */ 0, "37"}, + {37, kInt | kPos, /*width = */ 6, "____37"}, + {37, kInt | kBase, /*width = */ 0, "37"}, + {37, kInt | kBase, /*width = */ 6, "____37"}, + {37, kInt | kBase | kPos, /*width = */ 0, "37"}, + {37, kInt | kBase | kPos, /*width = */ 6, "____37"}, + {37, kInt | kUpper, /*width = */ 0, "37"}, + {37, kInt | kUpper, /*width = */ 6, "____37"}, + {37, kInt | kUpper | kPos, /*width = */ 0, "37"}, + {37, kInt | kUpper | kPos, /*width = */ 6, "____37"}, + {37, kInt | kUpper | kBase, /*width = */ 0, "37"}, + {37, kInt | kUpper | kBase, /*width = */ 6, "____37"}, + {37, kInt | kUpper | kBase | kPos, /*width = */ 0, "37"}, + {37, kInt | kUpper | kBase | kPos, /*width = */ 6, "____37"}, + {37, kRight, /*width = */ 0, "37"}, + {37, kRight, /*width = */ 6, "____37"}, + {37, kRight | kPos, /*width = */ 0, "37"}, + {37, kRight | kPos, /*width = */ 6, "____37"}, + {37, kRight | kBase, /*width = */ 0, "37"}, + {37, kRight | kBase, /*width = */ 6, "____37"}, + {37, kRight | kBase | kPos, /*width = */ 0, "37"}, + {37, kRight | kBase | kPos, /*width = */ 6, "____37"}, + {37, kRight | kUpper, /*width = */ 0, "37"}, + {37, kRight | kUpper, /*width = */ 6, "____37"}, + {37, kRight | kUpper | kPos, /*width = */ 0, "37"}, + {37, kRight | kUpper | kPos, /*width = */ 6, "____37"}, + {37, kRight | kUpper | kBase, /*width = */ 0, "37"}, + {37, kRight | kUpper | kBase, /*width = */ 6, "____37"}, + {37, kRight | kUpper | kBase | kPos, /*width = */ 0, "37"}, + {37, kRight | kUpper | kBase | kPos, /*width = */ 6, "____37"}, + {37, kDec, /*width = */ 0, "37"}, + {37, kDec, /*width = */ 6, "____37"}, + {37, kDec | kPos, /*width = */ 0, "37"}, + {37, kDec | kPos, /*width = */ 6, "____37"}, + {37, kDec | kBase, /*width = */ 0, "37"}, + {37, kDec | kBase, /*width = */ 6, "____37"}, + {37, kDec | kBase | kPos, /*width = */ 0, "37"}, + {37, kDec | kBase | kPos, /*width = */ 6, "____37"}, + {37, kDec | kUpper, /*width = */ 0, "37"}, + {37, kDec | kUpper, /*width = */ 6, "____37"}, + {37, kDec | kUpper | kPos, /*width = */ 0, "37"}, + {37, kDec | kUpper | kPos, /*width = */ 6, "____37"}, + {37, kDec | kUpper | kBase, /*width = */ 0, "37"}, + {37, kDec | kUpper | kBase, /*width = */ 6, "____37"}, + {37, kDec | kUpper | kBase | kPos, /*width = */ 0, "37"}, + {37, kDec | kUpper | kBase | kPos, /*width = */ 6, "____37"}, + {37, kDec | kLeft, /*width = */ 0, "37"}, + {37, kDec | kLeft, /*width = */ 6, "37____"}, + {37, kDec | kLeft | kPos, /*width = */ 0, "37"}, + {37, kDec | kLeft | kPos, /*width = */ 6, "37____"}, + {37, kDec | kLeft | kBase, /*width = */ 0, "37"}, + {37, kDec | kLeft | kBase, /*width = */ 6, "37____"}, + {37, kDec | kLeft | kBase | kPos, /*width = */ 0, "37"}, + {37, kDec | kLeft | kBase | kPos, /*width = */ 6, "37____"}, + {37, kDec | kLeft | kUpper, /*width = */ 0, "37"}, + {37, kDec | kLeft | kUpper, /*width = */ 6, "37____"}, + {37, kDec | kLeft | kUpper | kPos, /*width = */ 0, "37"}, + {37, kDec | kLeft | kUpper | kPos, /*width = */ 6, "37____"}, + {37, kDec | kLeft | kUpper | kBase, /*width = */ 0, "37"}, + {37, kDec | kLeft | kUpper | kBase, /*width = */ 6, "37____"}, + {37, kDec | kLeft | kUpper | kBase | kPos, /*width = */ 0, "37"}, + {37, kDec | kLeft | kUpper | kBase | kPos, /*width = */ 6, "37____"}, + {37, kDec | kInt, /*width = */ 0, "37"}, + {37, kDec | kInt, /*width = */ 6, "____37"}, + {37, kDec | kInt | kPos, /*width = */ 0, "37"}, + {37, kDec | kInt | kPos, /*width = */ 6, "____37"}, + {37, kDec | kInt | kBase, /*width = */ 0, "37"}, + {37, kDec | kInt | kBase, /*width = */ 6, "____37"}, + {37, kDec | kInt | kBase | kPos, /*width = */ 0, "37"}, + {37, kDec | kInt | kBase | kPos, /*width = */ 6, "____37"}, + {37, kDec | kInt | kUpper, /*width = */ 0, "37"}, + {37, kDec | kInt | kUpper, /*width = */ 6, "____37"}, + {37, kDec | kInt | kUpper | kPos, /*width = */ 0, "37"}, + {37, kDec | kInt | kUpper | kPos, /*width = */ 6, "____37"}, + {37, kDec | kInt | kUpper | kBase, /*width = */ 0, "37"}, + {37, kDec | kInt | kUpper | kBase, /*width = */ 6, "____37"}, + {37, kDec | kInt | kUpper | kBase | kPos, /*width = */ 0, "37"}, + {37, kDec | kInt | kUpper | kBase | kPos, /*width = */ 6, "____37"}, + {37, kDec | kRight, /*width = */ 0, "37"}, + {37, kDec | kRight, /*width = */ 6, "____37"}, + {37, kDec | kRight | kPos, /*width = */ 0, "37"}, + {37, kDec | kRight | kPos, /*width = */ 6, "____37"}, + {37, kDec | kRight | kBase, /*width = */ 0, "37"}, + {37, kDec | kRight | kBase, /*width = */ 6, "____37"}, + {37, kDec | kRight | kBase | kPos, /*width = */ 0, "37"}, + {37, kDec | kRight | kBase | kPos, /*width = */ 6, "____37"}, + {37, kDec | kRight | kUpper, /*width = */ 0, "37"}, + {37, kDec | kRight | kUpper, /*width = */ 6, "____37"}, + {37, kDec | kRight | kUpper | kPos, /*width = */ 0, "37"}, + {37, kDec | kRight | kUpper | kPos, /*width = */ 6, "____37"}, + {37, kDec | kRight | kUpper | kBase, /*width = */ 0, "37"}, + {37, kDec | kRight | kUpper | kBase, /*width = */ 6, "____37"}, + {37, kDec | kRight | kUpper | kBase | kPos, /*width = */ 0, "37"}, + {37, kDec | kRight | kUpper | kBase | kPos, /*width = */ 6, "____37"}, + {37, kOct, /*width = */ 0, "45"}, + {37, kOct, /*width = */ 6, "____45"}, + {37, kOct | kPos, /*width = */ 0, "45"}, + {37, kOct | kPos, /*width = */ 6, "____45"}, + {37, kOct | kBase, /*width = */ 0, "045"}, + {37, kOct | kBase, /*width = */ 6, "___045"}, + {37, kOct | kBase | kPos, /*width = */ 0, "045"}, + {37, kOct | kBase | kPos, /*width = */ 6, "___045"}, + {37, kOct | kUpper, /*width = */ 0, "45"}, + {37, kOct | kUpper, /*width = */ 6, "____45"}, + {37, kOct | kUpper | kPos, /*width = */ 0, "45"}, + {37, kOct | kUpper | kPos, /*width = */ 6, "____45"}, + {37, kOct | kUpper | kBase, /*width = */ 0, "045"}, + {37, kOct | kUpper | kBase, /*width = */ 6, "___045"}, + {37, kOct | kUpper | kBase | kPos, /*width = */ 0, "045"}, + {37, kOct | kUpper | kBase | kPos, /*width = */ 6, "___045"}, + {37, kOct | kLeft, /*width = */ 0, "45"}, + {37, kOct | kLeft, /*width = */ 6, "45____"}, + {37, kOct | kLeft | kPos, /*width = */ 0, "45"}, + {37, kOct | kLeft | kPos, /*width = */ 6, "45____"}, + {37, kOct | kLeft | kBase, /*width = */ 0, "045"}, + {37, kOct | kLeft | kBase, /*width = */ 6, "045___"}, + {37, kOct | kLeft | kBase | kPos, /*width = */ 0, "045"}, + {37, kOct | kLeft | kBase | kPos, /*width = */ 6, "045___"}, + {37, kOct | kLeft | kUpper, /*width = */ 0, "45"}, + {37, kOct | kLeft | kUpper, /*width = */ 6, "45____"}, + {37, kOct | kLeft | kUpper | kPos, /*width = */ 0, "45"}, + {37, kOct | kLeft | kUpper | kPos, /*width = */ 6, "45____"}, + {37, kOct | kLeft | kUpper | kBase, /*width = */ 0, "045"}, + {37, kOct | kLeft | kUpper | kBase, /*width = */ 6, "045___"}, + {37, kOct | kLeft | kUpper | kBase | kPos, /*width = */ 0, "045"}, + {37, kOct | kLeft | kUpper | kBase | kPos, /*width = */ 6, "045___"}, + {37, kOct | kInt, /*width = */ 0, "45"}, + {37, kOct | kInt, /*width = */ 6, "____45"}, + {37, kOct | kInt | kPos, /*width = */ 0, "45"}, + {37, kOct | kInt | kPos, /*width = */ 6, "____45"}, + {37, kOct | kInt | kBase, /*width = */ 0, "045"}, + {37, kOct | kInt | kBase, /*width = */ 6, "___045"}, + {37, kOct | kInt | kBase | kPos, /*width = */ 0, "045"}, + {37, kOct | kInt | kBase | kPos, /*width = */ 6, "___045"}, + {37, kOct | kInt | kUpper, /*width = */ 0, "45"}, + {37, kOct | kInt | kUpper, /*width = */ 6, "____45"}, + {37, kOct | kInt | kUpper | kPos, /*width = */ 0, "45"}, + {37, kOct | kInt | kUpper | kPos, /*width = */ 6, "____45"}, + {37, kOct | kInt | kUpper | kBase, /*width = */ 0, "045"}, + {37, kOct | kInt | kUpper | kBase, /*width = */ 6, "___045"}, + {37, kOct | kInt | kUpper | kBase | kPos, /*width = */ 0, "045"}, + {37, kOct | kInt | kUpper | kBase | kPos, /*width = */ 6, "___045"}, + {37, kOct | kRight, /*width = */ 0, "45"}, + {37, kOct | kRight, /*width = */ 6, "____45"}, + {37, kOct | kRight | kPos, /*width = */ 0, "45"}, + {37, kOct | kRight | kPos, /*width = */ 6, "____45"}, + {37, kOct | kRight | kBase, /*width = */ 0, "045"}, + {37, kOct | kRight | kBase, /*width = */ 6, "___045"}, + {37, kOct | kRight | kBase | kPos, /*width = */ 0, "045"}, + {37, kOct | kRight | kBase | kPos, /*width = */ 6, "___045"}, + {37, kOct | kRight | kUpper, /*width = */ 0, "45"}, + {37, kOct | kRight | kUpper, /*width = */ 6, "____45"}, + {37, kOct | kRight | kUpper | kPos, /*width = */ 0, "45"}, + {37, kOct | kRight | kUpper | kPos, /*width = */ 6, "____45"}, + {37, kOct | kRight | kUpper | kBase, /*width = */ 0, "045"}, + {37, kOct | kRight | kUpper | kBase, /*width = */ 6, "___045"}, + {37, kOct | kRight | kUpper | kBase | kPos, /*width = */ 0, "045"}, + {37, kOct | kRight | kUpper | kBase | kPos, /*width = */ 6, "___045"}, + {37, kHex, /*width = */ 0, "25"}, + {37, kHex, /*width = */ 6, "____25"}, + {37, kHex | kPos, /*width = */ 0, "25"}, + {37, kHex | kPos, /*width = */ 6, "____25"}, + {37, kHex | kBase, /*width = */ 0, "0x25"}, + {37, kHex | kBase, /*width = */ 6, "__0x25"}, + {37, kHex | kBase | kPos, /*width = */ 0, "0x25"}, + {37, kHex | kBase | kPos, /*width = */ 6, "__0x25"}, + {37, kHex | kUpper, /*width = */ 0, "25"}, + {37, kHex | kUpper, /*width = */ 6, "____25"}, + {37, kHex | kUpper | kPos, /*width = */ 0, "25"}, + {37, kHex | kUpper | kPos, /*width = */ 6, "____25"}, + {37, kHex | kUpper | kBase, /*width = */ 0, "0X25"}, + {37, kHex | kUpper | kBase, /*width = */ 6, "__0X25"}, + {37, kHex | kUpper | kBase | kPos, /*width = */ 0, "0X25"}, + {37, kHex | kUpper | kBase | kPos, /*width = */ 6, "__0X25"}, + {37, kHex | kLeft, /*width = */ 0, "25"}, + {37, kHex | kLeft, /*width = */ 6, "25____"}, + {37, kHex | kLeft | kPos, /*width = */ 0, "25"}, + {37, kHex | kLeft | kPos, /*width = */ 6, "25____"}, + {37, kHex | kLeft | kBase, /*width = */ 0, "0x25"}, + {37, kHex | kLeft | kBase, /*width = */ 6, "0x25__"}, + {37, kHex | kLeft | kBase | kPos, /*width = */ 0, "0x25"}, + {37, kHex | kLeft | kBase | kPos, /*width = */ 6, "0x25__"}, + {37, kHex | kLeft | kUpper, /*width = */ 0, "25"}, + {37, kHex | kLeft | kUpper, /*width = */ 6, "25____"}, + {37, kHex | kLeft | kUpper | kPos, /*width = */ 0, "25"}, + {37, kHex | kLeft | kUpper | kPos, /*width = */ 6, "25____"}, + {37, kHex | kLeft | kUpper | kBase, /*width = */ 0, "0X25"}, + {37, kHex | kLeft | kUpper | kBase, /*width = */ 6, "0X25__"}, + {37, kHex | kLeft | kUpper | kBase | kPos, /*width = */ 0, "0X25"}, + {37, kHex | kLeft | kUpper | kBase | kPos, /*width = */ 6, "0X25__"}, + {37, kHex | kInt, /*width = */ 0, "25"}, + {37, kHex | kInt, /*width = */ 6, "____25"}, + {37, kHex | kInt | kPos, /*width = */ 0, "25"}, + {37, kHex | kInt | kPos, /*width = */ 6, "____25"}, + {37, kHex | kInt | kBase, /*width = */ 0, "0x25"}, + {37, kHex | kInt | kBase, /*width = */ 6, "0x__25"}, + {37, kHex | kInt | kBase | kPos, /*width = */ 0, "0x25"}, + {37, kHex | kInt | kBase | kPos, /*width = */ 6, "0x__25"}, + {37, kHex | kInt | kUpper, /*width = */ 0, "25"}, + {37, kHex | kInt | kUpper, /*width = */ 6, "____25"}, + {37, kHex | kInt | kUpper | kPos, /*width = */ 0, "25"}, + {37, kHex | kInt | kUpper | kPos, /*width = */ 6, "____25"}, + {37, kHex | kInt | kUpper | kBase, /*width = */ 0, "0X25"}, + {37, kHex | kInt | kUpper | kBase, /*width = */ 6, "0X__25"}, + {37, kHex | kInt | kUpper | kBase | kPos, /*width = */ 0, "0X25"}, + {37, kHex | kInt | kUpper | kBase | kPos, /*width = */ 6, "0X__25"}, + {37, kHex | kRight, /*width = */ 0, "25"}, + {37, kHex | kRight, /*width = */ 6, "____25"}, + {37, kHex | kRight | kPos, /*width = */ 0, "25"}, + {37, kHex | kRight | kPos, /*width = */ 6, "____25"}, + {37, kHex | kRight | kBase, /*width = */ 0, "0x25"}, + {37, kHex | kRight | kBase, /*width = */ 6, "__0x25"}, + {37, kHex | kRight | kBase | kPos, /*width = */ 0, "0x25"}, + {37, kHex | kRight | kBase | kPos, /*width = */ 6, "__0x25"}, + {37, kHex | kRight | kUpper, /*width = */ 0, "25"}, + {37, kHex | kRight | kUpper, /*width = */ 6, "____25"}, + {37, kHex | kRight | kUpper | kPos, /*width = */ 0, "25"}, + {37, kHex | kRight | kUpper | kPos, /*width = */ 6, "____25"}, + {37, kHex | kRight | kUpper | kBase, /*width = */ 0, "0X25"}, + {37, kHex | kRight | kUpper | kBase, /*width = */ 6, "__0X25"}, + {37, kHex | kRight | kUpper | kBase | kPos, /*width = */ 0, "0X25"}, + {37, kHex | kRight | kUpper | kBase | kPos, /*width = */ 6, "__0X25"}}; +} + +} // namespace diff --git a/Firestore/third_party/abseil-cpp/absl/numeric/int128_test.cc b/Firestore/third_party/abseil-cpp/absl/numeric/int128_test.cc new file mode 100644 index 0000000..d674cb1 --- /dev/null +++ b/Firestore/third_party/abseil-cpp/absl/numeric/int128_test.cc @@ -0,0 +1,429 @@ +// Copyright 2017 The Abseil Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "absl/numeric/int128.h" + +#include +#include +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include "absl/base/internal/cycleclock.h" +#include "absl/meta/type_traits.h" + +#if defined(_MSC_VER) && _MSC_VER == 1900 +// Disable "unary minus operator applied to unsigned type" warnings in Microsoft +// Visual C++ 14 (2015). +#pragma warning(disable:4146) +#endif + +namespace { + +template +class Uint128IntegerTraitsTest : public ::testing::Test {}; +typedef ::testing::Types // NOLINT(runtime/int) + IntegerTypes; + +template +class Uint128FloatTraitsTest : public ::testing::Test {}; +typedef ::testing::Types FloatingPointTypes; + +TYPED_TEST_CASE(Uint128IntegerTraitsTest, IntegerTypes); + +TYPED_TEST(Uint128IntegerTraitsTest, ConstructAssignTest) { + static_assert(std::is_constructible::value, + "absl::uint128 must be constructible from TypeParam"); + static_assert(std::is_assignable::value, + "absl::uint128 must be assignable from TypeParam"); + static_assert(!std::is_assignable::value, + "TypeParam must not be assignable from absl::uint128"); +} + +TYPED_TEST_CASE(Uint128FloatTraitsTest, FloatingPointTypes); + +TYPED_TEST(Uint128FloatTraitsTest, ConstructAssignTest) { + static_assert(std::is_constructible::value, + "absl::uint128 must be constructible from TypeParam"); + static_assert(!std::is_assignable::value, + "absl::uint128 must not be assignable from TypeParam"); + static_assert(!std::is_assignable::value, + "TypeParam must not be assignable from absl::uint128"); +} + +#ifdef ABSL_HAVE_INTRINSIC_INT128 +// These type traits done separately as TYPED_TEST requires typeinfo, and not +// all platforms have this for __int128 even though they define the type. +TEST(Uint128, IntrinsicTypeTraitsTest) { + static_assert(std::is_constructible::value, + "absl::uint128 must be constructible from __int128"); + static_assert(std::is_assignable::value, + "absl::uint128 must be assignable from __int128"); + static_assert(!std::is_assignable<__int128&, absl::uint128>::value, + "__int128 must not be assignable from absl::uint128"); + + static_assert(std::is_constructible::value, + "absl::uint128 must be constructible from unsigned __int128"); + static_assert(std::is_assignable::value, + "absl::uint128 must be assignable from unsigned __int128"); + static_assert(!std::is_assignable::value, + "unsigned __int128 must not be assignable from absl::uint128"); +} +#endif // ABSL_HAVE_INTRINSIC_INT128 + +TEST(Uint128, TrivialTraitsTest) { + static_assert(absl::is_trivially_default_constructible::value, + ""); + static_assert(absl::is_trivially_copy_constructible::value, + ""); + static_assert(absl::is_trivially_copy_assignable::value, ""); + static_assert(std::is_trivially_destructible::value, ""); +} + +TEST(Uint128, AllTests) { + absl::uint128 zero = 0; + absl::uint128 one = 1; + absl::uint128 one_2arg = absl::MakeUint128(0, 1); + absl::uint128 two = 2; + absl::uint128 three = 3; + absl::uint128 big = absl::MakeUint128(2000, 2); + absl::uint128 big_minus_one = absl::MakeUint128(2000, 1); + absl::uint128 bigger = absl::MakeUint128(2001, 1); + absl::uint128 biggest = absl::kuint128max; + absl::uint128 high_low = absl::MakeUint128(1, 0); + absl::uint128 low_high = + absl::MakeUint128(0, std::numeric_limits::max()); + EXPECT_LT(one, two); + EXPECT_GT(two, one); + EXPECT_LT(one, big); + EXPECT_LT(one, big); + EXPECT_EQ(one, one_2arg); + EXPECT_NE(one, two); + EXPECT_GT(big, one); + EXPECT_GE(big, two); + EXPECT_GE(big, big_minus_one); + EXPECT_GT(big, big_minus_one); + EXPECT_LT(big_minus_one, big); + EXPECT_LE(big_minus_one, big); + EXPECT_NE(big_minus_one, big); + EXPECT_LT(big, biggest); + EXPECT_LE(big, biggest); + EXPECT_GT(biggest, big); + EXPECT_GE(biggest, big); + EXPECT_EQ(big, ~~big); + EXPECT_EQ(one, one | one); + EXPECT_EQ(big, big | big); + EXPECT_EQ(one, one | zero); + EXPECT_EQ(one, one & one); + EXPECT_EQ(big, big & big); + EXPECT_EQ(zero, one & zero); + EXPECT_EQ(zero, big & ~big); + EXPECT_EQ(zero, one ^ one); + EXPECT_EQ(zero, big ^ big); + EXPECT_EQ(one, one ^ zero); + + // Shift operators. + EXPECT_EQ(big, big << 0); + EXPECT_EQ(big, big >> 0); + EXPECT_GT(big << 1, big); + EXPECT_LT(big >> 1, big); + EXPECT_EQ(big, (big << 10) >> 10); + EXPECT_EQ(big, (big >> 1) << 1); + EXPECT_EQ(one, (one << 80) >> 80); + EXPECT_EQ(zero, (one >> 80) << 80); + + // Shift assignments. + absl::uint128 big_copy = big; + EXPECT_EQ(big << 0, big_copy <<= 0); + big_copy = big; + EXPECT_EQ(big >> 0, big_copy >>= 0); + big_copy = big; + EXPECT_EQ(big << 1, big_copy <<= 1); + big_copy = big; + EXPECT_EQ(big >> 1, big_copy >>= 1); + big_copy = big; + EXPECT_EQ(big << 10, big_copy <<= 10); + big_copy = big; + EXPECT_EQ(big >> 10, big_copy >>= 10); + big_copy = big; + EXPECT_EQ(big << 64, big_copy <<= 64); + big_copy = big; + EXPECT_EQ(big >> 64, big_copy >>= 64); + big_copy = big; + EXPECT_EQ(big << 73, big_copy <<= 73); + big_copy = big; + EXPECT_EQ(big >> 73, big_copy >>= 73); + + EXPECT_EQ(absl::Uint128High64(biggest), std::numeric_limits::max()); + EXPECT_EQ(absl::Uint128Low64(biggest), std::numeric_limits::max()); + EXPECT_EQ(zero + one, one); + EXPECT_EQ(one + one, two); + EXPECT_EQ(big_minus_one + one, big); + EXPECT_EQ(one - one, zero); + EXPECT_EQ(one - zero, one); + EXPECT_EQ(zero - one, biggest); + EXPECT_EQ(big - big, zero); + EXPECT_EQ(big - one, big_minus_one); + EXPECT_EQ(big + std::numeric_limits::max(), bigger); + EXPECT_EQ(biggest + 1, zero); + EXPECT_EQ(zero - 1, biggest); + EXPECT_EQ(high_low - one, low_high); + EXPECT_EQ(low_high + one, high_low); + EXPECT_EQ(absl::Uint128High64((absl::uint128(1) << 64) - 1), 0); + EXPECT_EQ(absl::Uint128Low64((absl::uint128(1) << 64) - 1), + std::numeric_limits::max()); + EXPECT_TRUE(!!one); + EXPECT_TRUE(!!high_low); + EXPECT_FALSE(!!zero); + EXPECT_FALSE(!one); + EXPECT_FALSE(!high_low); + EXPECT_TRUE(!zero); + EXPECT_TRUE(zero == 0); // NOLINT(readability/check) + EXPECT_FALSE(zero != 0); // NOLINT(readability/check) + EXPECT_FALSE(one == 0); // NOLINT(readability/check) + EXPECT_TRUE(one != 0); // NOLINT(readability/check) + EXPECT_FALSE(high_low == 0); // NOLINT(readability/check) + EXPECT_TRUE(high_low != 0); // NOLINT(readability/check) + + absl::uint128 test = zero; + EXPECT_EQ(++test, one); + EXPECT_EQ(test, one); + EXPECT_EQ(test++, one); + EXPECT_EQ(test, two); + EXPECT_EQ(test -= 2, zero); + EXPECT_EQ(test, zero); + EXPECT_EQ(test += 2, two); + EXPECT_EQ(test, two); + EXPECT_EQ(--test, one); + EXPECT_EQ(test, one); + EXPECT_EQ(test--, one); + EXPECT_EQ(test, zero); + EXPECT_EQ(test |= three, three); + EXPECT_EQ(test &= one, one); + EXPECT_EQ(test ^= three, two); + EXPECT_EQ(test >>= 1, one); + EXPECT_EQ(test <<= 1, two); + + EXPECT_EQ(big, -(-big)); + EXPECT_EQ(two, -((-one) - 1)); + EXPECT_EQ(absl::kuint128max, -one); + EXPECT_EQ(zero, -zero); +} + +TEST(Uint128, ConversionTests) { + EXPECT_TRUE(absl::MakeUint128(1, 0)); + +#ifdef ABSL_HAVE_INTRINSIC_INT128 + unsigned __int128 intrinsic = + (static_cast(0x3a5b76c209de76f6) << 64) + + 0x1f25e1d63a2b46c5; + absl::uint128 custom = + absl::MakeUint128(0x3a5b76c209de76f6, 0x1f25e1d63a2b46c5); + + EXPECT_EQ(custom, absl::uint128(intrinsic)); + EXPECT_EQ(custom, absl::uint128(static_cast<__int128>(intrinsic))); + EXPECT_EQ(intrinsic, static_cast(custom)); + EXPECT_EQ(intrinsic, static_cast<__int128>(custom)); +#endif // ABSL_HAVE_INTRINSIC_INT128 + + // verify that an integer greater than 2**64 that can be stored precisely + // inside a double is converted to a absl::uint128 without loss of + // information. + double precise_double = 0x530e * std::pow(2.0, 64.0) + 0xda74000000000000; + absl::uint128 from_precise_double(precise_double); + absl::uint128 from_precise_ints = + absl::MakeUint128(0x530e, 0xda74000000000000); + EXPECT_EQ(from_precise_double, from_precise_ints); + EXPECT_DOUBLE_EQ(static_cast(from_precise_ints), precise_double); + + double approx_double = 0xffffeeeeddddcccc * std::pow(2.0, 64.0) + + 0xbbbbaaaa99998888; + absl::uint128 from_approx_double(approx_double); + EXPECT_DOUBLE_EQ(static_cast(from_approx_double), approx_double); + + double round_to_zero = 0.7; + double round_to_five = 5.8; + double round_to_nine = 9.3; + EXPECT_EQ(static_cast(round_to_zero), 0); + EXPECT_EQ(static_cast(round_to_five), 5); + EXPECT_EQ(static_cast(round_to_nine), 9); +} + +TEST(Uint128, OperatorAssignReturnRef) { + absl::uint128 v(1); + (v += 4) -= 3; + EXPECT_EQ(2, v); +} + +TEST(Uint128, Multiply) { + absl::uint128 a, b, c; + + // Zero test. + a = 0; + b = 0; + c = a * b; + EXPECT_EQ(0, c); + + // Max carries. + a = absl::uint128(0) - 1; + b = absl::uint128(0) - 1; + c = a * b; + EXPECT_EQ(1, c); + + // Self-operation with max carries. + c = absl::uint128(0) - 1; + c *= c; + EXPECT_EQ(1, c); + + // 1-bit x 1-bit. + for (int i = 0; i < 64; ++i) { + for (int j = 0; j < 64; ++j) { + a = absl::uint128(1) << i; + b = absl::uint128(1) << j; + c = a * b; + EXPECT_EQ(absl::uint128(1) << (i + j), c); + } + } + + // Verified with dc. + a = absl::MakeUint128(0xffffeeeeddddcccc, 0xbbbbaaaa99998888); + b = absl::MakeUint128(0x7777666655554444, 0x3333222211110000); + c = a * b; + EXPECT_EQ(absl::MakeUint128(0x530EDA741C71D4C3, 0xBF25975319080000), c); + EXPECT_EQ(0, c - b * a); + EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); + + // Verified with dc. + a = absl::MakeUint128(0x0123456789abcdef, 0xfedcba9876543210); + b = absl::MakeUint128(0x02468ace13579bdf, 0xfdb97531eca86420); + c = a * b; + EXPECT_EQ(absl::MakeUint128(0x97a87f4f261ba3f2, 0x342d0bbf48948200), c); + EXPECT_EQ(0, c - b * a); + EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); +} + +TEST(Uint128, AliasTests) { + absl::uint128 x1 = absl::MakeUint128(1, 2); + absl::uint128 x2 = absl::MakeUint128(2, 4); + x1 += x1; + EXPECT_EQ(x2, x1); + + absl::uint128 x3 = absl::MakeUint128(1, static_cast(1) << 63); + absl::uint128 x4 = absl::MakeUint128(3, 0); + x3 += x3; + EXPECT_EQ(x4, x3); +} + +TEST(Uint128, DivideAndMod) { + using std::swap; + + // a := q * b + r + absl::uint128 a, b, q, r; + + // Zero test. + a = 0; + b = 123; + q = a / b; + r = a % b; + EXPECT_EQ(0, q); + EXPECT_EQ(0, r); + + a = absl::MakeUint128(0x530eda741c71d4c3, 0xbf25975319080000); + q = absl::MakeUint128(0x4de2cab081, 0x14c34ab4676e4bab); + b = absl::uint128(0x1110001); + r = absl::uint128(0x3eb455); + ASSERT_EQ(a, q * b + r); // Sanity-check. + + absl::uint128 result_q, result_r; + result_q = a / b; + result_r = a % b; + EXPECT_EQ(q, result_q); + EXPECT_EQ(r, result_r); + + // Try the other way around. + swap(q, b); + result_q = a / b; + result_r = a % b; + EXPECT_EQ(q, result_q); + EXPECT_EQ(r, result_r); + // Restore. + swap(b, q); + + // Dividend < divisor; result should be q:0 r:. + swap(a, b); + result_q = a / b; + result_r = a % b; + EXPECT_EQ(0, result_q); + EXPECT_EQ(a, result_r); + // Try the other way around. + swap(a, q); + result_q = a / b; + result_r = a % b; + EXPECT_EQ(0, result_q); + EXPECT_EQ(a, result_r); + // Restore. + swap(q, a); + swap(b, a); + + // Try a large remainder. + b = a / 2 + 1; + absl::uint128 expected_r = + absl::MakeUint128(0x29876d3a0e38ea61, 0xdf92cba98c83ffff); + // Sanity checks. + ASSERT_EQ(a / 2 - 1, expected_r); + ASSERT_EQ(a, b + expected_r); + result_q = a / b; + result_r = a % b; + EXPECT_EQ(1, result_q); + EXPECT_EQ(expected_r, result_r); +} + +TEST(Uint128, DivideAndModRandomInputs) { + const int kNumIters = 1 << 18; + std::minstd_rand random(testing::UnitTest::GetInstance()->random_seed()); + std::uniform_int_distribution uniform_uint64; + for (int i = 0; i < kNumIters; ++i) { + const absl::uint128 a = + absl::MakeUint128(uniform_uint64(random), uniform_uint64(random)); + const absl::uint128 b = + absl::MakeUint128(uniform_uint64(random), uniform_uint64(random)); + if (b == 0) { + continue; // Avoid a div-by-zero. + } + const absl::uint128 q = a / b; + const absl::uint128 r = a % b; + ASSERT_EQ(a, b * q + r); + } +} + +TEST(Uint128, ConstexprTest) { + constexpr absl::uint128 zero = absl::uint128(); + constexpr absl::uint128 one = 1; + constexpr absl::uint128 minus_two = -2; + EXPECT_EQ(zero, absl::uint128(0)); + EXPECT_EQ(one, absl::uint128(1)); + EXPECT_EQ(minus_two, absl::MakeUint128(-1, -2)); +} + +} // namespace -- cgit v1.2.3