From 4d30438400932d18c095a8b85c3e51789d5f0feb Mon Sep 17 00:00:00 2001 From: bmc4 Date: Sun, 10 Jan 2021 03:30:40 -0300 Subject: [PATCH] Remove Condition from Generate_Move Loop it seems it's faster to handle blockers_for_king(~Us) outside loops Passed STC: LLR: 2.96 (-2.94,2.94) {-0.25,1.25} Total: 22184 W: 2063 L: 1919 D: 18202 Ptnml(0-2): 63, 1485, 7855, 1623, 66 https://tests.stockfishchess.org/tests/view/5ffbee2f6019e097de3ef18d closes https://github.com/official-stockfish/Stockfish/pull/3299 No functional change --- AUTHORS | 1 + src/movegen.cpp | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/AUTHORS b/AUTHORS index b31a36e9..d170364e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -33,6 +33,7 @@ Bill Henry (VoyagerOne) Bojun Guo (noobpwnftw, Nooby) braich Brian Sheppard (SapphireBrand, briansheppard-toast) +Bruno de Melo Costa (BM123499) Bryan Cross (crossbr) candirufish Chess13234 diff --git a/src/movegen.cpp b/src/movegen.cpp index e017d8fe..855a203e 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -175,25 +175,19 @@ namespace { } - template - ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Bitboard target) { + template + ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Bitboard piecesToMove, Bitboard target) { static_assert(Pt != KING && Pt != PAWN, "Unsupported piece type in generate_moves()"); - Bitboard bb = pos.pieces(Us, Pt); + Bitboard bb = piecesToMove & pos.pieces(Pt); while (bb) { Square from = pop_lsb(&bb); - if (Checks) - { - if ( (Pt == BISHOP || Pt == ROOK || Pt == QUEEN) - && !(attacks_bb(from) & target & pos.check_squares(Pt))) - continue; - - if (pos.blockers_for_king(~Us) & from) - continue; - } + if (Checks && (Pt == BISHOP || Pt == ROOK || Pt == QUEEN) + && !(attacks_bb(from) & target & pos.check_squares(Pt))) + continue; Bitboard b = attacks_bb(from, pos.pieces()) & target; @@ -211,7 +205,10 @@ namespace { template ExtMove* generate_all(const Position& pos, ExtMove* moveList) { constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations - Bitboard target; + Bitboard target, piecesToMove = pos.pieces(Us); + + if(Type == QUIET_CHECKS) + piecesToMove &= ~pos.blockers_for_king(~Us); switch (Type) { @@ -236,10 +233,10 @@ namespace { } moveList = generate_pawn_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); + moveList = generate_moves(pos, moveList, piecesToMove, target); + moveList = generate_moves(pos, moveList, piecesToMove, target); + moveList = generate_moves< ROOK, Checks>(pos, moveList, piecesToMove, target); + moveList = generate_moves< QUEEN, Checks>(pos, moveList, piecesToMove, target); if (Type != QUIET_CHECKS && Type != EVASIONS) { -- 2.39.2