6
6
#define CARBON_COMMON_HASHING_H_
7
7
8
8
#include < concepts>
9
+ #include < cstdint>
9
10
#include < string>
10
11
#include < tuple>
11
12
#include < type_traits>
12
13
#include < utility>
13
14
14
- #include " common/check.h"
15
- #include " common/ostream.h"
16
- #include " llvm/ADT/APFloat.h"
17
- #include " llvm/ADT/APInt.h"
18
- #include " llvm/ADT/ArrayRef.h"
19
- #include " llvm/ADT/SmallVector.h"
20
- #include " llvm/ADT/StringRef.h"
21
- #include " llvm/Support/FormatVariadic.h"
15
+ #include " third_party/carbon/lang/ common/check.h"
16
+ #include " third_party/carbon/lang/ common/ostream.h"
17
+ #include " third_party/llvm/llvm-project/llvm/include/ llvm/ADT/APFloat.h"
18
+ #include " third_party/llvm/llvm-project/llvm/include/ llvm/ADT/APInt.h"
19
+ #include " third_party/llvm/llvm-project/llvm/include/ llvm/ADT/ArrayRef.h"
20
+ #include " third_party/llvm/llvm-project/llvm/include/ llvm/ADT/SmallVector.h"
21
+ #include " third_party/llvm/llvm-project/llvm/include/ llvm/ADT/StringRef.h"
22
+ #include " third_party/llvm/llvm-project/llvm/include/ llvm/Support/FormatVariadic.h"
22
23
23
24
#ifdef __ARM_ACLE
24
25
#include < arm_acle.h>
@@ -387,6 +388,13 @@ class Hasher {
387
388
return data;
388
389
}
389
390
391
+ // As above, but for small offsets, we can use aligned loads, which are
392
+ // faster. The offset must be in the range [0, 8).
393
+ static auto SampleAlignedRandomData (ssize_t offset) -> uint64_t {
394
+ CARBON_DCHECK (offset < sizeof (StaticRandomData) / sizeof (uint64_t ));
395
+ return StaticRandomData[offset];
396
+ }
397
+
390
398
// Random data taken from the hexadecimal digits of Pi's fractional component,
391
399
// written in lexical order for convenience of reading. The resulting
392
400
// byte-stream will be different due to little-endian integers. These can be
@@ -408,7 +416,7 @@ class Hasher {
408
416
// | sed -e "s/.\{4\}/&'/g" \
409
417
// | sed -e "s/\(.\{4\}'.\{4\}'.\{4\}'.\{4\}\)'/0x\1,\n/g"
410
418
// ```
411
- alignas ( 64 ) static constexpr std::array<uint64_t , 8 > StaticRandomData = {
419
+ static constexpr std::array<uint64_t , 8 > StaticRandomData = {
412
420
0x243f'6a88'85a3'08d3 , 0x1319'8a2e'0370'7344 , 0xa409'3822'299f'31d0 ,
413
421
0x082e'fa98'ec4e'6c89 , 0x4528'21e6'38d0'1377 , 0xbe54'66cf'34e9'0c6c ,
414
422
0xc0ac'29b7'c97c'50dd , 0x3f84'd5b5'b547'0917 ,
@@ -950,7 +958,7 @@ inline auto Hasher::HashSizedBytes(llvm::ArrayRef<std::byte> bytes) -> void {
950
958
// Note that we don't drop to the `WeakMix` routine here because we want
951
959
// to use sampled random data to encode the size, which may not be as
952
960
// effective without the full 128-bit folded result.
953
- buffer = Mix (data ^ buffer, SampleRandomData (size));
961
+ buffer = Mix (data ^ buffer, SampleAlignedRandomData (size - 1 ));
954
962
CARBON_MCA_END (" dynamic-8b" );
955
963
return ;
956
964
}
0 commit comments