mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 17:46:26 +08:00
Speed-up generate<LEGAL>
The trick here is to check for legality only in the (rare) cases we have pinned pieces or a king move or an en-passant. This trick is able to increase the speed of perft of more then 20%! No functional change.
This commit is contained in:
@@ -420,11 +420,13 @@ MoveStack* generate<LEGAL>(const Position& pos, MoveStack* mlist) {
|
|||||||
|
|
||||||
MoveStack *end, *cur = mlist;
|
MoveStack *end, *cur = mlist;
|
||||||
Bitboard pinned = pos.pinned_pieces();
|
Bitboard pinned = pos.pinned_pieces();
|
||||||
|
Square ksq = pos.king_square(pos.side_to_move());
|
||||||
|
|
||||||
end = pos.in_check() ? generate<EVASIONS>(pos, mlist)
|
end = pos.in_check() ? generate<EVASIONS>(pos, mlist)
|
||||||
: generate<NON_EVASIONS>(pos, mlist);
|
: generate<NON_EVASIONS>(pos, mlist);
|
||||||
while (cur != end)
|
while (cur != end)
|
||||||
if (!pos.pl_move_is_legal(cur->move, pinned))
|
if ( (pinned || from_sq(cur->move) == ksq || type_of(cur->move) == ENPASSANT)
|
||||||
|
&& !pos.pl_move_is_legal(cur->move, pinned))
|
||||||
cur->move = (--end)->move;
|
cur->move = (--end)->move;
|
||||||
else
|
else
|
||||||
cur++;
|
cur++;
|
||||||
|
|||||||
Reference in New Issue
Block a user