TranspositionTable TT; // Our global transposition table
-/// TranspositionTable::set_size() sets the size of the transposition table,
+/// TranspositionTable::resize() sets the size of the transposition table,
/// measured in megabytes. Transposition table consists of a power of 2 number
/// of clusters and each cluster consists of ClusterSize number of TTEntry.
-void TranspositionTable::set_size(size_t mbSize) {
+void TranspositionTable::resize(uint64_t mbSize) {
assert(msb((mbSize << 20) / sizeof(TTEntry)) < 32);
const TTEntry* TranspositionTable::probe(const Key key) const {
- const TTEntry* tte = first_entry(key);
+ TTEntry* tte = first_entry(key);
uint32_t key32 = key >> 32;
for (unsigned i = 0; i < ClusterSize; ++i, ++tte)
- if (tte->key() == key32)
+ if (tte->key32 == key32)
+ {
+ tte->generation8 = generation; // Refresh
return tte;
+ }
return NULL;
}
void TranspositionTable::store(const Key key, Value v, Bound b, Depth d, Move m, Value statV) {
- int c1, c2, c3;
TTEntry *tte, *replace;
uint32_t key32 = key >> 32; // Use the high 32 bits as key inside the cluster
for (unsigned i = 0; i < ClusterSize; ++i, ++tte)
{
- if (!tte->key() || tte->key() == key32) // Empty or overwrite old
+ if (!tte->key32 || tte->key32 == key32) // Empty or overwrite old
{
if (!m)
m = tte->move(); // Preserve any existing ttMove
}
// Implement replace strategy
- c1 = (replace->generation() == generation ? 2 : 0);
- c2 = (tte->generation() == generation || tte->bound() == BOUND_EXACT ? -2 : 0);
- c3 = (tte->depth() < replace->depth() ? 1 : 0);
-
- if (c1 + c2 + c3 > 0)
+ if ( ( tte->generation8 == generation || tte->bound() == BOUND_EXACT)
+ - (replace->generation8 == generation)
+ - (tte->depth16 < replace->depth16) < 0)
replace = tte;
}