Skip to content

Commit 82ad9ce

Browse files
authored
Assorted trivial cleanups 3/2019 (#2030)
No functional change.
1 parent 95ba7f7 commit 82ad9ce

File tree

9 files changed

+34
-39
lines changed

9 files changed

+34
-39
lines changed

src/bitboard.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
uint8_t PopCnt16[1 << 16];
2828
uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
2929

30-
Bitboard SquareBB[SQUARE_NB];
31-
Bitboard ForwardRanksBB[COLOR_NB][RANK_NB];
3230
Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
3331
Bitboard LineBB[SQUARE_NB][SQUARE_NB];
3432
Bitboard DistanceRingBB[SQUARE_NB][8];
3533
Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
3634
Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
35+
Bitboard SquareBB[SQUARE_NB];
3736

3837
Bitboard KingFlank[FILE_NB] = {
3938
QueenSide ^ FileDBB, QueenSide, QueenSide,

src/bitboard.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ constexpr Bitboard Center = (FileDBB | FileEBB) & (Rank4BB | Rank5BB);
6868
extern uint8_t PopCnt16[1 << 16];
6969
extern uint8_t SquareDistance[SQUARE_NB][SQUARE_NB];
7070

71-
extern Bitboard SquareBB[SQUARE_NB];
7271
extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
7372
extern Bitboard LineBB[SQUARE_NB][SQUARE_NB];
7473
extern Bitboard DistanceRingBB[SQUARE_NB][8];
7574
extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
7675
extern Bitboard PawnAttacks[COLOR_NB][SQUARE_NB];
7776
extern Bitboard KingFlank[FILE_NB];
77+
extern Bitboard SquareBB[SQUARE_NB];
7878

7979

8080
/// Magic holds all magic bitboards relevant data for a single square
@@ -102,15 +102,14 @@ struct Magic {
102102
extern Magic RookMagics[SQUARE_NB];
103103
extern Magic BishopMagics[SQUARE_NB];
104104

105-
106-
/// Overloads of bitwise operators between a Bitboard and a Square for testing
107-
/// whether a given bit is set in a bitboard, and for setting and clearing bits.
108-
109105
inline Bitboard square_bb(Square s) {
110106
assert(s >= SQ_A1 && s <= SQ_H8);
111107
return SquareBB[s];
112108
}
113-
109+
110+
/// Overloads of bitwise operators between a Bitboard and a Square for testing
111+
/// whether a given bit is set in a bitboard, and for setting and clearing bits.
112+
114113
inline Bitboard operator&( Bitboard b, Square s) { return b & square_bb(s); }
115114
inline Bitboard operator|( Bitboard b, Square s) { return b | square_bb(s); }
116115
inline Bitboard operator^( Bitboard b, Square s) { return b ^ square_bb(s); }

src/endgame.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ namespace {
7676
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
7777
sq = Square(sq ^ 7); // Mirror SQ_H1 -> SQ_A1
7878

79-
if (strongSide == BLACK)
80-
sq = ~sq;
81-
82-
return sq;
79+
return strongSide == WHITE ? sq : ~sq;
8380
}
8481

8582
} // namespace
@@ -285,18 +282,18 @@ Value Endgame<KQKR>::operator()(const Position& pos) const {
285282
}
286283

287284

288-
/// KNN vs KP. Simply push the opposing king to the corner.
285+
/// KNN vs KP. Simply push the opposing king to the corner
289286
template<>
290287
Value Endgame<KNNKP>::operator()(const Position& pos) const {
291288

292-
assert(verify_material(pos, strongSide, 2 * KnightValueMg, 0));
293-
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
289+
assert(verify_material(pos, strongSide, 2 * KnightValueMg, 0));
290+
assert(verify_material(pos, weakSide, VALUE_ZERO, 1));
294291

295-
Value result = 2 * KnightValueEg
296-
- PawnValueEg
297-
+ PushToEdges[pos.square<KING>(weakSide)];
292+
Value result = 2 * KnightValueEg
293+
- PawnValueEg
294+
+ PushToEdges[pos.square<KING>(weakSide)];
298295

299-
return strongSide == pos.side_to_move() ? result : -result;
296+
return strongSide == pos.side_to_move() ? result : -result;
300297
}
301298

302299

src/material.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ Entry* probe(const Position& pos) {
149149

150150
// OK, we didn't find any special evaluation function for the current material
151151
// configuration. Is there a suitable specialized scaling function?
152-
const EndgameBase<ScaleFactor>* sf;
152+
const auto* sf = pos.this_thread()->endgames.probe<ScaleFactor>(key);
153153

154-
if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)
154+
if (sf)
155155
{
156156
e->scalingFunction[sf->strongSide] = sf; // Only strong color assigned
157157
return e;

src/misc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct HashTable {
5353
Entry* operator[](Key key) { return &table[(uint32_t)key & (Size - 1)]; }
5454

5555
private:
56-
std::vector<Entry> table = std::vector<Entry>(Size);
56+
std::vector<Entry> table = std::vector<Entry>(Size); // Allocate on the heap
5757
};
5858

5959

src/position.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ bool Position::pseudo_legal(const Move m) const {
628628
{
629629
// We have already handled promotion moves, so destination
630630
// cannot be on the 8th/1st rank.
631-
if (rank_of(to) == relative_rank(us, RANK_8))
631+
if ((Rank8BB | Rank1BB) & to)
632632
return false;
633633

634634
if ( !(attacks_from<PAWN>(from, us) & pieces(~us) & to) // Not a capture

src/position.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ inline void Position::move_piece(Piece pc, Square from, Square to) {
413413

414414
// index[from] is not updated and becomes stale. This works as long as index[]
415415
// is accessed just by known occupied squares.
416-
Bitboard fromTo = square_bb(from) ^ square_bb(to);
416+
Bitboard fromTo = square_bb(from) | square_bb(to);
417417
byTypeBB[ALL_PIECES] ^= fromTo;
418418
byTypeBB[type_of(pc)] ^= fromTo;
419419
byColorBB[color_of(pc)] ^= fromTo;

src/search.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ namespace {
8484
return d > 17 ? 0 : 29 * d * d + 138 * d - 134;
8585
}
8686

87-
// Add a small random component to draw evaluations to keep search dynamic
88-
// and to avoid 3fold-blindness.
87+
// Add a small random component to draw evaluations to avoid 3fold-blindness
8988
Value value_draw(Depth depth, Thread* thisThread) {
9089
return depth < 4 ? VALUE_DRAW
91-
: VALUE_DRAW + Value(2 * (thisThread->nodes.load(std::memory_order_relaxed) % 2) - 1);
90+
: VALUE_DRAW + Value(2 * (thisThread->nodes & 1) - 1);
9291
}
9392

9493
// Skill structure is used to implement strength limit
@@ -162,12 +161,12 @@ void Search::clear() {
162161
Time.availableNodes = 0;
163162
TT.clear();
164163
Threads.clear();
165-
Tablebases::init(Options["SyzygyPath"]); // Free up mapped files
164+
Tablebases::init(Options["SyzygyPath"]); // Free mapped files
166165
}
167166

168167

169-
/// MainThread::search() is called by the main thread when the program receives
170-
/// the UCI 'go' command. It searches from the root position and outputs the "bestmove".
168+
/// MainThread::search() is started when the program receives the UCI 'go'
169+
/// command. It searches from the root position and outputs the "bestmove".
171170

172171
void MainThread::search() {
173172

@@ -221,8 +220,9 @@ void MainThread::search() {
221220
if (Limits.npmsec)
222221
Time.availableNodes += Limits.inc[us] - Threads.nodes_searched();
223222

224-
// Check if there are threads with a better score than main thread
225223
Thread* bestThread = this;
224+
225+
// Check if there are threads with a better score than main thread
226226
if ( Options["MultiPV"] == 1
227227
&& !Limits.depth
228228
&& !Skill(Options["Skill Level"]).enabled()
@@ -273,9 +273,9 @@ void MainThread::search() {
273273

274274
void Thread::search() {
275275

276-
// To allow access to (ss-5) up to (ss+2), the stack must be oversized.
276+
// To allow access to (ss-7) up to (ss+2), the stack must be oversized.
277277
// The former is needed to allow update_continuation_histories(ss-1, ...),
278-
// which accesses its argument at ss-4, also near the root.
278+
// which accesses its argument at ss-6, also near the root.
279279
// The latter is needed for statScores and killer initialization.
280280
Stack stack[MAX_PLY+10], *ss = stack+7;
281281
Move pv[MAX_PLY+1];
@@ -317,7 +317,7 @@ void Thread::search() {
317317
: Options["Analysis Contempt"] == "Black" && us == WHITE ? -ct
318318
: ct;
319319

320-
// In evaluate.cpp the evaluation is from the white point of view
320+
// Evaluation score is from the white point of view
321321
contempt = (us == WHITE ? make_score(ct, ct / 2)
322322
: -make_score(ct, ct / 2));
323323

@@ -832,8 +832,7 @@ namespace {
832832
}
833833

834834
// Step 11. Internal iterative deepening (~2 Elo)
835-
if ( depth >= 8 * ONE_PLY
836-
&& !ttMove)
835+
if (depth >= 8 * ONE_PLY && !ttMove)
837836
{
838837
search<NT>(pos, ss, alpha, beta, depth - 7 * ONE_PLY, cutNode);
839838

@@ -847,15 +846,16 @@ namespace {
847846
const PieceToHistory* contHist[] = { (ss-1)->continuationHistory, (ss-2)->continuationHistory,
848847
nullptr, (ss-4)->continuationHistory,
849848
nullptr, (ss-6)->continuationHistory };
849+
850850
Move countermove = thisThread->counterMoves[pos.piece_on(prevSq)][prevSq];
851851

852852
MovePicker mp(pos, ttMove, depth, &thisThread->mainHistory,
853853
&thisThread->captureHistory,
854854
contHist,
855855
countermove,
856856
ss->killers);
857-
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
858857

858+
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
859859
moveCountPruning = false;
860860
ttCapture = ttMove && pos.capture_or_promotion(ttMove);
861861

@@ -946,7 +946,7 @@ namespace {
946946
&& bestValue > VALUE_MATED_IN_MAX_PLY)
947947
{
948948
// Skip quiet moves if movecount exceeds our FutilityMoveCount threshold
949-
moveCountPruning = moveCount >= futility_move_count(improving,depth / ONE_PLY);
949+
moveCountPruning = moveCount >= futility_move_count(improving, depth / ONE_PLY);
950950

951951
if ( !captureOrPromotion
952952
&& !givesCheck

src/thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ThreadPool Threads; // Global object
3131

3232

3333
/// Thread constructor launches the thread and waits until it goes to sleep
34-
/// in idle_loop(). Note that 'searching' and 'exit' should be alredy set.
34+
/// in idle_loop(). Note that 'searching' and 'exit' should be already set.
3535

3636
Thread::Thread(size_t n) : idx(n), stdThread(&Thread::idle_loop, this) {
3737

0 commit comments

Comments
 (0)