From ec42154ef2569a58dae2164e328d5bbffcb2aee9 Mon Sep 17 00:00:00 2001 From: Guy Vreuls Date: Sat, 13 Mar 2021 17:40:07 +0100 Subject: [PATCH] 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 https://github.com/official-stockfish/Stockfish/pull/3404 No functional change. --- src/bitbase.cpp | 4 ++-- src/bitboard.h | 8 ++++---- src/evaluate.cpp | 8 ++++---- src/movegen.cpp | 30 +++++++++++++++--------------- src/nnue/features/half_kp.cpp | 2 +- src/pawns.cpp | 4 ++-- src/position.cpp | 6 +++--- src/syzygy/tbprobe.cpp | 4 ++-- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/bitbase.cpp b/src/bitbase.cpp index ece9ec72..10aab6d9 100644 --- a/src/bitbase.cpp +++ b/src/bitbase.cpp @@ -150,8 +150,8 @@ namespace { Bitboard b = attacks_bb(ksq[stm]); while (b) - r |= stm == WHITE ? db[index(BLACK, ksq[BLACK] , pop_lsb(&b), psq)] - : db[index(WHITE, pop_lsb(&b), ksq[WHITE], psq)]; + r |= stm == WHITE ? db[index(BLACK, ksq[BLACK] , pop_lsb(b), psq)] + : db[index(WHITE, pop_lsb(b), ksq[WHITE], psq)]; if (stm == WHITE) { diff --git a/src/bitboard.h b/src/bitboard.h index 70835e8e..c663f4bd 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -428,10 +428,10 @@ inline Bitboard least_significant_square_bb(Bitboard b) { /// pop_lsb() finds and clears the least significant bit in a non-zero bitboard -inline Square pop_lsb(Bitboard* b) { - assert(*b); - const Square s = lsb(*b); - *b &= *b - 1; +inline Square pop_lsb(Bitboard& b) { + assert(b); + const Square s = lsb(b); + b &= b - 1; return s; } diff --git a/src/evaluate.cpp b/src/evaluate.cpp index bb4f9ef7..d4138cfa 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -397,7 +397,7 @@ namespace { attackedBy[Us][Pt] = 0; while (b1) { - Square s = pop_lsb(&b1); + Square s = pop_lsb(b1); // Find attacked squares, including x-ray attacks for bishops and rooks b = Pt == BISHOP ? attacks_bb(s, pos.pieces() ^ pos.pieces(QUEEN)) @@ -658,11 +658,11 @@ namespace { { b = (defended | weak) & (attackedBy[Us][KNIGHT] | attackedBy[Us][BISHOP]); while (b) - score += ThreatByMinor[type_of(pos.piece_on(pop_lsb(&b)))]; + score += ThreatByMinor[type_of(pos.piece_on(pop_lsb(b)))]; b = weak & attackedBy[Us][ROOK]; while (b) - score += ThreatByRook[type_of(pos.piece_on(pop_lsb(&b)))]; + score += ThreatByRook[type_of(pos.piece_on(pop_lsb(b)))]; if (weak & attackedBy[Us][KING]) score += ThreatByKing; @@ -760,7 +760,7 @@ namespace { while (b) { - Square s = pop_lsb(&b); + Square s = pop_lsb(b); assert(!(pos.pieces(Them, PAWN) & forward_file_bb(Us, s + Up))); diff --git a/src/movegen.cpp b/src/movegen.cpp index 742dbf40..8b043f42 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -102,13 +102,13 @@ namespace { while (b1) { - Square to = pop_lsb(&b1); + Square to = pop_lsb(b1); *moveList++ = make_move(to - Up, to); } while (b2) { - Square to = pop_lsb(&b2); + Square to = pop_lsb(b2); *moveList++ = make_move(to - Up - Up, to); } } @@ -127,13 +127,13 @@ namespace { Bitboard b3 = shift(pawnsOn7) & emptySquares; while (b1) - moveList = make_promotions(moveList, pop_lsb(&b1), ksq); + moveList = make_promotions(moveList, pop_lsb(b1), ksq); while (b2) - moveList = make_promotions(moveList, pop_lsb(&b2), ksq); + moveList = make_promotions(moveList, pop_lsb(b2), ksq); while (b3) - moveList = make_promotions(moveList, pop_lsb(&b3), ksq); + moveList = make_promotions(moveList, pop_lsb(b3), ksq); } // Standard and en passant captures @@ -144,13 +144,13 @@ namespace { while (b1) { - Square to = pop_lsb(&b1); + Square to = pop_lsb(b1); *moveList++ = make_move(to - UpRight, to); } while (b2) { - Square to = pop_lsb(&b2); + Square to = pop_lsb(b2); *moveList++ = make_move(to - UpLeft, to); } @@ -167,7 +167,7 @@ namespace { assert(b1); while (b1) - *moveList++ = make(pop_lsb(&b1), pos.ep_square()); + *moveList++ = make(pop_lsb(b1), pos.ep_square()); } } @@ -183,14 +183,14 @@ namespace { Bitboard bb = piecesToMove & pos.pieces(Pt); while (bb) { - Square from = pop_lsb(&bb); + Square from = pop_lsb(bb); Bitboard b = attacks_bb(from, pos.pieces()) & target; if constexpr (Checks) b &= pos.check_squares(Pt); while (b) - *moveList++ = make_move(from, pop_lsb(&b)); + *moveList++ = make_move(from, pop_lsb(b)); } return moveList; @@ -236,7 +236,7 @@ namespace { Square ksq = pos.square(Us); Bitboard b = attacks_bb(ksq) & target; while (b) - *moveList++ = make_move(ksq, pop_lsb(&b)); + *moveList++ = make_move(ksq, pop_lsb(b)); if ((Type != CAPTURES) && pos.can_castle(Us & ANY_CASTLING)) for (CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } ) @@ -286,7 +286,7 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { while (dc) { - Square from = pop_lsb(&dc); + Square from = pop_lsb(dc); PieceType pt = type_of(pos.piece_on(from)); Bitboard b = attacks_bb(pt, from, pos.pieces()) & ~pos.pieces(); @@ -295,7 +295,7 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { b &= ~attacks_bb(pos.square(~us)); while (b) - *moveList++ = make_move(from, pop_lsb(&b)); + *moveList++ = make_move(from, pop_lsb(b)); } return us == WHITE ? generate_all(pos, moveList) @@ -319,12 +319,12 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { // the king evasions in order to skip known illegal moves, which avoids any // useless legality checks later on. while (sliders) - sliderAttacks |= line_bb(ksq, pop_lsb(&sliders)) & ~pos.checkers(); + sliderAttacks |= line_bb(ksq, pop_lsb(sliders)) & ~pos.checkers(); // Generate evasions for king, capture and non capture moves Bitboard b = attacks_bb(ksq) & ~pos.pieces(us) & ~sliderAttacks; while (b) - *moveList++ = make_move(ksq, pop_lsb(&b)); + *moveList++ = make_move(ksq, pop_lsb(b)); if (more_than_one(pos.checkers())) return moveList; // Double check, only a king move can save the day diff --git a/src/nnue/features/half_kp.cpp b/src/nnue/features/half_kp.cpp index ac6317e7..3a25a91d 100644 --- a/src/nnue/features/half_kp.cpp +++ b/src/nnue/features/half_kp.cpp @@ -41,7 +41,7 @@ namespace Stockfish::Eval::NNUE::Features { Square ksq = orient(perspective, pos.square(perspective)); Bitboard bb = pos.pieces() & ~pos.pieces(KING); while (bb) { - Square s = pop_lsb(&bb); + Square s = pop_lsb(bb); active->push_back(make_index(perspective, s, pos.piece_on(s), ksq)); } } diff --git a/src/pawns.cpp b/src/pawns.cpp index 9a0610a0..81255813 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -110,7 +110,7 @@ namespace { // Loop through all pawns of the current color and score each pawn while (b) { - s = pop_lsb(&b); + s = pop_lsb(b); assert(pos.piece_on(s) == make_piece(Us, PAWN)); @@ -290,7 +290,7 @@ Score Entry::do_king_safety(const Position& pos) { if (pawns & attacks_bb(ksq)) minPawnDist = 1; else while (pawns) - minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(&pawns))); + minPawnDist = std::min(minPawnDist, distance(ksq, pop_lsb(pawns))); return shelter - make_score(0, 16 * minPawnDist); } diff --git a/src/position.cpp b/src/position.cpp index 772e4545..6c5a11b2 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -73,7 +73,7 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) { << std::setfill(' ') << std::dec << "\nCheckers: "; for (Bitboard b = pos.checkers(); b; ) - os << UCI::square(pop_lsb(&b)) << " "; + os << UCI::square(pop_lsb(b)) << " "; if ( int(Tablebases::MaxCardinality) >= popcount(pos.pieces()) && !pos.can_castle(ANY_CASTLING)) @@ -359,7 +359,7 @@ void Position::set_state(StateInfo* si) const { for (Bitboard b = pieces(); b; ) { - Square s = pop_lsb(&b); + Square s = pop_lsb(b); Piece pc = piece_on(s); si->key ^= Zobrist::psq[pc][s]; @@ -476,7 +476,7 @@ Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners while (snipers) { - Square sniperSq = pop_lsb(&snipers); + Square sniperSq = pop_lsb(snipers); Bitboard b = between_bb(s, sniperSq) & occupancy; if (b && !more_than_one(b)) diff --git a/src/syzygy/tbprobe.cpp b/src/syzygy/tbprobe.cpp index 5cfd38e5..0500dd5a 100644 --- a/src/syzygy/tbprobe.cpp +++ b/src/syzygy/tbprobe.cpp @@ -711,7 +711,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu leadPawns = b = pos.pieces(color_of(pc), PAWN); do - squares[size++] = pop_lsb(&b) ^ flipSquares; + squares[size++] = pop_lsb(b) ^ flipSquares; while (b); leadPawnsCnt = size; @@ -731,7 +731,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu // directly map them to the correct color and square. b = pos.pieces() ^ leadPawns; do { - Square s = pop_lsb(&b); + Square s = pop_lsb(b); squares[size] = s ^ flipSquares; pieces[size++] = Piece(pos.piece_on(s) ^ flipColor); } while (b); -- 2.39.2