Skip to content

Commit ec42154

Browse files
gvreulssnicolet
authored andcommitted
Use reference instead of pointer for pop_lsb() signature
This patch changes the pop_lsb() signature from Square pop_lsb(Bitboard*) to Square pop_lsb(Bitboard&). This is more idomatic for C++ style signatures. Passed a non-regression STC test: LLR: 2.93 (-2.94,2.94) {-1.25,0.25} Total: 21280 W: 1928 L: 1847 D: 17505 Ptnml(0-2): 71, 1427, 7558, 1518, 66 https://tests.stockfishchess.org/tests/view/6053a1e22433018de7a38e2f We have verified that the generated binary is identical on gcc-10. Closes #3404 No functional change.
1 parent ace9632 commit ec42154

File tree

8 files changed

+33
-33
lines changed

8 files changed

+33
-33
lines changed

src/bitbase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ namespace {
150150
Bitboard b = attacks_bb<KING>(ksq[stm]);
151151

152152
while (b)
153-
r |= stm == WHITE ? db[index(BLACK, ksq[BLACK] , pop_lsb(&b), psq)]
154-
: db[index(WHITE, pop_lsb(&b), ksq[WHITE], psq)];
153+
r |= stm == WHITE ? db[index(BLACK, ksq[BLACK] , pop_lsb(b), psq)]
154+
: db[index(WHITE, pop_lsb(b), ksq[WHITE], psq)];
155155

156156
if (stm == WHITE)
157157
{

src/bitboard.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,10 @@ inline Bitboard least_significant_square_bb(Bitboard b) {
428428

429429
/// pop_lsb() finds and clears the least significant bit in a non-zero bitboard
430430

431-
inline Square pop_lsb(Bitboard* b) {
432-
assert(*b);
433-
const Square s = lsb(*b);
434-
*b &= *b - 1;
431+
inline Square pop_lsb(Bitboard& b) {
432+
assert(b);
433+
const Square s = lsb(b);
434+
b &= b - 1;
435435
return s;
436436
}
437437

src/evaluate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ namespace {
397397
attackedBy[Us][Pt] = 0;
398398

399399
while (b1) {
400-
Square s = pop_lsb(&b1);
400+
Square s = pop_lsb(b1);
401401

402402
// Find attacked squares, including x-ray attacks for bishops and rooks
403403
b = Pt == BISHOP ? attacks_bb<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN))
@@ -658,11 +658,11 @@ namespace {
658658
{
659659
b = (defended | weak) & (attackedBy[Us][KNIGHT] | attackedBy[Us][BISHOP]);
660660
while (b)
661-
score += ThreatByMinor[type_of(pos.piece_on(pop_lsb(&b)))];
661+
score += ThreatByMinor[type_of(pos.piece_on(pop_lsb(b)))];
662662

663663
b = weak & attackedBy[Us][ROOK];
664664
while (b)
665-
score += ThreatByRook[type_of(pos.piece_on(pop_lsb(&b)))];
665+
score += ThreatByRook[type_of(pos.piece_on(pop_lsb(b)))];
666666

667667
if (weak & attackedBy[Us][KING])
668668
score += ThreatByKing;
@@ -760,7 +760,7 @@ namespace {
760760

761761
while (b)
762762
{
763-
Square s = pop_lsb(&b);
763+
Square s = pop_lsb(b);
764764

765765
assert(!(pos.pieces(Them, PAWN) & forward_file_bb(Us, s + Up)));
766766

src/movegen.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ namespace {
102102

103103
while (b1)
104104
{
105-
Square to = pop_lsb(&b1);
105+
Square to = pop_lsb(b1);
106106
*moveList++ = make_move(to - Up, to);
107107
}
108108

109109
while (b2)
110110
{
111-
Square to = pop_lsb(&b2);
111+
Square to = pop_lsb(b2);
112112
*moveList++ = make_move(to - Up - Up, to);
113113
}
114114
}
@@ -127,13 +127,13 @@ namespace {
127127
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
128128

129129
while (b1)
130-
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(&b1), ksq);
130+
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(b1), ksq);
131131

132132
while (b2)
133-
moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(&b2), ksq);
133+
moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(b2), ksq);
134134

135135
while (b3)
136-
moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ksq);
136+
moveList = make_promotions<Type, Up >(moveList, pop_lsb(b3), ksq);
137137
}
138138

139139
// Standard and en passant captures
@@ -144,13 +144,13 @@ namespace {
144144

145145
while (b1)
146146
{
147-
Square to = pop_lsb(&b1);
147+
Square to = pop_lsb(b1);
148148
*moveList++ = make_move(to - UpRight, to);
149149
}
150150

151151
while (b2)
152152
{
153-
Square to = pop_lsb(&b2);
153+
Square to = pop_lsb(b2);
154154
*moveList++ = make_move(to - UpLeft, to);
155155
}
156156

@@ -167,7 +167,7 @@ namespace {
167167
assert(b1);
168168

169169
while (b1)
170-
*moveList++ = make<EN_PASSANT>(pop_lsb(&b1), pos.ep_square());
170+
*moveList++ = make<EN_PASSANT>(pop_lsb(b1), pos.ep_square());
171171
}
172172
}
173173

@@ -183,14 +183,14 @@ namespace {
183183
Bitboard bb = piecesToMove & pos.pieces(Pt);
184184

185185
while (bb) {
186-
Square from = pop_lsb(&bb);
186+
Square from = pop_lsb(bb);
187187

188188
Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
189189
if constexpr (Checks)
190190
b &= pos.check_squares(Pt);
191191

192192
while (b)
193-
*moveList++ = make_move(from, pop_lsb(&b));
193+
*moveList++ = make_move(from, pop_lsb(b));
194194
}
195195

196196
return moveList;
@@ -236,7 +236,7 @@ namespace {
236236
Square ksq = pos.square<KING>(Us);
237237
Bitboard b = attacks_bb<KING>(ksq) & target;
238238
while (b)
239-
*moveList++ = make_move(ksq, pop_lsb(&b));
239+
*moveList++ = make_move(ksq, pop_lsb(b));
240240

241241
if ((Type != CAPTURES) && pos.can_castle(Us & ANY_CASTLING))
242242
for (CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
@@ -286,7 +286,7 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
286286

287287
while (dc)
288288
{
289-
Square from = pop_lsb(&dc);
289+
Square from = pop_lsb(dc);
290290
PieceType pt = type_of(pos.piece_on(from));
291291

292292
Bitboard b = attacks_bb(pt, from, pos.pieces()) & ~pos.pieces();
@@ -295,7 +295,7 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
295295
b &= ~attacks_bb<QUEEN>(pos.square<KING>(~us));
296296

297297
while (b)
298-
*moveList++ = make_move(from, pop_lsb(&b));
298+
*moveList++ = make_move(from, pop_lsb(b));
299299
}
300300

301301
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList)
@@ -319,12 +319,12 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
319319
// the king evasions in order to skip known illegal moves, which avoids any
320320
// useless legality checks later on.
321321
while (sliders)
322-
sliderAttacks |= line_bb(ksq, pop_lsb(&sliders)) & ~pos.checkers();
322+
sliderAttacks |= line_bb(ksq, pop_lsb(sliders)) & ~pos.checkers();
323323

324324
// Generate evasions for king, capture and non capture moves
325325
Bitboard b = attacks_bb<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;
326326
while (b)
327-
*moveList++ = make_move(ksq, pop_lsb(&b));
327+
*moveList++ = make_move(ksq, pop_lsb(b));
328328

329329
if (more_than_one(pos.checkers()))
330330
return moveList; // Double check, only a king move can save the day

src/nnue/features/half_kp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace Stockfish::Eval::NNUE::Features {
4141
Square ksq = orient(perspective, pos.square<KING>(perspective));
4242
Bitboard bb = pos.pieces() & ~pos.pieces(KING);
4343
while (bb) {
44-
Square s = pop_lsb(&bb);
44+
Square s = pop_lsb(bb);
4545
active->push_back(make_index(perspective, s, pos.piece_on(s), ksq));
4646
}
4747
}

src/pawns.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ namespace {
110110

111111
// Loop through all pawns of the current color and score each pawn
112112
while (b) {
113-
s = pop_lsb(&b);
113+
s = pop_lsb(b);
114114

115115
assert(pos.piece_on(s) == make_piece(Us, PAWN));
116116

@@ -290,7 +290,7 @@ Score Entry::do_king_safety(const Position& pos) {
290290
if (pawns & attacks_bb<KING>(ksq))
291291
minPawnDist = 1;
292292
else while (pawns)
293-
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns)));
293+
minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(pawns)));
294294

295295
return shelter - make_score(0, 16 * minPawnDist);
296296
}

src/position.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) {
7373
<< std::setfill(' ') << std::dec << "\nCheckers: ";
7474

7575
for (Bitboard b = pos.checkers(); b; )
76-
os << UCI::square(pop_lsb(&b)) << " ";
76+
os << UCI::square(pop_lsb(b)) << " ";
7777

7878
if ( int(Tablebases::MaxCardinality) >= popcount(pos.pieces())
7979
&& !pos.can_castle(ANY_CASTLING))
@@ -359,7 +359,7 @@ void Position::set_state(StateInfo* si) const {
359359

360360
for (Bitboard b = pieces(); b; )
361361
{
362-
Square s = pop_lsb(&b);
362+
Square s = pop_lsb(b);
363363
Piece pc = piece_on(s);
364364
si->key ^= Zobrist::psq[pc][s];
365365

@@ -476,7 +476,7 @@ Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners
476476

477477
while (snipers)
478478
{
479-
Square sniperSq = pop_lsb(&snipers);
479+
Square sniperSq = pop_lsb(snipers);
480480
Bitboard b = between_bb(s, sniperSq) & occupancy;
481481

482482
if (b && !more_than_one(b))

src/syzygy/tbprobe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
711711

712712
leadPawns = b = pos.pieces(color_of(pc), PAWN);
713713
do
714-
squares[size++] = pop_lsb(&b) ^ flipSquares;
714+
squares[size++] = pop_lsb(b) ^ flipSquares;
715715
while (b);
716716

717717
leadPawnsCnt = size;
@@ -731,7 +731,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
731731
// directly map them to the correct color and square.
732732
b = pos.pieces() ^ leadPawns;
733733
do {
734-
Square s = pop_lsb(&b);
734+
Square s = pop_lsb(b);
735735
squares[size] = s ^ flipSquares;
736736
pieces[size++] = Piece(pos.piece_on(s) ^ flipColor);
737737
} while (b);

0 commit comments

Comments
 (0)