From 3aad0d90ee7e5ae7936bf247c470091ae1e20d4f Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 11 Apr 2025 23:41:26 +0200 Subject: [PATCH] removed hashSize global | bench 1857933 --- source/tt.cpp | 4 ++-- source/tt.h | 9 ++++----- source/uci.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/source/tt.cpp b/source/tt.cpp index 3df1649..85d83c6 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -1,7 +1,7 @@ #include "tt.h" SEARCH::SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { - TTEntry *current = &table[hashKey % hashSize]; + TTEntry *current = &table[hashKey % table.size()]; if (current->hashKey == hashKey) { if (current->depth >= depth) { @@ -20,7 +20,7 @@ SEARCH::SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int } void TTable::WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move bestMove) { - TTEntry *current = &table[hashKey % hashSize]; + TTEntry *current = &table[hashKey % table.size()]; current->hashKey = hashKey; current->nodeType = nodeType; diff --git a/source/tt.h b/source/tt.h index 7b9897e..2e8e468 100644 --- a/source/tt.h +++ b/source/tt.h @@ -21,27 +21,26 @@ constexpr U64 maxHash = (64* 1000000) / sizeof(TTEntry); // 5 MB constexpr U64 defaultHash = (5 * 1000000) / sizeof(TTEntry); -inline U64 hashSize = defaultHash; - constexpr int invalidEntry = 111111; class TTable { private: std::vector table; public: - TTable() : table(hashSize) {}; + TTable() : table(defaultHash) {}; void Resize(U64 size) { table.resize(size); } void Clear() { + U64 size = table.size(); table.clear(); - table.resize(hashSize); + table.resize(size); } TTEntry* GetRawEntry(U64 &hashKey) { - TTEntry *current = &table[hashKey % hashSize]; + TTEntry *current = &table[hashKey % table.size()]; return current; } diff --git a/source/uci.cpp b/source/uci.cpp index 8943d0f..ba89003 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -94,7 +94,7 @@ static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext& c static void SetOption(std::string &command, SEARCH::SearchContext& ctx) { if (command.find("Hash") != std::string::npos) { - hashSize = (ReadParam("value", command) * 1000000) / sizeof(TTEntry); + U64 hashSize = (ReadParam("value", command) * 1000000) / sizeof(TTEntry); ctx.TT->Resize(hashSize); } }