-inline bool squares_aligned(Square s1, Square s2, Square s3) {
- return (BetweenBB[s1][s2] | BetweenBB[s1][s3] | BetweenBB[s2][s3])
- & ( SetMaskBB[s1] | SetMaskBB[s2] | SetMaskBB[s3]);
+// Returns the least significant bit in a non-zero bitboard.
+inline Square lsb(Bitboard b) {
+ assert(b);
+
+#if defined(__GNUC__) // GCC, Clang, ICX
+
+ return Square(__builtin_ctzll(b));
+
+#elif defined(_MSC_VER)
+ #ifdef _WIN64 // MSVC, WIN64
+
+ unsigned long idx;
+ _BitScanForward64(&idx, b);
+ return Square(idx);
+
+ #else // MSVC, WIN32
+ unsigned long idx;
+
+ if (b & 0xffffffff)
+ {
+ _BitScanForward(&idx, int32_t(b));
+ return Square(idx);
+ }
+ else
+ {
+ _BitScanForward(&idx, int32_t(b >> 32));
+ return Square(idx + 32);
+ }
+ #endif
+#else // Compiler is neither GCC nor MSVC compatible
+ #error "Compiler not supported."
+#endif