about summary refs log tree commit diff
path: root/absl
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-02-06T14·42-0800
committerkatzdm <katzdm@google.com>2018-02-06T20·03-0500
commit3917120a4c6ba8c401714c1655b4a6d7ace3d049 (patch)
tree19793d9bcfa24105d7569b6af17b6d76f26d088a /absl
parentbf7fc9986e20f664958fc227547fd8d2fdcf863e (diff)
Changes imported from Abseil "staging" branch:
  - b7ac57541b07fadc3ed054cc3d62bc192a2098a7 Redefine arithmetic assign operators in terms of the bina... by Alex Strelnikov <strel@google.com>
  - bb2bf3fd86eb9f24420376aad1b9fe84068ad7e4 Cmake CI for Ubuntu by Jon Cohen <cohenjon@google.com>
  - 3ff3e6d6b4d99627f0785cad5b562362bdf1ae37 Fix internal namespace (debug_internal -> debugging_inter... by Derek Mauro <dmauro@google.com>
  - b50753d757c95a3430cc2d6cfc0272af1e5c219c Internal change. by Alex Strelnikov <strel@google.com>

GitOrigin-RevId: b7ac57541b07fadc3ed054cc3d62bc192a2098a7
Change-Id: I7561639e296d1cc5dc7ee75e6645e8dae3f1bf97
Diffstat (limited to 'absl')
-rw-r--r--absl/debugging/internal/address_is_readable.cc8
-rw-r--r--absl/debugging/internal/address_is_readable.h4
-rw-r--r--absl/debugging/internal/elf_mem_image.cc4
-rw-r--r--absl/debugging/internal/elf_mem_image.h4
-rw-r--r--absl/debugging/internal/stacktrace_aarch64-inl.inc6
-rw-r--r--absl/debugging/internal/stacktrace_powerpc-inl.inc8
-rw-r--r--absl/debugging/internal/stacktrace_x86-inl.inc10
-rw-r--r--absl/debugging/internal/vdso_support.cc12
-rw-r--r--absl/debugging/internal/vdso_support.h4
-rw-r--r--absl/numeric/int128.cc15
-rw-r--r--absl/numeric/int128.h126
11 files changed, 115 insertions, 86 deletions
diff --git a/absl/debugging/internal/address_is_readable.cc b/absl/debugging/internal/address_is_readable.cc
index 30d2e71da1b3..7455aa0b4164 100644
--- a/absl/debugging/internal/address_is_readable.cc
+++ b/absl/debugging/internal/address_is_readable.cc
@@ -20,12 +20,12 @@
 #if !defined(__linux__) || defined(__ANDROID__)
 
 namespace absl {
-namespace debug_internal {
+namespace debugging_internal {
 
 // On platforms other than Linux, just return true.
 bool AddressIsReadable(const void* /* addr */) { return true; }
 
-}  // namespace debug_internal
+}  // namespace debugging_internal
 }  // namespace absl
 
 #else
@@ -40,7 +40,7 @@ bool AddressIsReadable(const void* /* addr */) { return true; }
 #include "absl/base/internal/raw_logging.h"
 
 namespace absl {
-namespace debug_internal {
+namespace debugging_internal {
 
 // Pack a pid and two file descriptors into a 64-bit word,
 // using 16, 24, and 24 bits for each respectively.
@@ -127,7 +127,7 @@ bool AddressIsReadable(const void *addr) {
   return bytes_written == 1;
 }
 
-}  // namespace debug_internal
+}  // namespace debugging_internal
 }  // namespace absl
 
 #endif
diff --git a/absl/debugging/internal/address_is_readable.h b/absl/debugging/internal/address_is_readable.h
index a8b32923550c..9d48030065c8 100644
--- a/absl/debugging/internal/address_is_readable.h
+++ b/absl/debugging/internal/address_is_readable.h
@@ -17,13 +17,13 @@
 #define ABSL_DEBUGGING_INTERNAL_ADDRESS_IS_READABLE_H_
 
 namespace absl {
-namespace debug_internal {
+namespace debugging_internal {
 
 // Return whether the byte at *addr is readable, without faulting.
 // Save and restores errno.
 bool AddressIsReadable(const void *addr);
 
-}  // namespace debug_internal
+}  // namespace debugging_internal
 }  // namespace absl
 
 #endif  // ABSL_DEBUGGING_INTERNAL_ADDRESS_IS_READABLE_H_
diff --git a/absl/debugging/internal/elf_mem_image.cc b/absl/debugging/internal/elf_mem_image.cc
index 3dfef5e83e57..d6d519246036 100644
--- a/absl/debugging/internal/elf_mem_image.cc
+++ b/absl/debugging/internal/elf_mem_image.cc
@@ -38,7 +38,7 @@
 #define VERSYM_VERSION 0x7fff
 
 namespace absl {
-namespace debug_internal {
+namespace debugging_internal {
 
 namespace {
 
@@ -392,7 +392,7 @@ void ElfMemImage::SymbolIterator::Update(int increment) {
   info_.symbol  = symbol;
 }
 
-}  // namespace debug_internal
+}  // namespace debugging_internal
 }  // namespace absl
 
 #endif  // ABSL_HAVE_ELF_MEM_IMAGE
diff --git a/absl/debugging/internal/elf_mem_image.h b/absl/debugging/internal/elf_mem_image.h
index 20a32a490cb2..993508362056 100644
--- a/absl/debugging/internal/elf_mem_image.h
+++ b/absl/debugging/internal/elf_mem_image.h
@@ -39,7 +39,7 @@
 #include <link.h>  // for ElfW
 
 namespace absl {
-namespace debug_internal {
+namespace debugging_internal {
 
 // An in-memory ELF image (may not exist on disk).
 class ElfMemImage {
@@ -122,7 +122,7 @@ class ElfMemImage {
   ElfW(Addr) link_base_;     // Link-time base (p_vaddr of first PT_LOAD).
 };
 
-}  // namespace debug_internal
+}  // namespace debugging_internal
 }  // namespace absl
 
 #endif  // ABSL_HAVE_ELF_MEM_IMAGE
diff --git a/absl/debugging/internal/stacktrace_aarch64-inl.inc b/absl/debugging/internal/stacktrace_aarch64-inl.inc
index 45802e7383bb..a861c0a18260 100644
--- a/absl/debugging/internal/stacktrace_aarch64-inl.inc
+++ b/absl/debugging/internal/stacktrace_aarch64-inl.inc
@@ -33,9 +33,9 @@ static const unsigned char* GetKernelRtSigreturnAddress() {
   address = reinterpret_cast<uintptr_t>(nullptr);
 
 #ifdef ABSL_HAVE_VDSO_SUPPORT
-  absl::debug_internal::VDSOSupport vdso;
+  absl::debugging_internal::VDSOSupport vdso;
   if (vdso.IsPresent()) {
-    absl::debug_internal::VDSOSupport::SymbolInfo symbol_info;
+    absl::debugging_internal::VDSOSupport::SymbolInfo symbol_info;
     if (!vdso.LookupSymbol("__kernel_rt_sigreturn", "LINUX_2.6.39", STT_FUNC,
                            &symbol_info) ||
         symbol_info.address == nullptr) {
@@ -90,7 +90,7 @@ static void **NextStackFrame(void **old_frame_pointer, const void *uc) {
       // Check that alleged frame pointer is actually readable. This is to
       // prevent "double fault" in case we hit the first fault due to e.g.
       // stack corruption.
-      if (!absl::debug_internal::AddressIsReadable(
+      if (!absl::debugging_internal::AddressIsReadable(
               pre_signal_frame_pointer))
         return nullptr;
 
diff --git a/absl/debugging/internal/stacktrace_powerpc-inl.inc b/absl/debugging/internal/stacktrace_powerpc-inl.inc
index 4b113269a8e0..297bdadf8fc9 100644
--- a/absl/debugging/internal/stacktrace_powerpc-inl.inc
+++ b/absl/debugging/internal/stacktrace_powerpc-inl.inc
@@ -99,13 +99,13 @@ static void **NextStackFrame(void **old_sp, const void *uc) {
     // possibly be there.
     static const unsigned char *kernel_sigtramp_rt64_address = nullptr;
     if (kernel_symbol_status == kNotInitialized) {
-      absl::debug_internal::VDSOSupport vdso;
+      absl::debugging_internal::VDSOSupport vdso;
       if (vdso.IsPresent()) {
-        absl::debug_internal::VDSOSupport::SymbolInfo
+        absl::debugging_internal::VDSOSupport::SymbolInfo
             sigtramp_rt64_symbol_info;
         if (!vdso.LookupSymbol(
                 "__kernel_sigtramp_rt64", "LINUX_2.6.15",
-                absl::debug_internal::VDSOSupport::kVDSOSymbolType,
+                absl::debugging_internal::VDSOSupport::kVDSOSymbolType,
                 &sigtramp_rt64_symbol_info) ||
             sigtramp_rt64_symbol_info.address == nullptr) {
           // Unexpected: VDSO is present, yet the expected symbol is missing
@@ -137,7 +137,7 @@ static void **NextStackFrame(void **old_sp, const void *uc) {
         // Check that alleged stack pointer is actually readable. This is to
         // prevent a "double fault" in case we hit the first fault due to e.g.
         // a stack corruption.
-        if (absl::debug_internal::AddressIsReadable(sp_before_signal)) {
+        if (absl::debugging_internal::AddressIsReadable(sp_before_signal)) {
           // Alleged stack pointer is readable, use it for further unwinding.
           new_sp = sp_before_signal;
         }
diff --git a/absl/debugging/internal/stacktrace_x86-inl.inc b/absl/debugging/internal/stacktrace_x86-inl.inc
index 7c146ad3221f..ac85b9203324 100644
--- a/absl/debugging/internal/stacktrace_x86-inl.inc
+++ b/absl/debugging/internal/stacktrace_x86-inl.inc
@@ -170,11 +170,11 @@ static void **NextStackFrame(void **old_fp, const void *uc) {
     static const unsigned char *kernel_rt_sigreturn_address = nullptr;
     static const unsigned char *kernel_vsyscall_address = nullptr;
     if (num_push_instructions == -1) {
-      absl::debug_internal::VDSOSupport vdso;
+      absl::debugging_internal::VDSOSupport vdso;
       if (vdso.IsPresent()) {
-        absl::debug_internal::VDSOSupport::SymbolInfo
+        absl::debugging_internal::VDSOSupport::SymbolInfo
             rt_sigreturn_symbol_info;
-        absl::debug_internal::VDSOSupport::SymbolInfo vsyscall_symbol_info;
+        absl::debugging_internal::VDSOSupport::SymbolInfo vsyscall_symbol_info;
         if (!vdso.LookupSymbol("__kernel_rt_sigreturn", "LINUX_2.5", STT_FUNC,
                                &rt_sigreturn_symbol_info) ||
             !vdso.LookupSymbol("__kernel_vsyscall", "LINUX_2.5", STT_FUNC,
@@ -221,7 +221,7 @@ static void **NextStackFrame(void **old_fp, const void *uc) {
           // "double fault" in case we hit the first fault due to e.g. stack
           // corruption.
           void *const reg_esp2 = reg_esp[num_push_instructions - 1];
-          if (absl::debug_internal::AddressIsReadable(reg_esp2)) {
+          if (absl::debugging_internal::AddressIsReadable(reg_esp2)) {
             // Alleged %esp is readable, use it for further unwinding.
             new_fp = reinterpret_cast<void **>(reg_esp2);
           }
@@ -273,7 +273,7 @@ static void **NextStackFrame(void **old_fp, const void *uc) {
     // Note: NextStackFrame<false>() is only called while the program
     //       is already on its last leg, so it's ok to be slow here.
 
-    if (!absl::debug_internal::AddressIsReadable(new_fp)) {
+    if (!absl::debugging_internal::AddressIsReadable(new_fp)) {
       return nullptr;
     }
   }
diff --git a/absl/debugging/internal/vdso_support.cc b/absl/debugging/internal/vdso_support.cc
index 815e702f5699..44ec7c02f513 100644
--- a/absl/debugging/internal/vdso_support.cc
+++ b/absl/debugging/internal/vdso_support.cc
@@ -38,18 +38,18 @@
 #endif
 
 namespace absl {
-namespace debug_internal {
+namespace debugging_internal {
 
 ABSL_CONST_INIT
 std::atomic<const void *> VDSOSupport::vdso_base_(
-    debug_internal::ElfMemImage::kInvalidBase);
+    debugging_internal::ElfMemImage::kInvalidBase);
 
 std::atomic<VDSOSupport::GetCpuFn> VDSOSupport::getcpu_fn_(&InitAndGetCPU);
 VDSOSupport::VDSOSupport()
     // If vdso_base_ is still set to kInvalidBase, we got here
     // before VDSOSupport::Init has been called. Call it now.
     : image_(vdso_base_.load(std::memory_order_relaxed) ==
-                     debug_internal::ElfMemImage::kInvalidBase
+                     debugging_internal::ElfMemImage::kInvalidBase
                  ? Init()
                  : vdso_base_.load(std::memory_order_relaxed)) {}
 
@@ -63,7 +63,7 @@ VDSOSupport::VDSOSupport()
 // Finally, even if there is a race here, it is harmless, because
 // the operation should be idempotent.
 const void *VDSOSupport::Init() {
-  const auto kInvalidBase = debug_internal::ElfMemImage::kInvalidBase;
+  const auto kInvalidBase = debugging_internal::ElfMemImage::kInvalidBase;
 #if __GLIBC_PREREQ(2, 16)
   if (vdso_base_.load(std::memory_order_relaxed) == kInvalidBase) {
     errno = 0;
@@ -120,7 +120,7 @@ const void *VDSOSupport::Init() {
 }
 
 const void *VDSOSupport::SetBase(const void *base) {
-  ABSL_RAW_CHECK(base != debug_internal::ElfMemImage::kInvalidBase,
+  ABSL_RAW_CHECK(base != debugging_internal::ElfMemImage::kInvalidBase,
                  "internal error");
   const void *old_base = vdso_base_.load(std::memory_order_relaxed);
   vdso_base_.store(base, std::memory_order_relaxed);
@@ -186,7 +186,7 @@ static class VDSOInitHelper {
   VDSOInitHelper() { VDSOSupport::Init(); }
 } vdso_init_helper;
 
-}  // namespace debug_internal
+}  // namespace debugging_internal
 }  // namespace absl
 
 #endif  // ABSL_HAVE_VDSO_SUPPORT
diff --git a/absl/debugging/internal/vdso_support.h b/absl/debugging/internal/vdso_support.h
index a6a7a17794e3..870a60a4109c 100644
--- a/absl/debugging/internal/vdso_support.h
+++ b/absl/debugging/internal/vdso_support.h
@@ -52,7 +52,7 @@
 #endif
 
 namespace absl {
-namespace debug_internal {
+namespace debugging_internal {
 
 // NOTE: this class may be used from within tcmalloc, and can not
 // use any memory allocation routines.
@@ -147,7 +147,7 @@ class VDSOSupport {
 // support SYS_getcpu.
 int GetCPU();
 
-}  // namespace debug_internal
+}  // namespace debugging_internal
 }  // namespace absl
 
 #endif  // ABSL_HAVE_ELF_MEM_IMAGE
diff --git a/absl/numeric/int128.cc b/absl/numeric/int128.cc
index b32d8095fdf1..f24b785c04c0 100644
--- a/absl/numeric/int128.cc
+++ b/absl/numeric/int128.cc
@@ -20,6 +20,7 @@
 #include <iostream>  // NOLINT(readability/streams)
 #include <sstream>
 #include <string>
+#include <type_traits>
 
 namespace absl {
 
@@ -128,19 +129,17 @@ uint128::uint128(float v) : uint128(MakeUint128FromFloat(v)) {}
 uint128::uint128(double v) : uint128(MakeUint128FromFloat(v)) {}
 uint128::uint128(long double v) : uint128(MakeUint128FromFloat(v)) {}
 
-uint128& uint128::operator/=(uint128 other) {
+uint128 operator/(uint128 lhs, uint128 rhs) {
   uint128 quotient = 0;
   uint128 remainder = 0;
-  DivModImpl(*this, other, &quotient, &remainder);
-  *this = quotient;
-  return *this;
+  DivModImpl(lhs, rhs, &quotient, &remainder);
+  return quotient;
 }
-uint128& uint128::operator%=(uint128 other) {
+uint128 operator%(uint128 lhs, uint128 rhs) {
   uint128 quotient = 0;
   uint128 remainder = 0;
-  DivModImpl(*this, other, &quotient, &remainder);
-  *this = remainder;
-  return *this;
+  DivModImpl(lhs, rhs, &quotient, &remainder);
+  return remainder;
 }
 
 namespace {
diff --git a/absl/numeric/int128.h b/absl/numeric/int128.h
index bbb76edb4ba9..cfbf74c46689 100644
--- a/absl/numeric/int128.h
+++ b/absl/numeric/int128.h
@@ -262,21 +262,50 @@ inline uint128& uint128::operator=(unsigned __int128 v) {
 }
 #endif  // ABSL_HAVE_INTRINSIC_INT128
 
-// Shift and arithmetic operators.
+// Arithmetic operators.
 
-inline uint128 operator<<(uint128 lhs, int amount) { return lhs <<= amount; }
+uint128 operator<<(uint128 lhs, int amount);
+uint128 operator>>(uint128 lhs, int amount);
+uint128 operator+(uint128 lhs, uint128 rhs);
+uint128 operator-(uint128 lhs, uint128 rhs);
+uint128 operator*(uint128 lhs, uint128 rhs);
+uint128 operator/(uint128 lhs, uint128 rhs);
+uint128 operator%(uint128 lhs, uint128 rhs);
 
-inline uint128 operator>>(uint128 lhs, int amount) { return lhs >>= amount; }
+inline uint128& uint128::operator<<=(int amount) {
+  *this = *this << amount;
+  return *this;
+}
 
-inline uint128 operator+(uint128 lhs, uint128 rhs) { return lhs += rhs; }
+inline uint128& uint128::operator>>=(int amount) {
+  *this = *this >> amount;
+  return *this;
+}
 
-inline uint128 operator-(uint128 lhs, uint128 rhs) { return lhs -= rhs; }
+inline uint128& uint128::operator+=(uint128 other) {
+  *this = *this + other;
+  return *this;
+}
 
-inline uint128 operator*(uint128 lhs, uint128 rhs) { return lhs *= rhs; }
+inline uint128& uint128::operator-=(uint128 other) {
+  *this = *this - other;
+  return *this;
+}
 
-inline uint128 operator/(uint128 lhs, uint128 rhs) { return lhs /= rhs; }
+inline uint128& uint128::operator*=(uint128 other) {
+  *this = *this * other;
+  return *this;
+}
 
-inline uint128 operator%(uint128 lhs, uint128 rhs) { return lhs %= rhs; }
+inline uint128& uint128::operator/=(uint128 other) {
+  *this = *this / other;
+  return *this;
+}
+
+inline uint128& uint128::operator%=(uint128 other) {
+  *this = *this % other;
+  return *this;
+}
 
 constexpr uint64_t Uint128Low64(uint128 v) { return v.lo_; }
 
@@ -514,9 +543,9 @@ inline uint128& uint128::operator^=(uint128 other) {
   return *this;
 }
 
-// Shift and arithmetic assign operators.
+// Arithmetic operators.
 
-inline uint128& uint128::operator<<=(int amount) {
+inline uint128 operator<<(uint128 lhs, int amount) {
   assert(amount >= 0);   // Negative shifts are undefined.
   assert(amount < 128);  // Shifts of >= 128 are undefined.
 
@@ -524,17 +553,16 @@ inline uint128& uint128::operator<<=(int amount) {
   // special-casing.
   if (amount < 64) {
     if (amount != 0) {
-      hi_ = (hi_ << amount) | (lo_ >> (64 - amount));
-      lo_ = lo_ << amount;
+      return MakeUint128(
+          (Uint128High64(lhs) << amount) | (Uint128Low64(lhs) >> (64 - amount)),
+          Uint128Low64(lhs) << amount);
     }
-  } else {
-    hi_ = lo_ << (amount - 64);
-    lo_ = 0;
+    return lhs;
   }
-  return *this;
+  return MakeUint128(Uint128Low64(lhs) << (amount - 64), 0);
 }
 
-inline uint128& uint128::operator>>=(int amount) {
+inline uint128 operator>>(uint128 lhs, int amount) {
   assert(amount >= 0);   // Negative shifts are undefined.
   assert(amount < 128);  // Shifts of >= 128 are undefined.
 
@@ -542,49 +570,51 @@ inline uint128& uint128::operator>>=(int amount) {
   // special-casing.
   if (amount < 64) {
     if (amount != 0) {
-      lo_ = (lo_ >> amount) | (hi_ << (64 - amount));
-      hi_ = hi_ >> amount;
+      return MakeUint128(Uint128High64(lhs) >> amount,
+                         (Uint128Low64(lhs) >> amount) |
+                             (Uint128High64(lhs) << (64 - amount)));
     }
-  } else {
-    lo_ = hi_ >> (amount - 64);
-    hi_ = 0;
+    return lhs;
   }
-  return *this;
+  return MakeUint128(0, Uint128High64(lhs) >> (amount - 64));
 }
 
-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 operator+(uint128 lhs, uint128 rhs) {
+  uint128 result = MakeUint128(Uint128High64(lhs) + Uint128High64(rhs),
+                               Uint128Low64(lhs) + Uint128Low64(rhs));
+  if (Uint128Low64(result) < Uint128Low64(lhs)) {  // check for carry
+    return MakeUint128(Uint128High64(result) + 1, Uint128Low64(result));
+  }
+  return result;
 }
 
-inline uint128& uint128::operator-=(uint128 other) {
-  hi_ -= other.hi_;
-  if (other.lo_ > lo_) --hi_;
-  lo_ -= other.lo_;
-  return *this;
+inline uint128 operator-(uint128 lhs, uint128 rhs) {
+  uint128 result = MakeUint128(Uint128High64(lhs) - Uint128High64(rhs),
+                               Uint128Low64(lhs) - Uint128Low64(rhs));
+  if (Uint128Low64(lhs) < Uint128Low64(rhs)) {  // check for carry
+    return MakeUint128(Uint128High64(result) - 1, Uint128Low64(result));
+  }
+  return result;
 }
 
-inline uint128& uint128::operator*=(uint128 other) {
+inline uint128 operator*(uint128 lhs, uint128 rhs) {
 #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<unsigned __int128>(*this) *
-          static_cast<unsigned __int128>(other);
-  return *this;
+  return static_cast<unsigned __int128>(lhs) *
+         static_cast<unsigned __int128>(rhs);
 #else   // ABSL_HAVE_INTRINSIC128
-  uint64_t a32 = lo_ >> 32;
-  uint64_t a00 = lo_ & 0xffffffff;
-  uint64_t b32 = other.lo_ >> 32;
-  uint64_t b00 = other.lo_ & 0xffffffff;
-  hi_ = hi_ * other.lo_ + lo_ * other.hi_ + a32 * b32;
-  lo_ = a00 * b00;
-  *this += uint128(a32 * b00) << 32;
-  *this += uint128(a00 * b32) << 32;
-  return *this;
+  uint64_t a32 = Uint128Low64(lhs) >> 32;
+  uint64_t a00 = Uint128Low64(lhs) & 0xffffffff;
+  uint64_t b32 = Uint128Low64(rhs) >> 32;
+  uint64_t b00 = Uint128Low64(rhs) & 0xffffffff;
+  uint128 result =
+      MakeUint128(Uint128High64(lhs) * Uint128Low64(rhs) +
+                      Uint128Low64(lhs) * Uint128High64(rhs) + a32 * b32,
+                  a00 * b00);
+  result += uint128(a32 * b00) << 32;
+  result += uint128(a00 * b32) << 32;
+  return result;
 #endif  // ABSL_HAVE_INTRINSIC128
 }