summaryrefslogtreecommitdiff
path: root/absl/hash
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-07-13 10:51:10 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-07-13 10:52:00 -0700
commitb8ebbc2ecadb64239dc0767b55296ab9c4510b0f (patch)
tree86a1a63c7745dc95e4ee9ecac89bde26a88675ce /absl/hash
parent1adf896ec842bd9788a1bbede94a33e1402b8ecb (diff)
Adding sw prefetchers to absl::hash.
PiperOrigin-RevId: 547850162 Change-Id: I43208c7fa1eaa2a7acfad5891b80c150ee58c65f
Diffstat (limited to 'absl/hash')
-rw-r--r--absl/hash/BUILD.bazel1
-rw-r--r--absl/hash/CMakeLists.txt1
-rw-r--r--absl/hash/internal/low_level_hash.cc6
3 files changed, 8 insertions, 0 deletions
diff --git a/absl/hash/BUILD.bazel b/absl/hash/BUILD.bazel
index 7f964ae7..4346fc49 100644
--- a/absl/hash/BUILD.bazel
+++ b/absl/hash/BUILD.bazel
@@ -183,6 +183,7 @@ cc_library(
deps = [
"//absl/base:config",
"//absl/base:endian",
+ "//absl/base:prefetch",
"//absl/numeric:int128",
],
)
diff --git a/absl/hash/CMakeLists.txt b/absl/hash/CMakeLists.txt
index 1adce617..65fd2a5f 100644
--- a/absl/hash/CMakeLists.txt
+++ b/absl/hash/CMakeLists.txt
@@ -165,6 +165,7 @@ absl_cc_library(
absl::config
absl::endian
absl::int128
+ absl::prefetch
)
absl_cc_test(
diff --git a/absl/hash/internal/low_level_hash.cc b/absl/hash/internal/low_level_hash.cc
index c917457a..b5db0b89 100644
--- a/absl/hash/internal/low_level_hash.cc
+++ b/absl/hash/internal/low_level_hash.cc
@@ -15,6 +15,7 @@
#include "absl/hash/internal/low_level_hash.h"
#include "absl/base/internal/unaligned_access.h"
+#include "absl/base/prefetch.h"
#include "absl/numeric/int128.h"
namespace absl {
@@ -29,6 +30,8 @@ static uint64_t Mix(uint64_t v0, uint64_t v1) {
uint64_t LowLevelHash(const void* data, size_t len, uint64_t seed,
const uint64_t salt[5]) {
+ // Prefetch the cacheline that data resides in.
+ PrefetchToLocalCache(data);
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];
@@ -40,6 +43,9 @@ uint64_t LowLevelHash(const void* data, size_t len, uint64_t seed,
uint64_t duplicated_state = current_state;
do {
+ // Always prefetch the next cacheline.
+ PrefetchToLocalCache(ptr + ABSL_CACHELINE_SIZE);
+
uint64_t a = absl::base_internal::UnalignedLoad64(ptr);
uint64_t b = absl::base_internal::UnalignedLoad64(ptr + 8);
uint64_t c = absl::base_internal::UnalignedLoad64(ptr + 16);