X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbitboard.h;h=00f0f576d91972762e7f2781a585c3600f371e24;hp=9704839408e8ad7d9698222ecb2b664d0235cc53;hb=b1b0c640462aed199a3665e575f9cb208b8e4687;hpb=5ea08e79c4e510b65b3e18c9ab09919132976eec diff --git a/src/bitboard.h b/src/bitboard.h index 97048394..00f0f576 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -60,24 +60,22 @@ extern Bitboard SquaresInFrontMask[2][64]; extern Bitboard PassedPawnMask[2][64]; extern Bitboard AttackSpanMask[2][64]; -extern const uint64_t RMult[64]; -extern const int RShift[64]; -extern Bitboard RMask[64]; -extern int RAttackIndex[64]; -extern Bitboard RAttacks[0x19000]; - -extern const uint64_t BMult[64]; -extern const int BShift[64]; -extern Bitboard BMask[64]; -extern int BAttackIndex[64]; -extern Bitboard BAttacks[0x1480]; - extern Bitboard BishopPseudoAttacks[64]; extern Bitboard RookPseudoAttacks[64]; extern Bitboard QueenPseudoAttacks[64]; extern uint8_t BitCount8Bit[256]; +struct Magics { + Bitboard mask; + uint64_t mult; + uint32_t shift; + Bitboard* attacks; +}; + +extern Magics RMagics[64]; +extern Magics BMagics[64]; + /// Functions for testing whether a given bit is set in a bitboard, and for /// setting and clearing bits. @@ -173,28 +171,28 @@ inline Bitboard in_front_bb(Color c, Square s) { #if defined(IS_64BIT) -inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) { - Bitboard b = blockers & RMask[s]; - return RAttacks[RAttackIndex[s] + ((b * RMult[s]) >> RShift[s])]; +inline Bitboard rook_attacks_bb(Square s, Bitboard occ) { + const Magics& m = RMagics[s]; + return m.attacks[((occ & m.mask) * m.mult) >> m.shift]; } -inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) { - Bitboard b = blockers & BMask[s]; - return BAttacks[BAttackIndex[s] + ((b * BMult[s]) >> BShift[s])]; +inline Bitboard bishop_attacks_bb(Square s, Bitboard occ) { + const Magics& m = BMagics[s]; + return m.attacks[((occ & m.mask) * m.mult) >> m.shift]; } #else // if !defined(IS_64BIT) -inline Bitboard rook_attacks_bb(Square s, Bitboard blockers) { - Bitboard b = blockers & RMask[s]; - return RAttacks[RAttackIndex[s] + - (unsigned(int(b) * int(RMult[s]) ^ int(b >> 32) * int(RMult[s] >> 32)) >> RShift[s])]; +inline Bitboard rook_attacks_bb(Square s, Bitboard occ) { + const Magics& m = RMagics[s]; + Bitboard b = occ & m.mask; + return m.attacks[(unsigned(b) * unsigned(m.mult) ^ unsigned(b >> 32) * unsigned(m.mult >> 32)) >> m.shift]; } -inline Bitboard bishop_attacks_bb(Square s, Bitboard blockers) { - Bitboard b = blockers & BMask[s]; - return BAttacks[BAttackIndex[s] + - (unsigned(int(b) * int(BMult[s]) ^ int(b >> 32) * int(BMult[s] >> 32)) >> BShift[s])]; +inline Bitboard bishop_attacks_bb(Square s, Bitboard occ) { + const Magics& m = BMagics[s]; + Bitboard b = occ & m.mask; + return m.attacks[(unsigned(b) * unsigned(m.mult) ^ unsigned(b >> 32) * unsigned(m.mult >> 32)) >> m.shift]; } #endif