mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
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.
This commit is contained in:
parent
ace9632c67
commit
ec42154ef2
8 changed files with 33 additions and 33 deletions
|
@ -150,8 +150,8 @@ namespace {
|
||||||
Bitboard b = attacks_bb<KING>(ksq[stm]);
|
Bitboard b = attacks_bb<KING>(ksq[stm]);
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
r |= stm == WHITE ? db[index(BLACK, ksq[BLACK] , pop_lsb(&b), psq)]
|
r |= stm == WHITE ? db[index(BLACK, ksq[BLACK] , pop_lsb(b), psq)]
|
||||||
: db[index(WHITE, pop_lsb(&b), ksq[WHITE], psq)];
|
: db[index(WHITE, pop_lsb(b), ksq[WHITE], psq)];
|
||||||
|
|
||||||
if (stm == WHITE)
|
if (stm == WHITE)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
/// pop_lsb() finds and clears the least significant bit in a non-zero bitboard
|
||||||
|
|
||||||
inline Square pop_lsb(Bitboard* b) {
|
inline Square pop_lsb(Bitboard& b) {
|
||||||
assert(*b);
|
assert(b);
|
||||||
const Square s = lsb(*b);
|
const Square s = lsb(b);
|
||||||
*b &= *b - 1;
|
b &= b - 1;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -397,7 +397,7 @@ namespace {
|
||||||
attackedBy[Us][Pt] = 0;
|
attackedBy[Us][Pt] = 0;
|
||||||
|
|
||||||
while (b1) {
|
while (b1) {
|
||||||
Square s = pop_lsb(&b1);
|
Square s = pop_lsb(b1);
|
||||||
|
|
||||||
// Find attacked squares, including x-ray attacks for bishops and rooks
|
// Find attacked squares, including x-ray attacks for bishops and rooks
|
||||||
b = Pt == BISHOP ? attacks_bb<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN))
|
b = Pt == BISHOP ? attacks_bb<BISHOP>(s, pos.pieces() ^ pos.pieces(QUEEN))
|
||||||
|
@ -658,11 +658,11 @@ namespace {
|
||||||
{
|
{
|
||||||
b = (defended | weak) & (attackedBy[Us][KNIGHT] | attackedBy[Us][BISHOP]);
|
b = (defended | weak) & (attackedBy[Us][KNIGHT] | attackedBy[Us][BISHOP]);
|
||||||
while (b)
|
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];
|
b = weak & attackedBy[Us][ROOK];
|
||||||
while (b)
|
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])
|
if (weak & attackedBy[Us][KING])
|
||||||
score += ThreatByKing;
|
score += ThreatByKing;
|
||||||
|
@ -760,7 +760,7 @@ namespace {
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
Square s = pop_lsb(&b);
|
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)));
|
||||||
|
|
||||||
|
|
|
@ -102,13 +102,13 @@ namespace {
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
Square to = pop_lsb(&b1);
|
Square to = pop_lsb(b1);
|
||||||
*moveList++ = make_move(to - Up, to);
|
*moveList++ = make_move(to - Up, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (b2)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,13 +127,13 @@ namespace {
|
||||||
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(&b1), ksq);
|
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(b1), ksq);
|
||||||
|
|
||||||
while (b2)
|
while (b2)
|
||||||
moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(&b2), ksq);
|
moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(b2), ksq);
|
||||||
|
|
||||||
while (b3)
|
while (b3)
|
||||||
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
|
||||||
|
@ -144,13 +144,13 @@ namespace {
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
{
|
{
|
||||||
Square to = pop_lsb(&b1);
|
Square to = pop_lsb(b1);
|
||||||
*moveList++ = make_move(to - UpRight, to);
|
*moveList++ = make_move(to - UpRight, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (b2)
|
while (b2)
|
||||||
{
|
{
|
||||||
Square to = pop_lsb(&b2);
|
Square to = pop_lsb(b2);
|
||||||
*moveList++ = make_move(to - UpLeft, to);
|
*moveList++ = make_move(to - UpLeft, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ namespace {
|
||||||
assert(b1);
|
assert(b1);
|
||||||
|
|
||||||
while (b1)
|
while (b1)
|
||||||
*moveList++ = make<EN_PASSANT>(pop_lsb(&b1), pos.ep_square());
|
*moveList++ = make<EN_PASSANT>(pop_lsb(b1), pos.ep_square());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,14 +183,14 @@ namespace {
|
||||||
Bitboard bb = piecesToMove & pos.pieces(Pt);
|
Bitboard bb = piecesToMove & pos.pieces(Pt);
|
||||||
|
|
||||||
while (bb) {
|
while (bb) {
|
||||||
Square from = pop_lsb(&bb);
|
Square from = pop_lsb(bb);
|
||||||
|
|
||||||
Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
|
Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
|
||||||
if constexpr (Checks)
|
if constexpr (Checks)
|
||||||
b &= pos.check_squares(Pt);
|
b &= pos.check_squares(Pt);
|
||||||
|
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(from, pop_lsb(&b));
|
*moveList++ = make_move(from, pop_lsb(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
return moveList;
|
return moveList;
|
||||||
|
@ -236,7 +236,7 @@ namespace {
|
||||||
Square ksq = pos.square<KING>(Us);
|
Square ksq = pos.square<KING>(Us);
|
||||||
Bitboard b = attacks_bb<KING>(ksq) & target;
|
Bitboard b = attacks_bb<KING>(ksq) & target;
|
||||||
while (b)
|
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))
|
if ((Type != CAPTURES) && pos.can_castle(Us & ANY_CASTLING))
|
||||||
for (CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
|
for (CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
|
||||||
|
@ -286,7 +286,7 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
||||||
|
|
||||||
while (dc)
|
while (dc)
|
||||||
{
|
{
|
||||||
Square from = pop_lsb(&dc);
|
Square from = pop_lsb(dc);
|
||||||
PieceType pt = type_of(pos.piece_on(from));
|
PieceType pt = type_of(pos.piece_on(from));
|
||||||
|
|
||||||
Bitboard b = attacks_bb(pt, from, pos.pieces()) & ~pos.pieces();
|
Bitboard b = attacks_bb(pt, from, pos.pieces()) & ~pos.pieces();
|
||||||
|
@ -295,7 +295,7 @@ ExtMove* generate<QUIET_CHECKS>(const Position& pos, ExtMove* moveList) {
|
||||||
b &= ~attacks_bb<QUEEN>(pos.square<KING>(~us));
|
b &= ~attacks_bb<QUEEN>(pos.square<KING>(~us));
|
||||||
|
|
||||||
while (b)
|
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)
|
||||||
|
@ -319,12 +319,12 @@ ExtMove* generate<EVASIONS>(const Position& pos, ExtMove* moveList) {
|
||||||
// the king evasions in order to skip known illegal moves, which avoids any
|
// the king evasions in order to skip known illegal moves, which avoids any
|
||||||
// useless legality checks later on.
|
// useless legality checks later on.
|
||||||
while (sliders)
|
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
|
// Generate evasions for king, capture and non capture moves
|
||||||
Bitboard b = attacks_bb<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;
|
Bitboard b = attacks_bb<KING>(ksq) & ~pos.pieces(us) & ~sliderAttacks;
|
||||||
while (b)
|
while (b)
|
||||||
*moveList++ = make_move(ksq, pop_lsb(&b));
|
*moveList++ = make_move(ksq, pop_lsb(b));
|
||||||
|
|
||||||
if (more_than_one(pos.checkers()))
|
if (more_than_one(pos.checkers()))
|
||||||
return moveList; // Double check, only a king move can save the day
|
return moveList; // Double check, only a king move can save the day
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace Stockfish::Eval::NNUE::Features {
|
||||||
Square ksq = orient(perspective, pos.square<KING>(perspective));
|
Square ksq = orient(perspective, pos.square<KING>(perspective));
|
||||||
Bitboard bb = pos.pieces() & ~pos.pieces(KING);
|
Bitboard bb = pos.pieces() & ~pos.pieces(KING);
|
||||||
while (bb) {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ namespace {
|
||||||
|
|
||||||
// Loop through all pawns of the current color and score each pawn
|
// Loop through all pawns of the current color and score each pawn
|
||||||
while (b) {
|
while (b) {
|
||||||
s = pop_lsb(&b);
|
s = pop_lsb(b);
|
||||||
|
|
||||||
assert(pos.piece_on(s) == make_piece(Us, PAWN));
|
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<KING>(ksq))
|
if (pawns & attacks_bb<KING>(ksq))
|
||||||
minPawnDist = 1;
|
minPawnDist = 1;
|
||||||
else while (pawns)
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) {
|
||||||
<< std::setfill(' ') << std::dec << "\nCheckers: ";
|
<< std::setfill(' ') << std::dec << "\nCheckers: ";
|
||||||
|
|
||||||
for (Bitboard b = pos.checkers(); b; )
|
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())
|
if ( int(Tablebases::MaxCardinality) >= popcount(pos.pieces())
|
||||||
&& !pos.can_castle(ANY_CASTLING))
|
&& !pos.can_castle(ANY_CASTLING))
|
||||||
|
@ -359,7 +359,7 @@ void Position::set_state(StateInfo* si) const {
|
||||||
|
|
||||||
for (Bitboard b = pieces(); b; )
|
for (Bitboard b = pieces(); b; )
|
||||||
{
|
{
|
||||||
Square s = pop_lsb(&b);
|
Square s = pop_lsb(b);
|
||||||
Piece pc = piece_on(s);
|
Piece pc = piece_on(s);
|
||||||
si->key ^= Zobrist::psq[pc][s];
|
si->key ^= Zobrist::psq[pc][s];
|
||||||
|
|
||||||
|
@ -476,7 +476,7 @@ Bitboard Position::slider_blockers(Bitboard sliders, Square s, Bitboard& pinners
|
||||||
|
|
||||||
while (snipers)
|
while (snipers)
|
||||||
{
|
{
|
||||||
Square sniperSq = pop_lsb(&snipers);
|
Square sniperSq = pop_lsb(snipers);
|
||||||
Bitboard b = between_bb(s, sniperSq) & occupancy;
|
Bitboard b = between_bb(s, sniperSq) & occupancy;
|
||||||
|
|
||||||
if (b && !more_than_one(b))
|
if (b && !more_than_one(b))
|
||||||
|
|
|
@ -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);
|
leadPawns = b = pos.pieces(color_of(pc), PAWN);
|
||||||
do
|
do
|
||||||
squares[size++] = pop_lsb(&b) ^ flipSquares;
|
squares[size++] = pop_lsb(b) ^ flipSquares;
|
||||||
while (b);
|
while (b);
|
||||||
|
|
||||||
leadPawnsCnt = size;
|
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.
|
// directly map them to the correct color and square.
|
||||||
b = pos.pieces() ^ leadPawns;
|
b = pos.pieces() ^ leadPawns;
|
||||||
do {
|
do {
|
||||||
Square s = pop_lsb(&b);
|
Square s = pop_lsb(b);
|
||||||
squares[size] = s ^ flipSquares;
|
squares[size] = s ^ flipSquares;
|
||||||
pieces[size++] = Piece(pos.piece_on(s) ^ flipColor);
|
pieces[size++] = Piece(pos.piece_on(s) ^ flipColor);
|
||||||
} while (b);
|
} while (b);
|
||||||
|
|
Loading…
Add table
Reference in a new issue