Merge pull request #149 from rektdie/tt-aging
tt aging | bench 1743358
This commit was merged in pull request #149.
This commit is contained in:
3 files changed
+37
-1
No files matched your search
@@ -896,6 +896,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext* ctx) {
|
|||||||
template <searchMode mode>
|
template <searchMode mode>
|
||||||
SearchResults SearchPosition(Board &board, SearchParams params, SearchContext* ctx) {
|
SearchResults SearchPosition(Board &board, SearchParams params, SearchContext* ctx) {
|
||||||
searchStopped = false;
|
searchStopped = false;
|
||||||
|
ctx->TT->IncreaseAge();
|
||||||
ctx->seldepth = 0;
|
ctx->seldepth = 0;
|
||||||
ctx->nodesTable = {};
|
ctx->nodesTable = {};
|
||||||
if constexpr (mode != bench) {
|
if constexpr (mode != bench) {
|
||||||
|
|||||||
+24
-1
@@ -10,18 +10,41 @@ void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move b
|
|||||||
current = &bucket->depthPreferred;
|
current = &bucket->depthPreferred;
|
||||||
} else if (bucket->alwaysReplace && bucket->alwaysReplace.hashKey == hashKey) {
|
} else if (bucket->alwaysReplace && bucket->alwaysReplace.hashKey == hashKey) {
|
||||||
current = &bucket->alwaysReplace;
|
current = &bucket->alwaysReplace;
|
||||||
|
} else if (!bucket->alwaysReplace) {
|
||||||
|
current = &bucket->alwaysReplace;
|
||||||
|
} else if (!bucket->depthPreferred) {
|
||||||
|
current = &bucket->depthPreferred;
|
||||||
} else if (ttpv) {
|
} else if (ttpv) {
|
||||||
current = &bucket->depthPreferred;
|
current = &bucket->depthPreferred;
|
||||||
} else if (!bucket->depthPreferred || bucket->depthPreferred.depth <= depth) {
|
} else {
|
||||||
|
const int depthPreferredValue = GetReplacementValue(bucket->depthPreferred);
|
||||||
|
const int alwaysReplaceValue = GetReplacementValue(bucket->alwaysReplace);
|
||||||
|
|
||||||
|
if (depthPreferredValue <= alwaysReplaceValue) {
|
||||||
current = &bucket->depthPreferred;
|
current = &bucket->depthPreferred;
|
||||||
} else {
|
} else {
|
||||||
current = &bucket->alwaysReplace;
|
current = &bucket->alwaysReplace;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool samePosition = current->hashKey == hashKey;
|
||||||
|
const bool exactBound = nodeType == PV;
|
||||||
|
const bool entryFromCurrentAge = current->age == age;
|
||||||
|
const int writeDepth = depth + 4 + ttpv * 2;
|
||||||
|
|
||||||
|
if (samePosition && !exactBound && entryFromCurrentAge && writeDepth <= current->depth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
current->hashKey = hashKey;
|
current->hashKey = hashKey;
|
||||||
current->nodeType = nodeType;
|
current->nodeType = nodeType;
|
||||||
current->score = score;
|
current->score = score;
|
||||||
current->depth = depth;
|
current->depth = depth;
|
||||||
|
|
||||||
|
if (bestMove || !samePosition) {
|
||||||
current->bestMove = bestMove;
|
current->bestMove = bestMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
current->age = age;
|
||||||
current->ttpv = ttpv;
|
current->ttpv = ttpv;
|
||||||
}
|
}
|
||||||
+12
@@ -26,6 +26,7 @@ public:
|
|||||||
Move bestMove = Move();
|
Move bestMove = Move();
|
||||||
uint8_t depth = 0;
|
uint8_t depth = 0;
|
||||||
uint8_t nodeType = 0;
|
uint8_t nodeType = 0;
|
||||||
|
uint8_t age = 0;
|
||||||
bool ttpv = false;
|
bool ttpv = false;
|
||||||
|
|
||||||
TTEntry() {}
|
TTEntry() {}
|
||||||
@@ -55,6 +56,13 @@ constexpr int16_t invalidEntry = 11111;
|
|||||||
class TTable {
|
class TTable {
|
||||||
private:
|
private:
|
||||||
std::vector<TTBucket> table;
|
std::vector<TTBucket> table;
|
||||||
|
|
||||||
|
uint8_t age = 0;
|
||||||
|
|
||||||
|
int GetReplacementValue(const TTEntry& entry) const {
|
||||||
|
const int ageDelta = uint8_t(age - entry.age);
|
||||||
|
return entry.depth - ageDelta * 4 + entry.ttpv * 2;
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
TTable() : table(defaultHash) {};
|
TTable() : table(defaultHash) {};
|
||||||
|
|
||||||
@@ -72,6 +80,10 @@ public:
|
|||||||
__builtin_prefetch(&table[hashKey % table.size()]);
|
__builtin_prefetch(&table[hashKey % table.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IncreaseAge() {
|
||||||
|
age++;
|
||||||
|
}
|
||||||
|
|
||||||
TTEntry GetEntry(U64 &hashKey) {
|
TTEntry GetEntry(U64 &hashKey) {
|
||||||
TTBucket *current = &table[hashKey % table.size()];
|
TTBucket *current = &table[hashKey % table.size()];
|
||||||
if (current->depthPreferred.hashKey == hashKey) {
|
if (current->depthPreferred.hashKey == hashKey) {
|
||||||
|
|||||||
Reference in new issue
Block a user