Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
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
  • Loading branch information
Abseil Team authored and derekmauro committed Aug 13, 2021
1 parent f04a040 commit 8910297
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 88 deletions.
4 changes: 2 additions & 2 deletions CMake/AbseilDll.cmake
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE
Expand Up @@ -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"],
)
4 changes: 2 additions & 2 deletions absl/BUILD.bazel
Expand Up @@ -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",
],
)

Expand Down
2 changes: 1 addition & 1 deletion absl/debugging/internal/stack_consumption.cc
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion absl/debugging/internal/stack_consumption.h
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions absl/debugging/internal/symbolize.h
Expand Up @@ -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>
Expand Down
14 changes: 7 additions & 7 deletions absl/hash/BUILD.bazel
Expand Up @@ -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",
Expand Down Expand Up @@ -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"],
Expand All @@ -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",
],
Expand Down
14 changes: 7 additions & 7 deletions absl/hash/CMakeLists.txt
Expand Up @@ -36,7 +36,7 @@ absl_cc_library(
absl::optional
absl::variant
absl::utility
absl::wyhash
absl::low_level_hash
PUBLIC
)

Expand Down Expand Up @@ -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
Expand All @@ -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
)
13 changes: 7 additions & 6 deletions absl/hash/internal/hash.cc
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions absl/hash/internal/hash.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())) {
Expand Down
Expand Up @@ -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"
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
24 changes: 13 additions & 11 deletions absl/hash/internal/wyhash.h → absl/hash/internal/low_level_hash.h
Expand Up @@ -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>
Expand All @@ -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_

0 comments on commit 8910297

Please sign in to comment.