Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commit e8fb927f6cdfed33e8c7d31838fc43684546e8df
- Author: Kuba <[email protected]>
- Date: Tue Dec 9 08:06:52 2025 +0100
- TT: Store full 64-bit key to reduce collisions
- - Change key16 (uint16_t) to key64 (Key/uint64_t)
- - Reduce ClusterSize from 3 to 2 for 32-byte alignment
- - Entry size: 10 → 16 bytes
- - Virtually eliminates false positive key matches within clusters
- diff --git a/tt.cpp b/tt.cpp
- index 9533489..79ae409 100644
- --- a/tt.cpp
- +++ b/tt.cpp
- @@ -32,9 +32,9 @@
- namespace Stockfish {
- -// TTEntry struct is the 10 bytes transposition table entry, defined as below:
- +// TTEntry struct is the 16 bytes transposition table entry, defined as below:
- //
- -// key 16 bit
- +// key 64 bit
- // depth 8 bit
- // generation 5 bit
- // pv node 1 bit
- @@ -63,7 +63,7 @@ struct TTEntry {
- private:
- friend class TranspositionTable;
- - uint16_t key16;
- + Key key64;
- uint8_t depth8;
- uint8_t genBound8;
- Move move16;
- @@ -94,17 +94,17 @@ void TTEntry::save(
- Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev, uint8_t generation8) {
- // Preserve the old ttmove if we don't have a new one
- - if (m || uint16_t(k) != key16)
- + if (m || k != key64)
- move16 = m;
- // Overwrite less valuable entries (cheapest checks first)
- - if (b == BOUND_EXACT || uint16_t(k) != key16 || d - DEPTH_ENTRY_OFFSET + 2 * pv > depth8 - 4
- + if (b == BOUND_EXACT || k != key64 || d - DEPTH_ENTRY_OFFSET + 2 * pv > depth8 - 4
- || relative_age(generation8))
- {
- assert(d > DEPTH_ENTRY_OFFSET);
- assert(d < 256 + DEPTH_ENTRY_OFFSET);
- - key16 = uint16_t(k);
- + key64 = k;
- depth8 = uint8_t(d - DEPTH_ENTRY_OFFSET);
- genBound8 = uint8_t(generation8 | uint8_t(pv) << 2 | b);
- value16 = int16_t(v);
- @@ -139,11 +139,10 @@ void TTWriter::write(
- // of TTEntry. Each non-empty TTEntry contains information on exactly one position. The size of a Cluster should
- // divide the size of a cache line for best performance, as the cacheline is prefetched when possible.
- -static constexpr int ClusterSize = 3;
- +static constexpr int ClusterSize = 2;
- struct Cluster {
- - TTEntry entry[ClusterSize];
- - char padding[2]; // Pad to 32 bytes
- + TTEntry entry[ClusterSize]; // 2 × 16 = 32 bytes, no padding needed
- };
- static_assert(sizeof(Cluster) == 32, "Suboptimal Cluster size");
- @@ -224,11 +223,10 @@ uint8_t TranspositionTable::generation() const { return generation8; }
- // TTEntry t2 if its replace value is greater than that of t2.
- std::tuple<bool, TTData, TTWriter> TranspositionTable::probe(const Key key) const {
- - TTEntry* const tte = first_entry(key);
- - const uint16_t key16 = uint16_t(key); // Use the low 16 bits as key inside the cluster
- + TTEntry* const tte = first_entry(key);
- for (int i = 0; i < ClusterSize; ++i)
- - if (tte[i].key16 == key16)
- + if (tte[i].key64 == key)
- // This gap is the main place for read races.
- // After `read()` completes that copy is final, but may be self-inconsistent.
- return {tte[i].is_occupied(), tte[i].read(), TTWriter(&tte[i])};
Advertisement
Add Comment
Please, Sign In to add comment