mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Micro optimization of generate_piece_moves()
This patch make the piece list always terminated by SQ_NONE, so that we can use a simpler and faster loop in move generation. Speedup is about 0.6%. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
dcb323bf0d
commit
48b74142ef
3 changed files with 12 additions and 4 deletions
|
@ -476,10 +476,10 @@ namespace {
|
||||||
|
|
||||||
Square from;
|
Square from;
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
|
const Square* ptr = pos.piece_list_begin(us, Piece);
|
||||||
|
|
||||||
for (int i = 0, e = pos.piece_count(us, Piece); i < e; i++)
|
while ((from = *ptr++) != SQ_NONE)
|
||||||
{
|
{
|
||||||
from = pos.piece_list(us, Piece, i);
|
|
||||||
b = pos.attacks_from<Piece>(from) & target;
|
b = pos.attacks_from<Piece>(from) & target;
|
||||||
SERIALIZE_MOVES(b);
|
SERIALIZE_MOVES(b);
|
||||||
}
|
}
|
||||||
|
@ -502,10 +502,10 @@ namespace {
|
||||||
Color us, Bitboard target, Bitboard pinned) {
|
Color us, Bitboard target, Bitboard pinned) {
|
||||||
Square from;
|
Square from;
|
||||||
Bitboard b;
|
Bitboard b;
|
||||||
|
const Square* ptr = pos.piece_list_begin(us, Piece);
|
||||||
|
|
||||||
for (int i = 0, e = pos.piece_count(us, Piece); i < e; i++)
|
while ((from = *ptr++) != SQ_NONE)
|
||||||
{
|
{
|
||||||
from = pos.piece_list(us, Piece, i);
|
|
||||||
if (pinned && bit_is_set(pinned, from))
|
if (pinned && bit_is_set(pinned, from))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -838,6 +838,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
|
||||||
Square lastPawnSquare = pieceList[us][PAWN][pieceCount[us][PAWN]];
|
Square lastPawnSquare = pieceList[us][PAWN][pieceCount[us][PAWN]];
|
||||||
index[lastPawnSquare] = index[to];
|
index[lastPawnSquare] = index[to];
|
||||||
pieceList[us][PAWN][index[lastPawnSquare]] = lastPawnSquare;
|
pieceList[us][PAWN][index[lastPawnSquare]] = lastPawnSquare;
|
||||||
|
pieceList[us][PAWN][pieceCount[us][PAWN]] = SQ_NONE;
|
||||||
index[to] = pieceCount[us][promotion] - 1;
|
index[to] = pieceCount[us][promotion] - 1;
|
||||||
pieceList[us][promotion][index[to]] = to;
|
pieceList[us][promotion][index[to]] = to;
|
||||||
|
|
||||||
|
@ -943,6 +944,7 @@ void Position::do_capture_move(Bitboard& key, PieceType capture, Color them, Squ
|
||||||
Square lastPieceSquare = pieceList[them][capture][pieceCount[them][capture]];
|
Square lastPieceSquare = pieceList[them][capture][pieceCount[them][capture]];
|
||||||
index[lastPieceSquare] = index[capsq];
|
index[lastPieceSquare] = index[capsq];
|
||||||
pieceList[them][capture][index[lastPieceSquare]] = lastPieceSquare;
|
pieceList[them][capture][index[lastPieceSquare]] = lastPieceSquare;
|
||||||
|
pieceList[them][capture][pieceCount[them][capture]] = SQ_NONE;
|
||||||
|
|
||||||
// Reset rule 50 counter
|
// Reset rule 50 counter
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
|
@ -1099,6 +1101,7 @@ void Position::undo_move(Move m) {
|
||||||
Square lastPromotionSquare = pieceList[us][promotion][pieceCount[us][promotion]];
|
Square lastPromotionSquare = pieceList[us][promotion][pieceCount[us][promotion]];
|
||||||
index[lastPromotionSquare] = index[to];
|
index[lastPromotionSquare] = index[to];
|
||||||
pieceList[us][promotion][index[lastPromotionSquare]] = lastPromotionSquare;
|
pieceList[us][promotion][index[lastPromotionSquare]] = lastPromotionSquare;
|
||||||
|
pieceList[us][promotion][pieceCount[us][promotion]] = SQ_NONE;
|
||||||
index[to] = pieceCount[us][PAWN] - 1;
|
index[to] = pieceCount[us][PAWN] - 1;
|
||||||
pieceList[us][PAWN][index[to]] = to;
|
pieceList[us][PAWN][index[to]] = to;
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,6 +193,7 @@ public:
|
||||||
|
|
||||||
// Piece lists
|
// Piece lists
|
||||||
Square piece_list(Color c, PieceType pt, int index) const;
|
Square piece_list(Color c, PieceType pt, int index) const;
|
||||||
|
const Square* piece_list_begin(Color c, PieceType pt) const;
|
||||||
|
|
||||||
// Information about attacks to or from a given square
|
// Information about attacks to or from a given square
|
||||||
Bitboard attackers_to(Square s) const;
|
Bitboard attackers_to(Square s) const;
|
||||||
|
@ -403,6 +404,10 @@ inline Square Position::piece_list(Color c, PieceType pt, int index) const {
|
||||||
return pieceList[c][pt][index];
|
return pieceList[c][pt][index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const Square* Position::piece_list_begin(Color c, PieceType pt) const {
|
||||||
|
return pieceList[c][pt];
|
||||||
|
}
|
||||||
|
|
||||||
inline Square Position::ep_square() const {
|
inline Square Position::ep_square() const {
|
||||||
return st->epSquare;
|
return st->epSquare;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue