]> git.sesse.net Git - stockfish/commitdiff
Prefer 0 to EmptyBoardBB
authorMarco Costalba <mcostalba@gmail.com>
Sat, 3 Dec 2011 10:56:11 +0000 (11:56 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 3 Dec 2011 11:02:13 +0000 (12:02 +0100)
Easier and even faster or at least easier to optimize.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/bitbase.cpp
src/bitboard.cpp
src/bitboard.h
src/endgame.cpp
src/evaluate.cpp
src/movegen.cpp
src/pawns.cpp
src/position.cpp
src/types.h

index 96ada8dd59d2ac95e6dd6ab2d7d8826db0022354..5e31cc5c8b89a7cf7222c1a0e760393afba621bd 100644 (file)
@@ -151,7 +151,7 @@ namespace {
     //
     // Case 1: Stalemate
     if (   sideToMove == BLACK
-        && (bk_attacks() & ~(wk_attacks() | pawn_attacks())) == EmptyBoardBB)
+        && !(bk_attacks() & ~(wk_attacks() | pawn_attacks())))
         return RESULT_DRAW;
 
     // Case 2: King can capture pawn
index 794f54cf68326cf92fec7ff172a1f1959eaa62d2..0e035b15f37b6867d1601431eae1f5c98298e90c 100644 (file)
@@ -166,7 +166,7 @@ void bitboards_init() {
       ClearMaskBB[s] = ~SetMaskBB[s];
   }
 
-  ClearMaskBB[SQ_NONE] = ~EmptyBoardBB;
+  ClearMaskBB[SQ_NONE] = ~0ULL;
 
   FileBB[FILE_A] = FileABB;
   RankBB[RANK_1] = Rank1BB;
@@ -231,9 +231,9 @@ void bitboards_init() {
 
   for (Square s = SQ_A1; s <= SQ_H8; s++)
   {
-      BishopPseudoAttacks[s] = bishop_attacks_bb(s, EmptyBoardBB);
-      RookPseudoAttacks[s]   = rook_attacks_bb(s, EmptyBoardBB);
-      QueenPseudoAttacks[s]  = queen_attacks_bb(s, EmptyBoardBB);
+      BishopPseudoAttacks[s] = bishop_attacks_bb(s, 0);
+      RookPseudoAttacks[s]   = rook_attacks_bb(s, 0);
+      QueenPseudoAttacks[s]  = queen_attacks_bb(s, 0);
   }
 
   for (Square s1 = SQ_A1; s1 <= SQ_H8; s1++)
@@ -324,7 +324,7 @@ namespace {
         // all the attacks for each possible subset of the mask and so is 2 power
         // the number of 1s of the mask. Hence we deduce the size of the shift to
         // apply to the 64 or 32 bits word to get the index.
-        masks[s]  = sliding_attacks(pt, s, EmptyBoardBB) & ~edges;
+        masks[s]  = sliding_attacks(pt, s, 0) & ~edges;
         shifts[s] = (CpuIs64Bit ? 64 : 32) - count_1s<CNT32_MAX15>(masks[s]);
 
         // Use Carry-Rippler trick to enumerate all subsets of masks[s] and
index 1c8a8c2245bee5a8000016eacf1d3fa3b9b7a2fa..8366827804dea8a87afa2aaae09aa73ffb9ea79a 100644 (file)
 
 #include "types.h"
 
-const Bitboard EmptyBoardBB = 0;
-
-const Bitboard FileABB = 0x0101010101010101ULL;
-const Bitboard FileBBB = FileABB << 1;
-const Bitboard FileCBB = FileABB << 2;
-const Bitboard FileDBB = FileABB << 3;
-const Bitboard FileEBB = FileABB << 4;
-const Bitboard FileFBB = FileABB << 5;
-const Bitboard FileGBB = FileABB << 6;
-const Bitboard FileHBB = FileABB << 7;
-
-const Bitboard Rank1BB = 0xFF;
-const Bitboard Rank2BB = Rank1BB << (8 * 1);
-const Bitboard Rank3BB = Rank1BB << (8 * 2);
-const Bitboard Rank4BB = Rank1BB << (8 * 3);
-const Bitboard Rank5BB = Rank1BB << (8 * 4);
-const Bitboard Rank6BB = Rank1BB << (8 * 5);
-const Bitboard Rank7BB = Rank1BB << (8 * 6);
-const Bitboard Rank8BB = Rank1BB << (8 * 7);
-
 extern Bitboard SquaresByColorBB[2];
 extern Bitboard FileBB[8];
 extern Bitboard NeighboringFilesBB[8];
index 4e6de80968fc45e3e67d65cf7024541f2ec6c2ff..2ebc8f97142522e02d5d3e1aa4ce8673697c8dd3 100644 (file)
@@ -376,7 +376,7 @@ Value Endgame<KBBKN>::apply(const Position& pos) const {
   assert(pos.non_pawn_material(strongerSide) == 2*BishopValueMidgame);
   assert(pos.piece_count(weakerSide, KNIGHT) == 1);
   assert(pos.non_pawn_material(weakerSide) == KnightValueMidgame);
-  assert(pos.pieces(PAWN) == EmptyBoardBB);
+  assert(!pos.pieces(PAWN));
 
   Value result = BishopValueEndgame;
   Square wksq = pos.king_square(strongerSide);
@@ -428,7 +428,7 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
 
   // All pawns are on a single rook file ?
   if (   (pawnFile == FILE_A || pawnFile == FILE_H)
-      && (pawns & ~file_bb(pawnFile)) == EmptyBoardBB)
+      && !(pawns & ~file_bb(pawnFile)))
   {
       Square bishopSq = pos.piece_list(strongerSide, BISHOP)[0];
       Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8));
@@ -443,12 +443,12 @@ ScaleFactor Endgame<KBPsK>::apply(const Position& pos) const {
           Rank rank;
           if (strongerSide == WHITE)
           {
-              for (rank = RANK_7; (rank_bb(rank) & pawns) == EmptyBoardBB; rank--) {}
+              for (rank = RANK_7; !(rank_bb(rank) & pawns); rank--) {}
               assert(rank >= RANK_2 && rank <= RANK_7);
           }
           else
           {
-              for (rank = RANK_2; (rank_bb(rank) & pawns) == EmptyBoardBB; rank++) {}
+              for (rank = RANK_2; !(rank_bb(rank) & pawns); rank++) {}
               rank = Rank(rank ^ 7);  // HACK to get the relative rank
               assert(rank >= RANK_2 && rank <= RANK_7);
           }
@@ -667,21 +667,21 @@ ScaleFactor Endgame<KPsK>::apply(const Position& pos) const {
   Bitboard pawns = pos.pieces(PAWN, strongerSide);
 
   // Are all pawns on the 'a' file?
-  if ((pawns & ~FileABB) == EmptyBoardBB)
+  if (!(pawns & ~FileABB))
   {
       // Does the defending king block the pawns?
       if (   square_distance(ksq, relative_square(strongerSide, SQ_A8)) <= 1
           || (   file_of(ksq) == FILE_A
-              && (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
+              && !in_front_bb(strongerSide, ksq) & pawns))
           return SCALE_FACTOR_ZERO;
   }
   // Are all pawns on the 'h' file?
-  else if ((pawns & ~FileHBB) == EmptyBoardBB)
+  else if (!(pawns & ~FileHBB))
   {
     // Does the defending king block the pawns?
     if (   square_distance(ksq, relative_square(strongerSide, SQ_H8)) <= 1
         || (   file_of(ksq) == FILE_H
-            && (in_front_bb(strongerSide, ksq) & pawns) == EmptyBoardBB))
+            && !in_front_bb(strongerSide, ksq) & pawns))
         return SCALE_FACTOR_ZERO;
   }
   return SCALE_FACTOR_NONE;
index 6b15f6c7f0b8838b151aeba3d48380d60da34572..6d95fd58cb6cca53a1c968d7fbdaddf142f1e934 100644 (file)
@@ -462,8 +462,8 @@ namespace {
     // no minor piece which can exchange the outpost piece.
     if (bonus && bit_is_set(ei.attackedBy[Us][PAWN], s))
     {
-        if (    pos.pieces(KNIGHT, Them) == EmptyBoardBB
-            && (SquaresByColorBB[color_of(s)] & pos.pieces(BISHOP, Them)) == EmptyBoardBB)
+        if (   !pos.pieces(KNIGHT, Them)
+            && !(SquaresByColorBB[color_of(s)] & pos.pieces(BISHOP, Them)))
             bonus += bonus + bonus / 2;
         else
             bonus += bonus / 2;
@@ -488,7 +488,7 @@ namespace {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
     const Square* pl = pos.piece_list(Us, Piece);
 
-    ei.attackedBy[Us][Piece] = EmptyBoardBB;
+    ei.attackedBy[Us][Piece] = 0;
 
     while ((s = *pl++) != SQ_NONE)
     {
index dd849c15604813c9ba6acf005d807fa4e508f682..ba1cc334f40cb8e3f69d043763ca2e16656ca426 100644 (file)
@@ -251,7 +251,7 @@ MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
   Color us = pos.side_to_move();
   Square ksq = pos.king_square(us);
   Bitboard checkers = pos.checkers();
-  Bitboard sliderAttacks = EmptyBoardBB;
+  Bitboard sliderAttacks = 0;
 
   assert(pos.piece_on(ksq) == make_piece(us, KING));
   assert(checkers);
@@ -485,7 +485,7 @@ namespace {
 
         b1 = pawns & pos.attacks_from<PAWN>(pos.ep_square(), Them);
 
-        assert(b1 != EmptyBoardBB);
+        assert(b1);
 
         while (b1)
         {
index d5514e2eaea411e474e1802230ac1da2985ec95b..3aede5adfa7f111b42ddef9332e9182a5dfba8f5 100644 (file)
@@ -182,7 +182,7 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
       // pawn on neighboring files is higher or equal than the number of
       // enemy pawns in the forward direction on the neighboring files.
       candidate =   !(opposed | passed | backward | isolated)
-                 && (b = attack_span_mask(Them, s + pawn_push(Us)) & ourPawns) != EmptyBoardBB
+                 && (b = attack_span_mask(Them, s + pawn_push(Us)) & ourPawns) != 0
                  &&  count_1s<Max15>(b) >= count_1s<Max15>(attack_span_mask(Us, s) & theirPawns);
 
       // Passed pawns will be properly scored in evaluation because we need
index 2f18427d827f8111d0357416d92525bb4ad7bb72..bed08ebad00865a1cbe4c67347552ed4872e8196 100644 (file)
@@ -89,7 +89,7 @@ CheckInfo::CheckInfo(const Position& pos) {
   checkSq[BISHOP] = pos.attacks_from<BISHOP>(ksq);
   checkSq[ROOK]   = pos.attacks_from<ROOK>(ksq);
   checkSq[QUEEN]  = checkSq[BISHOP] | checkSq[ROOK];
-  checkSq[KING]   = EmptyBoardBB;
+  checkSq[KING]   = 0;
 }
 
 
@@ -931,7 +931,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
   st->key = key;
 
   // Update checkers bitboard, piece must be already moved
-  st->checkersBB = EmptyBoardBB;
+  st->checkersBB = 0;
 
   if (moveIsCheck)
   {
@@ -1697,7 +1697,7 @@ bool Position::pos_is_ok(int* failedStep) const {
   if (debugBitboards)
   {
       // The intersection of the white and black pieces must be empty
-      if ((pieces(WHITE) & pieces(BLACK)) != EmptyBoardBB)
+      if (!(pieces(WHITE) & pieces(BLACK)))
           return false;
 
       // The union of the white and black pieces must be equal to all
index 841c794ad0b87691043b7d3a58c692b6fdb8d5f5..7040b5ad8fd8d333835143ea5cb96566eb4dd1fd 100644 (file)
@@ -158,6 +158,24 @@ typedef uint64_t Bitboard;
 const int PLY_MAX = 100;
 const int PLY_MAX_PLUS_2 = PLY_MAX + 2;
 
+const Bitboard FileABB = 0x0101010101010101ULL;
+const Bitboard FileBBB = FileABB << 1;
+const Bitboard FileCBB = FileABB << 2;
+const Bitboard FileDBB = FileABB << 3;
+const Bitboard FileEBB = FileABB << 4;
+const Bitboard FileFBB = FileABB << 5;
+const Bitboard FileGBB = FileABB << 6;
+const Bitboard FileHBB = FileABB << 7;
+
+const Bitboard Rank1BB = 0xFF;
+const Bitboard Rank2BB = Rank1BB << (8 * 1);
+const Bitboard Rank3BB = Rank1BB << (8 * 2);
+const Bitboard Rank4BB = Rank1BB << (8 * 3);
+const Bitboard Rank5BB = Rank1BB << (8 * 4);
+const Bitboard Rank6BB = Rank1BB << (8 * 5);
+const Bitboard Rank7BB = Rank1BB << (8 * 6);
+const Bitboard Rank8BB = Rank1BB << (8 * 7);
+
 enum ValueType {
   VALUE_TYPE_NONE  = 0,
   VALUE_TYPE_UPPER = 1,