Export of internal Abseil changes

--
3a9b4e8e5ecba532db5cc4ac12d12660307ce9fb by Derek Mauro <dmauro@google.com>:

Use the Bazel @platforms repository for platform constraints
Fixes #1000

PiperOrigin-RevId: 390644226

--
b34e4d2f8a86b54bd483ec4c9c3dd781ad2d8b68 by Abseil Team <absl-team@google.com>:

debugging: add some handling for RISC-V

The RISC-V architecture uses a downward growing stack and can host Linux using
ELF files.  Adjust a few sites accordingly to indicate how to handle the RISC-V
architecture.

PiperOrigin-RevId: 390631894

--
5fa3a0961bf3dd0799c048956a0128f7b8113f1e by Samuel Benzaquen <sbenza@google.com>:

Rename the buffer hash function to LowLevelHash.
Although it started as wyhash, it will depart from it so it does not make sense
to keep the name.

PiperOrigin-RevId: 390483506

--
2e7867a2301d58ad4cd5abcaa5fd6f0db973ae7b by Abseil Team <absl-team@google.com>:

This is an internal change.

PiperOrigin-RevId: 390349746
GitOrigin-RevId: 3a9b4e8e5ecba532db5cc4ac12d12660307ce9fb
Change-Id: I322c3762552a2107e6c6b108c25c01e5efa8aecd
pull/1002/head
Abseil Team 3 years ago committed by Derek Mauro
parent f04a040862
commit 8910297baf
  1. 4
      CMake/AbseilDll.cmake
  2. 8
      WORKSPACE
  3. 4
      absl/BUILD.bazel
  4. 2
      absl/debugging/internal/stack_consumption.cc
  5. 2
      absl/debugging/internal/stack_consumption.h
  6. 4
      absl/debugging/internal/symbolize.h
  7. 14
      absl/hash/BUILD.bazel
  8. 14
      absl/hash/CMakeLists.txt
  9. 13
      absl/hash/internal/hash.cc
  10. 14
      absl/hash/internal/hash.h
  11. 22
      absl/hash/internal/low_level_hash.cc
  12. 24
      absl/hash/internal/low_level_hash.h
  13. 58
      absl/hash/internal/low_level_hash_test.cc
  14. 4
      absl/time/internal/cctz/BUILD.bazel

@ -124,8 +124,8 @@ set(ABSL_INTERNAL_DLL_FILES
"hash/internal/hash.h"
"hash/internal/hash.cc"
"hash/internal/spy_hash_state.h"
"hash/internal/wyhash.h"
"hash/internal/wyhash.cc"
"hash/internal/low_level_hash.h"
"hash/internal/low_level_hash.cc"
"memory/memory.h"
"meta/type_traits.h"
"numeric/bits.h"

@ -42,3 +42,11 @@ http_archive(
strip_prefix = "rules_cc-daf6ace7cfeacd6a83e9ff2ed659f416537b6c74",
urls = ["https://github.com/bazelbuild/rules_cc/archive/daf6ace7cfeacd6a83e9ff2ed659f416537b6c74.zip"],
)
# Bazel platform rules.
http_archive(
name = "platforms",
sha256 = "b601beaf841244de5c5a50d2b2eddd34839788000fa1be4260ce6603ca0d8eb7",
strip_prefix = "platforms-98939346da932eef0b54cf808622f5bb0928f00b",
urls = ["https://github.com/bazelbuild/platforms/archive/98939346da932eef0b54cf808622f5bb0928f00b.zip"],
)

@ -44,14 +44,14 @@ config_setting(
config_setting(
name = "osx",
constraint_values = [
"@bazel_tools//platforms:osx",
"@platforms//os:osx",
],
)
config_setting(
name = "ios",
constraint_values = [
"@bazel_tools//platforms:ios",
"@platforms//os:ios",
],
)

@ -43,7 +43,7 @@ namespace {
// unspecified. Therefore, instead we hardcode the direction of the
// stack on platforms we know about.
#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || \
defined(__aarch64__)
defined(__aarch64__) || defined(__riscv)
constexpr bool kStackGrowsDown = true;
#else
#error Need to define kStackGrowsDown

@ -26,7 +26,7 @@
#error ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION cannot be set directly
#elif !defined(__APPLE__) && !defined(_WIN32) && \
(defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || \
defined(__aarch64__))
defined(__aarch64__) || defined(__riscv))
#define ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION 1
namespace absl {

@ -28,8 +28,8 @@
#ifdef ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE
#error ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE cannot be directly set
#elif defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) && \
!defined(__asmjs__) && !defined(__wasm__)
#elif defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) \
&& !defined(__asmjs__) && !defined(__wasm__)
#define ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE 1
#include <elf.h>

@ -37,7 +37,7 @@ cc_library(
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":city",
":wyhash",
":low_level_hash",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:endian",
@ -143,9 +143,9 @@ cc_test(
)
cc_library(
name = "wyhash",
srcs = ["internal/wyhash.cc"],
hdrs = ["internal/wyhash.h"],
name = "low_level_hash",
srcs = ["internal/low_level_hash.cc"],
hdrs = ["internal/low_level_hash.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:private"],
@ -157,13 +157,13 @@ cc_library(
)
cc_test(
name = "wyhash_test",
srcs = ["internal/wyhash_test.cc"],
name = "low_level_hash_test",
srcs = ["internal/low_level_hash_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
visibility = ["//visibility:private"],
deps = [
":wyhash",
":low_level_hash",
"//absl/strings",
"@com_google_googletest//:gtest_main",
],

@ -36,7 +36,7 @@ absl_cc_library(
absl::optional
absl::variant
absl::utility
absl::wyhash
absl::low_level_hash
PUBLIC
)
@ -118,11 +118,11 @@ absl_cc_test(
absl_cc_library(
NAME
wyhash
low_level_hash
HDRS
"internal/wyhash.h"
"internal/low_level_hash.h"
SRCS
"internal/wyhash.cc"
"internal/low_level_hash.cc"
COPTS
${ABSL_DEFAULT_COPTS}
DEPS
@ -133,13 +133,13 @@ absl_cc_library(
absl_cc_test(
NAME
wyhash_test
low_level_hash_test
SRCS
"internal/wyhash_test.cc"
"internal/low_level_hash_test.cc"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::wyhash
absl::low_level_hash
absl::strings
GTest::gmock_main
)

@ -46,21 +46,22 @@ uint64_t MixingHashState::CombineLargeContiguousImpl64(
ABSL_CONST_INIT const void* const MixingHashState::kSeed = &kSeed;
// The salt array used by Wyhash. This array is NOT the mechanism used to make
// absl::Hash non-deterministic between program invocations. See `Seed()` for
// that mechanism.
// The salt array used by LowLevelHash. This array is NOT the mechanism used to
// make absl::Hash non-deterministic between program invocations. See `Seed()`
// for that mechanism.
//
// Any random values are fine. These values are just digits from the decimal
// part of pi.
// https://en.wikipedia.org/wiki/Nothing-up-my-sleeve_number
constexpr uint64_t kWyhashSalt[5] = {
constexpr uint64_t kHashSalt[5] = {
uint64_t{0x243F6A8885A308D3}, uint64_t{0x13198A2E03707344},
uint64_t{0xA4093822299F31D0}, uint64_t{0x082EFA98EC4E6C89},
uint64_t{0x452821E638D01377},
};
uint64_t MixingHashState::WyhashImpl(const unsigned char* data, size_t len) {
return Wyhash(data, len, Seed(), kWyhashSalt);
uint64_t MixingHashState::LowLevelHashImpl(const unsigned char* data,
size_t len) {
return LowLevelHash(data, len, Seed(), kHashSalt);
}
} // namespace hash_internal

@ -42,7 +42,7 @@
#include "absl/base/internal/unaligned_access.h"
#include "absl/base/port.h"
#include "absl/container/fixed_array.h"
#include "absl/hash/internal/wyhash.h"
#include "absl/hash/internal/low_level_hash.h"
#include "absl/meta/type_traits.h"
#include "absl/numeric/int128.h"
#include "absl/strings/string_view.h"
@ -874,14 +874,14 @@ class ABSL_DLL MixingHashState : public HashStateBase<MixingHashState> {
return static_cast<uint64_t>(m ^ (m >> (sizeof(m) * 8 / 2)));
}
// An extern to avoid bloat on a direct call to Wyhash() with fixed values for
// both the seed and salt parameters.
static uint64_t WyhashImpl(const unsigned char* data, size_t len);
// An extern to avoid bloat on a direct call to LowLevelHash() with fixed
// values for both the seed and salt parameters.
static uint64_t LowLevelHashImpl(const unsigned char* data, size_t len);
ABSL_ATTRIBUTE_ALWAYS_INLINE static uint64_t Hash64(const unsigned char* data,
size_t len) {
#ifdef ABSL_HAVE_INTRINSIC_INT128
return WyhashImpl(data, len);
return LowLevelHashImpl(data, len);
#else
return absl::hash_internal::CityHash64(reinterpret_cast<const char*>(data), len);
#endif
@ -945,8 +945,8 @@ inline uint64_t MixingHashState::CombineContiguousImpl(
inline uint64_t MixingHashState::CombineContiguousImpl(
uint64_t state, const unsigned char* first, size_t len,
std::integral_constant<int, 8> /* sizeof_size_t */) {
// For large values we use Wyhash or CityHash depending on the platform, for
// small ones we just use a multiplicative hash.
// For large values we use LowLevelHash or CityHash depending on the platform,
// for small ones we just use a multiplicative hash.
uint64_t v;
if (len > 16) {
if (ABSL_PREDICT_FALSE(len > PiecewiseChunkSize())) {

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/hash/internal/wyhash.h"
#include "absl/hash/internal/low_level_hash.h"
#include "absl/base/internal/unaligned_access.h"
#include "absl/numeric/int128.h"
@ -21,14 +21,14 @@ namespace absl {
ABSL_NAMESPACE_BEGIN
namespace hash_internal {
static uint64_t WyhashMix(uint64_t v0, uint64_t v1) {
static uint64_t Mix(uint64_t v0, uint64_t v1) {
absl::uint128 p = v0;
p *= v1;
return absl::Uint128Low64(p) ^ absl::Uint128High64(p);
}
uint64_t Wyhash(const void* data, size_t len, uint64_t seed,
const uint64_t salt[]) {
uint64_t LowLevelHash(const void* data, size_t len, uint64_t seed,
const uint64_t salt[]) {
const uint8_t* ptr = static_cast<const uint8_t*>(data);
uint64_t starting_length = static_cast<uint64_t>(len);
uint64_t current_state = seed ^ salt[0];
@ -49,12 +49,12 @@ uint64_t Wyhash(const void* data, size_t len, uint64_t seed,
uint64_t g = absl::base_internal::UnalignedLoad64(ptr + 48);
uint64_t h = absl::base_internal::UnalignedLoad64(ptr + 56);
uint64_t cs0 = WyhashMix(a ^ salt[1], b ^ current_state);
uint64_t cs1 = WyhashMix(c ^ salt[2], d ^ current_state);
uint64_t cs0 = Mix(a ^ salt[1], b ^ current_state);
uint64_t cs1 = Mix(c ^ salt[2], d ^ current_state);
current_state = (cs0 ^ cs1);
uint64_t ds0 = WyhashMix(e ^ salt[3], f ^ duplicated_state);
uint64_t ds1 = WyhashMix(g ^ salt[4], h ^ duplicated_state);
uint64_t ds0 = Mix(e ^ salt[3], f ^ duplicated_state);
uint64_t ds1 = Mix(g ^ salt[4], h ^ duplicated_state);
duplicated_state = (ds0 ^ ds1);
ptr += 64;
@ -70,7 +70,7 @@ uint64_t Wyhash(const void* data, size_t len, uint64_t seed,
uint64_t a = absl::base_internal::UnalignedLoad64(ptr);
uint64_t b = absl::base_internal::UnalignedLoad64(ptr + 8);
current_state = WyhashMix(a ^ salt[1], b ^ current_state);
current_state = Mix(a ^ salt[1], b ^ current_state);
ptr += 16;
len -= 16;
@ -101,9 +101,9 @@ uint64_t Wyhash(const void* data, size_t len, uint64_t seed,
b = 0;
}
uint64_t w = WyhashMix(a ^ salt[1], b ^ current_state);
uint64_t w = Mix(a ^ salt[1], b ^ current_state);
uint64_t z = salt[1] ^ starting_length;
return WyhashMix(w, z);
return Mix(w, z);
}
} // namespace hash_internal

@ -12,16 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// This file provides the Google-internal implementation of the Wyhash
// algorithm.
// This file provides the Google-internal implementation of LowLevelHash.
//
// Wyhash is a fast hash function for hash tables, the fastest we've currently
// (late 2020) found that passes the SMHasher tests. The algorithm relies on
// intrinsic 128-bit multiplication for speed. This is not meant to be secure -
// just fast.
// LowLevelHash is a fast hash function for hash tables, the fastest we've
// currently (late 2020) found that passes the SMHasher tests. The algorithm
// relies on intrinsic 128-bit multiplication for speed. This is not meant to be
// secure - just fast.
//
// It is closely based on a version of wyhash, but does not maintain or
// guarantee future compatibility with it.
#ifndef ABSL_HASH_INTERNAL_WYHASH_H_
#define ABSL_HASH_INTERNAL_WYHASH_H_
#ifndef ABSL_HASH_INTERNAL_LOW_LEVEL_HASH_H_
#define ABSL_HASH_INTERNAL_LOW_LEVEL_HASH_H_
#include <stdint.h>
#include <stdlib.h>
@ -38,11 +40,11 @@ namespace hash_internal {
// To allow all hashable types (including string_view and Span) to depend on
// this algorithm, we keep the API low-level, with as few dependencies as
// possible.
uint64_t Wyhash(const void* data, size_t len, uint64_t seed,
const uint64_t salt[5]);
uint64_t LowLevelHash(const void* data, size_t len, uint64_t seed,
const uint64_t salt[5]);
} // namespace hash_internal
ABSL_NAMESPACE_END
} // namespace absl
#endif // ABSL_HASH_INTERNAL_WYHASH_H_
#endif // ABSL_HASH_INTERNAL_LOW_LEVEL_HASH_H_

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "absl/hash/internal/wyhash.h"
#include "absl/hash/internal/low_level_hash.h"
#include "absl/strings/escaping.h"
#include "gmock/gmock.h"
@ -28,47 +28,47 @@ static const uint64_t kSalt[5] = {0xa0761d6478bd642f, 0xe7037ed1a0b428dbl,
// Note: We don't account for endianness, so the values here are only correct if
// you're also running on a little endian platform.
TEST(WyhashTest, EmptyString) {
TEST(LowLevelHashTest, EmptyString) {
const std::string s = "";
EXPECT_EQ(
absl::hash_internal::Wyhash(s.c_str(), s.length(), kCurrentSeed, kSalt),
4808886099364463827);
EXPECT_EQ(absl::hash_internal::LowLevelHash(s.c_str(), s.length(),
kCurrentSeed, kSalt),
4808886099364463827);
}
TEST(WyhashTest, Spaces) {
TEST(LowLevelHashTest, Spaces) {
const std::string s = " ";
EXPECT_EQ(
absl::hash_internal::Wyhash(s.c_str(), s.length(), kCurrentSeed, kSalt),
1686201463024549249);
EXPECT_EQ(absl::hash_internal::LowLevelHash(s.c_str(), s.length(),
kCurrentSeed, kSalt),
1686201463024549249);
}
TEST(WyhashTest, RepeatingString) {
TEST(LowLevelHashTest, RepeatingString) {
const std::string s = "aaaa";
EXPECT_EQ(
absl::hash_internal::Wyhash(s.c_str(), s.length(), kCurrentSeed, kSalt),
6646112255271966632);
EXPECT_EQ(absl::hash_internal::LowLevelHash(s.c_str(), s.length(),
kCurrentSeed, kSalt),
6646112255271966632);
}
TEST(WyhashTest, HexString) {
TEST(LowLevelHashTest, HexString) {
const std::string small = "\x01\x02\x03";
const std::string med = "\x01\x02\x03\x04";
EXPECT_EQ(absl::hash_internal::Wyhash(small.c_str(), small.length(),
kCurrentSeed, kSalt),
EXPECT_EQ(absl::hash_internal::LowLevelHash(small.c_str(), small.length(),
kCurrentSeed, kSalt),
11989428023081740911ULL);
EXPECT_EQ(absl::hash_internal::Wyhash(med.c_str(), med.length(), kCurrentSeed,
kSalt),
EXPECT_EQ(absl::hash_internal::LowLevelHash(med.c_str(), med.length(),
kCurrentSeed, kSalt),
9765997711188871556ULL);
}
TEST(WyhashTest, Words) {
TEST(LowLevelHashTest, Words) {
const std::string s = "third_party|wyhash|64";
EXPECT_EQ(
absl::hash_internal::Wyhash(s.c_str(), s.length(), kCurrentSeed, kSalt),
3702018632387611330);
EXPECT_EQ(absl::hash_internal::LowLevelHash(s.c_str(), s.length(),
kCurrentSeed, kSalt),
3702018632387611330);
}
TEST(WyhashTest, LongString) {
TEST(LowLevelHashTest, LongString) {
const std::string s =
"AbCdEfGhIjKlMnOpQrStUvWxYz0123456789AbCdEfGhIjKlMnOpQrStUvWxYz"
"0123456789AbCdEfGhIjKlMnOpQrStUvWxYz0123456789AbCdEfGhIjKlMnOp"
@ -76,12 +76,12 @@ TEST(WyhashTest, LongString) {
"GhIjKlMnOpQrStUvWxYz0123456789AbCdEfGhIjKlMnOpQrStUvWxYz012345"
"6789AbCdEfGhIjKlMnOpQrStUvWxYz0123456789";
EXPECT_EQ(
absl::hash_internal::Wyhash(s.c_str(), s.length(), kCurrentSeed, kSalt),
9245411362605796064ULL);
EXPECT_EQ(absl::hash_internal::LowLevelHash(s.c_str(), s.length(),
kCurrentSeed, kSalt),
9245411362605796064ULL);
}
TEST(WyhashTest, BigReference) {
TEST(LowLevelHashTest, BigReference) {
struct ExpectedResult {
absl::string_view base64_data;
uint64_t seed;
@ -477,8 +477,8 @@ TEST(WyhashTest, BigReference) {
for (const auto& expected_result : expected_results) {
std::string str;
ASSERT_TRUE(absl::Base64Unescape(expected_result.base64_data, &str));
EXPECT_EQ(absl::hash_internal::Wyhash(str.data(), str.size(),
expected_result.seed, kSalt),
EXPECT_EQ(absl::hash_internal::LowLevelHash(str.data(), str.size(),
expected_result.seed, kSalt),
expected_result.hash);
}
}

@ -26,14 +26,14 @@ filegroup(
config_setting(
name = "osx",
constraint_values = [
"@bazel_tools//platforms:osx",
"@platforms//os:osx",
],
)
config_setting(
name = "ios",
constraint_values = [
"@bazel_tools//platforms:ios",
"@platforms//os:ios",
],
)

Loading…
Cancel
Save