From af9eef34b0a7e315227343d345df3b37a2405a12 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sat, 1 May 2021 15:57:01 +0200 Subject: [PATCH] Make precalculated magics constexpr No functional change. --- src/bitboard.cpp | 4 ++-- src/magic.h | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 71e021f..c562ab8 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -108,7 +108,7 @@ namespace { template #ifdef PRECOMPUTED_MAGICS - void init_magics(Bitboard table[], Magic magics[], std::map directions, Bitboard magicsInit[]); + void init_magics(Bitboard table[], Magic magics[], std::map directions, const Bitboard magicsInit[]); #else void init_magics(Bitboard table[], Magic magics[], std::map directions); #endif @@ -359,7 +359,7 @@ namespace { template #ifdef PRECOMPUTED_MAGICS - void init_magics(Bitboard table[], Magic magics[], std::map directions, Bitboard magicsInit[]) { + void init_magics(Bitboard table[], Magic magics[], std::map directions, const Bitboard magicsInit[]) { #else void init_magics(Bitboard table[], Magic magics[], std::map directions) { #endif diff --git a/src/magic.h b/src/magic.h index 580e25a..5413a3e 100644 --- a/src/magic.h +++ b/src/magic.h @@ -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), @@ -145,7 +145,7 @@ B(0x4100480203840, 0x300080100804), B(0x2000200000, 0x1201011000802), }; - Bitboard RookMagicVInit[SQUARE_NB] = { + constexpr Bitboard RookMagicVInit[SQUARE_NB] = { B(0x202000812104400, 0x24800B01C0000303), B(0x340020400010D, 0x88060150C00400), B(0x400802040609, 0x49010200501A0002), @@ -267,7 +267,7 @@ B(0xA00002102810020, 0xB1080240015408), B(0x810080200806, 0x410440804080046) }; - Bitboard BishopMagicInit[SQUARE_NB] = { + constexpr Bitboard BishopMagicInit[SQUARE_NB] = { B(0x2001040305000010, 0x830200040400082), B(0x1042400080E01200, 0x2004904010811400), B(0x400010120200, 0x880080D080018000), @@ -389,7 +389,7 @@ B(0x400202081811400, 0x40081802050000C), B(0x1011002100821300, 0x2400825040804100) }; - Bitboard CannonMagicHInit[SQUARE_NB] = { + constexpr Bitboard CannonMagicHInit[SQUARE_NB] = { B(0x120000880110000, 0x1008000000020020), B(0x24200C080840A052, 0x2004004000010008), B(0xC030024000228800, 0x4000010400000020), @@ -511,7 +511,7 @@ B(0x4100480203840, 0x300080100804), B(0x2000200000, 0x1201011000802), }; - Bitboard CannonMagicVInit[SQUARE_NB] = { + constexpr Bitboard CannonMagicVInit[SQUARE_NB] = { B(0x202000812104400, 0x24800B01C0000303), B(0x340020400010D, 0x88060150C00400), B(0x400802040609, 0x49010200501A0002), @@ -633,7 +633,7 @@ B(0xA00002102810020, 0xB1080240015408), B(0x810080200806, 0x410440804080046), }; - Bitboard HorseMagicInit[SQUARE_NB] = { + constexpr Bitboard HorseMagicInit[SQUARE_NB] = { B(0x3C080482A592000C, 0x540104000020000), B(0x2802C40008000420, 0x4A00000001818009), B(0x1083040280804000, 0x120004C20100880), @@ -755,7 +755,7 @@ B(0x802020001202412, 0x2400404148426), B(0x8000440801040002, 0x444002800010052A), }; - Bitboard ElephantMagicInit[SQUARE_NB] = { + constexpr Bitboard ElephantMagicInit[SQUARE_NB] = { B(0x64D2990200008, 0x4401880001C000), B(0x29BAA00010020, 0x200000400800600), B(0x3024240000000, 0x4100400010080), @@ -877,7 +877,7 @@ B(0x224404002004268C, 0x202500204C7D254), B(0x290080000000, 0xA41297838F40D), }; - Bitboard JanggiElephantMagicInit[SQUARE_NB] = { + constexpr Bitboard JanggiElephantMagicInit[SQUARE_NB] = { B(0xC502282200061400, 0x2D07081241D90200), B(0xC502282200061400, 0x2D07081241D90200), B(0x8084810022440C2, 0x81402202004), @@ -999,7 +999,7 @@ B(0x220400000A80040, 0x806080020810010C), B(0xA000200000000080, 0x1040801A0081208), }; - Bitboard CannonDiagMagicInit[SQUARE_NB] = { + constexpr Bitboard CannonDiagMagicInit[SQUARE_NB] = { B(0x811801000400, 0x312260280280202), B(0x44A000402022680, 0x1020224880420005), B(0x8000C80800200880, 0x2000810060080C0), @@ -1121,7 +1121,7 @@ B(0x20012C2400880082, 0x7000880020C03200), B(0x204040300004, 0x840800041101002), }; - Bitboard NightriderMagicInit[SQUARE_NB] = { + constexpr Bitboard NightriderMagicInit[SQUARE_NB] = { B(0x8008100800020052, 0x8001440000000000), B(0x24028400210090, 0x4200000000021), B(0x22002020A0200800, 0x100820120000082), @@ -1243,7 +1243,7 @@ B(0x2000010441A0044, 0x500800502020188), B(0xA80000000180000, 0x234402012110080), }; - Bitboard GrasshopperMagicHInit[SQUARE_NB] = { + constexpr Bitboard GrasshopperMagicHInit[SQUARE_NB] = { B(0x120000880110000, 0x1008000000020020), B(0x24200C080840A052, 0x2004004000010008), B(0xC030024000228800, 0x4000010400000020), @@ -1365,7 +1365,7 @@ B(0x4100480203840, 0x300080100804), B(0x2000200000, 0x1201011000802), }; - Bitboard GrasshopperMagicVInit[SQUARE_NB] = { + constexpr Bitboard GrasshopperMagicVInit[SQUARE_NB] = { B(0x202000812104400, 0x24800B01C0000303), B(0x340020400010D, 0x88060150C00400), B(0x400802040609, 0x49010200501A0002), @@ -1487,7 +1487,7 @@ B(0xA00002102810020, 0xB1080240015408), B(0x810080200806, 0x410440804080046), }; - Bitboard GrasshopperMagicDInit[SQUARE_NB] = { + constexpr Bitboard GrasshopperMagicDInit[SQUARE_NB] = { B(0x811801000400, 0x312260280280202), B(0x44A000402022680, 0x1020224880420005), B(0x8000C80800200880, 0x2000810060080C0), -- 1.7.0.4