From: mstembera Date: Wed, 15 May 2019 08:41:58 +0000 (-0700) Subject: Remove per thread instances of Endgames. (#2056) X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=4a7b8180ecaef7d164fa53a1d545372df1173596 Remove per thread instances of Endgames. (#2056) Similar to PSQT we only need one instance of the Endgames resource. The current per thread copies are identical and read only(after initialization) so from a design point of view it doesn't make sense to have them. Tested for no slowdown. http://tests.stockfishchess.org/tests/view/5c94377a0ebc5925cfff43ca LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 17320 W: 3487 L: 3359 D: 10474 No functional change. --- diff --git a/src/endgame.cpp b/src/endgame.cpp index 5958e633..7c4efa3c 100644 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@ -82,6 +82,33 @@ namespace { } // namespace +namespace Endgames { + + std::pair, Map> maps; + + void init() { + + add("KPK"); + add("KNNK"); + add("KBNK"); + add("KRKP"); + add("KRKB"); + add("KRKN"); + add("KQKP"); + add("KQKR"); + add("KNNKP"); + + add("KNPK"); + add("KNPKB"); + add("KRPKR"); + add("KRPKB"); + add("KBPKB"); + add("KBPKN"); + add("KBPPKB"); + add("KRPPKRP"); + } +} + /// Mate with KX vs K. This function is used to evaluate positions with /// king and plenty of material vs a lone king. It simply gives the /// attacking side a bonus for driving the defending king towards the edge diff --git a/src/endgame.h b/src/endgame.h index 2a48488f..81afb2e5 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -95,10 +95,12 @@ struct Endgame : public EndgameBase { /// base objects in two std::map. We use polymorphism to invoke the actual /// endgame function by calling its virtual operator(). -class Endgames { +namespace Endgames { template using Ptr = std::unique_ptr>; template using Map = std::map>; + + extern std::pair, Map> maps; template Map& map() { @@ -113,35 +115,12 @@ class Endgames { map()[Position().set(code, BLACK, &st).material_key()] = Ptr(new Endgame(BLACK)); } - std::pair, Map> maps; - -public: - Endgames() { - - add("KPK"); - add("KNNK"); - add("KBNK"); - add("KRKP"); - add("KRKB"); - add("KRKN"); - add("KQKP"); - add("KQKR"); - add("KNNKP"); - - add("KNPK"); - add("KNPKB"); - add("KRPKR"); - add("KRPKB"); - add("KBPKB"); - add("KBPKN"); - add("KBPPKB"); - add("KRPPKRP"); - } - template const EndgameBase* probe(Key key) { return map().count(key) ? map()[key].get() : nullptr; } -}; + + void init(); +} #endif // #ifndef ENDGAME_H_INCLUDED diff --git a/src/main.cpp b/src/main.cpp index fc78b38c..57656f62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,7 @@ #include "thread.h" #include "tt.h" #include "uci.h" +#include "endgame.h" #include "syzygy/tbprobe.h" namespace PSQT { @@ -42,6 +43,7 @@ int main(int argc, char* argv[]) { Position::init(); Bitbases::init(); Search::init(); + Endgames::init(); Threads.set(Options["Threads"]); Search::clear(); // After threads are up diff --git a/src/material.cpp b/src/material.cpp index ee5d4bce..3a05f3fa 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -137,7 +137,7 @@ Entry* probe(const Position& pos) { // Let's look if we have a specialized evaluation function for this particular // material configuration. Firstly we look for a fixed configuration one, then // for a generic one if the previous search failed. - if ((e->evaluationFunction = pos.this_thread()->endgames.probe(key)) != nullptr) + if ((e->evaluationFunction = Endgames::probe(key)) != nullptr) return e; for (Color c = WHITE; c <= BLACK; ++c) @@ -149,7 +149,7 @@ Entry* probe(const Position& pos) { // OK, we didn't find any special evaluation function for the current material // configuration. Is there a suitable specialized scaling function? - const auto* sf = pos.this_thread()->endgames.probe(key); + const auto* sf = Endgames::probe(key); if (sf) { diff --git a/src/thread.h b/src/thread.h index fb11344c..0866d55d 100644 --- a/src/thread.h +++ b/src/thread.h @@ -59,7 +59,6 @@ public: Pawns::Table pawnsTable; Material::Table materialTable; - Endgames endgames; size_t pvIdx, pvLast; int selDepth, nmpMinPly; Color nmpColor;