Skip to content

Commit

Permalink
Fix readability of TTEntry occupancy check
Browse files Browse the repository at this point in the history
Passed STC:
https://tests.stockfishchess.org/tests/view/66695b6a602682471b064cfc
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 107520 W: 28138 L: 27998 D: 51384
Ptnml(0-2): 373, 12257, 28358, 12401, 371

closes #5394

No functional change
  • Loading branch information
dubslow authored and vondele committed Jun 15, 2024
1 parent b01fdb5 commit ff10f4a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/tt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct TTEntry {
Bound(genBound8 & 0x3), bool(genBound8 & 0x4)};
}

bool is_occupied() const;
void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev, uint8_t generation8);
// The returned age is a multiple of TranspositionTable::GENERATION_DELTA
uint8_t relative_age(const uint8_t generation8) const;
Expand Down Expand Up @@ -84,7 +85,8 @@ static constexpr int GENERATION_MASK = (0xFF << GENERATION_BITS) & 0xFF;

// DEPTH_ENTRY_OFFSET exists because 1) we use `bool(depth8)` as the occupancy check, but
// 2) we need to store negative depths for QS. (`depth8` is the only field with "spare bits":
// we sacrifice the ability to store depths greater than 1<<8 less the offset, as asserted below.)
// we sacrifice the ability to store depths greater than 1<<8 less the offset, as asserted in `save`.)
bool TTEntry::is_occupied() const { return bool(depth8); }

// Populates the TTEntry with a new node's data, possibly
// overwriting an old position. The update is not atomic and can be racy.
Expand Down Expand Up @@ -196,7 +198,7 @@ int TranspositionTable::hashfull() const {
int cnt = 0;
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < ClusterSize; ++j)
cnt += table[i].entry[j].depth8
cnt += table[i].entry[j].is_occupied()
&& (table[i].entry[j].genBound8 & GENERATION_MASK) == generation8;

return cnt / ClusterSize;
Expand Down Expand Up @@ -227,7 +229,7 @@ std::tuple<bool, TTData, TTWriter> TranspositionTable::probe(const Key key) cons
if (tte[i].key16 == key16)
// This gap is the main place for read races.
// After `read()` completes that copy is final, but may be self-inconsistent.
return {bool(tte[i].depth8), tte[i].read(), TTWriter(&tte[i])};
return {tte[i].is_occupied(), tte[i].read(), TTWriter(&tte[i])};

// Find an entry to be replaced according to the replacement strategy
TTEntry* replace = tte;
Expand Down

0 comments on commit ff10f4a

Please sign in to comment.