Stockfish 32-bit and hardware instructions on MSVC++
Posted: Tue Dec 30, 2014 11:58 am
Stockfish is doesn't seem to find hardware instructions on MSVC++ 32-bit. 32-bit MSVC++ doesn't have 64-bit functions like _BitScanForward64().
So, instead of:
they should've done:
Similar for popcnt.
The solution that worked for me was:
I hope the SF team considers this.
So, instead of:
Code: Select all
#ifdef USE_BSFQ
# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
FORCE_INLINE Square lsb(Bitboard b) {
unsigned long idx;
_BitScanForward64(&idx, b);
return (Square) idx;
}
FORCE_INLINE Square msb(Bitboard b) {
unsigned long idx;
_BitScanReverse64(&idx, b);
return (Square) idx;
}
...
Code: Select all
# if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#ifdef _WIN64
FORCE_INLINE Square lsb(Bitboard b) {
unsigned long idx;
_BitScanForward64(&idx, b);
return (Square) idx;
}
FORCE_INLINE Square msb(Bitboard b) {
unsigned long idx;
_BitScanReverse64(&idx, b);
return (Square) idx;
}
#else
FORCE_INLINE Square lsb(Bitboard b) {
unsigned long idx;
if (unsigned (b))
{
_BitScanForward(&idx, b);
return Square (idx);
} else
{
_BitScanForward(&idx, (b >> 32));
return Square(idx + 32);
}
/*unsigned long idx;
_BitScanForward64(&idx, b);
return (Square) idx;*/
}
FORCE_INLINE Square msb(Bitboard b) {
unsigned long idx, b32 = (b >> 32);
if (b32)
{
_BitScanReverse(&idx, b32);
return Square(idx + 32);
} else
{
_BitScanReverse(&idx, unsigned (b));
return Square(idx);
}
/*unsigned long idx;
_BitScanReverse64(&idx, b);
return (Square) idx;*/
}
#endif
Code: Select all
...
#elif defined(_MSC_VER) && defined(__INTEL_COMPILER) // Almost never true
return _mm_popcnt_u64(b);
#elif defined(_MSC_VER)
unsigned lo = b, hi = (b >> 32);
return _mm_popcnt_u32(lo) + _mm_popcnt_u32(hi);
//return (int) __popcnt64(b);
#else
...
Code: Select all
...
#elif defined(_MSC_VER)
#ifdef _WIN64
return _mm_popcnt_u64(b);
#else
unsigned lo = b, hi = (b >> 32);
return _mm_popcnt_u32(lo) + _mm_popcnt_u32(hi);
#endif
#else
...