1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Optimize TranspositionTable::store() and TranspositionTable::probe() for speed.

No functional change.

Resolves #85
This commit is contained in:
mstembera 2014-10-31 22:48:19 -07:00 committed by Joona Kiiski
parent d12378497c
commit 2fd075d1ea

View file

@ -69,14 +69,14 @@ void TranspositionTable::clear() {
const TTEntry* TranspositionTable::probe(const Key key) const { const TTEntry* TranspositionTable::probe(const Key key) const {
TTEntry* tte = first_entry(key); TTEntry* const tte = first_entry(key);
uint16_t key16 = key >> 48; const uint16_t key16 = key >> 48;
for (unsigned i = 0; i < TTClusterSize; ++i, ++tte) for (unsigned i = 0; i < TTClusterSize; ++i)
if (tte->key16 == key16) if (tte[i].key16 == key16)
{ {
tte->genBound8 = uint8_t(generation | tte->bound()); // Refresh tte[i].genBound8 = generation | (uint8_t)tte[i].bound(); // Refresh
return tte; return &tte[i];
} }
return NULL; return NULL;
@ -93,27 +93,27 @@ const TTEntry* TranspositionTable::probe(const Key key) const {
void TranspositionTable::store(const Key key, Value v, Bound b, Depth d, Move m, Value statV) { void TranspositionTable::store(const Key key, Value v, Bound b, Depth d, Move m, Value statV) {
TTEntry *tte, *replace; TTEntry* const tte = first_entry(key);
uint16_t key16 = key >> 48; // Use the high 16 bits as key inside the cluster const uint16_t key16 = key >> 48; // Use the high 16 bits as key inside the cluster
tte = replace = first_entry(key); for (unsigned i = 0; i < TTClusterSize; ++i)
for (unsigned i = 0; i < TTClusterSize; ++i, ++tte)
{ {
if (!tte->key16 || tte->key16 == key16) // Empty or overwrite old if (!tte[i].key16 || tte[i].key16 == key16) // Empty or overwrite old
{ {
if (!m) // Save preserving any existing ttMove
m = tte->move(); // Preserve any existing ttMove tte[i].save(key16, v, b, d, m ? m : tte[i].move(), generation, statV);
return;
replace = tte; }
break;
} }
// Implement replace strategy // Implement replace strategy
if ( (( tte->genBound8 & 0xFC) == generation || tte->bound() == BOUND_EXACT) TTEntry* replace = tte;
for (unsigned i = 1; i < TTClusterSize; ++i)
{
if ( (( tte[i].genBound8 & 0xFC) == generation || tte[i].bound() == BOUND_EXACT)
- ((replace->genBound8 & 0xFC) == generation) - ((replace->genBound8 & 0xFC) == generation)
- (tte->depth8 < replace->depth8) < 0) - (tte[i].depth8 < replace->depth8) < 0)
replace = tte; replace = &tte[i];
} }
replace->save(key16, v, b, d, m, generation, statV); replace->save(key16, v, b, d, m, generation, statV);