+ & ( SquareBB[s1] | SquareBB[s2] | SquareBB[s3]);
+}
+
+
+/// same_color_squares() returns a bitboard representing all squares with
+/// the same color of the given square.
+
+inline Bitboard same_color_squares(Square s) {
+ return Bitboard(0xAA55AA55AA55AA55ULL) & s ? 0xAA55AA55AA55AA55ULL
+ : ~0xAA55AA55AA55AA55ULL;
+}
+
+
+/// Functions for computing sliding attack bitboards. Function attacks_bb() takes
+/// a square and a bitboard of occupied squares as input, and returns a bitboard
+/// representing all squares attacked by Pt (bishop or rook) on the given square.
+template<PieceType Pt>
+FORCE_INLINE unsigned magic_index(Square s, Bitboard occ) {
+
+ Bitboard* const Masks = Pt == ROOK ? RMasks : BMasks;
+ Bitboard* const Magics = Pt == ROOK ? RMagics : BMagics;
+ unsigned* const Shifts = Pt == ROOK ? RShifts : BShifts;
+
+ if (Is64Bit)
+ return unsigned(((occ & Masks[s]) * Magics[s]) >> Shifts[s]);
+
+ unsigned lo = unsigned(occ) & unsigned(Masks[s]);
+ unsigned hi = unsigned(occ >> 32) & unsigned(Masks[s] >> 32);
+ return (lo * unsigned(Magics[s]) ^ hi * unsigned(Magics[s] >> 32)) >> Shifts[s];
+}
+
+template<PieceType Pt>
+inline Bitboard attacks_bb(Square s, Bitboard occ) {
+ return (Pt == ROOK ? RAttacks : BAttacks)[s][magic_index<Pt>(s, occ)];
+}
+
+
+/// lsb()/msb() finds the least/most significant bit in a nonzero bitboard.
+/// pop_lsb() finds and clears the least significant bit in a nonzero bitboard.
+
+#if defined(USE_BSFQ)
+
+# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
+
+FORCE_INLINE Square lsb(Bitboard b) {
+ unsigned long index;
+ _BitScanForward64(&index, b);
+ return (Square) index;
+}
+
+FORCE_INLINE Square msb(Bitboard b) {
+ unsigned long index;
+ _BitScanReverse64(&index, b);
+ return (Square) index;
+}
+
+# elif defined(__arm__)
+
+FORCE_INLINE int lsb32(uint32_t v) {
+ __asm__("rbit %0, %1" : "=r"(v) : "r"(v));
+ return __builtin_clz(v);
+}
+
+FORCE_INLINE Square msb(Bitboard b) {
+ return (Square) (63 - __builtin_clzll(b));