Skip to content

Commit b8ebbc2

Browse files
Abseil Teamcopybara-github
authored andcommitted
Adding sw prefetchers to absl::hash.
PiperOrigin-RevId: 547850162 Change-Id: I43208c7fa1eaa2a7acfad5891b80c150ee58c65f
1 parent 1adf896 commit b8ebbc2

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

absl/hash/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ cc_library(
183183
deps = [
184184
"//absl/base:config",
185185
"//absl/base:endian",
186+
"//absl/base:prefetch",
186187
"//absl/numeric:int128",
187188
],
188189
)

absl/hash/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ absl_cc_library(
165165
absl::config
166166
absl::endian
167167
absl::int128
168+
absl::prefetch
168169
)
169170

170171
absl_cc_test(

absl/hash/internal/low_level_hash.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "absl/hash/internal/low_level_hash.h"
1616

1717
#include "absl/base/internal/unaligned_access.h"
18+
#include "absl/base/prefetch.h"
1819
#include "absl/numeric/int128.h"
1920

2021
namespace absl {
@@ -29,6 +30,8 @@ static uint64_t Mix(uint64_t v0, uint64_t v1) {
2930

3031
uint64_t LowLevelHash(const void* data, size_t len, uint64_t seed,
3132
const uint64_t salt[5]) {
33+
// Prefetch the cacheline that data resides in.
34+
PrefetchToLocalCache(data);
3235
const uint8_t* ptr = static_cast<const uint8_t*>(data);
3336
uint64_t starting_length = static_cast<uint64_t>(len);
3437
uint64_t current_state = seed ^ salt[0];
@@ -40,6 +43,9 @@ uint64_t LowLevelHash(const void* data, size_t len, uint64_t seed,
4043
uint64_t duplicated_state = current_state;
4144

4245
do {
46+
// Always prefetch the next cacheline.
47+
PrefetchToLocalCache(ptr + ABSL_CACHELINE_SIZE);
48+
4349
uint64_t a = absl::base_internal::UnalignedLoad64(ptr);
4450
uint64_t b = absl::base_internal::UnalignedLoad64(ptr + 8);
4551
uint64_t c = absl::base_internal::UnalignedLoad64(ptr + 16);

0 commit comments

Comments
 (0)