Replace WeakMix usage with Mix and change H2 to use the most significant 7 bits - saving 1 cycle in H1.

Using Mix instead of WeakMix means that the entire 64 bits of hash are expected to have good entropy. Note that WeakMix only has lower latency than Mix on Arm, but not on x86.

PiperOrigin-RevId: 767203392
Change-Id: Ib9655bc4db2e525ea14f348b86f680acf02dcb29
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index ac0ff4a..e9486c3 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -521,15 +521,16 @@
   uint64_t data_;
 };
 
-// Extracts the H1 portion of a hash: 57 bits mixed with a per-table seed.
+// Mixes the hash with a per-table seed. Note that we only use the low bits of
+// H1 because we bitwise-and with capacity later.
 inline size_t H1(size_t hash, PerTableSeed seed) {
-  return (hash >> 7) ^ seed.seed();
+  return hash ^ seed.seed();
 }
 
-// Extracts the H2 portion of a hash: the 7 bits not used for H1.
+// Extracts the H2 portion of a hash: the 7 most significant bits.
 //
 // These are used as an occupied control byte.
-inline h2_t H2(size_t hash) { return hash & 0x7F; }
+inline h2_t H2(size_t hash) { return hash >> (sizeof(size_t) * 8 - 7); }
 
 // When there is an insertion with no reserved growth, we rehash with
 // probability `min(1, RehashProbabilityConstant() / capacity())`. Using a
diff --git a/absl/hash/internal/hash.h b/absl/hash/internal/hash.h
index 1564db9..30aede2 100644
--- a/absl/hash/internal/hash.h
+++ b/absl/hash/internal/hash.h
@@ -74,7 +74,6 @@
 #include <vector>
 
 #include "absl/base/attributes.h"
-#include "absl/base/internal/endian.h"
 #include "absl/base/internal/unaligned_access.h"
 #include "absl/base/optimization.h"
 #include "absl/base/port.h"
@@ -504,8 +503,7 @@
                                                              T ptr) {
   auto v = reinterpret_cast<uintptr_t>(ptr);
   // Due to alignment, pointers tend to have low bits as zero, and the next few
-  // bits follow a pattern since they are also multiples of some base value. The
-  // byte swap in WeakMix helps ensure we still have good entropy in low bits.
+  // bits follow a pattern since they are also multiples of some base value.
   // Mix pointers twice to ensure we have good entropy in low bits.
   return H::combine(std::move(hash_state), v, v);
 }
@@ -1121,7 +1119,7 @@
   template <typename T, absl::enable_if_t<IntegralFastPath<T>::value, int> = 0>
   static size_t hash(T value) {
     return static_cast<size_t>(
-        WeakMix(Seed(), static_cast<std::make_unsigned_t<T>>(value)));
+        Mix(Seed() ^ static_cast<std::make_unsigned_t<T>>(value), kMul));
   }
 
   // Overload of MixingHashState::hash()
@@ -1186,7 +1184,7 @@
   // optimize Read1To3 and Read4To8 differently for the string case.
   static MixingHashState combine_raw(MixingHashState hash_state,
                                      uint64_t value) {
-    return MixingHashState(WeakMix(hash_state.state_, value));
+    return MixingHashState(Mix(hash_state.state_ ^ value, kMul));
   }
 
   // Implementation of the base case for combine_contiguous where we actually
@@ -1214,7 +1212,7 @@
       // Empty string must modify the state.
       v = 0x57;
     }
-    return WeakMix(state, v);
+    return Mix(state ^ v, kMul);
   }
 
   ABSL_ATTRIBUTE_ALWAYS_INLINE static uint64_t CombineContiguousImpl9to16(
@@ -1323,16 +1321,6 @@
     return Uint128High64(m) ^ Uint128Low64(m);
   }
 
-  // Slightly lower latency than Mix, but with lower quality. The byte swap
-  // helps ensure that low bits still have high quality.
-  ABSL_ATTRIBUTE_ALWAYS_INLINE static uint64_t WeakMix(uint64_t lhs,
-                                                       uint64_t rhs) {
-    const uint64_t n = lhs ^ rhs;
-    // WeakMix doesn't work well on 32-bit platforms so just use Mix.
-    if constexpr (sizeof(size_t) < 8) return Mix(n, kMul);
-    return absl::gbswap_64(n * kMul);
-  }
-
   ABSL_ATTRIBUTE_ALWAYS_INLINE static uint64_t Hash64(const unsigned char* data,
                                                       size_t len,
                                                       uint64_t state) {