From b1fcfe4c5d1fbe7e538268b79f12224f8c4d5012 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Tue, 3 Jan 2012 15:16:01 +0100 Subject: [PATCH] Streamline generation of MV_NON_EVASION Small speed-up of 3% in perft. No functional change. Signed-off-by: Marco Costalba --- src/movegen.cpp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index 1082ad01..eb235b1d 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -101,8 +101,6 @@ namespace { FORCE_INLINE MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) { assert(Pt == PAWN); - assert(Type == MV_CAPTURE || Type == MV_NON_CAPTURE || Type == MV_EVASION); - return (us == WHITE ? generate_pawn_moves(p, m, t, SQ_NONE) : generate_pawn_moves(p, m, t, SQ_NONE)); } @@ -151,27 +149,22 @@ namespace { template MoveStack* generate(const Position& pos, MoveStack* mlist) { + assert(Type == MV_CAPTURE || Type == MV_NON_CAPTURE || Type == MV_NON_EVASION); assert(!pos.in_check()); Color us = pos.side_to_move(); Bitboard target; - if (Type == MV_CAPTURE || Type == MV_NON_EVASION) + if (Type == MV_CAPTURE) target = pos.pieces(flip(us)); + else if (Type == MV_NON_CAPTURE) target = pos.empty_squares(); - else - assert(false); - if (Type == MV_NON_EVASION) - { - mlist = generate_piece_moves(pos, mlist, us, target); - mlist = generate_piece_moves(pos, mlist, us, pos.empty_squares()); - target |= pos.empty_squares(); - } - else - mlist = generate_piece_moves(pos, mlist, us, target); + else if (Type == MV_NON_EVASION) + target = pos.pieces(flip(us)) | pos.empty_squares(); + mlist = generate_piece_moves(pos, mlist, us, target); mlist = generate_piece_moves(pos, mlist, us, target); mlist = generate_piece_moves(pos, mlist, us, target); mlist = generate_piece_moves(pos, mlist, us, target); @@ -339,7 +332,7 @@ namespace { Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p; } - template + template inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) { const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB); @@ -371,10 +364,10 @@ namespace { { to = pop_1st_bit(&b); - if (Type == MV_CAPTURE || Type == MV_EVASION) + if (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION) (*mlist++).move = make_promotion(to - Delta, to, QUEEN); - if (Type == MV_NON_CAPTURE || Type == MV_EVASION) + if (Type == MV_NON_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION) { (*mlist++).move = make_promotion(to - Delta, to, ROOK); (*mlist++).move = make_promotion(to - Delta, to, BISHOP); @@ -435,10 +428,10 @@ namespace { } // Standard captures - if (Type == MV_CAPTURE || Type == MV_EVASION) + if (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION) { - mlist = generate_pawn_captures(mlist, pawns, enemyPieces); - mlist = generate_pawn_captures(mlist, pawns, enemyPieces); + mlist = generate_pawn_captures(mlist, pawns, enemyPieces); + mlist = generate_pawn_captures(mlist, pawns, enemyPieces); } // Single and double pawn pushes @@ -470,7 +463,8 @@ namespace { } // En passant captures - if ((Type == MV_CAPTURE || Type == MV_EVASION) && pos.ep_square() != SQ_NONE) + if ( (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION) + && pos.ep_square() != SQ_NONE) { assert(Us != WHITE || rank_of(pos.ep_square()) == RANK_6); assert(Us != BLACK || rank_of(pos.ep_square()) == RANK_3); -- 2.39.2