]> git.sesse.net Git - stockfish/blobdiff - src/movegen.cpp
Optimize generate_moves
[stockfish] / src / movegen.cpp
index fafa65ee53f11100d396d717bb374ee32a5032aa..88c31cfa4856643e60ca45c64cfa53706aff1d97 100644 (file)
@@ -180,17 +180,17 @@ namespace {
 
     Bitboard bb = piecesToMove & pos.pieces(Pt);
 
 
     Bitboard bb = piecesToMove & pos.pieces(Pt);
 
+    if (!bb)
+        return moveList;
+
+    [[maybe_unused]] const Bitboard checkSquares = pos.check_squares(Pt);
+
     while (bb) {
         Square from = pop_lsb(&bb);
 
     while (bb) {
         Square from = pop_lsb(&bb);
 
-        if (Checks && (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
-            && !(attacks_bb<Pt>(from) & target & pos.check_squares(Pt)))
-            continue;
-
         Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
         Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
-
-        if (Checks)
-            b &= pos.check_squares(Pt);
+        if constexpr (Checks)
+            b &= checkSquares;
 
         while (b)
             *moveList++ = make_move(from, pop_lsb(&b));
 
         while (b)
             *moveList++ = make_move(from, pop_lsb(&b));