]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Use fast_copy() instead of full copy in sp_search
[stockfish] / src / search.cpp
index 5d2e5175b052bdc35fc5019bdf45dfa39bbd9860..2244a2f7da805599ea07d260134c52e2ee3e6b16 100644 (file)
@@ -442,6 +442,10 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
   {
       ActiveThreads = newActiveThreads;
       init_eval(ActiveThreads);
+      // HACK: init_eval() destroys the static castleRightsMask[] array in the
+      // Position class. The below line repairs the damage.
+      Position p(pos.to_fen());
+      assert(pos.is_ok());
   }
 
   // Wake up sleeping threads
@@ -1809,7 +1813,8 @@ namespace {
     assert(threadID >= 0 && threadID < ActiveThreads);
     assert(ActiveThreads > 1);
 
-    Position pos = Position(sp->pos);
+    Position pos;
+    pos.fast_copy(sp->pos);
     CheckInfo ci(pos);
     SearchStack* ss = sp->sstack[threadID];
     Value value = -VALUE_INFINITE;
@@ -1951,7 +1956,8 @@ namespace {
     assert(threadID >= 0 && threadID < ActiveThreads);
     assert(ActiveThreads > 1);
 
-    Position pos = Position(sp->pos);
+    Position pos;
+    pos.fast_copy(sp->pos);
     CheckInfo ci(pos);
     SearchStack* ss = sp->sstack[threadID];
     Value value = -VALUE_INFINITE;
@@ -2977,20 +2983,23 @@ namespace {
     splitPoint->mp = mp;
     splitPoint->moves = *moves;
     splitPoint->cpus = 1;
-    splitPoint->pos.copy(p);
+    splitPoint->pos.fast_copy(p);
     splitPoint->parentSstack = sstck;
     for (i = 0; i < ActiveThreads; i++)
         splitPoint->slaves[i] = 0;
 
-    // Copy the current search stack to the master thread
-    memcpy(splitPoint->sstack[master], sstck, (ply+1) * sizeof(SearchStack));
+    // Detach splitPoint Position from the master one
+    splitPoint->pos.detach();
+
+    // Copy the tail of current search stack to the master thread
+    memcpy(splitPoint->sstack[master] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
     Threads[master].splitPoint = splitPoint;
 
     // Make copies of the current position and search stack for each thread
     for (i = 0; i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint; i++)
         if (thread_is_available(i, master))
         {
-            memcpy(splitPoint->sstack[i], sstck, (ply+1) * sizeof(SearchStack));
+            memcpy(splitPoint->sstack[i] + ply - 1, sstck + ply - 1, 3 * sizeof(SearchStack));
             Threads[i].splitPoint = splitPoint;
             splitPoint->slaves[i] = 1;
             splitPoint->cpus++;