Skip to content

Commit be33b0a

Browse files
ezbrcopybara-github
authored andcommitted
Use rbit instruction on ARM rather than rev.
This is a followup to the change to use ARM hashing techniques in absl. I didn't realize the distinction between rev/rbit originally, but we expect that rbit will result in better hash quality at the same latency. LLVM-MCA rev: https://godbolt.org/z/94Mo71TKd LLVM-MCA rbit: https://godbolt.org/z/nK8bMfeKf PiperOrigin-RevId: 715443087 Change-Id: Ic05608851529d1447ed11557e7f430a088a4efcd
1 parent 3fba335 commit be33b0a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

absl/hash/internal/hash.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
#include <string_view>
8383
#endif
8484

85+
#ifdef __ARM_ACLE
86+
#include <arm_acle.h>
87+
#endif
88+
8589
namespace absl {
8690
ABSL_NAMESPACE_BEGIN
8791

@@ -1300,7 +1304,13 @@ class ABSL_DLL MixingHashState : public HashStateBase<MixingHashState> {
13001304
ABSL_ATTRIBUTE_ALWAYS_INLINE static uint64_t WeakMix(uint64_t n) {
13011305
// WeakMix doesn't work well on 32-bit platforms so just use Mix.
13021306
if (sizeof(size_t) < 8) return Mix(n, kMul);
1307+
#ifdef __ARM_ACLE
1308+
// gbswap_64 compiles to `rev` on ARM, but `rbit` is better because it
1309+
// reverses bits rather than reversing bytes.
1310+
return __rbitll(n * kMul);
1311+
#else
13031312
return absl::gbswap_64(n * kMul);
1313+
#endif
13041314
}
13051315

13061316
// An extern to avoid bloat on a direct call to LowLevelHash() with fixed

0 commit comments

Comments
 (0)