]> git.sesse.net Git - stockfish/blobdiff - src/bitboard.h
In razor qsearch use corrected beta
[stockfish] / src / bitboard.h
index d5c16a919006f75caf3ddd44ae0c406c3a5440dc..c0af52269afe5997bb7f73c526c77f3e4322d55e 100644 (file)
 #if !defined(BITBOARD_H_INCLUDED)
 #define BITBOARD_H_INCLUDED
 
-////
-//// Defines
-////
-
-// Quiet a warning on Intel compiler
-#if !defined(__SIZEOF_INT__ )
-#define __SIZEOF_INT__ 0
-#endif
-
-// Check for 64 bits for different compilers: Intel, MSVC and gcc
-#if defined(__x86_64) || defined(_WIN64) || (__SIZEOF_INT__ > 4)
-#define IS_64BIT
-#endif
-
-#if defined(IS_64BIT) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
-#define USE_BSFQ
-#endif
-
-
 ////
 //// Includes
 ////
 #include "types.h"
 
 
-////
-//// Types
-////
-
-typedef uint64_t Bitboard;
-
-
 ////
 //// Constants and variables
 ////
@@ -66,7 +40,6 @@ const Bitboard EmptyBoardBB = 0ULL;
 
 const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL;
 const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL;
-const Bitboard SquaresByColorBB[2] = { BlackSquaresBB, WhiteSquaresBB };
 
 const Bitboard FileABB = 0x0101010101010101ULL;
 const Bitboard FileBBB = 0x0202020202020202ULL;
@@ -77,22 +50,6 @@ const Bitboard FileFBB = 0x2020202020202020ULL;
 const Bitboard FileGBB = 0x4040404040404040ULL;
 const Bitboard FileHBB = 0x8080808080808080ULL;
 
-const Bitboard FileBB[8] = {
-  FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB
-};
-
-const Bitboard NeighboringFilesBB[8] = {
-  FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB,
-  FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB
-};
-
-const Bitboard ThisAndNeighboringFilesBB[8] = {
-  FileABB|FileBBB, FileABB|FileBBB|FileCBB,
-  FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB,
-  FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB,
-  FileFBB|FileGBB|FileHBB, FileGBB|FileHBB
-};
-
 const Bitboard Rank1BB = 0xFFULL;
 const Bitboard Rank2BB = 0xFF00ULL;
 const Bitboard Rank3BB = 0xFF0000ULL;
@@ -102,42 +59,13 @@ const Bitboard Rank6BB = 0xFF0000000000ULL;
 const Bitboard Rank7BB = 0xFF000000000000ULL;
 const Bitboard Rank8BB = 0xFF00000000000000ULL;
 
-const Bitboard RankBB[8] = {
-  Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB
-};
-
-const Bitboard RelativeRankBB[2][8] = {
-  { Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB },
-  { Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB }
-};
-
-const Bitboard InFrontBB[2][8] = {
-  { Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
-    Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
-    Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB,
-    Rank5BB | Rank6BB | Rank7BB | Rank8BB,
-    Rank6BB | Rank7BB | Rank8BB,
-    Rank7BB | Rank8BB,
-    Rank8BB,
-    EmptyBoardBB
-  },
-  { EmptyBoardBB,
-    Rank1BB,
-    Rank2BB | Rank1BB,
-    Rank3BB | Rank2BB | Rank1BB,
-    Rank4BB | Rank3BB | Rank2BB | Rank1BB,
-    Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
-    Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB,
-    Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB
-  }
-};
-
-const int BitTable[64] = {
-  63, 30, 3, 32, 25, 41, 22, 33, 15, 50, 42, 13, 11, 53, 19, 34, 61, 29, 2,
-  51, 21, 43, 45, 10, 18, 47, 1, 54, 9, 57, 0, 35, 62, 31, 40, 4, 49, 5, 52,
-  26, 60, 6, 23, 44, 46, 27, 56, 16, 7, 39, 48, 24, 59, 14, 12, 55, 38, 28,
-  58, 20, 37, 17, 36, 8
-};
+extern const Bitboard SquaresByColorBB[2];
+extern const Bitboard FileBB[8];
+extern const Bitboard NeighboringFilesBB[8];
+extern const Bitboard ThisAndNeighboringFilesBB[8];
+extern const Bitboard RankBB[8];
+extern const Bitboard RelativeRankBB[2][8];
+extern const Bitboard InFrontBB[2][8];
 
 extern Bitboard SetMaskBB[65];
 extern Bitboard ClearMaskBB[65];
@@ -165,6 +93,8 @@ extern Bitboard BishopPseudoAttacks[64];
 extern Bitboard RookPseudoAttacks[64];
 extern Bitboard QueenPseudoAttacks[64];
 
+extern uint8_t BitCount8Bit[256];
+
 
 ////
 //// Inline functions
@@ -393,13 +323,13 @@ inline Bitboard isolated_pawn_mask(Square s) {
 
 #if defined(USE_BSFQ) // Assembly code by Heinz van Saanen
 
-inline Square __attribute__((always_inline)) first_1(Bitboard b) {
+inline Square first_1(Bitboard b) {
   Bitboard dummy;
   __asm__("bsfq %1, %0": "=r"(dummy): "rm"(b) );
   return (Square)(dummy);
 }
 
-inline Square __attribute__((always_inline)) pop_1st_bit(Bitboard* b) {
+inline Square pop_1st_bit(Bitboard* b) {
   const Square s = first_1(*b);
   *b &= ~(1ULL<<s);
   return s;
@@ -407,12 +337,7 @@ inline Square __attribute__((always_inline)) pop_1st_bit(Bitboard* b) {
 
 #else // if !defined(USE_BSFQ)
 
-inline Square first_1(Bitboard b) {
-  b ^= (b - 1);
-  uint32_t fold = int(b) ^ int(b >> 32);
-  return Square(BitTable[(fold * 0x783a9b23) >> 26]);
-}
-
+extern Square first_1(Bitboard b);
 extern Square pop_1st_bit(Bitboard* b);
 
 #endif