1
0
Fork 0
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:
Marco Costalba 2009-09-23 21:45:32 +01:00
parent dcb323bf0d
commit 48b74142ef
3 changed files with 12 additions and 4 deletions

View file

@ -476,10 +476,10 @@ namespace {
Square from;
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;
SERIALIZE_MOVES(b);
}
@ -502,10 +502,10 @@ namespace {
Color us, Bitboard target, Bitboard pinned) {
Square from;
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))
continue;

View file

@ -838,6 +838,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
Square lastPawnSquare = pieceList[us][PAWN][pieceCount[us][PAWN]];
index[lastPawnSquare] = index[to];
pieceList[us][PAWN][index[lastPawnSquare]] = lastPawnSquare;
pieceList[us][PAWN][pieceCount[us][PAWN]] = SQ_NONE;
index[to] = pieceCount[us][promotion] - 1;
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]];
index[lastPieceSquare] = index[capsq];
pieceList[them][capture][index[lastPieceSquare]] = lastPieceSquare;
pieceList[them][capture][pieceCount[them][capture]] = SQ_NONE;
// Reset rule 50 counter
st->rule50 = 0;
@ -1099,6 +1101,7 @@ void Position::undo_move(Move m) {
Square lastPromotionSquare = pieceList[us][promotion][pieceCount[us][promotion]];
index[lastPromotionSquare] = index[to];
pieceList[us][promotion][index[lastPromotionSquare]] = lastPromotionSquare;
pieceList[us][promotion][pieceCount[us][promotion]] = SQ_NONE;
index[to] = pieceCount[us][PAWN] - 1;
pieceList[us][PAWN][index[to]] = to;
}

View file

@ -193,6 +193,7 @@ public:
// Piece lists
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
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];
}
inline const Square* Position::piece_list_begin(Color c, PieceType pt) const {
return pieceList[c][pt];
}
inline Square Position::ep_square() const {
return st->epSquare;
}