From: Marco Costalba Date: Sat, 1 Sep 2012 22:15:27 +0000 (+0200) Subject: Greatly speed up SEE X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=e6d8e7415220a11c06b9a707fde6f5c7dd27d34b Greatly speed up SEE Simply reshuffling the code inverting the condition in next_attacker() yields a miraculous speed up of more than 3% under gcc! On my laptop a bench run goes from 320Knps to 330Knps No functional change. --- diff --git a/src/position.cpp b/src/position.cpp index e8689ea7..26f457c5 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -106,25 +106,24 @@ void init() { /// valuable attacker for the side to move, remove the attacker we just found /// from the 'occupied' bitboard and scan for new X-ray attacks behind it. -template static FORCE_INLINE +template static FORCE_INLINE PieceType next_attacker(const Bitboard* bb, const Square& to, const Bitboard& stmAttackers, Bitboard& occupied, Bitboard& attackers) { - const PieceType NextPt = PieceType((int)Pt + 1); - - if (!(stmAttackers & bb[Pt])) - return next_attacker(bb, to, stmAttackers, occupied, attackers); - - Bitboard b = stmAttackers & bb[Pt]; - occupied ^= b & ~(b - 1); + if (stmAttackers & bb[Pt]) + { + Bitboard b = stmAttackers & bb[Pt]; + occupied ^= b & ~(b - 1); - if (Pt == PAWN || Pt == BISHOP || Pt == QUEEN) - attackers |= attacks_bb(to, occupied) & (bb[BISHOP] | bb[QUEEN]); + if (Pt == PAWN || Pt == BISHOP || Pt == QUEEN) + attackers |= attacks_bb(to, occupied) & (bb[BISHOP] | bb[QUEEN]); - if (Pt == ROOK || Pt == QUEEN) - attackers |= attacks_bb(to, occupied) & (bb[ROOK] | bb[QUEEN]); + if (Pt == ROOK || Pt == QUEEN) + attackers |= attacks_bb(to, occupied) & (bb[ROOK] | bb[QUEEN]); - return Pt; + return (PieceType)Pt; + } + return next_attacker(bb, to, stmAttackers, occupied, attackers); } template<> FORCE_INLINE @@ -1312,11 +1311,12 @@ int Position::see(Move m) const { stm = ~stm; stmAttackers = attackers & pieces(stm); - // Stop before processing a king capture - if (captured == KING && stmAttackers) + if (captured == KING) { - assert(slIndex < 32); - swapList[slIndex++] = QueenValueMg * 16; + // Stop before processing a king capture + if (stmAttackers) + swapList[slIndex++] = QueenValueMg * 16; + break; }