X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Ftt.cpp;h=9dbfcb5ac92e5fada772fd8c20a74a4a41921c63;hp=09a74d2d5936273b1a97d25358dd7c45ae63e5f4;hb=55bd27b8f08a151128d7065fa2819aa3e9605299;hpb=b76c04c0975326d3274d7d7fb6df4edef7a040b5 diff --git a/src/tt.cpp b/src/tt.cpp index 09a74d2d..9dbfcb5a 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -20,6 +20,7 @@ #include #include +#include "bitboard.h" #include "tt.h" TranspositionTable TT; // Our global transposition table @@ -37,18 +38,13 @@ TranspositionTable::~TranspositionTable() { /// TranspositionTable::set_size() sets the size of the transposition table, -/// measured in megabytes. +/// measured in megabytes. Transposition table consists of a power of 2 number of +/// TTCluster and each cluster consists of ClusterSize number of TTEntries. Each +/// non-empty entry contains information of exactly one position. void TranspositionTable::set_size(size_t mbSize) { - size_t newSize = 1024; - - // Transposition table consists of clusters and each cluster consists - // of ClusterSize number of TTEntries. Each non-empty entry contains - // information of exactly one position and newSize is the number of - // clusters we are going to allocate. - while (2ULL * newSize * sizeof(TTCluster) <= (mbSize << 20)) - newSize *= 2; + size_t newSize = 1ULL << msb((mbSize << 20) / sizeof(TTCluster)); if (newSize == size) return; @@ -56,13 +52,15 @@ void TranspositionTable::set_size(size_t mbSize) { size = newSize; delete [] entries; entries = new (std::nothrow) TTCluster[size]; + if (!entries) { std::cerr << "Failed to allocate " << mbSize << "MB for transposition table." << std::endl; exit(EXIT_FAILURE); } - clear(); + + clear(); // Operator new is not guaranteed to initialize memory to zero }