Skip to content

Commit 41641e3

Browse files
committed
Assorted tweaks from DON
Mainly renames and some little code style improvment, inspired by looking at DON sources: https://github.com/erashid/DON No functional change.
1 parent 2f5aaf7 commit 41641e3

File tree

16 files changed

+87
-88
lines changed

16 files changed

+87
-88
lines changed

src/benchmark.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void benchmark(const Position& current, istream& is) {
126126
file.close();
127127
}
128128

129-
int64_t nodes = 0;
129+
uint64_t nodes = 0;
130130
Search::StateStackPtr st;
131131
Time::point elapsed = Time::now();
132132

@@ -138,13 +138,13 @@ void benchmark(const Position& current, istream& is) {
138138

139139
if (limitType == "perft")
140140
{
141-
size_t cnt = Search::perft(pos, limits.depth * ONE_PLY);
141+
uint64_t cnt = Search::perft(pos, limits.depth * ONE_PLY);
142142
cerr << "\nPerft " << limits.depth << " leaf nodes: " << cnt << endl;
143143
nodes += cnt;
144144
}
145145
else
146146
{
147-
Threads.start_thinking(pos, limits, vector<Move>(), st);
147+
Threads.start_thinking(pos, limits, st);
148148
Threads.wait_for_think_finished();
149149
nodes += Search::RootPos.nodes_searched();
150150
}

src/bitboard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ namespace {
325325
if (attack && attack != reference[i])
326326
break;
327327

328-
assert(reference[i] != 0);
328+
assert(reference[i]);
329329

330330
attack = reference[i];
331331
}
332-
} while (i != size);
332+
} while (i < size);
333333
}
334334
}
335335
}

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main(int argc, char* argv[]) {
4040
Pawns::init();
4141
Eval::init();
4242
Threads.init();
43-
TT.set_size(Options["Hash"]);
43+
TT.resize(Options["Hash"]);
4444

4545
std::string args;
4646

src/misc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ std::ostream& operator<<(std::ostream& os, SyncCout sc) {
144144

145145
static Mutex m;
146146

147-
if (sc == io_lock)
147+
if (sc == IO_LOCK)
148148
m.lock();
149149

150-
if (sc == io_unlock)
150+
if (sc == IO_UNLOCK)
151151
m.unlock();
152152

153153
return os;

src/misc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ struct HashTable {
5959
};
6060

6161

62-
enum SyncCout { io_lock, io_unlock };
62+
enum SyncCout { IO_LOCK, IO_UNLOCK };
6363
std::ostream& operator<<(std::ostream&, SyncCout);
6464

65-
#define sync_cout std::cout << io_lock
66-
#define sync_endl std::endl << io_unlock
65+
#define sync_cout std::cout << IO_LOCK
66+
#define sync_endl std::endl << IO_UNLOCK
6767

6868
#endif // #ifndef MISC_H_INCLUDED

src/position.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ class Position {
159159
int game_ply() const;
160160
bool is_chess960() const;
161161
Thread* this_thread() const;
162-
int64_t nodes_searched() const;
163-
void set_nodes_searched(int64_t n);
162+
uint64_t nodes_searched() const;
163+
void set_nodes_searched(uint64_t n);
164164
bool is_draw() const;
165165

166166
// Position consistency check, for debugging
@@ -201,19 +201,19 @@ class Position {
201201
Square castlingRookSquare[COLOR_NB][CASTLING_SIDE_NB];
202202
Bitboard castlingPath[COLOR_NB][CASTLING_SIDE_NB];
203203
StateInfo startState;
204-
int64_t nodes;
204+
uint64_t nodes;
205205
int gamePly;
206206
Color sideToMove;
207207
Thread* thisThread;
208208
StateInfo* st;
209209
int chess960;
210210
};
211211

212-
inline int64_t Position::nodes_searched() const {
212+
inline uint64_t Position::nodes_searched() const {
213213
return nodes;
214214
}
215215

216-
inline void Position::set_nodes_searched(int64_t n) {
216+
inline void Position::set_nodes_searched(uint64_t n) {
217217
nodes = n;
218218
}
219219

src/rkiss.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ class RKISS {
4545

4646
uint64_t a, b, c, d;
4747

48-
uint64_t rotate(uint64_t x, uint64_t k) const {
48+
uint64_t rotate_L(uint64_t x, unsigned k) const {
4949
return (x << k) | (x >> (64 - k));
5050
}
5151

5252
uint64_t rand64() {
5353

54-
const uint64_t e = a - rotate(b, 7);
55-
a = b ^ rotate(c, 13);
56-
b = c + rotate(d, 37);
54+
const uint64_t e = a - rotate_L(b, 7);
55+
a = b ^ rotate_L(c, 13);
56+
b = c + rotate_L(d, 37);
5757
c = d + e;
5858
return d = e + a;
5959
}

src/search.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ void Search::init() {
154154
/// Search::perft() is our utility to verify move generation. All the leaf nodes
155155
/// up to the given depth are generated and counted and the sum returned.
156156

157-
static size_t perft(Position& pos, Depth depth) {
157+
static uint64_t perft(Position& pos, Depth depth) {
158158

159159
StateInfo st;
160-
size_t cnt = 0;
160+
uint64_t cnt = 0;
161161
CheckInfo ci(pos);
162162
const bool leaf = depth == 2 * ONE_PLY;
163163

@@ -170,7 +170,7 @@ static size_t perft(Position& pos, Depth depth) {
170170
return cnt;
171171
}
172172

173-
size_t Search::perft(Position& pos, Depth depth) {
173+
uint64_t Search::perft(Position& pos, Depth depth) {
174174
return depth > ONE_PLY ? ::perft(pos, depth) : MoveList<LEGAL>(pos).size();
175175
}
176176

src/search.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ struct LimitsType {
8181
LimitsType() { std::memset(this, 0, sizeof(LimitsType)); }
8282
bool use_time_management() const { return !(mate | movetime | depth | nodes | infinite); }
8383

84+
std::vector<Move> searchmoves;
8485
int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, nodes, movetime, mate, infinite, ponder;
8586
};
8687

@@ -89,7 +90,7 @@ struct LimitsType {
8990
/// typically in an async fashion e.g. to stop the search by the GUI.
9091

9192
struct SignalsType {
92-
bool stopOnPonderhit, firstRootMove, stop, failedLowAtRoot;
93+
bool stop, stopOnPonderhit, firstRootMove, failedLowAtRoot;
9394
};
9495

9596
typedef std::auto_ptr<std::stack<StateInfo> > StateStackPtr;
@@ -103,7 +104,7 @@ extern Time::point SearchTime, IterationTime;
103104
extern StateStackPtr SetupStates;
104105

105106
extern void init();
106-
extern size_t perft(Position& pos, Depth depth);
107+
extern uint64_t perft(Position& pos, Depth depth);
107108
extern void think();
108109

109110
} // namespace Search

src/thread.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ using namespace Search;
2929

3030
ThreadPool Threads; // Global object
3131

32+
extern void check_time();
33+
3234
namespace {
3335

3436
// start_routine() is the C function which is called when a new thread
@@ -90,9 +92,43 @@ Thread::Thread() /* : splitPoints() */ { // Value-initialization bug in MSVC
9092
}
9193

9294

95+
// Thread::cutoff_occurred() checks whether a beta cutoff has occurred in the
96+
// current active split point, or in some ancestor of the split point.
97+
98+
bool Thread::cutoff_occurred() const {
99+
100+
for (SplitPoint* sp = activeSplitPoint; sp; sp = sp->parentSplitPoint)
101+
if (sp->cutoff)
102+
return true;
103+
104+
return false;
105+
}
106+
107+
108+
// Thread::available_to() checks whether the thread is available to help the
109+
// thread 'master' at a split point. An obvious requirement is that thread must
110+
// be idle. With more than two threads, this is not sufficient: If the thread is
111+
// the master of some split point, it is only available as a slave to the slaves
112+
// which are busy searching the split point at the top of slave's split point
113+
// stack (the "helpful master concept" in YBWC terminology).
114+
115+
bool Thread::available_to(const Thread* master) const {
116+
117+
if (searching)
118+
return false;
119+
120+
// Make a local copy to be sure it doesn't become zero under our feet while
121+
// testing next condition and so leading to an out of bounds access.
122+
int size = splitPointsSize;
123+
124+
// No split points means that the thread is available as a slave for any
125+
// other thread otherwise apply the "helpful master" concept if possible.
126+
return !size || (splitPoints[size - 1].slavesMask & (1ULL << master->idx));
127+
}
128+
129+
93130
// TimerThread::idle_loop() is where the timer thread waits msec milliseconds
94131
// and then calls check_time(). If msec is 0 thread sleeps until it's woken up.
95-
extern void check_time();
96132

97133
void TimerThread::idle_loop() {
98134

@@ -144,41 +180,6 @@ void MainThread::idle_loop() {
144180
}
145181

146182

147-
// Thread::cutoff_occurred() checks whether a beta cutoff has occurred in the
148-
// current active split point, or in some ancestor of the split point.
149-
150-
bool Thread::cutoff_occurred() const {
151-
152-
for (SplitPoint* sp = activeSplitPoint; sp; sp = sp->parentSplitPoint)
153-
if (sp->cutoff)
154-
return true;
155-
156-
return false;
157-
}
158-
159-
160-
// Thread::available_to() checks whether the thread is available to help the
161-
// thread 'master' at a split point. An obvious requirement is that thread must
162-
// be idle. With more than two threads, this is not sufficient: If the thread is
163-
// the master of some split point, it is only available as a slave to the slaves
164-
// which are busy searching the split point at the top of slave's split point
165-
// stack (the "helpful master concept" in YBWC terminology).
166-
167-
bool Thread::available_to(const Thread* master) const {
168-
169-
if (searching)
170-
return false;
171-
172-
// Make a local copy to be sure it doesn't become zero under our feet while
173-
// testing next condition and so leading to an out of bounds access.
174-
int size = splitPointsSize;
175-
176-
// No split points means that the thread is available as a slave for any
177-
// other thread otherwise apply the "helpful master" concept if possible.
178-
return !size || (splitPoints[size - 1].slavesMask & (1ULL << master->idx));
179-
}
180-
181-
182183
// init() is called at startup to create and launch requested threads, that will
183184
// go immediately to sleep due to 'sleepWhileIdle' set to true. We cannot use
184185
// a c'tor because Threads is a static object and we need a fully initialized
@@ -264,8 +265,7 @@ void Thread::split(Position& pos, const Stack* ss, Value alpha, Value beta, Valu
264265
MovePicker* movePicker, int nodeType, bool cutNode) {
265266

266267
assert(pos.pos_is_ok());
267-
assert(*bestValue <= alpha && alpha < beta && beta <= VALUE_INFINITE);
268-
assert(*bestValue > -VALUE_INFINITE);
268+
assert(-VALUE_INFINITE < *bestValue && *bestValue <= alpha && alpha < beta && beta <= VALUE_INFINITE);
269269
assert(depth >= Threads.minimumSplitDepth);
270270
assert(searching);
271271
assert(splitPointsSize < MAX_SPLITPOINTS_PER_THREAD);
@@ -367,8 +367,8 @@ void ThreadPool::wait_for_think_finished() {
367367
// start_thinking() wakes up the main thread sleeping in MainThread::idle_loop()
368368
// so to start a new search, then returns immediately.
369369

370-
void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
371-
const std::vector<Move>& searchMoves, StateStackPtr& states) {
370+
void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits, StateStackPtr& states) {
371+
372372
wait_for_think_finished();
373373

374374
SearchTime = Time::now(); // As early as possible
@@ -386,8 +386,8 @@ void ThreadPool::start_thinking(const Position& pos, const LimitsType& limits,
386386
}
387387

388388
for (MoveList<LEGAL> it(pos); *it; ++it)
389-
if ( searchMoves.empty()
390-
|| std::count(searchMoves.begin(), searchMoves.end(), *it))
389+
if ( limits.searchmoves.empty()
390+
|| std::count(limits.searchmoves.begin(), limits.searchmoves.end(), *it))
391391
RootMoves.push_back(RootMove(*it));
392392

393393
main()->thinking = true;

0 commit comments

Comments
 (0)