Skip to content

Commit

Permalink
🦈 IMP: Prefetching Transposition Table Entries
Browse files Browse the repository at this point in the history
--- STC ---
ELO   | 12.71 +- 7.53 (95%)
SPRT  | 10.0+0.10s Threads=1 Hash=16MB
LLR   | 2.97 (-2.94, 2.94) [0.00, 5.00]
GAMES | N: 4760 W: 1474 L: 1300 D: 1986

--- LTC ---
ELO   | 14.66 +- 7.98 (95%)
SPRT  | 60.0+0.60s Threads=1 Hash=256MB
LLR   | 3.00 (-2.94, 2.94) [0.00, 5.00]
GAMES | N: 3888 W: 1121 L: 957 D: 1810

Bench: 8291587
  • Loading branch information
TheBlackPlague authored May 31, 2023
1 parent 338e909 commit df04152
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/Backend/TranspositionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <algorithm>
#include <execution>

#include <xmmintrin.h>

#include "Type/Zobrist.h"

#include "../External/fastrange.h"
Expand Down Expand Up @@ -53,6 +55,11 @@ namespace StockDory
return Internal[fastrange64(hash, Count)];
}

inline void Prefetch(const ZobristHash hash) const
{
_mm_prefetch(reinterpret_cast<const char*>(&Internal[fastrange64(hash, Count)]), _MM_HINT_T0);
}

[[nodiscard]]
inline uint64_t Size() const
{
Expand Down
13 changes: 7 additions & 6 deletions src/Engine/Search.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,12 @@ namespace StockDory
if (seeEvaluation > beta) return seeEvaluation;
//endregion

constexpr MoveType MT = NNUE | ZOBRIST;

PreviousState state = Board.Move<MT>(move.From(), move.To(), move.Promotion());
Nodes++;
const PreviousState state = EngineMove<false>(move);

int32_t evaluation =
-Q<OColor, Pv>(ply + 1, depth - 1, -beta, -alpha);

Board.UndoMove<MT>(state, move.From(), move.To());
EngineUndoMove<false>(state, move);

//region Handle Evaluation
if (evaluation <= bestEvaluation) continue;
Expand Down Expand Up @@ -525,7 +522,11 @@ namespace StockDory
const PreviousState state = Board.Move<MT>(move.From(), move.To(), move.Promotion());
Nodes++;

if (UpdateHistory) Repetition.Push(Board.Zobrist());
const ZobristHash hash = Board.Zobrist();

TTable.Prefetch(hash);

if (UpdateHistory) Repetition.Push(hash);

return state;
}
Expand Down

0 comments on commit df04152

Please sign in to comment.