]> git.sesse.net Git - stockfish/commitdiff
Micro optimize open files calculation
authorMarco Costalba <mcostalba@gmail.com>
Sat, 9 Oct 2010 14:04:24 +0000 (15:04 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 9 Oct 2010 14:22:00 +0000 (15:22 +0100)
Committed mostly because is also a cleanup...

No functional change.

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

index 4cd1a316db626d31aff71562e8fabce012cc7971..658a570079509e1aee2efad52bef96c887705e8f 100644 (file)
@@ -124,18 +124,19 @@ PawnInfo* PawnInfoTable::get_pawn_info(const Position& pos) const {
 
   // Clear the PawnInfo object, and set the key
   memset(pi, 0, sizeof(PawnInfo));
+  pi->halfOpenFiles[WHITE] = pi->halfOpenFiles[BLACK] = 0xFF;
   pi->kingSquares[WHITE] = pi->kingSquares[BLACK] = SQ_NONE;
   pi->key = key;
 
   // Calculate pawn attacks
-  Bitboard whitePawns = pos.pieces(PAWN, WHITE);
-  Bitboard blackPawns = pos.pieces(PAWN, BLACK);
-  pi->pawnAttacks[WHITE] = ((whitePawns << 9) & ~FileABB) | ((whitePawns << 7) & ~FileHBB);
-  pi->pawnAttacks[BLACK] = ((blackPawns >> 7) & ~FileABB) | ((blackPawns >> 9) & ~FileHBB);
+  Bitboard wPawns = pos.pieces(PAWN, WHITE);
+  Bitboard bPawns = pos.pieces(PAWN, BLACK);
+  pi->pawnAttacks[WHITE] = ((wPawns << 9) & ~FileABB) | ((wPawns << 7) & ~FileHBB);
+  pi->pawnAttacks[BLACK] = ((bPawns >> 7) & ~FileABB) | ((bPawns >> 9) & ~FileHBB);
 
   // Evaluate pawns for both colors
-  pi->value =  evaluate_pawns<WHITE>(pos, whitePawns, blackPawns, pi)
-             - evaluate_pawns<BLACK>(pos, blackPawns, whitePawns, pi);
+  pi->value =  evaluate_pawns<WHITE>(pos, wPawns, bPawns, pi)
+             - evaluate_pawns<BLACK>(pos, bPawns, wPawns, pi);
   return pi;
 }
 
@@ -154,11 +155,6 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
   const BitCountType Max15 = CpuIs64Bit ? CNT64_MAX15 : CNT32_MAX15;
   const Square* ptr = pos.piece_list_begin(Us, PAWN);
 
-  // Initialize halfOpenFiles[]
-  for (f = FILE_A; f <= FILE_H; f++)
-      if (!(ourPawns & file_bb(f)))
-          pi->halfOpenFiles[Us] |= (1 << f);
-
   // Loop through all pawns of the current color and score each pawn
   while ((s = *ptr++) != SQ_NONE)
   {
@@ -167,6 +163,9 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
       f = square_file(s);
       r = square_rank(s);
 
+      // This file cannot be half open
+      pi->halfOpenFiles[Us] &= ~(1 << f);
+
       // Our rank plus previous one. Used for chain detection.
       b = rank_bb(r) | rank_bb(Us == WHITE ? r - Rank(1) : r + Rank(1));