]> git.sesse.net Git - stockfish/blobdiff - src/movegen.cpp
Micro optimize generate_piece_checks() take 2
[stockfish] / src / movegen.cpp
index 0f2f6b4e0fd37d94187eeb05cfde1d6179e1b412..dff9e8c3b4624056f0642b29e152ffac3e9e12eb 100644 (file)
@@ -73,9 +73,8 @@ namespace {
         return Us == WHITE ? p << 9 : p >> 7;
     else if (Direction == DELTA_NW)
         return Us == WHITE ? p << 7 : p >> 9;
-
-    assert(false);
-    return p;
+    else
+        return p;
   }
 
   // Template generate_piece_checks() with specializations
@@ -815,9 +814,17 @@ namespace {
         return mlist;
 
     Bitboard checkSqs = pos.piece_attacks<Piece>(ksq) & pos.empty_squares();
+    if (!checkSqs)
+        return mlist;
+
     while (b)
     {
         Square from = pop_1st_bit(&b);
+        if (   (Piece == QUEEN  && !(QueenPseudoAttacks[from]  & checkSqs))
+            || (Piece == ROOK   && !(RookPseudoAttacks[from]   & checkSqs))
+            || (Piece == BISHOP && !(BishopPseudoAttacks[from] & checkSqs)))
+            continue;
+
         Bitboard bb = pos.piece_attacks<Piece>(from) & checkSqs;
         SERIALIZE_MOVES(bb);
     }