]> git.sesse.net Git - stockfish/blobdiff - src/bitboard.h
Micro-optimize perft
[stockfish] / src / bitboard.h
index 142c4c5a397f85b5b9092b4692c374cd1c6a2f01..06adbfe3850512902633fe3b514dff664863bb90 100644 (file)
@@ -63,7 +63,6 @@ extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
 extern Bitboard AttackSpanMask[COLOR_NB][SQUARE_NB];
 extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
 
-const Bitboard WhiteSquares = 0x55AA55AA55AA55AAULL;
 const Bitboard BlackSquares = 0xAA55AA55AA55AA55ULL;
 
 /// Overloads of bitwise operators between a Bitboard and a Square for testing
@@ -97,6 +96,18 @@ inline bool more_than_one(Bitboard b) {
 }
 
 
+/// shift_bb() moves bitboard one step along direction Delta. Mainly for pawns.
+
+template<Square Delta>
+inline Bitboard shift_bb(Bitboard b) {
+
+  return  Delta == DELTA_N  ?  b             << 8 : Delta == DELTA_S  ?  b             >> 8
+        : Delta == DELTA_NE ? (b & ~FileHBB) << 9 : Delta == DELTA_SE ? (b & ~FileHBB) >> 7
+        : Delta == DELTA_NW ? (b & ~FileABB) << 7 : Delta == DELTA_SW ? (b & ~FileABB) >> 9
+        : 0;
+}
+
+
 /// rank_bb() and file_bb() take a file or a square as input and return
 /// a bitboard representing all squares on the given file or rank.
 
@@ -201,8 +212,7 @@ inline bool squares_aligned(Square s1, Square s2, Square s3) {
 /// the same color of the given square.
 
 inline Bitboard same_color_squares(Square s) {
-  return Bitboard(0xAA55AA55AA55AA55ULL) & s ?  0xAA55AA55AA55AA55ULL
-                                             : ~0xAA55AA55AA55AA55ULL;
+  return BlackSquares & s ? BlackSquares : ~BlackSquares;
 }