]> git.sesse.net Git - stockfish/commitdiff
Better annotate unlikely conditions
authorMarco Costalba <mcostalba@gmail.com>
Mon, 15 Jul 2013 18:50:24 +0000 (20:50 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 15 Jul 2013 19:01:02 +0000 (21:01 +0200)
And in case of gcc we win also a small
speed optimization due to better branch
prediction.

No functional change.

src/evaluate.cpp
src/search.cpp
src/types.h

index 8bbd0bff161b3917f6fae299f6f21fe7ff65d2af..bb9a2f97c0f5b7fddbe3c5aec66eb20e8aab332a 100644 (file)
@@ -823,7 +823,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
                 // If there is an enemy rook or queen attacking the pawn from behind,
                 // add all X-ray attacks by the rook or queen. Otherwise consider only
                 // the squares in the pawn's path attacked or occupied by the enemy.
-                if (   (forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN)) // Unlikely
+                if (    unlikely(forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN))
                     && (forward_bb(Them, s) & pos.pieces(Them, ROOK, QUEEN) & pos.attacks_from<ROOK>(s)))
                     unsafeSquares = squaresToQueen;
                 else
index f47e601bfaa9651db0cfe55fe40ab20ad7352b96..eae2ea279e7818bc4838135521aca9b2127faba0 100644 (file)
@@ -1454,7 +1454,7 @@ moves_loop: // When in check and at SpNode search starts from here
                        | (attacks_bb<BISHOP>(m2to, occ) & pos.pieces(color_of(pc), QUEEN, BISHOP));
 
         // Verify attackers are triggered by our move and not already existing
-        if (xray && (xray & ~pos.attacks_from<QUEEN>(m2to))) // Unlikely xray
+        if (unlikely(xray) && (xray & ~pos.attacks_from<QUEEN>(m2to)))
             return true;
     }
 
index 444d7afd3d08eeab3132c389c155cae066a1ccd5..8eb994551d2d6ffc7515217b05ee03a86c0e326d 100644 (file)
 #  define FORCE_INLINE  inline
 #endif
 
+#ifdef __GNUC__
+#  define likely(x)   __builtin_expect(!!(x), 1)
+#  define unlikely(x) __builtin_expect(!!(x), 0)
+#else
+#  define likely(x)   (x)
+#  define unlikely(x) (x)
+#endif
+
 #if defined(USE_POPCNT)
 const bool HasPopCnt = true;
 #else