mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-23 10:36:26 +08:00
Simplify array initializations
also retire a few std::memset calls. Passed non-regresion STC: https://tests.stockfishchess.org/tests/view/65b8e162c865510db0276901 LLR: 2.95 (-2.94,2.94) <-1.75,0.25> Total: 97504 W: 25294 L: 25140 D: 47070 Ptnml(1-2): 378, 11102, 25667, 11198, 407 closes https://github.com/official-stockfish/Stockfish/pull/5018 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
fcbb02ffde
commit
13eb023fc0
@@ -19,6 +19,7 @@
|
|||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@@ -107,9 +108,8 @@ inline int H1(Key h) { return h & 0x1fff; }
|
|||||||
inline int H2(Key h) { return (h >> 16) & 0x1fff; }
|
inline int H2(Key h) { return (h >> 16) & 0x1fff; }
|
||||||
|
|
||||||
// Cuckoo tables with Zobrist hashes of valid reversible moves, and the moves themselves
|
// Cuckoo tables with Zobrist hashes of valid reversible moves, and the moves themselves
|
||||||
Key cuckoo[8192];
|
std::array<Key, 8192> cuckoo;
|
||||||
Move cuckooMove[8192];
|
std::array<Move, 8192> cuckooMove;
|
||||||
|
|
||||||
|
|
||||||
// Initializes at startup the various arrays used to compute hash keys
|
// Initializes at startup the various arrays used to compute hash keys
|
||||||
void Position::init() {
|
void Position::init() {
|
||||||
@@ -130,8 +130,8 @@ void Position::init() {
|
|||||||
Zobrist::noPawns = rng.rand<Key>();
|
Zobrist::noPawns = rng.rand<Key>();
|
||||||
|
|
||||||
// Prepare the cuckoo tables
|
// Prepare the cuckoo tables
|
||||||
std::memset(cuckoo, 0, sizeof(cuckoo));
|
cuckoo.fill(0);
|
||||||
std::memset(cuckooMove, 0, sizeof(cuckooMove));
|
cuckooMove.fill(Move::none());
|
||||||
[[maybe_unused]] int count = 0;
|
[[maybe_unused]] int count = 0;
|
||||||
for (Piece pc : Pieces)
|
for (Piece pc : Pieces)
|
||||||
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
for (Square s1 = SQ_A1; s1 <= SQ_H8; ++s1)
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -212,21 +211,26 @@ void Search::Worker::start_searching() {
|
|||||||
// consumed, the user stops the search, or the maximum search depth is reached.
|
// consumed, the user stops the search, or the maximum search depth is reached.
|
||||||
void Search::Worker::iterative_deepening() {
|
void Search::Worker::iterative_deepening() {
|
||||||
|
|
||||||
|
SearchManager* mainThread = (thread_idx == 0 ? main_manager() : nullptr);
|
||||||
|
|
||||||
|
Move pv[MAX_PLY + 1];
|
||||||
|
|
||||||
|
Depth lastBestMoveDepth = 0;
|
||||||
|
Value lastBestScore = -VALUE_INFINITE;
|
||||||
|
auto lastBestPV = std::vector{Move::none()};
|
||||||
|
|
||||||
|
Value alpha, beta;
|
||||||
|
Value bestValue = -VALUE_INFINITE;
|
||||||
|
Color us = rootPos.side_to_move();
|
||||||
|
double timeReduction = 1, totBestMoveChanges = 0;
|
||||||
|
int delta, iterIdx = 0;
|
||||||
|
|
||||||
// Allocate stack with extra size to allow access from (ss - 7) to (ss + 2):
|
// Allocate stack with extra size to allow access from (ss - 7) to (ss + 2):
|
||||||
// (ss - 7) is needed for update_continuation_histories(ss - 1) which accesses (ss - 6),
|
// (ss - 7) is needed for update_continuation_histories(ss - 1) which accesses (ss - 6),
|
||||||
// (ss + 2) is needed for initialization of cutOffCnt and killers.
|
// (ss + 2) is needed for initialization of cutOffCnt and killers.
|
||||||
Stack stack[MAX_PLY + 10], *ss = stack + 7;
|
Stack stack[MAX_PLY + 10] = {};
|
||||||
Move pv[MAX_PLY + 1];
|
Stack* ss = stack + 7;
|
||||||
Value alpha, beta;
|
|
||||||
Value lastBestScore = -VALUE_INFINITE;
|
|
||||||
std::vector<Move> lastBestPV = {Move::none()};
|
|
||||||
Depth lastBestMoveDepth = 0;
|
|
||||||
SearchManager* mainThread = (thread_idx == 0 ? main_manager() : nullptr);
|
|
||||||
double timeReduction = 1, totBestMoveChanges = 0;
|
|
||||||
Color us = rootPos.side_to_move();
|
|
||||||
int delta, iterIdx = 0;
|
|
||||||
|
|
||||||
std::memset(ss - 7, 0, 10 * sizeof(Stack));
|
|
||||||
for (int i = 7; i > 0; --i)
|
for (int i = 7; i > 0; --i)
|
||||||
{
|
{
|
||||||
(ss - i)->continuationHistory =
|
(ss - i)->continuationHistory =
|
||||||
@@ -239,16 +243,12 @@ void Search::Worker::iterative_deepening() {
|
|||||||
|
|
||||||
ss->pv = pv;
|
ss->pv = pv;
|
||||||
|
|
||||||
Value bestValue = -VALUE_INFINITE;
|
|
||||||
|
|
||||||
if (mainThread)
|
if (mainThread)
|
||||||
{
|
{
|
||||||
if (mainThread->bestPreviousScore == VALUE_INFINITE)
|
if (mainThread->bestPreviousScore == VALUE_INFINITE)
|
||||||
for (int i = 0; i < 4; ++i)
|
mainThread->iterValue.fill(VALUE_ZERO);
|
||||||
mainThread->iterValue[i] = VALUE_ZERO;
|
|
||||||
else
|
else
|
||||||
for (int i = 0; i < 4; ++i)
|
mainThread->iterValue.fill(mainThread->bestPreviousScore);
|
||||||
mainThread->iterValue[i] = mainThread->bestPreviousScore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t multiPV = size_t(options["MultiPV"]);
|
size_t multiPV = size_t(options["MultiPV"]);
|
||||||
@@ -489,7 +489,7 @@ void Search::Worker::clear() {
|
|||||||
h->fill(-71);
|
h->fill(-71);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 1; i < MAX_MOVES; ++i)
|
for (size_t i = 1; i < reductions.size(); ++i)
|
||||||
reductions[i] = int((20.37 + std::log(size_t(options["Threads"])) / 2) * std::log(i));
|
reductions[i] = int((20.37 + std::log(size_t(options["Threads"])) / 2) * std::log(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/search.h
13
src/search.h
@@ -19,6 +19,7 @@
|
|||||||
#ifndef SEARCH_H_INCLUDED
|
#ifndef SEARCH_H_INCLUDED
|
||||||
#define SEARCH_H_INCLUDED
|
#define SEARCH_H_INCLUDED
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@@ -153,11 +154,11 @@ class SearchManager: public ISearchManager {
|
|||||||
int callsCnt;
|
int callsCnt;
|
||||||
std::atomic_bool ponder;
|
std::atomic_bool ponder;
|
||||||
|
|
||||||
double previousTimeReduction;
|
std::array<Value, 4> iterValue;
|
||||||
Value bestPreviousScore;
|
double previousTimeReduction;
|
||||||
Value bestPreviousAverageScore;
|
Value bestPreviousScore;
|
||||||
Value iterValue[4];
|
Value bestPreviousAverageScore;
|
||||||
bool stopOnPonderhit;
|
bool stopOnPonderhit;
|
||||||
|
|
||||||
size_t id;
|
size_t id;
|
||||||
};
|
};
|
||||||
@@ -233,7 +234,7 @@ class Worker {
|
|||||||
size_t thread_idx;
|
size_t thread_idx;
|
||||||
|
|
||||||
// Reductions lookup table initialized at startup
|
// Reductions lookup table initialized at startup
|
||||||
int reductions[MAX_MOVES]; // [depth or moveNumber]
|
std::array<int, MAX_MOVES> reductions; // [depth or moveNumber]
|
||||||
|
|
||||||
// The main thread has a SearchManager, the others have a NullSearchManager
|
// The main thread has a SearchManager, the others have a NullSearchManager
|
||||||
std::unique_ptr<ISearchManager> manager;
|
std::unique_ptr<ISearchManager> manager;
|
||||||
|
|||||||
Reference in New Issue
Block a user