[llvm] [Hashing] Replace CityHash mixers with xxh3 (PR #194567)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat May 9 15:38:04 PDT 2026
================
@@ -432,24 +265,22 @@ hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last) {
template <typename ValueT>
std::enable_if_t<is_hashable_data<ValueT>::value, hash_code>
hash_combine_range_impl(ValueT *first, ValueT *last) {
- const uint64_t seed = get_execution_seed();
- const char *s_begin = reinterpret_cast<const char *>(first);
- const char *s_end = reinterpret_cast<const char *>(last);
- const size_t length = std::distance(s_begin, s_end);
- if (length <= 64)
- return hash_short(s_begin, length, seed);
-
- const char *s_aligned_end = s_begin + (length & ~63);
- hash_state state = state.create(s_begin, seed);
- s_begin += 64;
- while (s_begin != s_aligned_end) {
- state.mix(s_begin);
- s_begin += 64;
- }
- if (length & 63)
- state.mix(s_end - 64);
+ return combine_bytes(reinterpret_cast<const char *>(first),
+ size_t(last - first) * sizeof(ValueT));
+}
+
+/// Sum of `sizeof(get_hashable_data(arg))` across a parameter pack.
+template <typename... Ts> constexpr size_t total_hashable_size() {
+ return (size_t(0) + ... +
+ sizeof(decltype(get_hashable_data(std::declval<Ts>()))));
+}
- return state.finalize(length);
+/// Copy `get_hashable_data(arg)` into `buf` at offset `off`, advancing `off`.
+template <typename T>
+inline void store_hashable_data(char *buf, size_t &off, const T &arg) {
+ auto data = get_hashable_data(arg);
+ std::memcpy(buf + off, &data, sizeof(data));
----------------
MaskRay wrote:
The cross-host instability is probably desired - so that we can more reliably catch misuses.
https://github.com/llvm/llvm-project/pull/194567
More information about the llvm-commits
mailing list