From e1ed67aacbe7fb4b462b9141d3137bed0a3ea70b Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Tue, 2 Jun 2009 09:35:49 +0100 Subject: [PATCH] Avoid using EmptySearchStack global This reduces contention in SMP case and also cleanups the code a bit. No functional change Signed-off-by: Marco Costalba --- src/movepick.cpp | 15 ++++++++++----- src/movepick.h | 4 +--- src/san.cpp | 4 ++-- src/search.cpp | 13 +++---------- src/search.h | 1 - 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/movepick.cpp b/src/movepick.cpp index 7b2479fc..797f5e94 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -63,13 +63,18 @@ namespace { /// search captures, promotions and some checks) and about how important good /// move ordering is at the current node. -MovePicker::MovePicker(const Position& p, bool pv, Move ttm, - const SearchStack& ss, Depth d) : pos(p) { +MovePicker::MovePicker(const Position& p, bool pv, Move ttm, Depth d, SearchStack* ss) : pos(p) { + pvNode = pv; ttMove = ttm; - mateKiller = (ss.mateKiller == ttm)? MOVE_NONE : ss.mateKiller; - killer1 = ss.killers[0]; - killer2 = ss.killers[1]; + if (ss) + { + mateKiller = (ss->mateKiller == ttm)? MOVE_NONE : ss->mateKiller; + killer1 = ss->killers[0]; + killer2 = ss->killers[1]; + } else + mateKiller = killer1 = killer2 = MOVE_NONE; + depth = d; movesPicked = 0; numOfMoves = 0; diff --git a/src/movepick.h b/src/movepick.h index 3d87b9c3..56efb321 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -37,8 +37,6 @@ struct EvalInfo; struct SearchStack; -extern SearchStack EmptySearchStack; - /// MovePicker is a class which is used to pick one legal move at a time from /// the current position. It is initialized with a Position object and a few /// moves we have reason to believe are good. The most important method is @@ -66,7 +64,7 @@ public: PH_STOP }; - MovePicker(const Position& p, bool pvnode, Move ttm, const SearchStack& ss, Depth d); + MovePicker(const Position& p, bool pvnode, Move ttm, Depth d, SearchStack* ss = NULL); Move get_next_move(); Move get_next_move(Lock& lock); int number_of_moves() const; diff --git a/src/san.cpp b/src/san.cpp index ecba7ab3..0429830c 100644 --- a/src/san.cpp +++ b/src/san.cpp @@ -143,7 +143,7 @@ Move move_from_san(const Position& pos, const string& movestr) { assert(pos.is_ok()); - MovePicker mp = MovePicker(pos, false, MOVE_NONE, EmptySearchStack, OnePly); + MovePicker mp = MovePicker(pos, false, MOVE_NONE, OnePly); // Castling moves if (movestr == "O-O-O" || movestr == "O-O-O+") @@ -367,7 +367,7 @@ namespace { if (type_of_piece(pc) == KING) return AMBIGUITY_NONE; - MovePicker mp = MovePicker(pos, false, MOVE_NONE, EmptySearchStack, OnePly); + MovePicker mp = MovePicker(pos, false, MOVE_NONE, OnePly); Move mv, moveList[8]; int n = 0; diff --git a/src/search.cpp b/src/search.cpp index ba5ad365..16c46c91 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -332,9 +332,6 @@ Lock IOLock; History H; // Should be made local? -// The empty search stack -SearchStack EmptySearchStack; - // SearchStack::init() initializes a search stack. Used at the beginning of a // new search from the root. @@ -597,10 +594,6 @@ void init_threads() { // Wait until the thread has finished launching: while (!Threads[i].running); } - - // Init also the empty search stack - EmptySearchStack.init(0); - EmptySearchStack.initKillers(); } @@ -1063,7 +1056,7 @@ namespace { // Initialize a MovePicker object for the current position, and prepare // to search all moves - MovePicker mp = MovePicker(pos, true, ttMove, ss[ply], depth); + MovePicker mp = MovePicker(pos, true, ttMove, depth, &ss[ply]); Move move, movesSearched[256]; int moveCount = 0; @@ -1324,7 +1317,7 @@ namespace { // Initialize a MovePicker object for the current position, and prepare // to search all moves: - MovePicker mp = MovePicker(pos, false, ttMove, ss[ply], depth); + MovePicker mp = MovePicker(pos, false, ttMove, depth, &ss[ply]); Move move, movesSearched[256]; int moveCount = 0; @@ -1545,7 +1538,7 @@ namespace { // Initialize a MovePicker object for the current position, and prepare // to search the moves. Because the depth is <= 0 here, only captures, // queen promotions and checks (only if depth == 0) will be generated. - MovePicker mp = MovePicker(pos, pvNode, ttMove, EmptySearchStack, depth); + MovePicker mp = MovePicker(pos, pvNode, ttMove, depth); Move move; int moveCount = 0; Bitboard dcCandidates = mp.discovered_check_candidates(); diff --git a/src/search.h b/src/search.h index da9e7ff9..62d3fe9e 100644 --- a/src/search.h +++ b/src/search.h @@ -69,7 +69,6 @@ struct SearchStack { //// Global variables //// -extern SearchStack EmptySearchStack; extern TranspositionTable TT; extern int ActiveThreads; extern Lock SMPLock; -- 2.39.2