]> git.sesse.net Git - stockfish/commitdiff
Speed-up generate<LEGAL>
authorMarco Costalba <mcostalba@gmail.com>
Tue, 11 Sep 2012 18:00:58 +0000 (20:00 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Tue, 11 Sep 2012 18:24:31 +0000 (20:24 +0200)
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.

src/movegen.cpp

index 0b46298b9c80f9ca770e88766d4b6d74d20f1fa3..4a1903456da8210edbf79a7dc034f73650ed90bb 100644 (file)
@@ -420,11 +420,13 @@ MoveStack* generate<LEGAL>(const Position& pos, MoveStack* mlist) {
 
   MoveStack *end, *cur = mlist;
   Bitboard pinned = pos.pinned_pieces();
+  Square ksq = pos.king_square(pos.side_to_move());
 
   end = pos.in_check() ? generate<EVASIONS>(pos, mlist)
                        : generate<NON_EVASIONS>(pos, mlist);
   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;
       else
           cur++;