Skip to content

Commit c65d67f

Browse files
committed
Revert "Use a per-thread array"
This reverts commit 800410e and instead increases stack size. I went through the old emails with Daylen that reported the crash issue on Mac OS X and was fixed by 0049d3f. It was reported default stack size for a thread in Mac OS X is 8 megabytes while the patch that we are reverting allows to reduce stack size at max of about 217KB, so the reason for the crash was only marginal in MAX_MOVES value. On those emails Daylen also hinted how to increase stack size for Mac OS X to 16MB. So prefer to increase stack size to 16MB instad of re-inventing the wheel and do our home grown stack as we did with the patch that we are now reverting (it will remain anyhow in git history for documentation purposes). No functional change.
1 parent bc6faf6 commit c65d67f

File tree

5 files changed

+7
-15
lines changed

5 files changed

+7
-15
lines changed

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ ifneq ($(comp),mingw)
273273
endif
274274

275275
ifeq ($(os),osx)
276-
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.0
276+
LDFLAGS += -arch $(arch) -mmacosx-version-min=10.0 -stack_size,0x4000
277277
endif
278278

279279
### 3.4 Debugging

src/movepick.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
7575

7676
assert(d > DEPTH_ZERO);
7777

78-
cur = end = moves = pos.this_thread()->get_moves_array();
78+
cur = end = moves;
7979
endBadCaptures = moves + MAX_MOVES - 1;
8080
countermoves = cm;
8181
ss = s;
@@ -91,11 +91,10 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
9191
}
9292

9393
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
94-
Square sq) : pos(p), history(h) {
94+
Square sq) : pos(p), history(h), cur(moves), end(moves) {
9595

9696
assert(d <= DEPTH_ZERO);
9797

98-
cur = end = moves = pos.this_thread()->get_moves_array();
9998
if (p.checkers())
10099
stage = EVASION;
101100

@@ -124,11 +123,10 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
124123
}
125124

126125
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, PieceType pt)
127-
: pos(p), history(h) {
126+
: pos(p), history(h), cur(moves), end(moves) {
128127

129128
assert(!pos.checkers());
130129

131-
cur = end = moves = pos.this_thread()->get_moves_array();
132130
stage = PROBCUT;
133131

134132
// In ProbCut we generate only captures better than parent's captured piece
@@ -141,7 +139,6 @@ MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, Piece
141139
end += (ttMove != MOVE_NONE);
142140
}
143141

144-
MovePicker::~MovePicker() { pos.this_thread()->free_moves_array(); }
145142

146143
/// score() assign a numerical move ordering score to each move in a move list.
147144
/// The moves with highest scores will be picked first.

src/movepick.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class MovePicker {
8787
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
8888
MovePicker(const Position&, Move, const HistoryStats&, PieceType);
8989
MovePicker(const Position&, Move, Depth, const HistoryStats&, Move*, Search::Stack*);
90-
~MovePicker();
9190

9291
template<bool SpNode> Move next_move();
9392

@@ -104,7 +103,8 @@ class MovePicker {
104103
ExtMove killers[4];
105104
Square recaptureSquare;
106105
int captureThreshold, stage;
107-
ExtMove *moves, *cur, *end, *endQuiets, *endBadCaptures;
106+
ExtMove *cur, *end, *endQuiets, *endBadCaptures;
107+
ExtMove moves[MAX_MOVES];
108108
};
109109

110110
#endif // #ifndef MOVEPICK_H_INCLUDED

src/thread.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@ void ThreadBase::wait_for(volatile const bool& b) {
8383
Thread::Thread() /* : splitPoints() */ { // Value-initialization bug in MSVC
8484

8585
searching = false;
86-
maxPly = splitPointsSize = curPage = 0;
86+
maxPly = splitPointsSize = 0;
8787
activeSplitPoint = NULL;
8888
activePosition = NULL;
8989
idx = Threads.size();
90-
movePages.resize(MAX_PLY_PLUS_6 * MAX_MOVES);
9190
}
9291

9392

src/thread.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ struct Thread : public ThreadBase {
115115
virtual void idle_loop();
116116
bool cutoff_occurred() const;
117117
bool is_available_to(const Thread* master) const;
118-
ExtMove* get_moves_array() { return &movePages[curPage += MAX_MOVES]; }
119-
void free_moves_array() { curPage -= MAX_MOVES; }
120118

121119
template <bool Fake>
122120
void split(Position& pos, const Search::Stack* ss, Value alpha, Value beta, Value* bestValue, Move* bestMove,
@@ -127,8 +125,6 @@ struct Thread : public ThreadBase {
127125
Endgames endgames;
128126
Pawns::Table pawnsTable;
129127
Position* activePosition;
130-
std::vector<ExtMove> movePages;
131-
int curPage;
132128
size_t idx;
133129
int maxPly;
134130
SplitPoint* volatile activeSplitPoint;

0 commit comments

Comments
 (0)