Microptimization in do_evaluate()
authorMarco Costalba <mcostalba@gmail.com>
Thu, 23 Jul 2009 17:30:56 +0000 (18:30 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 23 Jul 2009 21:01:42 +0000 (22:01 +0100)
Do not call count_1s_max_15() if not necessary, as is
not in the common case (>95%).

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/evaluate.cpp

index ecc73b3..13bc975 100644 (file)
@@ -353,8 +353,13 @@ Value do_evaluate(const Position& pos, EvalInfo& ei, int threadID) {
   // Initialize pawn attack bitboards for both sides
   ei.attackedBy[WHITE][PAWN] = ((pos.pawns(WHITE) << 9) & ~FileABB) | ((pos.pawns(WHITE) << 7) & ~FileHBB);
   ei.attackedBy[BLACK][PAWN] = ((pos.pawns(BLACK) >> 7) & ~FileABB) | ((pos.pawns(BLACK) >> 9) & ~FileHBB);
-  ei.kingAttackersCount[WHITE] = count_1s_max_15<HasPopCnt>(ei.attackedBy[WHITE][PAWN] & ei.attackedBy[BLACK][KING])/2;
-  ei.kingAttackersCount[BLACK] = count_1s_max_15<HasPopCnt>(ei.attackedBy[BLACK][PAWN] & ei.attackedBy[WHITE][KING])/2;
+  Bitboard b1 = ei.attackedBy[WHITE][PAWN] & ei.attackedBy[BLACK][KING];
+  Bitboard b2 = ei.attackedBy[BLACK][PAWN] & ei.attackedBy[WHITE][KING];
+  if (b1)
+      ei.kingAttackersCount[WHITE] = count_1s_max_15<HasPopCnt>(b1)/2;
+
+  if (b2)
+      ei.kingAttackersCount[BLACK] = count_1s_max_15<HasPopCnt>(b2)/2;
 
   // Evaluate pieces
   for (Color c = WHITE; c <= BLACK; c++)