X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbitboard.cpp;h=89065c49fe81eb11d0328e08b121cb0018c23f77;hp=e4fcb7ce438de974b17303135427868b441ad002;hb=ff211469bafcdc36c8964ae0a4b87ae277cef51a;hpb=1373a00187f9f6ee282a77a6039386c2746964b6 diff --git a/src/bitboard.cpp b/src/bitboard.cpp index e4fcb7ce..89065c49 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -21,6 +21,16 @@ //// Includes //// +#ifdef _MSC_VER + #include + #ifdef _WIN64 + #pragma intrinsic(_BitScanForward64) + #else + #pragma intrinsic(_BitScanForward) + #endif + #define USING_INTRINSICS +#endif + #include #include "bitboard.h" @@ -274,7 +284,7 @@ namespace { #if defined(USE_COMPACT_ROOK_ATTACKS) void init_file_and_rank_attacks(); #endif -}; +} //// @@ -341,18 +351,37 @@ Square first_1(Bitboard b) { #if defined(USE_32BIT_ATTACKS) +// Use type-punning +union b_union { + + Bitboard b; + struct { + uint32_t l; + uint32_t h; + }; +}; + +// WARNING: Needs -fno-strict-aliasing compiler option Square pop_1st_bit(Bitboard *bb) { - uint32_t a = uint32_t(*bb); - uint32_t* ptr = a ? (uint32_t*)bb : (uint32_t*)bb + 1; // Little endian only? - uint32_t b = a ? a : *ptr; - uint32_t c = ~(b ^ (b - 1)); + b_union u; + uint32_t b; - *ptr = b & c; // clear the bit - if (a) - c = ~c; + u.b = *bb; - return Square(BitTable[(c * 0x783a9b23) >> 26]); + if (u.l) + { + b = u.l; + *((uint32_t*)bb) = b & (b - 1); + b ^= (b - 1); + } + else + { + b = u.h; + *((uint32_t*)bb+1) = b & (b - 1); // Little endian only? + b = ~(b ^ (b - 1)); + } + return Square(BitTable[(b * 0x783a9b23) >> 26]); } #else