Make precalculated magics constexpr
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 1 May 2021 13:57:01 +0000 (15:57 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 1 May 2021 13:57:01 +0000 (15:57 +0200)
No functional change.

src/bitboard.cpp
src/magic.h

index 71e021f..c562ab8 100644 (file)
@@ -108,7 +108,7 @@ namespace {
 
   template <MovementType MT>
 #ifdef PRECOMPUTED_MAGICS
-  void init_magics(Bitboard table[], Magic magics[], std::map<Direction, int> directions, Bitboard magicsInit[]);
+  void init_magics(Bitboard table[], Magic magics[], std::map<Direction, int> directions, const Bitboard magicsInit[]);
 #else
   void init_magics(Bitboard table[], Magic magics[], std::map<Direction, int> directions);
 #endif
@@ -359,7 +359,7 @@ namespace {
 
   template <MovementType MT>
 #ifdef PRECOMPUTED_MAGICS
-  void init_magics(Bitboard table[], Magic magics[], std::map<Direction, int> directions, Bitboard magicsInit[]) {
+  void init_magics(Bitboard table[], Magic magics[], std::map<Direction, int> directions, const Bitboard magicsInit[]) {
 #else
   void init_magics(Bitboard table[], Magic magics[], std::map<Direction, int> directions) {
 #endif
index 580e25a..5413a3e 100644 (file)
@@ -23,7 +23,7 @@
 #define B(a, b) (Bitboard(a) << 64) ^ Bitboard(b)
   // Use precomputed magics if pext is not available,
   // since the magics generation is very slow.
-  Bitboard RookMagicHInit[SQUARE_NB] = {
+  constexpr Bitboard RookMagicHInit[SQUARE_NB] = {
       B(0x120000880110000, 0x1008000000020020),
       B(0x24200C080840A052, 0x2004004000010008),
       B(0xC030024000228800, 0x4000010400000020),
       B(0x4100480203840, 0x300080100804),
       B(0x2000200000, 0x1201011000802),
   };
-  Bitboard RookMagicVInit[SQUARE_NB] = {
+  constexpr Bitboard RookMagicVInit[SQUARE_NB] = {
       B(0x202000812104400, 0x24800B01C0000303),
       B(0x340020400010D, 0x88060150C00400),
       B(0x400802040609, 0x49010200501A0002),
       B(0xA00002102810020, 0xB1080240015408),
       B(0x810080200806, 0x410440804080046)
   };
-  Bitboard BishopMagicInit[SQUARE_NB] = {
+  constexpr Bitboard BishopMagicInit[SQUARE_NB] = {
       B(0x2001040305000010, 0x830200040400082),
       B(0x1042400080E01200, 0x2004904010811400),
       B(0x400010120200, 0x880080D080018000),
       B(0x400202081811400, 0x40081802050000C),
       B(0x1011002100821300, 0x2400825040804100)
   };
-  Bitboard CannonMagicHInit[SQUARE_NB] = {
+  constexpr Bitboard CannonMagicHInit[SQUARE_NB] = {
       B(0x120000880110000, 0x1008000000020020),
       B(0x24200C080840A052, 0x2004004000010008),
       B(0xC030024000228800, 0x4000010400000020),
       B(0x4100480203840, 0x300080100804),
       B(0x2000200000, 0x1201011000802),
   };
-  Bitboard CannonMagicVInit[SQUARE_NB] = {
+  constexpr Bitboard CannonMagicVInit[SQUARE_NB] = {
       B(0x202000812104400, 0x24800B01C0000303),
       B(0x340020400010D, 0x88060150C00400),
       B(0x400802040609, 0x49010200501A0002),
       B(0xA00002102810020, 0xB1080240015408),
       B(0x810080200806, 0x410440804080046),
   };
-  Bitboard HorseMagicInit[SQUARE_NB] = {
+  constexpr Bitboard HorseMagicInit[SQUARE_NB] = {
       B(0x3C080482A592000C, 0x540104000020000),
       B(0x2802C40008000420, 0x4A00000001818009),
       B(0x1083040280804000, 0x120004C20100880),
       B(0x802020001202412, 0x2400404148426),
       B(0x8000440801040002, 0x444002800010052A),
   };
-  Bitboard ElephantMagicInit[SQUARE_NB] = {
+  constexpr Bitboard ElephantMagicInit[SQUARE_NB] = {
       B(0x64D2990200008, 0x4401880001C000),
       B(0x29BAA00010020, 0x200000400800600),
       B(0x3024240000000, 0x4100400010080),
       B(0x224404002004268C, 0x202500204C7D254),
       B(0x290080000000, 0xA41297838F40D),
   };
-  Bitboard JanggiElephantMagicInit[SQUARE_NB] = {
+  constexpr Bitboard JanggiElephantMagicInit[SQUARE_NB] = {
       B(0xC502282200061400, 0x2D07081241D90200),
       B(0xC502282200061400, 0x2D07081241D90200),
       B(0x8084810022440C2, 0x81402202004),
       B(0x220400000A80040, 0x806080020810010C),
       B(0xA000200000000080, 0x1040801A0081208),
   };
-  Bitboard CannonDiagMagicInit[SQUARE_NB] = {
+  constexpr Bitboard CannonDiagMagicInit[SQUARE_NB] = {
       B(0x811801000400, 0x312260280280202),
       B(0x44A000402022680, 0x1020224880420005),
       B(0x8000C80800200880, 0x2000810060080C0),
       B(0x20012C2400880082, 0x7000880020C03200),
       B(0x204040300004, 0x840800041101002),
   };
-  Bitboard NightriderMagicInit[SQUARE_NB] = {
+  constexpr Bitboard NightriderMagicInit[SQUARE_NB] = {
       B(0x8008100800020052, 0x8001440000000000),
       B(0x24028400210090, 0x4200000000021),
       B(0x22002020A0200800, 0x100820120000082),
       B(0x2000010441A0044, 0x500800502020188),
       B(0xA80000000180000, 0x234402012110080),
   };
-  Bitboard GrasshopperMagicHInit[SQUARE_NB] = {
+  constexpr Bitboard GrasshopperMagicHInit[SQUARE_NB] = {
       B(0x120000880110000, 0x1008000000020020),
       B(0x24200C080840A052, 0x2004004000010008),
       B(0xC030024000228800, 0x4000010400000020),
       B(0x4100480203840, 0x300080100804),
       B(0x2000200000, 0x1201011000802),
   };
-  Bitboard GrasshopperMagicVInit[SQUARE_NB] = {
+  constexpr Bitboard GrasshopperMagicVInit[SQUARE_NB] = {
       B(0x202000812104400, 0x24800B01C0000303),
       B(0x340020400010D, 0x88060150C00400),
       B(0x400802040609, 0x49010200501A0002),
       B(0xA00002102810020, 0xB1080240015408),
       B(0x810080200806, 0x410440804080046),
   };
-  Bitboard GrasshopperMagicDInit[SQUARE_NB] = {
+  constexpr Bitboard GrasshopperMagicDInit[SQUARE_NB] = {
       B(0x811801000400, 0x312260280280202),
       B(0x44A000402022680, 0x1020224880420005),
       B(0x8000C80800200880, 0x2000810060080C0),