]> git.sesse.net Git - stockfish/commitdiff
Avoid using EmptySearchStack global
authorMarco Costalba <mcostalba@gmail.com>
Tue, 2 Jun 2009 08:35:49 +0000 (09:35 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 2 Jun 2009 08:35:49 +0000 (09:35 +0100)
This reduces contention in SMP case and also
cleanups the code a bit.

No functional change

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/movepick.cpp
src/movepick.h
src/san.cpp
src/search.cpp
src/search.h

index 7b2479fca6135574ec5aa0c645afb34532849d2b..797f5e9497ab14e6d142a0bad75b560914f6018a 100644 (file)
@@ -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;
index 3d87b9c3b5c7998121366efb615f58525247d5f5..56efb321aedf238a7d8b1ae52ca1e1e26f037f58 100644 (file)
@@ -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;
index ecba7ab31a20b5a7bd77fec2419fc02b7d304820..0429830c37c7baa6fca2429511fda84749fbf5a7 100644 (file)
@@ -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;
index ba5ad365af2f1caffb95fa56caa9004ec1520dc5..16c46c9104fed8f75e10835959fd866a216c5cf7 100644 (file)
@@ -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();
index da9e7ff9bee47fea95a76208d9ecd8544703b294..62d3fe9ed9f4055eadd1800679bee69f9f25b274 100644 (file)
@@ -69,7 +69,6 @@ struct SearchStack {
 //// Global variables
 ////
 
-extern SearchStack EmptySearchStack;
 extern TranspositionTable TT;
 extern int ActiveThreads;
 extern Lock SMPLock;