Skip to content

Commit f991ebb

Browse files
authored
[Support] Add llvm::xxh3_128bits (#95863)
Add a 128-bit xxhash function, following the existing `llvm::xxh3_64bits` and `llvm::xxHash` implementations. Previously, 48e93f5 added support for `llvm::xxh3_64bits`, which closely follows the upstream implementation at https://github.com/Cyan4973/xxHash, with simplifications from Devin Hussey's xxhash-clean. However, it is desirable to have a larger 128-bit hash key for use cases such as filesystem checksums where chance of collision needs to be negligible. So to that end this also ports over the 128-bit xxh3_128bits as `llvm::xxh3_128bits`. Testing: - Add a test based on xsum_sanity_check.c in upstream xxhash.
1 parent c008647 commit f991ebb

File tree

3 files changed

+623
-35
lines changed

3 files changed

+623
-35
lines changed

llvm/include/llvm/Support/xxhash.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,38 @@
4242
#include "llvm/ADT/StringRef.h"
4343

4444
namespace llvm {
45+
4546
uint64_t xxHash64(llvm::StringRef Data);
4647
uint64_t xxHash64(llvm::ArrayRef<uint8_t> Data);
4748

4849
uint64_t xxh3_64bits(ArrayRef<uint8_t> data);
4950
inline uint64_t xxh3_64bits(StringRef data) {
5051
return xxh3_64bits(ArrayRef(data.bytes_begin(), data.size()));
5152
}
52-
}
53+
54+
/*-**********************************************************************
55+
* XXH3 128-bit variant
56+
************************************************************************/
57+
58+
/*!
59+
* @brief The return value from 128-bit hashes.
60+
*
61+
* Stored in little endian order, although the fields themselves are in native
62+
* endianness.
63+
*/
64+
struct XXH128_hash_t {
65+
uint64_t low64; /*!< `value & 0xFFFFFFFFFFFFFFFF` */
66+
uint64_t high64; /*!< `value >> 64` */
67+
68+
/// Convenience equality check operator.
69+
bool operator==(const XXH128_hash_t rhs) const {
70+
return low64 == rhs.low64 && high64 == rhs.high64;
71+
}
72+
};
73+
74+
/// XXH3's 128-bit variant.
75+
XXH128_hash_t xxh3_128bits(ArrayRef<uint8_t> data);
76+
77+
} // namespace llvm
5378

5479
#endif

0 commit comments

Comments
 (0)