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.
Bitboard b = attacks_bb<KING>(ksq[stm]);
while (b)
Bitboard b = attacks_bb<KING>(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)];
/// pop_lsb() finds and clears the least significant bit in a non-zero bitboard
/// 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;
attackedBy[Us][Pt] = 0;
while (b1) {
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<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN))
// Find attacked squares, including x-ray attacks for bishops and rooks
b = Pt == BISHOP ? attacks_bb<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN))
{
b = (defended | weak) & (attackedBy[Us][KNIGHT] | attackedBy[Us][BISHOP]);
while (b)
{
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)
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;
if (weak & attackedBy[Us][KING])
score += ThreatByKing;
- Square s = pop_lsb(&b);
assert(!(pos.pieces(Them, PAWN) & forward_file_bb(Us, s + Up)));
assert(!(pos.pieces(Them, PAWN) & forward_file_bb(Us, s + Up)));
- Square to = pop_lsb(&b1);
+ Square to = pop_lsb(b1);
*moveList++ = make_move(to - Up, to);
}
while (b2)
{
*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);
}
}
*moveList++ = make_move(to - Up - Up, to);
}
}
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
while (b1)
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
while (b1)
- moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(&b1), ksq);
+ moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(b1), ksq);
- moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(&b2), ksq);
+ moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(b2), ksq);
- moveList = make_promotions<Type, Up >(moveList, pop_lsb(&b3), ksq);
+ moveList = make_promotions<Type, Up >(moveList, pop_lsb(b3), ksq);
}
// Standard and en passant captures
}
// Standard and en passant captures
- Square to = pop_lsb(&b1);
+ Square to = pop_lsb(b1);
*moveList++ = make_move(to - UpRight, to);
}
while (b2)
{
*moveList++ = make_move(to - UpRight, to);
}
while (b2)
{
- Square to = pop_lsb(&b2);
+ Square to = pop_lsb(b2);
*moveList++ = make_move(to - UpLeft, to);
}
*moveList++ = make_move(to - UpLeft, to);
}
- *moveList++ = make<EN_PASSANT>(pop_lsb(&b1), pos.ep_square());
+ *moveList++ = make<EN_PASSANT>(pop_lsb(b1), pos.ep_square());
Bitboard bb = piecesToMove & pos.pieces(Pt);
while (bb) {
Bitboard bb = piecesToMove & pos.pieces(Pt);
while (bb) {
- Square from = pop_lsb(&bb);
+ Square from = pop_lsb(bb);
Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
if constexpr (Checks)
b &= pos.check_squares(Pt);
while (b)
Bitboard b = attacks_bb<Pt>(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));
Square ksq = pos.square<KING>(Us);
Bitboard b = attacks_bb<KING>(ksq) & target;
while (b)
Square ksq = pos.square<KING>(Us);
Bitboard b = attacks_bb<KING>(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 } )
if ((Type != CAPTURES) && pos.can_castle(Us & ANY_CASTLING))
for (CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
- 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();
PieceType pt = type_of(pos.piece_on(from));
Bitboard b = attacks_bb(pt, from, pos.pieces()) & ~pos.pieces();
b &= ~attacks_bb<QUEEN>(pos.square<KING>(~us));
while (b)
b &= ~attacks_bb<QUEEN>(pos.square<KING>(~us));
while (b)
- *moveList++ = make_move(from, pop_lsb(&b));
+ *moveList++ = make_move(from, pop_lsb(b));
}
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList)
}
return us == WHITE ? generate_all<WHITE, QUIET_CHECKS>(pos, moveList)
// the king evasions in order to skip known illegal moves, which avoids any
// useless legality checks later on.
while (sliders)
// 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<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;
while (b)
// Generate evasions for king, capture and non capture moves
Bitboard b = attacks_bb<KING>(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
if (more_than_one(pos.checkers()))
return moveList; // Double check, only a king move can save the day
Square ksq = orient(perspective, pos.square<KING>(perspective));
Bitboard bb = pos.pieces() & ~pos.pieces(KING);
while (bb) {
Square ksq = orient(perspective, pos.square<KING>(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));
}
}
active->push_back(make_index(perspective, s, pos.piece_on(s), ksq));
}
}
// Loop through all pawns of the current color and score each pawn
while (b) {
// Loop through all pawns of the current color and score each pawn
while (b) {
assert(pos.piece_on(s) == make_piece(Us, PAWN));
assert(pos.piece_on(s) == make_piece(Us, PAWN));
if (pawns & attacks_bb<KING>(ksq))
minPawnDist = 1;
else while (pawns)
if (pawns & attacks_bb<KING>(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);
}
return shelter - make_score(0, 16 * minPawnDist);
}
<< std::setfill(' ') << std::dec << "\nCheckers: ";
for (Bitboard b = pos.checkers(); b; )
<< 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))
if ( int(Tablebases::MaxCardinality) >= popcount(pos.pieces())
&& !pos.can_castle(ANY_CASTLING))
for (Bitboard b = pieces(); b; )
{
for (Bitboard b = pieces(); b; )
{
- Square s = pop_lsb(&b);
Piece pc = piece_on(s);
si->key ^= Zobrist::psq[pc][s];
Piece pc = piece_on(s);
si->key ^= Zobrist::psq[pc][s];
- Square sniperSq = pop_lsb(&snipers);
+ Square sniperSq = pop_lsb(snipers);
Bitboard b = between_bb(s, sniperSq) & occupancy;
if (b && !more_than_one(b))
Bitboard b = between_bb(s, sniperSq) & occupancy;
if (b && !more_than_one(b))
leadPawns = b = pos.pieces(color_of(pc), PAWN);
do
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;
while (b);
leadPawnsCnt = size;
// directly map them to the correct color and square.
b = pos.pieces() ^ leadPawns;
do {
// directly map them to the correct color and square.
b = pos.pieces() ^ leadPawns;
do {
- Square s = pop_lsb(&b);
squares[size] = s ^ flipSquares;
pieces[size++] = Piece(pos.piece_on(s) ^ flipColor);
} while (b);
squares[size] = s ^ flipSquares;
pieces[size++] = Piece(pos.piece_on(s) ^ flipColor);
} while (b);