From: Marco Costalba Date: Mon, 15 Jul 2013 18:50:24 +0000 (+0200) Subject: Better annotate unlikely conditions X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=cbb1a8ed31679fe32d2694448a10b031390a32b3 Better annotate unlikely conditions And in case of gcc we win also a small speed optimization due to better branch prediction. No functional change. --- diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 8bbd0bff..bb9a2f97 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -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(s))) unsafeSquares = squaresToQueen; else diff --git a/src/search.cpp b/src/search.cpp index f47e601b..eae2ea27 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1454,7 +1454,7 @@ moves_loop: // When in check and at SpNode search starts from here | (attacks_bb(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(m2to))) // Unlikely xray + if (unlikely(xray) && (xray & ~pos.attacks_from(m2to))) return true; } diff --git a/src/types.h b/src/types.h index 444d7afd..8eb99455 100644 --- a/src/types.h +++ b/src/types.h @@ -71,6 +71,14 @@ # 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