Skip to content

Commit

Permalink
[Support] Add llvm::xxh3_128bits
Browse files Browse the repository at this point in the history
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 `llvm::xxh3_128bits`.

Testing:
- Add a test based on xsum_sanity_check.c in upstream xxhash.
  • Loading branch information
dukebw committed Jun 17, 2024
1 parent 8ef5c98 commit 90ce7bd
Show file tree
Hide file tree
Showing 3 changed files with 655 additions and 35 deletions.
27 changes: 26 additions & 1 deletion llvm/include/llvm/Support/xxhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,38 @@
#include "llvm/ADT/StringRef.h"

namespace llvm {

uint64_t xxHash64(llvm::StringRef Data);
uint64_t xxHash64(llvm::ArrayRef<uint8_t> Data);

uint64_t xxh3_64bits(ArrayRef<uint8_t> data);
inline uint64_t xxh3_64bits(StringRef data) {
return xxh3_64bits(ArrayRef(data.bytes_begin(), data.size()));
}
}

/*-**********************************************************************
* XXH3 128-bit variant
************************************************************************/

/*!
* @brief The return value from 128-bit hashes.
*
* Stored in little endian order, although the fields themselves are in native
* endianness.
*/
struct XXH128_hash_t {
uint64_t low64; /*!< `value & 0xFFFFFFFFFFFFFFFF` */
uint64_t high64; /*!< `value >> 64` */

/// Convenience equality check operator.
bool operator==(const XXH128_hash_t rhs) const {
return low64 == rhs.low64 && high64 == rhs.high64;
}
};

/// XXH3's 128-bit variant.
XXH128_hash_t xxh3_128bits(ArrayRef<uint8_t> data);

} // namespace llvm

#endif
Loading

0 comments on commit 90ce7bd

Please sign in to comment.