-/// piece of type Pt (bishop or rook) placed on 's'. The helper magic_index()
-/// looks up the index using the 'magic bitboards' approach.
-template<PieceType Pt>
-inline unsigned magic_index(Square s, Bitboard occupied) {
-
- extern Magic RookMagics[SQUARE_NB];
- extern Magic BishopMagics[SQUARE_NB];
-
- const Magic* Magics = Pt == ROOK ? RookMagics : BishopMagics;
- Bitboard mask = Magics[s].mask;
- Bitboard magic = Magics[s].magic;
- unsigned shift = Magics[s].shift;
-
- if (HasPext)
- return unsigned(pext(occupied, mask));
-
- if (Is64Bit)
- return unsigned(((occupied & mask) * magic) >> shift);
-
- unsigned lo = unsigned(occupied) & unsigned(mask);
- unsigned hi = unsigned(occupied >> 32) & unsigned(mask >> 32);
- return (lo * unsigned(magic) ^ hi * unsigned(magic >> 32)) >> shift;
-}