X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fsearch.cpp;h=387c92b01acc2021b2103aaa9b78bfafff281108;hb=cb08413dc4e51ac246887613184b51b46bf11226;hp=22f9edf37b1b3509cd3856d637e0ec191c2e71a7;hpb=4bfa0c429e66879d99e896e04ef68d8799c35e13;p=stockfish diff --git a/src/search.cpp b/src/search.cpp index 22f9edf3..387c92b0 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -150,6 +150,23 @@ namespace { // Depth limit for razoring const Depth RazorDepth = 4 * OnePly; + /// Lookup tables initialized at startup + + // Reduction lookup tables and their getter functions + int8_t PVReductionMatrix[64][64]; // [depth][moveNumber] + int8_t NonPVReductionMatrix[64][64]; // [depth][moveNumber] + + inline Depth pv_reduction(Depth d, int mn) { return (Depth) PVReductionMatrix[Min(d / 2, 63)][Min(mn, 63)]; } + inline Depth nonpv_reduction(Depth d, int mn) { return (Depth) NonPVReductionMatrix[Min(d / 2, 63)][Min(mn, 63)]; } + + // Futility lookup tables and their getter functions + const Value FutilityMarginQS = Value(0x80); + int32_t FutilityMarginsMatrix[14][64]; // [depth][moveNumber] + int FutilityMoveCountArray[32]; // [depth] + + inline Value futility_margin(Depth d, int mn) { return Value(d < 7*OnePly ? FutilityMarginsMatrix[Max(d, 0)][Min(mn, 63)] : 2 * VALUE_INFINITE); } + inline int futility_move_count(Depth d) { return d < 16*OnePly ? FutilityMoveCountArray[d] : 512; } + /// Variables initialized by UCI options // Depth limit for use of dynamic threat detection @@ -195,20 +212,6 @@ namespace { bool UseLogFile; std::ofstream LogFile; - // Futility lookup tables and their getter functions - const Value FutilityMarginQS = Value(0x80); - int32_t FutilityMarginsMatrix[14][64]; // [depth][moveNumber] - - inline Value futility_margin(Depth d, int mn) { return (Value) (d < 14? FutilityMarginsMatrix[Max(d, 0)][Min(mn, 63)] : 2*VALUE_INFINITE); } - - // Reduction lookup tables and their getter functions - // Initialized at startup - int8_t PVReductionMatrix[64][64]; // [depth][moveNumber] - int8_t NonPVReductionMatrix[64][64]; // [depth][moveNumber] - - inline Depth pv_reduction(Depth d, int mn) { return (Depth) PVReductionMatrix[Min(d / 2, 63)][Min(mn, 63)]; } - inline Depth nonpv_reduction(Depth d, int mn) { return (Depth) NonPVReductionMatrix[Min(d / 2, 63)][Min(mn, 63)]; } - // MP related variables int ActiveThreads = 1; Depth MinimumSplitDepth; @@ -524,21 +527,12 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move, } -/// init_threads() is called during startup. It launches all helper threads, -/// and initializes the split point stack and the global locks and condition -/// objects. - -void init_threads() { - - volatile int i; - bool ok; +/// init_search() is called during startup. It initializes various lookup tables -#if !defined(_MSC_VER) - pthread_t pthread[1]; -#endif +void init_search() { // Init our reduction lookup tables - for (i = 1; i < 64; i++) // i == depth + for (int i = 1; i < 64; i++) // i == depth (OnePly = 1) for (int j = 1; j < 64; j++) // j == moveNumber { double pvRed = 0.5 + log(double(i)) * log(double(j)) / 6.0; @@ -548,12 +542,31 @@ void init_threads() { } // Init futility margins array - for (i = 0; i < 14; i++) // i == depth (OnePly = 2) + for (int i = 0; i < 14; i++) // i == depth (OnePly = 2) for (int j = 0; j < 64; j++) // j == moveNumber { FutilityMarginsMatrix[i][j] = (i < 2 ? 0 : 112 * bitScanReverse32(i * i / 2)) - 8 * j; // FIXME: test using log instead of BSR } + // Init futility move count array + for (int i = 0; i < 32; i++) // i == depth (OnePly = 2) + FutilityMoveCountArray[i] = 3 + (1 << (3 * i / 8)); +} + + +/// init_threads() is called during startup. It launches all helper threads, +/// and initializes the split point stack and the global locks and condition +/// objects. + +void init_threads() { + + volatile int i; + bool ok; + +#if !defined(_MSC_VER) + pthread_t pthread[1]; +#endif + for (i = 0; i < THREAD_MAX; i++) Threads[i].activeSplitPoints = 0; @@ -640,7 +653,6 @@ void SearchStack::init(int ply) { currentMove = threatMove = MOVE_NONE; reduction = Depth(0); eval = VALUE_NONE; - evalInfo = NULL; } void SearchStack::initKillers() { @@ -1367,19 +1379,13 @@ namespace { isCheck = pos.is_check(); - // Calculate depth dependant futility pruning parameters - const int FutilityMoveCountMargin = 3 + (1 << (3 * int(depth) / 8)); - // Evaluate the position statically if (!isCheck) { if (tte && (tte->type() & VALUE_TYPE_EVAL)) staticValue = value_from_tt(tte->value(), ply); else - { staticValue = evaluate(pos, ei, threadID); - ss[ply].evalInfo = &ei; - } ss[ply].eval = staticValue; futilityValue = staticValue + futility_margin(depth, 0); //FIXME: Remove me, only for split @@ -1526,14 +1532,15 @@ namespace { && move != ttMove) { // Move count based pruning - if ( moveCount >= FutilityMoveCountMargin + if ( moveCount >= futility_move_count(depth) && ok_to_prune(pos, move, ss[ply].threatMove) && bestValue > value_mated_in(PLY_MAX)) continue; // Value based pruning Depth predictedDepth = newDepth - nonpv_reduction(depth, moveCount); //FIXME: We are ignoring condition: depth >= 3*OnePly, BUG?? - futilityValueScaled = ss[ply].eval + futility_margin(predictedDepth, moveCount) + H.gain(pos.piece_on(move_from(move)), move_to(move)) + 45; + futilityValueScaled = ss[ply].eval + futility_margin(predictedDepth, moveCount) + + H.gain(pos.piece_on(move_from(move)), move_to(move)) + 45; if (futilityValueScaled < beta) { @@ -1841,8 +1848,6 @@ namespace { bool useFutilityPruning = sp->depth < 7 * OnePly //FIXME: sync with search && !isCheck; - const int FutilityMoveCountMargin = 3 + (1 << (3 * int(sp->depth) / 8)); - while ( lock_grab_bool(&(sp->lock)) && sp->bestValue < sp->beta && !thread_should_stop(threadID) @@ -1869,7 +1874,7 @@ namespace { && !captureOrPromotion) { // Move count based pruning - if ( moveCount >= FutilityMoveCountMargin + if ( moveCount >= futility_move_count(sp->depth) && ok_to_prune(pos, move, ss[sp->ply].threatMove) && sp->bestValue > value_mated_in(PLY_MAX)) continue;