]> git.sesse.net Git - stockfish/commitdiff
Reduce stack usage
authorMarco Costalba <mcostalba@gmail.com>
Sun, 8 Apr 2012 07:16:37 +0000 (08:16 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 8 Apr 2012 07:46:04 +0000 (08:46 +0100)
Shrink dimensions of the biggest stack consumers arrays.
In particular movesSearched[] can be safely shrinked
without any impact on strenght or risk of crashing.
Also MAX_PLY can be reverted to 100 with almost no impact
so to limit search recursion and hence stack allocation.

A different case is for MAX_MOVES (used by Movepicker's
moves[]), because we know that do exsist some artificial
position with about 220 legal moves, so in those cases SF
will crash. Anyhow these cases are never found in games.
An open risk remains perft, especially run above handcrafted
positions.

This patch originates from a report by Daylen that found
SF crashing on his Mac OS X 10.7.3 while in deep analysys
on the following position:

8/3Q1pk1/5p2/4r3/5K2/8/8/8 w - - 0 1

No functional change.

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

index 920310da713d1fbacc11c9ad60334c49a82b5aa0..7349e96b48d9c2f93372eeabe9ad2c56bc9095cb 100644 (file)
@@ -531,7 +531,7 @@ namespace {
     assert((alpha == beta - 1) || PvNode);
     assert(depth > DEPTH_ZERO);
 
     assert((alpha == beta - 1) || PvNode);
     assert(depth > DEPTH_ZERO);
 
-    Move movesSearched[MAX_MOVES];
+    Move movesSearched[64];
     StateInfo st;
     const TTEntry *tte;
     Key posKey;
     StateInfo st;
     const TTEntry *tte;
     Key posKey;
@@ -944,7 +944,7 @@ split_point_start: // At split points actual search starts from here
       }
 
       ss->currentMove = move;
       }
 
       ss->currentMove = move;
-      if (!SpNode && !captureOrPromotion)
+      if (!SpNode && !captureOrPromotion && playedMoveCount < 64)
           movesSearched[playedMoveCount++] = move;
 
       // Step 14. Make the move
           movesSearched[playedMoveCount++] = move;
 
       // Step 14. Make the move
index 031cb0babda381b50f1643a9dfe2a945a3a12a02..ba25ef6ed07cc0735f3170b28e903e852bec8ac3 100644 (file)
@@ -79,8 +79,8 @@ const bool Is64Bit = false;
 typedef uint64_t Key;
 typedef uint64_t Bitboard;
 
 typedef uint64_t Key;
 typedef uint64_t Bitboard;
 
-const int MAX_MOVES      = 256;
-const int MAX_PLY        = 256;
+const int MAX_MOVES      = 192;
+const int MAX_PLY        = 100;
 const int MAX_PLY_PLUS_2 = MAX_PLY + 2;
 
 const Bitboard FileABB = 0x0101010101010101ULL;
 const int MAX_PLY_PLUS_2 = MAX_PLY + 2;
 
 const Bitboard FileABB = 0x0101010101010101ULL;