From 9d26dc028d1409e7f5f16793b0ad856350e94d47 Mon Sep 17 00:00:00 2001 From: rektdie Date: Mon, 15 Sep 2025 07:53:41 +0200 Subject: [PATCH] prefetching tt for speedup | bench 5829415 --- source/search.cpp | 7 +++++++ source/tt.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/source/search.cpp b/source/search.cpp index 5157394..3432b7a 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -329,6 +329,9 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear } ctx->positionHistory[copy.positionIndex] = copy.hashKey; ctx->nodes++; + + ctx->TT.PrefetchEntry(copy.hashKey); + int score = -Quiescence(copy, -beta, -alpha, ply + 1, ctx).score; if (score >= beta) { @@ -430,6 +433,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC const int reduction = 4 + improving + depth / 3; + ctx->TT.PrefetchEntry(copy.hashKey); + ctx->doingNullMove = true; int score = -PVS(copy, depth - reduction, -beta, -beta + 1, ply + 1, ctx, !cutnode).score; ctx->doingNullMove = false; @@ -508,6 +513,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC ctx->positionHistory[copy.positionIndex] = copy.hashKey; ctx->nodes++; + ctx->TT.PrefetchEntry(copy.hashKey); + int extension = 0; if (ply diff --git a/source/tt.h b/source/tt.h index 071d76c..e07e74f 100644 --- a/source/tt.h +++ b/source/tt.h @@ -61,6 +61,10 @@ public: table.resize(size); } + void PrefetchEntry(U64 &hashKey) { + __builtin_prefetch(&table[hashKey % table.size()]); + } + TTEntry GetRawEntry(U64 &hashKey) { TTEntry *current = &table[hashKey % table.size()]; return *current; -- 2.47.3