mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Enable _BitScanForward64 at runtime
Only add infrastructure, still disabled. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
ce5d9eb19d
commit
f90f810ac4
3 changed files with 26 additions and 2 deletions
|
@ -340,7 +340,7 @@ Square pop_1st_bit(Bitboard *b) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
#else // defined(USE_FOLDED_BITSCAN)
|
||||||
|
|
||||||
static const int BitTable[64] = {
|
static const int BitTable[64] = {
|
||||||
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15,
|
0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40, 5, 17, 26, 38, 15,
|
||||||
|
|
|
@ -66,6 +66,7 @@ inline bool cpu_has_popcnt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) __popcnt64(x)
|
#define POPCNT_INTRINSIC(x) __popcnt64(x)
|
||||||
|
#define BITSCAN_INTRINSIC(idx, x) _BitScanForward64(idx, x)
|
||||||
|
|
||||||
#elif defined(__INTEL_COMPILER) && (defined(__x86_64) || defined(_M_X64)) // Intel compiler
|
#elif defined(__INTEL_COMPILER) && (defined(__x86_64) || defined(_M_X64)) // Intel compiler
|
||||||
|
|
||||||
|
@ -79,12 +80,14 @@ inline bool cpu_has_popcnt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) _mm_popcnt_u64(x)
|
#define POPCNT_INTRINSIC(x) _mm_popcnt_u64(x)
|
||||||
|
#define BITSCAN_INTRINSIC(idx, x) _BitScanForward64(idx, x)
|
||||||
|
|
||||||
#else // Safe fallback for unsupported compilers
|
#else // Safe fallback for unsupported compilers
|
||||||
|
|
||||||
inline bool cpu_has_popcnt() { return false; }
|
inline bool cpu_has_popcnt() { return false; }
|
||||||
|
|
||||||
#define POPCNT_INTRINSIC(x) sw_count_1s(x)
|
#define POPCNT_INTRINSIC(x) sw_count_1s(x)
|
||||||
|
#define BITSCAN_INTRINSIC(idx, x) sw_count_1s(x) // dummy
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -183,4 +186,25 @@ const bool CpuHas64BitPath = true;
|
||||||
const bool CpuHas64BitPath = false;
|
const bool CpuHas64BitPath = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/// pop_1st_bit() finds and clears the least significant nonzero bit in a
|
||||||
|
/// nonzero bitboard. If template parameter is true an intrinsic is called,
|
||||||
|
/// otherwise we fallback on a software implementation.
|
||||||
|
|
||||||
|
template<bool UseIntrinsic>
|
||||||
|
inline Square pop_1st_bit(Bitboard *b) {
|
||||||
|
|
||||||
|
return pop_1st_bit(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline Square pop_1st_bit<true>(Bitboard *b) {
|
||||||
|
|
||||||
|
unsigned long idx;
|
||||||
|
Bitboard bb = *b;
|
||||||
|
BITSCAN_INTRINSIC(&idx, bb);
|
||||||
|
*b &= (bb - 1);
|
||||||
|
return Square(idx);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !defined(BITCOUNT_H_INCLUDED)
|
#endif // !defined(BITCOUNT_H_INCLUDED)
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
// Simple macro to wrap a very common while loop, no facny, no flexibility,
|
// Simple macro to wrap a very common while loop, no facny, no flexibility,
|
||||||
// hardcoded list name 'mlist' and from square 'from'.
|
// hardcoded list name 'mlist' and from square 'from'.
|
||||||
#define SERIALIZE_MOVES(b) while (b) (*mlist++).move = make_move(from, pop_1st_bit(&b))
|
#define SERIALIZE_MOVES(b) while (b) (*mlist++).move = make_move(from, pop_1st_bit<false>(&b))
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Local definitions
|
//// Local definitions
|
||||||
|
|
Loading…
Add table
Reference in a new issue