Coding style in TT code

In particular seems more natural to return
bool and TTEntry on the same line, actually
we should pass and return them as a pair,
but due to limitations of C++ and not wanting
to use std::pair this can be an acceptable
compromise.

No functional change.

Resolves #157
This commit is contained in:
Marco Costalba
2014-12-13 09:27:39 +01:00
committed by Joona Kiiski
parent 0edb6348d2
commit 413b243809
3 changed files with 26 additions and 30 deletions

View File

@@ -458,13 +458,12 @@ namespace {
Move pv[MAX_PLY+1], quietsSearched[64];
StateInfo st;
TTEntry* tte;
bool ttHit;
SplitPoint* splitPoint;
Key posKey;
Move ttMove, move, excludedMove, bestMove;
Depth extension, newDepth, predictedDepth;
Value bestValue, value, ttValue, eval, nullValue, futilityValue;
bool inCheck, givesCheck, singularExtensionNode, improving;
bool ttHit, inCheck, givesCheck, singularExtensionNode, improving;
bool captureOrPromotion, dangerous, doFullDepthSearch;
int moveCount, quietCount;
@@ -568,7 +567,7 @@ namespace {
tte->save(posKey, value_to_tt(value, ss->ply), BOUND_EXACT,
std::min(DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY),
MOVE_NONE, VALUE_NONE, TT.get_generation());
MOVE_NONE, VALUE_NONE, TT.generation());
return value;
}
@@ -598,7 +597,7 @@ namespace {
eval = ss->staticEval =
(ss-1)->currentMove != MOVE_NULL ? evaluate(pos) : -(ss-1)->staticEval + 2 * Eval::Tempo;
tte->save(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.get_generation());
tte->save(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.generation());
}
if (ss->skipEarlyPruning)
@@ -1084,7 +1083,7 @@ moves_loop: // When in check and at SpNode search starts from here
tte->save(posKey, value_to_tt(bestValue, ss->ply),
bestValue >= beta ? BOUND_LOWER :
PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER,
depth, bestMove, ss->staticEval, TT.get_generation());
depth, bestMove, ss->staticEval, TT.generation());
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
@@ -1110,11 +1109,10 @@ moves_loop: // When in check and at SpNode search starts from here
Move pv[MAX_PLY+1];
StateInfo st;
TTEntry* tte;
bool ttHit;
Key posKey;
Move ttMove, move, bestMove;
Value bestValue, value, ttValue, futilityValue, futilityBase, oldAlpha;
bool givesCheck, evasionPrunable;
bool ttHit, givesCheck, evasionPrunable;
Depth ttDepth;
if (PvNode)
@@ -1184,7 +1182,7 @@ moves_loop: // When in check and at SpNode search starts from here
{
if (!ttHit)
tte->save(pos.key(), value_to_tt(bestValue, ss->ply), BOUND_LOWER,
DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.get_generation());
DEPTH_NONE, MOVE_NONE, ss->staticEval, TT.generation());
return bestValue;
}
@@ -1283,7 +1281,7 @@ moves_loop: // When in check and at SpNode search starts from here
else // Fail high
{
tte->save(posKey, value_to_tt(value, ss->ply), BOUND_LOWER,
ttDepth, move, ss->staticEval, TT.get_generation());
ttDepth, move, ss->staticEval, TT.generation());
return value;
}
@@ -1298,7 +1296,7 @@ moves_loop: // When in check and at SpNode search starts from here
tte->save(posKey, value_to_tt(bestValue, ss->ply),
PvNode && bestValue > oldAlpha ? BOUND_EXACT : BOUND_UPPER,
ttDepth, bestMove, ss->staticEval, TT.get_generation());
ttDepth, bestMove, ss->staticEval, TT.generation());
assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE);
@@ -1480,7 +1478,7 @@ void RootMove::insert_pv_in_tt(Position& pos) {
TTEntry* tte = TT.probe(pos.key(), ttHit);
if (!ttHit || tte->move() != pv[idx]) // Don't overwrite correct entries
tte->save(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[idx], VALUE_NONE, TT.get_generation());
tte->save(pos.key(), VALUE_NONE, BOUND_NONE, DEPTH_NONE, pv[idx], VALUE_NONE, TT.generation());
assert(MoveList<LEGAL>(pos).contains(pv[idx]));

View File

@@ -63,12 +63,12 @@ void TranspositionTable::clear() {
}
/// TranspositionTable::probe() looks up the current position in the
/// transposition table. It returns true and a pointer to the TTEntry if
/// the position is found. Otherwise, it returns false and a pointer to an empty or
/// least valuable TTEntry to be replaced later. A TTEntry t1 is considered
/// to be more valuable than a TTEntry t2 if t1 is from the current search and t2
/// is from a previous search, or if the depth of t1 is bigger than the depth of t2.
/// TranspositionTable::probe() looks up the current position in the transposition
/// table. It returns true and a pointer to the TTEntry if the position is found.
/// Otherwise, it returns false and a pointer to an empty or least valuable TTEntry
/// to be replaced later. A TTEntry t1 is considered to be more valuable than a
/// TTEntry t2 if t1 is from the current search and t2 is from a previous search,
/// or if the depth of t1 is bigger than the depth of t2.
TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
@@ -79,20 +79,18 @@ TTEntry* TranspositionTable::probe(const Key key, bool& found) const {
if (!tte[i].key16 || tte[i].key16 == key16)
{
if (tte[i].key16)
tte[i].genBound8 = uint8_t(generation | tte[i].bound()); // Refresh
tte[i].genBound8 = uint8_t(generation8 | tte[i].bound()); // Refresh
found = (bool)tte[i].key16;
return &tte[i];
return found = (bool)tte[i].key16, &tte[i];
}
// Find an entry to be replaced according to the replacement strategy
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)
if ( (( tte[i].genBound8 & 0xFC) == generation8 || tte[i].bound() == BOUND_EXACT)
- ((replace->genBound8 & 0xFC) == generation8)
- (tte[i].depth8 < replace->depth8) < 0)
replace = &tte[i];
found = false;
return replace;
return found = false, replace;
}

View File

@@ -43,10 +43,10 @@ struct TTEntry {
void save(Key k, Value v, Bound b, Depth d, Move m, Value ev, uint8_t g) {
k >>= 48;
if (m || k != key16) // preserve any existing ttMove
if (m || (k >> 48) != key16) // Preserve any existing move for the same position
move16 = (uint16_t)m;
key16 = (uint16_t)k;
key16 = (uint16_t)(k >> 48);
value16 = (int16_t)v;
evalValue = (int16_t)ev;
genBound8 = (uint8_t)(g | b);
@@ -86,8 +86,8 @@ class TranspositionTable {
public:
~TranspositionTable() { free(mem); }
void new_search() { generation += 4; } // Lower 2 bits are used by Bound
uint8_t get_generation() const { return generation; }
void new_search() { generation8 += 4; } // Lower 2 bits are used by Bound
uint8_t generation() const { return generation8; }
TTEntry* probe(const Key key, bool& found) const;
TTEntry* first_entry(const Key key) const;
void resize(size_t mbSize);
@@ -97,7 +97,7 @@ private:
size_t clusterCount;
TTCluster* table;
void* mem;
uint8_t generation; // Size must be not bigger than TTEntry::genBound8
uint8_t generation8; // Size must be not bigger than TTEntry::genBound8
};
extern TranspositionTable TT;