Skip to content

Commit

Permalink
Avoid unnecessarily initializing TTData with 0's with some fixes. (Re…
Browse files Browse the repository at this point in the history
…based)

No functional change
bench: 1379150
  • Loading branch information
mstembera committed Jan 12, 2025
1 parent c085670 commit b3678cd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ Value Search::Worker::search(
// If we have a good enough capture (or queen promotion) and a reduced search
// returns a value much above beta, we can (almost) safely prune the previous move.
probCutBeta = beta + 174 - 56 * improving;
if (depth > 3
if (depth > 3 //&& ttHit //1 changes bench to 1180821
&& !is_decisive(beta)
// If value from transposition table is lower than probCutBeta, don't attempt
// probCut there and in further interactions with transposition table cutoff
Expand Down Expand Up @@ -910,7 +910,7 @@ Value Search::Worker::search(

// Step 12. A small Probcut idea (~4 Elo)
probCutBeta = beta + 412;
if ((ttData.bound & BOUND_LOWER) && ttData.depth >= depth - 4 && ttData.value >= probCutBeta
if (ttHit && (ttData.bound & BOUND_LOWER) && ttData.depth >= depth - 4 && ttData.value >= probCutBeta //2 ok
&& !is_decisive(beta) && is_valid(ttData.value) && !is_decisive(ttData.value))
return probCutBeta;

Expand Down Expand Up @@ -1143,7 +1143,8 @@ Value Search::Worker::search(

// Decrease reduction if position is or has been on the PV (~7 Elo)
if (ss->ttPv)
r -= 1037 + (ttData.value > alpha) * 965 + (ttData.depth >= depth) * 960;
r -= 1037 + (/*ttHit &&*/ ttData.value > alpha) * 965 //3a changes bench to 1327627
+ (ttHit && ttData.depth >= depth) * 960; //3b ok

// Decrease reduction for PvNodes (~0 Elo on STC, ~2 Elo on LTC)
if (PvNode)
Expand All @@ -1157,7 +1158,7 @@ Value Search::Worker::search(

// Increase reduction for cut nodes (~4 Elo)
if (cutNode)
r += 2355 - (ttData.depth >= depth && ss->ttPv) * 1141;
r += 2355 - (ttHit && ttData.depth >= depth && ss->ttPv) * 1141; //4 ok

// Increase reduction if ttMove is a capture but the current move is not a capture (~3 Elo)
if (ttCapture && !capture)
Expand All @@ -1168,7 +1169,7 @@ Value Search::Worker::search(
r += 940 + allNode * 887;

// For first picked move (ttMove) reduce reduction (~3 Elo)
else if (move == ttData.move)
else if (ttHit && move == ttData.move) //5 ok
r -= 1960;

if (capture)
Expand Down Expand Up @@ -1220,7 +1221,7 @@ Value Search::Worker::search(
else if (!PvNode || moveCount > 1)
{
// Increase reduction if ttMove is not present (~6 Elo)
if (!ttData.move)
if (/*ttHit && */ !ttData.move) //6 changes bench to 1425435
r += 2111;

// Note that if expected reduction is high, we reduce search depth by 1 here (~9 Elo)
Expand Down Expand Up @@ -1516,7 +1517,7 @@ Value Search::Worker::qsearch(Position& pos, Stack* ss, Value alpha, Value beta)
pvHit = ttHit && ttData.is_pv;

// At non-PV nodes we check for an early TT cutoff
if (!PvNode && ttData.depth >= DEPTH_QS
if (!PvNode && ttHit && ttData.depth >= DEPTH_QS //7 ok
&& is_valid(ttData.value) // Can happen when !ttHit or when access race in probe()
&& (ttData.bound & (ttData.value >= beta ? BOUND_LOWER : BOUND_UPPER)))
return ttData.value;
Expand Down
10 changes: 10 additions & 0 deletions src/tt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,17 @@ std::tuple<bool, TTData, TTWriter> TranspositionTable::probe(const Key key) cons
> tte[i].depth8 - tte[i].relative_age(generation8) * 2)
replace = &tte[i];

#if !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
return {false, TTData(), TTWriter(replace)};
//return {false,
//TTData{Move::none(), VALUE_NONE, VALUE_NONE, DEPTH_ENTRY_OFFSET, BOUND_NONE, false},
//TTWriter(replace)};
#if !defined(__clang__)
#pragma GCC diagnostic pop
#endif
}


Expand Down
5 changes: 5 additions & 0 deletions src/tt.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ struct TTData {
Depth depth;
Bound bound;
bool is_pv;

//TTData() = delete;
TTData() {}; // Prevent the default constructor from initializing to 0
TTData(Move m, Value v, Value ev, Depth d, Bound b, bool pv) :
move(m), value(v), eval(ev), depth(d), bound(b), is_pv(pv) {};
};


Expand Down

0 comments on commit b3678cd

Please sign in to comment.